Skip to content
VaelJS Blog

vael:chars

Unicode scalar character classification and single-code-point case conversion predicates.

Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes. All classification predicates are total and never throw.

import ... from "vael:chars"
Since v0.0.0-alpha.0 vjs (V8) vjs-lite (QuickJS)
Cargo feature: vael-chars (enabled by default in vaeljs-core and vaeljs-lite-core)
import { isDigit, isLetter, isSpace, toLower, toUpper } from "vael:chars";
console.log(isLetter("A".codePointAt(0))); // true
console.log(isDigit("7".codePointAt(0))); // true
console.log(isSpace(" ".codePointAt(0))); // true
console.log(String.fromCodePoint(toUpper(0x61), toLower(0x5a))); // "Az"
API Symbols
Functions (14)
isCharv0.0.0-alpha.0
Return true if value is a Unicode scalar value (integer in 0..=0x10FFFF excluding UTF-16 surrogates 0xD800..=0xDFFF).
isAsciiv0.0.0-alpha.0
Return true if value is an ASCII scalar value (0..=0x7F). Total predicate.
isLatin1v0.0.0-alpha.0
Return true if value is a Latin-1 scalar value (0..=0xFF). Total predicate.
isControlv0.0.0-alpha.0
Return true if value is a Unicode control character (category Cc). Total predicate.
isDigitv0.0.0-alpha.0
Return true if value is a decimal digit (Unicode category Nd). Total predicate.
isLetterv0.0.0-alpha.0
Return true if value is a Unicode letter (category L: Lu | Ll | Lt | Lm | Lo). Total predicate.
isLetterOrDigitv0.0.0-alpha.0
Return true if value is a Unicode letter (L) or decimal digit (Nd). Total predicate.
isLowerv0.0.0-alpha.0
Return true if value is a lowercase letter (Unicode category Ll). Total predicate.
isUpperv0.0.0-alpha.0
Return true if value is an uppercase letter (Unicode category Lu). Total predicate.
isPuncv0.0.0-alpha.0
Return true if value is Unicode punctuation (category P). Total predicate.
isSpacev0.0.0-alpha.0
Return true if value is whitespace (\t, \n, \v, \f, \r, space, U+0085, or Unicode categories Zs, Zl, Zp).
isSymbolv0.0.0-alpha.0
Return true if value is a Unicode symbol (category S, including emoji). Total predicate.
toLowerv0.0.0-alpha.0
Map a Unicode scalar value to its single-code-point lowercase equivalent.
toUpperv0.0.0-alpha.0
Map a Unicode scalar value to its single-code-point uppercase equivalent.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isChar(value: unknown): boolean;

Return true if value is a Unicode scalar value (integer in 0..=0x10FFFF excluding UTF-16 surrogates 0xD800..=0xDFFF).

Total predicate: non-numbers, NaN, infinities, fractions, and out-of-range values return false.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a valid Unicode scalar code point.
import { isChar } from "vael:chars";
console.log(isChar(0x1f680)); // true
console.log(isChar(0xd800)); // false (surrogate)
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isAscii(value: unknown): boolean;

Return true if value is an ASCII scalar value (0..=0x7F). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is an integer in 0..=0x7F.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isLatin1(value: unknown): boolean;

Return true if value is a Latin-1 scalar value (0..=0xFF). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is an integer in 0..=0xFF.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isControl(value: unknown): boolean;

Return true if value is a Unicode control character (category Cc). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode control scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isDigit(value: unknown): boolean;

Return true if value is a decimal digit (Unicode category Nd). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode decimal digit scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isLetter(value: unknown): boolean;

Return true if value is a Unicode letter (category L: Lu | Ll | Lt | Lm | Lo). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode letter scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isLetterOrDigit(value: unknown): boolean;

Return true if value is a Unicode letter (L) or decimal digit (Nd). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode letter or decimal digit scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isLower(value: unknown): boolean;

Return true if value is a lowercase letter (Unicode category Ll). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode lowercase letter scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isUpper(value: unknown): boolean;

Return true if value is an uppercase letter (Unicode category Lu). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode uppercase letter scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isPunc(value: unknown): boolean;

Return true if value is Unicode punctuation (category P). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode punctuation scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isSpace(value: unknown): boolean;

Return true if value is whitespace (\t, \n, \v, \f, \r, space, U+0085, or Unicode categories Zs, Zl, Zp).

Follows Go unicode.IsSpace semantics: U+FEFF and U+200B return false. Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode whitespace scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function isSymbol(value: unknown): boolean;

Return true if value is a Unicode symbol (category S, including emoji). Total predicate.

Parameters
NameTypeDescription
valueunknownCandidate value to test.
Returns
boolean — true when value is a Unicode symbol scalar.
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function toLower(value: number): number;

Map a Unicode scalar value to its single-code-point lowercase equivalent.

Multi-code-point expansions leave the scalar unchanged.

Parameters
NameTypeDescription
valuenumberUnicode scalar value (0..=0x10FFFF, excluding surrogates).
Returns
number — Lowercase Unicode scalar code point.
Exceptions
  • TypeError — when value is not a number.
  • RangeError — when value is not a Unicode scalar value.
import { toLower } from "vael:chars";
console.log(String.fromCodePoint(toLower(0x41))); // "a"
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function toUpper(value: number): number;

Map a Unicode scalar value to its single-code-point uppercase equivalent.

Multi-code-point expansions such as U+00DF (ß) leave the scalar unchanged.

Parameters
NameTypeDescription
valuenumberUnicode scalar value (0..=0x10FFFF, excluding surrogates).
Returns
number — Uppercase Unicode scalar code point.
Exceptions
  • TypeError — when value is not a number.
  • RangeError — when value is not a Unicode scalar value.
import { toUpper } from "vael:chars";
console.log(String.fromCodePoint(toUpper(0x61))); // "A"