A library for working with Unicode character sets
Want to see pretty graphs? Log in now!
npm install characterset
|12||downloads in the last week|
|23||downloads in the last month|
|Last Published By|
|Version||1.1.3 last updated 4 months ago|
|Keywords||unicode, utf16, characterset, character set, surrogate pair|
If you are using Node.js you can install it using npm:
$ npm install characterset
If you want to use CharacterSet in the browser, use the global
CharacterSet constructor or include CharacterSet as an AMD module.
The constructor takes a single input value, which can either be a number, a string or a range. A range is an array of numbers or number pairs.
// Creates a character set with a single code point for  var cs = new CharacterSet(97); // Creates a character set for the code points [97, 98, 99] var cs = new CharacterSet('abc'); // Creates a character set for the code points [97, 98, 99] var cs = new CharacterSet([97, 98, 99]); // Creates a character set for the code points [97, 98, 99] using a range var cs = new CharacterSet([[97, 99]]); // Combines pairs and numbers in ranges for [0, 97, 98, 99] var cs = new CharacterSet([48, [97, 99]]);
Once you have an instance of CharacterSet you can use the following methods on it:
- Returns the number of code points in this set.
- Returns all code points in this set as a sorted array.
- Returns all code points in this set as a range (i.e. compressed.)
- Returns true if this set is empty.
- add(codePoint, ...)
- Adds the given code point(s) to this set.
- remove(codePoint, ...)
- Removes the given code point(s) from this set.
- Returns true if the given code point is in this set.
- Returns true if the
otherset is equal to this set.
- Returns a new character set from the combined code points from
otherand this character set.
- Returns a new character set containing only the code points
otherand this character set have in common.
- Returns a new character set containing only the code points from this that are not in
- Returns true if this character set is a subset of
- Returns a RegExp matching the code points in this character set
- Returns a string representation of this character set.
CharacterSet is licensed under the three clause BSD license (see BSD.txt.)