Function toString

  • Parses given value to string, if number is given, then that's used as a radix and a function is returned expecting an actual value.

    Example

    const toDecimal = toString(10);

    toDecimal(10); // "10"
    toString(16)(16); // "10"
    toString(2)(2); // "10"
    toString({}); // "[object Object]"
    toString({ toString: _ => "test" }); // "test"

    Returns

    string or function expecting a value.

    Type Parameters

    • Input extends Stringable | {
          toString: (() => string);
      }

    Parameters

    • input: Input

    Returns Input extends Stringable ? `${Input}` : Input extends {
        toString: (() => string);
    } ? ReturnType<Input["toString"]> : string