Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmythro committed Sep 1, 2014
1 parent cb2ea8f commit 9098b14
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "to-uri",
"version": "1.0.2",
"version": "1.0.3",
"description": "Transliteration for JavaScript & Node.js, basically used for URI generation. As small and simple as possible.",
"keywords": [
"annexare",
Expand Down
48 changes: 48 additions & 0 deletions lib/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>toURI() Test Page</title>
<style>
body, input {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
}
.block {
display: block;
margin: .5em auto;
padding: 4px 10px;
text-align: left;
width: 600px;
}
</style>
</head>
<body>

<h1 class="block">toURI() Test Page</h1>
<center>
<input type="text" id="text" onkeyup="checkURI(); return false;" size="100" class="block">
<p id="result" class="block"></p>
</center>

<script src="toURI.js"></script>
<script>
var text = document.getElementById('text'),
result = document.getElementById('result');

window.checkURI = function (e) {
if (e) {
e.stopPropagation();
}

console.log(' > ', text.value);
result.innerHTML = toURI(text.value || '');

return false;
};

text.focus();
</script>

</body>
</html>
20 changes: 12 additions & 8 deletions lib/toURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
'п': 'p', 'р': 'r', 'с': 's', 'т': 't',
'у': 'u', 'ф': 'f', 'х': 'h', 'ц': 'ts',
'ч': 'ch', 'ш': 'sh', 'щ': 'shch','ъ': '',
'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu',
'я': 'ya', 'є': 'ye', 'і': 'i', 'ї': 'yi',
'ґ': 'g',
'ы': 'y', 'ь': '', 'э': 'e',
// Part is done as: http://zakon4.rada.gov.ua/laws/show/55-2010-%D0%BF
// But don't agree with "Гг | Hh", nobody talks like that.
'^ю': 'yu', '\\s+ю': ' yu', 'ю': 'iu',
'^я': 'ya', '\\s+я': ' ya', 'я': 'ia',
'^є': 'ye', '\\s+є': ' ye', 'є': 'ie',
'і': 'i',
'^ї': 'yi', '\\s+ї': ' yi', 'ї': 'i',
'ґ': 'gh',
// Symbols & Accents
'\\.': '_',
'&': 'and',
Expand Down Expand Up @@ -59,8 +65,8 @@
'₴': 'UAH',
'¢': 'cent'
},
isRU = /ы|ъ|э|ё|ъ|[\s|^]и|жь|чь|шь|иа|ие|ии|ио|иу|аи|еи|ои|уи|цк|ц[\s|$]/,
isUA = /є|i|ї|ґ|зьк|ськ|цьк|ць[\s|$]/,
isRU = /ы|ъ|э|ё|ъ|(\s|^)и|жь|чь|шь|иа|ие|ии|ио|иу|аи|еи|ои|уи|цк|ец(\s|$)/,
isUA = /є|i|ї|ґ|зьк|ськ|цьк|ць(\s|$)|(нн|тт|чч)[юя]/,
strtr = function (string, pairs) {
// Just like this:
// http://php.net/manual/en/function.strtr.php
Expand Down Expand Up @@ -91,9 +97,7 @@
}

text = text.toLowerCase();
if ((text.search(isRU) !== -1) && (text.search(isUA) === -1)) {
pairs['и'] = 'i';
}
pairs['и'] = ((text.search(isRU) !== -1) && (text.search(isUA) === -1)) ? 'i' : 'y';

text = strtr(text, pairs);

Expand Down
4 changes: 2 additions & 2 deletions lib/toURI.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "to-uri",
"version": "1.0.2",
"version": "1.0.3",
"description": "Transliteration for JavaScript & Node.js, basically used for URI generation. As small and simple as possible.",
"keywords": [
"annexare",
Expand Down

0 comments on commit 9098b14

Please sign in to comment.