unicode-substring
Unicode-aware substring
Last updated 9 years ago by lautis .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install unicode-substring 
SYNC missed versions from official npm registry.

unicode-substring Build Status

Unicode-aware substring for JavaScript. Surrogate pairs are counted as a single character.

What?

Characters in JavaScript strings are exposed as 16-bit code points, also known as UCS-2 encoding. This usually good enough, but since there are more than 2^16 characters in Unicode, 16 bits is not enough to represent all characters. To overcome this limitation, characters with scalar value over 0x10FFFF need to be encoded as surrogate pairs. This encoding is known as UTF-16.

The purpose of this library is to treat surrogate pairs as one character when extracting substrings from a string. This might be preferable if indices are returned from an Unicode-compatible environment.

Usage


var unicodeSubstring = require('unicode-substring')
// unicodeSubstring(string, start, end)
unicodeSubstring("💥Emoji Rule💥", 0, 6)
// => "💥Emoji"

The start and end parameters behave similarly as String.prototype.substring.

Current Tags

  • 1.0.0                                ...           latest (9 years ago)

2 Versions

  • 1.0.0                                ...           9 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 4
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE