Skip to content

shiyou0130011/Numeric-Character-Reference-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.