GithubHelp home page GithubHelp logo

mrzeta / node-transliteration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dzcpy/transliteration

1.0 2.0 0.0 351 KB

Transliteration module for node.js

License: MIT License

HTML 27.06% JavaScript 72.94%

node-transliteration's Introduction

Transliteration

Transliteration module for node.js. It converts special characters in unicode text into corresponding ascii letters, with support of nearly every common languages including CJK (Chinese, Japanese and Korean).

Install

npm install transliteration

Usage

transliteration(str, [unknown])

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');
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

Client side usage

Transliteration module can be run in the browser as well.

Donload the library with bower:

bower install transliteration

It supports AMD / CommonJS standard or just to be loaded as a global variable.

When use in the browser, by default it will create global variables under window object:

TR('你好, World'); // window.TR
// or
Transliteration('String'); // window.Transliteration

If you don't like the default variable names or they conflict with other libraries, you can call noConfilict() method before loading other libraries, then both window.TR and window.Transliteration will be deleted from windows object and Transliteration function will be returned:

var trans = Transliteration.noConflict();
trans('你好, World');
trans.slugify('你好, World');

For detailed usage, please check example.html.

node-transliteration's People

Contributors

dzcpy avatar koopero avatar

Stargazers

Alessandro Benoit avatar

Watchers

James Cloos avatar MrZeta 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.