@metreeca/core - v0.9.22
    Preparing search index...

    Function isWellFormed

    • 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