Function optionalFormat

  • Impure version of format which changes depending on the current NodeJS globalThis.process environment.

    Example

    // In a environment with color:
    optionalFormat(42)(13)("Vangware"); // "\x1b[42mVangware\x1b[13m"
    // In an environment without color:
    optionalFormat(42)(13)("Vangware"); // "Vangware"
    // It also works with tagged templates:
    optionalFormat(42)(13)`Vangware`; // "\x1b[42mVangware\x1b[13m"

    Returns

    Either the formatted string, or just the passed string.

    Type Parameters

    • Close extends number

    Parameters

    • close: Close

    Returns (<Open>(open: Open) => ((input: string | Readonly<TemplateStringsArray>, ...expressions: ReadOnlyArray<unknown>) => string))

      • <Open>(open: Open): ((input: string | Readonly<TemplateStringsArray>, ...expressions: ReadOnlyArray<unknown>) => string)
      • Type Parameters

        • Open extends number

        Parameters

        • open: Open

        Returns ((input: string | Readonly<TemplateStringsArray>, ...expressions: ReadOnlyArray<unknown>) => string)

          • (input: string | Readonly<TemplateStringsArray>, ...expressions: ReadOnlyArray<unknown>): string
          • Parameters

            • input: string | Readonly<TemplateStringsArray>
            • Rest ...expressions: ReadOnlyArray<unknown>

            Returns string