Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→string-character-is-astral-surrogatenext

string-character-is-astral-surrogate3.2.0

Tells, is given character a part of astral character, specifically, a high and low surrogate

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • IDEA
  • API
  • Changelog

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 (sourceopens in a new tab). 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, false is 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.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab