Giter VIP home page Giter VIP logo

node-transliteration's Introduction

Transliteration

Build Status NPM Version Bower Dependencies Dev Dependencies NPM Download License

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).

Install in Node.js

npm install transliteration --save

Breaking changes since 1.0.0

Please note that the code has been entirely refactored since version 1.0.0.

Usage

transliterate(str, options)

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

slugify(str, options)

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

Usage in browser

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.

node-transliteration's People

Contributors

barwin avatar dzcpy avatar koopero avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.