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

    Function unescape

    • Unescapes a string as string literal content.

      Reads every escape back as the character it stands for, taking the character assigned to it, or, failing that, the code point its \uXXXX / \UXXXXXXXX numeric form denotes; everything else is left as it is.

      Reading is lenient, so hand-written content is recovered rather than rejected: an escape neither the assigned forms nor the numeric ones account for stands for the character it introduces, so \x reads back as x, and a reverse solidus trailing at the end of the string, with nothing to escape, is left as it is. No input is malformed and none is refused.

      JSON unescaping — unescape(string)

      Reads the escapes a JSON string may carry: the seven two-character forms (\", \\, \b, \f, \n, \r, \t), the optional /, and the four-digit numeric form, plus the eight-digit form escape spells supplementary code points with. Hexadecimal digits are read in either case, while \u and \U are told apart, as they introduce forms of different width. A pair of escaped surrogates reads back as the single supplementary character it denotes, and an isolated one as itself, so text escape produced is recovered exactly, ill-formed halves included.

      Custom unescaping — unescape(string, pattern, escapes?)

      Reads a syntax of the caller's choosing: pattern selects the sequences to be read, for instance the entity references of a markup syntax, and escapes supplies the character each stands for, as a Resolver listing them or computing them on demand. A selected sequence escapes assigns no character to still falls back to the numeric forms and then to the plain form, so a syntax sharing the numeric convention need only list its short forms.

      Unaccounted sequences

      A selected sequence no character is assigned to and no numeric form accounts for is read as the sequence stripped of its leading reverse solidus, and, where it carries none, as the sequence itself; the incomplete numeric forms, whose digits are too few, are read this way too. A numeric form whose code point falls outside the Unicode range denotes no character and is read as U+FFFD REPLACEMENT CHARACTER, the stand-in toWellFormed likewise substitutes for text that denotes no character. A zero-width match, which selects no sequence at all, contributes nothing and leaves the text around it as it is.

      Parameters

      • string: string

        The string to unescape

      • pattern: RegExp = ...

        The pattern selecting the escape sequences to read; must be global; defaults to the JSON set

      • escapes: Resolver = JSONUnescapes

        The lookup supplying the character each selected sequence stands for, taken in preference to the numeric forms; defaults to the two-character JSON escapes

      Returns string

      A copy of string with every sequence pattern selects replaced by the character escapes assigns it, or by the code point its numeric form denotes, or, where neither accounts for it, by the sequence stripped of a leading reverse solidus, a numeric form outside the Unicode range contributing the replacement character

      TypeError If pattern doesn't carry the g flag