Utilities for Unicode codepoint
npm install codepointIn this module, _Unicode code point_ is used for character values in the
range between 0x0000 and 0x10FFFF.
On the other hand, _Unicode code unit_ is used for 16-bit integer values
that are code units of the UTF-16 encoding.
$ npm install codepoint
``javascript`
var codepoint = require('codepoint');
The maximum value of a Unicode code point, constant 0x10FFFF.
The maximum value of a Unicode high-surrogate code unit in the UTF-16 encoding,
constant 0xDBFF.
The maximum value of a Unicode low-surrogate code unit in the UTF-16 encoding,
constant 0xDFFF.
The maximum value of a Unicode surrogate code unit in the UTF-16 encoding,
constant 0xDFFF.
The maximum value of a Unicode code unit in the UTF-16 encoding,
constant 0xFFFF.
The minimum value of a Unicode code point, constant 0x0000.
The minimum value of a Unicode code unit in the UTF-16 encoding,
constant 0x0000.
The minimum value of a Unicode high-surrogate code unit in the UTF-16 encoding,
constant 0xD800.
The minimum value of a Unicode low-surrogate code unit in the UTF-16 encoding,
constant 0xDC00.
The minimum value of a Unicode supplementary code point, constant 0x10000.
The minimum value of a Unicode surrogate code unit in the UTF-16 encoding,
constant 0xD800.
Determines the number of Unicode code units needed to represent the specified
Unicode code point. If the specified code point is equal to or greater
than codepoint.MIN_SUPPLEMENTARY_CODE_POINT, then the function returns 2.1
Otherwise, the function returns .
* Arguments
* cp: the Unicode code point to be tested.2
* Returns
* if the Unicode code point is a valid supplementary code point;1
otherwise.
Returns the code point at the given index of the str.index
If the code unit value at the given in the str is in theindex
high-surrogate range, the following is less than the lengthstr
of the , and the code unit value at the following index is inindex
the low-surrogate range, then the supplementary code point corresponding
to this surrogate pair is returned.
Otherwise, the code unit value at the given is returned.
* Arguments
* str: the string.index
* : the index to the Unicode code units in str to be converted.0
Defaults to .
* Returns
* the Unicode code point value at the given index.
Returns the code point preceding the given index of the str.index - 1
If the code unit value at () in the str is in theindex - 2
low-surrogate range, () is not negative, and the code unitindex - 2
value at () in the str is in the high-surrogate range,index - 1
then the supplementary code point corresponding to this surrogate pair
is returned.
Otherwise, the code unit value at () is returned.
* Arguments
* str: the string.index
* : the index following the code point that should be returned.str.length
Defaults to .
* Returns
* the Unicode code point value before the given index.
Returns the number of Unicode code points in the text range of the specified
str. The text range begins at the specified beginIndex and extends toendIndex - 1
the Unicode code unit at index .endIndex-beginIndex
Thus the length (in code units) of the text range is .
Unpaired surrogates within the text range count as one code point each.
* Arguments
* str: the string.beginIndex
* : the index to the first code unit of the text range.0
Defaults to .endIndex
* : the index after the last code unit of the text range.str.length
Defaults to .
* Returns
* the number of Unicode code points in the specified text range.
Executes a provided function (cb) once for each code point present instr
the .
* Arguments
* str: the string.cb
* : callback function.thisArg
* : this value for each invocationof cb.undefined
if it is not provided, is used instead.
cb is invoked with three arguments:
* Arguments
* cp: the code point value.index
* : the index to the code point of the str.cp === codepoint.codePointAt(str, index)
(i.e. )str
* : the string being traversed.
Returns a string value containing as many code points as the number of
arguments. Each argument specifies one code point of the resulting string,
with the first argument specifing the first code point, and so on,
from left to right.
* Argument
* cp: Unicode code point.
* Returns
* the string.
Returns the leading surrogate (a high surrogate code unit) of the surrogate
pair representing the specified supplementary code point in the UTF-16
encoding.
If the specified Unicode code point is not a supplementary code point,
an unspecified code unit is returned.
* Arguments
* cp: a supplementary code point.
* Returns
* the leading surrogate code unit used to represent the character
in the UTF-16 encoding
Determines whether the specified Unicode code point is in the Basic
Multilingual Plane (BMP). Such code points can be represented using a
single code unit.
* Arguments
* cp: the Unicode code point to be tested.true
* Returns
* if the specified code point is between codepoint.MIN_CODE_POINTcodepoint.MAX_CODE_UNIT
and inclusive; false otherwise.
Determines if the given Unicode code unit is a Unicode high-surrogate
code unit (also known as leading-surrogate code unit).
* Arguments
* cu: the Unicode code unit to be tested.true
* Returns
* if the code unit is between codepoint.MIN_HIGH_SURROGATE andcodepoint.MAX_HIGH_SURROGATE
inclusive; false otherwise.
Determines if the given Unicode code unit is a Unicode low-surrogate
code unit (also known as trailing-surrogate code unit).
* Arguments
* cu: the Unicode code unit to be tested.true
* Returns
* if the code unit is between codepoint.MIN_LOW_SURROGATE andcodepoint.MAX_LOW_SURROGATE
inclusive; false otherwise.
Determines whether the specified Unicode code point is in the supplementary
character range.
* Arguments
* cp: the Unicode code point to be tested.true
* Returns
* if the specified code point is betweenMIN_SUPPLEMENTARY_CODE_POINT
and MAX_CODE_POINT inclusive;false
otherwise.
Determines if the given Unicode code unit is a Unicode surrogate code unit.
* Arguments
* cu: the Unicode code unit to be tested.true
* Returns
* if the code unit is between codepoint.MIN_SURROGATE andcodepoint.MAX_SURROGATE
inclusive; false otherwise.
Determines whether the specified pair of code units is a valid Unicode
surrogate pair.
* Arguments
* highCu: the high-surrogate code unit to be tested.lowCu
* : the low-surrogate code unit to be tested.true
* Returns
* if the specified high and low-surrogate code values representfalse
a valid surrogate pair; otherwise.
Returns the trailing surrogate (a low surrogate code unit) of the
surrogate pair representing the specified supplementary code point in the UTF-16 encoding.
If the specified code point is not a supplementary character, an unspecified
code unit is returned.
* Arguments
* cp: a supplementary code point.
* Returns
* the trailing surrogate code unit used to represent the character
in the UTF-16 encoding
Returns the index within the given str that is offset from the given indexcodePointOffset
by code points. Unpaired surrogates within the text rangeindex
given by and codePointOffset count as one code point each.
* Arguments
* str: the string.index
* : the index to be offset.codePointOffset
* : the offset in code points.str
* Returns
* the index within the .-1
if index is negative or larger then the length of the str,codePointOffset
or if is positive and the subsequence startingindex
with has fewer than codePointOffset code points, or ifcodePointOffset
is negative and the subsequence before index hascodePointOffset
fewer than the absolute value of code points.
Converts the specified Unicode code point to its UTF-16 representation
stored in an array of code units. If the specified code point is a BMP
(Basic Multilingual Plane or Plane 0) value, the resulting array has
the same value as codePoint. If the specified code point is a supplementary
code point, the resulting array has the corresponding surrogate pair.
* Arguments
* cp: a Unicode code point
* Returns
* an array of code units having codePoint's UTF-16 representation.
Converts the specified surrogate pair to its supplementary code point value.
This method does not validate the specified surrogate pair. The caller must
validate it using codepoint.isSurrogatePair() if necessary.
* Arguments
* highSurrogate: the high-surrogate code unit.lowSurrogate`: the low-surrogate code unit.
*
* Returns
* the supplementary code point composed from the specified surrogate pair.
node-codeunit is licensed under the
MIT license.