View on GitHub

Numeric-character-reference-js

Download this project as a .zip file Download this project as a tar.gz file

Numeric Character Reference js Apache 2.0 License

This is a javascript (typescript) project used for conversion between “Numeric Character Reference” (HTML Entity) and the char.

Compile

This project is written by typescript.

Please install typescript first:

npm install -g typescript

Then compile it

cd /path/of/the/source/code
tsc

The output javascript code will in the folder /path/of/the/source/code/out

Example

Parsing English

NCR.encode("Hello World")   // will return ("Hello World")

NCR.decode("Hello World")   // will return ("Hello World")

Parsing Chinese

NCR.encode("你好,世界")   // will return "你好,世界"

NCR.decode("你好,世界")  // will return "你好,世界"

String width Emoji

NCR.encode("This is a penguin: \uD83D\uDC27")       // will return "This is a penguin: 🐧"
NCR.encode("This is a penguin: \uD83D\uDC27", true) // will return "This is a penguin: 🐧"

NCR.decode("This is a penguin: 🐧")          // Using HTML Entity (Hexadecimal). It will return "This is a penguin: \uD83D\uDC27"

NCR.decode("This is a penguin: 🐧")          // Using HTML Entity (Decimal). It will return "This is a penguin: \uD83D\uDC27", too.