JS Utils Kit - v0.5.1
    Preparing search index...

    Variable trimConst

    trim: Trim = ...

    String trimming utilities. Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.

    The string to trim.

    The string with leading and trailing whitespace removed.

    • The main callable form behaves like String.prototype.trim, removing whitespace from both ends.
    • .start removes only leading whitespace (like String.prototype.trimStart).
    • .end removes only trailing whitespace (like String.prototype.trimEnd).
    • .normalizeWhitespace trims the string and replaces any sequence of whitespace characters with a single space.
    // Trim both sides
    console.log(trim(" hello ")); // "hello"
    console.log(trim("")); // ""
    console.log(trim("hello")); // "hello"

    // Trim leading whitespace
    console.log(trim.start(" hello ")); // "hello "
    console.log(trim.start("")); // ""
    console.log(trim.start("hello")); // "hello"

    // Trim trailing whitespace
    console.log(trim.end(" hello ")); // " hello"
    console.log(trim.end("")); // ""
    console.log(trim.end("hello")); // "hello"

    // Normalize whitespace
    console.log(trim.normalizeWhitespace(" hello world ")); // "hello world"
    console.log(trim.normalizeWhitespace("hello\t world")); // "hello world"
    console.log(trim.normalizeWhitespace("")); // ""