cyrillic-to-translit-js
Advanced tools
Comparing version 1.0.2 to 1.0.3
'use strict'; | ||
module.exports = function cyrillicToTranslit() { | ||
var _associations = { | ||
"а": "a", | ||
"б": "b", | ||
"в": "v", | ||
"ґ": "g", | ||
"г": "g", | ||
"д": "d", | ||
"е": "e", | ||
"ё": "e", | ||
"є": "ye", | ||
"ж": "zh", | ||
"з": "z", | ||
"и": "i", | ||
"і": "i", | ||
"ї": "yi", | ||
"й": "i", | ||
"к": "k", | ||
"л": "l", | ||
"м": "m", | ||
"н": "n", | ||
"о": "o", | ||
"п": "p", | ||
"р": "r", | ||
"с": "s", | ||
"т": "t", | ||
"у": "u", | ||
"ф": "f", | ||
"x": "h", | ||
"ц": "c", | ||
"ч": "ch", | ||
"ш": "sh", | ||
"щ": "sh'", | ||
"ъ": "", | ||
"ы": "", | ||
"ь": "", | ||
"э": "", | ||
"ю": "yu", | ||
"я": "ya" | ||
}; | ||
return { | ||
transform: transform | ||
const _associations = { | ||
"а": "a", | ||
"б": "b", | ||
"в": "v", | ||
"ґ": "g", | ||
"г": "g", | ||
"д": "d", | ||
"е": "e", | ||
"ё": "e", | ||
"є": "ye", | ||
"ж": "zh", | ||
"з": "z", | ||
"и": "i", | ||
"і": "i", | ||
"ї": "yi", | ||
"й": "i", | ||
"к": "k", | ||
"л": "l", | ||
"м": "m", | ||
"н": "n", | ||
"о": "o", | ||
"п": "p", | ||
"р": "r", | ||
"с": "s", | ||
"т": "t", | ||
"у": "u", | ||
"ф": "f", | ||
"x": "h", | ||
"ц": "c", | ||
"ч": "ch", | ||
"ш": "sh", | ||
"щ": "sh'", | ||
"ъ": "", | ||
"ы": "i", | ||
"ь": "", | ||
"э": "e", | ||
"ю": "yu", | ||
"я": "ya" | ||
}; | ||
return { | ||
transform: transform | ||
} | ||
function transform(str, spaceReplacement) { | ||
if (!str) { | ||
return ""; | ||
} | ||
function transform(str, spaceReplacement) { | ||
if (!str) { | ||
return ""; | ||
} | ||
var new_str = ""; | ||
for (var i = 0; i < str.length; i++) { | ||
var strLowerCase = str[i].toLowerCase(); | ||
if (strLowerCase === " " && spaceReplacement) { | ||
new_str += spaceReplacement; | ||
continue; | ||
} | ||
if (!_associations[strLowerCase]) { | ||
new_str += strLowerCase; | ||
} | ||
else { | ||
new_str += _associations[strLowerCase]; | ||
} | ||
} | ||
return new_str; | ||
let new_str = ""; | ||
for (let i = 0; i < str.length; i++) { | ||
let strLowerCase = str[i].toLowerCase(); | ||
if (strLowerCase === " " && spaceReplacement) { | ||
new_str += spaceReplacement; | ||
continue; | ||
} | ||
let new_letter = _associations[strLowerCase] | ||
if ("undefined" === typeof new_letter) { | ||
new_str += strLowerCase; | ||
} | ||
else { | ||
new_str += new_letter; | ||
} | ||
} | ||
return new_str; | ||
} | ||
}; |
{ | ||
"name": "cyrillic-to-translit-js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Simple javascript function for converting Cyrillic symbols to Translit", | ||
"main": "CyrillicToTranslit.js", | ||
"devDependencies": { | ||
"coveralls": "^2.11.6", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.4.5", | ||
"mocha-lcov-reporter": "^1.0.0", | ||
"should": "^8.2.1" | ||
"coveralls": "^2.13.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.4.2", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"should": "^11.2.1" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
# cyrillic-to-translit-js | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/greybax/cyrillic-to-translit-js.svg)](https://greenkeeper.io/) | ||
[![NPM version][npm-image]][npm-url] | ||
@@ -42,2 +44,11 @@ [![Build Status][travis-image]][travis-url] | ||
>privet_mir! | ||
``` | ||
``` | ||
## Credits | ||
* [kunashir](https://github.com/kunashir) | ||
* [vasergen](https://github.com/vasergen) | ||
## License | ||
MIT © Aleksandr Filatov [alfilatov.com](http://alfilatov.com) |
@@ -22,2 +22,11 @@ 'use strict'; | ||
}); | ||
it('should return translit when first parameter cyrillic with using ыьъ', function () { | ||
assert.equal("uchebnii_material_1!", cyrillicToTranslit().transform("учебный материал 1ьъ!", '_')); | ||
}); | ||
it('should return translit when first parameter cyrillic whith using ъ', function () { | ||
assert.equal("novi_podezd", cyrillicToTranslit().transform("новый подъезд", '_')); | ||
}); | ||
it('should return translit when first parameter cyrillic whith using ь', function () { | ||
assert.equal("ploхaya_svyaz", cyrillicToTranslit().transform("плохая связь", '_')); | ||
}); | ||
it('should return translit with replaced " " on "_"', function () { | ||
@@ -24,0 +33,0 @@ assert.equal("privet_mir!", cyrillicToTranslit().transform("привет мир!", "_")); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6254
100
53