Class String

Additional static members for the native String class.

Does not extend the native String class.

Constructors

Methods

Constructors

Methods

  • Dedent a template literal with an auto-determined number of tabs. Remove up to n number of tabs from the beginning of each literal line in the template literal. Does not affect interpolated expressions. n is determined by the number of tabs following the first line break in the literal. If there are no line breaks, 0 is assumed.

    Parameters

    • strings: TemplateStringsArray
    • Rest ...interps: unknown[]

    Returns string

    a string with each line dedented by the determined number of tabs

    Example

    assert.strictEqual(dedent`
    this will be
    dedented by
    up to
    3 tabs
    `, `
    this will be
    dedented by
    up to
    3 tabs
    `);
  • Convert a thing into a string.

    If the argument is an array, it is joined. If it is an object, JSON.stringify is called on it. This method calls .toString() on everything else, except null and undefined, which are converted to the strings 'null' and 'undefined' respectively. Useful for JSON objects where the value could be a single string or an array of strings.

    Parameters

    • thing: unknown

      anything to convert

    Returns string

    a string version of the argument