Tags a template literal as Text content.
Tags a template literal as Markdown content.
Clips a string to a code point budget.
Tidies the whitespace of a string.
Splits a string into tidied, non-empty values.
Fills the placeholders of a template string.
Removes the common indentation from a block of text or a template literal.
Escapes a string as string literal content.
Compiles a glob pattern into a matcher.
Checks whether a string is well-formed UTF-16 text.
Converts a string to well-formed UTF-16 text.
General-purpose string operations.
Declaring Text and Markdown Content
Record whether a string carries markup, either as a type annotation on an API or as a template tag that also realigns the literal:
Clipping Text
Shorten a string to a budget of code points, leaving an ellipsis to report that content was dropped, so that a value quoted in a log entry or a diagnostic message can't overrun it:
Tidying Whitespace
Collapse the whitespace of a string to single spaces and drop what sits at either end, either folding the whole string to the single line a label or a message expects, or tidying each line on its own where the line structure matters:
Splitting Separated Values
Break a string into the values it lists, tidying the whitespace of each and dropping the empty ones stray separators leave behind, taking the values to be separated by whitespace or by a separator of your own:
Filling Template Placeholders
Complete a template from values computed elsewhere, replacing each
{key}placeholder with the value a record or a lookup function assigns to its key, percent-encoding what must travel safely inside a URL and leaving#-marked placeholders unfilled for a later pass:Dedenting Indented Text
Remove the leading whitespace shared by every non-blank line of a block of text, either as a plain function or as a template tag:
Escaping Text for String Literals
Rewrite as escapes the characters a JSON string literal may not carry, ready to sit between quotation marks, or target a syntax of your own by supplying the pattern that selects the characters and the short forms it defines:
Matching Names Against Glob Patterns
Decide whether a slash-separated name matches a wildcard pattern, taking
?for a single character,*for a run within one segment and**for a run across segments, with everything else read literally:Checking and Repairing UTF-16 Text
Report whether a string is well-formed UTF-16 text, free of the isolated surrogates that denote no Unicode character, or replace those surrogates with the Unicode replacement character: