GithubHelp home page GithubHelp logo

jsunidecode's Introduction

JSunidecode

This project is a (rather simple) JavaScript port of the Python Unicode transliteration library unidecode, done for the generation of slugs from Chinese article titles.

Upon importing, it basically injects a unidecode function, which is a near-verbatim translation of the original Python worker function, into String.prototype so that it can be used anywhere.

The datasheet mapping the vast number of Unicode codepoints to ASCII is rather space-consuming, so you may want to turn on gzipping for your JS files. It is created by importing all the individual Python data modules, converting them into a Python dict, then dumping the dict into JSON format.

Usage

The code can be incorporated into your JS environment in several ways. Of course you can import the function and datasheet separately:

<!-- XXX This method is NOT recommended --> <!-- datasheet must be imported first, for obvious reasons --> <script src="datasheet.js"></script> <script src="unidecode.js"></script>

... but this approach has the apparent disadvantage of leaking a datasheet variable into the global namespace, subject to potential overwrite. So you can first "embed" the datasheet into the closure using the supplied Python script, then import unidecode.omni.js inside the build directory (the output path is hardcoded at the moment).

For maximum bandwidth saving, you may also want to minify the resulting file using, for example, the YUI compressor. The datasheet's size is not quite sensitive to minification though; you definitely want to turn on gzipping for at least this file, as well.

Bugs and Limitations

The code is a near-exact translation of the Python (translation), so it should be reasonably functionally equivalent to the Python library. Thus, it can NOT handle transliteration of Japanese Kanji nor Korean Hanja correctly -- they are all treated as Chinese characters and thus transliterated with Standard Mandarin pronunciation. For that purpose you may look at AJAX approaches, or try out Google's Transliteration API for now.

jsunidecode's People

Contributors

xen0n avatar

Stargazers

 avatar  avatar ender avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

qiyuan4f

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.