Installation
Quick Take
Examples
- Treat a missing code unit as not being a surrogate
- Inspect the first UTF-16 code unit of an astral character
Idea
This program identifies high and low surrogates, specifically.
In theory, high surrogate goes first, low surrogate goes second (source). This program enables us to detect surrogate-related errors, for example, malformed emoji or parts of emoji.
API
Two functions, same API:
Input: zero or more characters, where charCodeAt(0) will be evaluated.
Output: A boolean
- If input is empty string or undefined,
falseis returned. - If input is anything other than the string or undefined, type error is thrown.
- If input consists of more characters, everything beyond
.charCodeAt(0)is ignored.
The program returns false to make life easier when traversing the string. When you check the “next” character, if it doesn’t exist, as far as astral-ness is concerned that’s fine, so it yields false. Otherwise, you’d have to check the input before feeding into this library and that’s is tedious. This is a low-level library and it doesn’t have to be picky.