vael:strings
Unicode 16.0 case-folding string comparisons and code-point trimming.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Implements locale-independent Go strings.EqualFold semantics over UTF-16
strings and code-point-based trimming.
import ... from "vael:strings"
vael-strings (enabled by default in vaeljs-core and vaeljs-lite-core)Example
Section titled “Example”import { equalFold, indexOfFold, trim } from "vael:strings";
console.log(equalFold("GoLang", "golang")); // trueconsole.log(indexOfFold("Hello World", "WORLD")); // 6console.log(trim("///path/to/file///", "/")); // "path/to/file"equalFoldv0.0.0-alpha.0text and other under locale-independent Unicode 16.0 simple case folding (Go strings.EqualFold semantics over UTF-16 code u...startsWithFoldv0.0.0-alpha.0true if text starts with prefix under Unicode 16.0 simple case folding.endsWithFoldv0.0.0-alpha.0true if text ends with suffix under Unicode 16.0 simple case folding.indexOfFoldv0.0.0-alpha.0search in text at or after fromIndex under Unicode 16.0 simple case fo...lastIndexOfFoldv0.0.0-alpha.0search in text starting at or before fromIndex under Unicode 16.0 simpl...trimv0.0.0-alpha.0chars (or standard ECMAScript String.prototype.trim whitespace when chars is o...trimStartv0.0.0-alpha.0chars (or ECMAScript whitespace when chars is omitted).trimEndv0.0.0-alpha.0chars (or ECMAScript whitespace when chars is omitted).Functions
Section titled “Functions”equalFold
Section titled “equalFold”export function equalFold(text: string, other: string): boolean;
Compare text and other under locale-independent Unicode 16.0 simple
case folding (Go strings.EqualFold semantics over UTF-16 code units).
Lone surrogates fold to themselves and never match half of a surrogate pair.
| Name | Type | Description |
|---|---|---|
text | string | First string to compare. |
other | string | Second string to compare. |
boolean — true if text and other are equal under Unicode simple case folding.TypeError— whentextorotheris not a string.
import { equalFold } from "vael:strings";
console.log(equalFold("Kelvin", "Kelvin")); // truestartsWithFold
Section titled “startsWithFold”export function startsWithFold(text: string, prefix: string): boolean;
Return true if text starts with prefix under Unicode 16.0 simple case
folding.
| Name | Type | Description |
|---|---|---|
text | string | Input string. |
prefix | string | Prefix string to match. |
boolean — true if text starts with prefix under case folding.TypeError— whentextorprefixis not a string.
endsWithFold
Section titled “endsWithFold”export function endsWithFold(text: string, suffix: string): boolean;
Return true if text ends with suffix under Unicode 16.0 simple case
folding.
| Name | Type | Description |
|---|---|---|
text | string | Input string. |
suffix | string | Suffix string to match. |
boolean — true if text ends with suffix under case folding.TypeError— whentextorsuffixis not a string.
indexOfFold
Section titled “indexOfFold”export function indexOfFold(text: string, search: string, fromIndex?: number): number;
Return the UTF-16 code-unit index of the first occurrence of search in
text at or after fromIndex under Unicode 16.0 simple case folding, or
-1 if not found.
| Name | Type | Description |
|---|---|---|
text | string | Input string to search. |
search | string | Substring to locate. |
fromIndex optional | number | Optional UTF-16 code-unit offset (clamped at 0 and text.length; Infinity / -Infinity clamp, NaN and fractions throw RangeError). |
number — UTF-16 code-unit index of the first match, or -1.TypeError— whentextorsearchis not a string, orfromIndexis defined and not a number.RangeError— whenfromIndexisNaNor a non-integer finite number.
import { indexOfFold } from "vael:strings";
console.log(indexOfFold("alpha BETA beta", "beta", 7)); // 11lastIndexOfFold
Section titled “lastIndexOfFold”export function lastIndexOfFold(text: string, search: string, fromIndex?: number): number;
Return the UTF-16 code-unit index of the last occurrence of search in
text starting at or before fromIndex under Unicode 16.0 simple case
folding, or -1 if not found.
| Name | Type | Description |
|---|---|---|
text | string | Input string to search. |
search | string | Substring to locate. |
fromIndex optional | number | Optional UTF-16 code-unit offset (defaults to text.length). |
number — UTF-16 code-unit index of the last match, or -1.TypeError— whentextorsearchis not a string, orfromIndexis defined and not a number.RangeError— whenfromIndexisNaNor a non-integer finite number.
export function trim(text: string, chars?: string): string;
Remove leading and trailing code points contained in chars (or standard
ECMAScript String.prototype.trim whitespace when chars is omitted).
Preserves lone surrogates in the retained interior.
| Name | Type | Description |
|---|---|---|
text | string | Input string to trim. |
chars optional | string | Optional cutset string of code points to strip from both ends. |
string — Trimmed string.TypeError— whentextis not a string, orcharsis defined and not a string.
import { trim } from "vael:strings";
console.log(trim("--hello--", "-")); // "hello"trimStart
Section titled “trimStart”export function trimStart(text: string, chars?: string): string;
Remove leading code points contained in chars (or ECMAScript whitespace
when chars is omitted).
| Name | Type | Description |
|---|---|---|
text | string | Input string to trim. |
chars optional | string | Optional cutset string of code points to strip from the start. |
string — String with matching leading code points removed.TypeError— whentextis not a string, orcharsis defined and not a string.
trimEnd
Section titled “trimEnd”export function trimEnd(text: string, chars?: string): string;
Remove trailing code points contained in chars (or ECMAScript whitespace
when chars is omitted).
| Name | Type | Description |
|---|---|---|
text | string | Input string to trim. |
chars optional | string | Optional cutset string of code points to strip from the end. |
string — String with matching trailing code points removed.TypeError— whentextis not a string, orcharsis defined and not a string.
