Transliteration module for node.js and browser. Transliterate unicode special characters into corresponding pure ascii so it can be safely used as URL slug or as file name etc., with support of nearly every common languages including CJK (Chinese, Japanese and Korean).
npm install transliteration --save
Please note that the code has been entirely refactored since version 1.0.0.
Transliterate the string str
. Characters which this module doesn't recognise will be converted to the character in the unknown
parameter, defaults to [?]
.
Example
var tr = require('transliteration').transliterate;
tr('你好,世界'); // Ni Hao , Shi Jie
tr('Γεια σας, τον κόσμο'); // Geia sas, ton kosmo
tr('안녕하세요, 세계'); // annyeonghaseyo, segye
Converts unicode string to slugs. So it can be safely used in URL or file name.
Options:
{
lowercase: true,
separator: '-'
}
If no options
parameter provided it will use the above default values.
Example:
var slugify = require('transliteration').slugify;
slugify('你好,世界'); // ni-hao-shi-jie
slugify('你好,世界', { lowercase: false, separator: '_' }); // Ni_Hao_Shi_Jie
Transliteration module can be run in the browser as well.
Download the library with bower:
bower install transliteration
It supports AMD / CommonJS standard or just to be loaded as a global variable (UMD).
When use in browser, by default it will create global variables under window
object:
transl('你好, World'); // window.transl
// or
slugify('Hello, 世界'); // window.slugify
If the name of the variables conflict with other libraries in your project or you prefer not to use global variables, you can then call noConfilict() before loading other libraries which contails the possible conflict.:
var tr = transl.noConflict();
console.log(transl); // undefined
tr('你好, World'); // Ni Hao , World
var slug = slugify.noConfilict();
slug('你好, World'); // ni-hao-world
console.log(slugify); // undefined
For detailed usage, please check the demo at example.html.