Checks whether a string is well-formed UTF-16 text.
Strings are sequences of UTF-16 code units, and nothing prevents one from carrying a surrogate that is not part of a
pair; a string holding such an isolated surrogate denotes no Unicode text and has no UTF-8 representation, so
operations that must produce bytes, TextEncoder.encode and encodeURI among them, either replace it with the
replacement character or throw.
Note
Stands in for String.prototype.isWellFormed, standardised in ECMAScript 2024 and declared by TypeScript at the
ES2024 lib level: this package compiles at ES2022, where the native method runs on every supported engine
but remains invisible to the type checker. Will give way to the native method once the compilation target moves
to ES2024.
Parameters
string: string
The string to test
Returns boolean
true if string carries no isolated surrogate, that is if every high surrogate is followed by a low
surrogate and every low surrogate preceded by a high one; false otherwise
See
toWellFormed for the matching repair, replacing every isolated surrogate with U+FFFD
Checks whether a string is well-formed UTF-16 text.
Strings are sequences of UTF-16 code units, and nothing prevents one from carrying a surrogate that is not part of a pair; a string holding such an isolated surrogate denotes no Unicode text and has no UTF-8 representation, so operations that must produce bytes,
TextEncoder.encodeandencodeURIamong them, either replace it with the replacement character or throw.Stands in for
String.prototype.isWellFormed, standardised in ECMAScript 2024 and declared by TypeScript at theES2024lib level: this package compiles atES2022, where the native method runs on every supported engine but remains invisible to the type checker. Will give way to the native method once the compilation target moves toES2024.