Options
All
  • Public
  • Public/Protected
  • All
Menu

@marcelkloubert/strings

Index

Type aliases

StringFormatter: (value: any) => any

Type declaration

    • (value: any): any
    • A string formatter.

      Parameters

      • value: any

        The input value.

      Returns any

      The output value.

StringFormatters: Record<string, StringFormatter>

A repository of string formatters.

Variables

stringFormatters: StringFormatters = ...

List of string formatters.

Functions

  • asString(value: any): string
  • Converts a value to its string representation.

    example
    import { asString } from "@marcelkloubert/strings"

    const myObject = {
    toString: () => "!!!myObject!!!",
    };

    asString(12) // "12"
    asString("") // ""
    asString(null) // ""
    asString(undefined) // ""
    asString(myObject) // "!!!myObject!!!"

    Parameters

    • value: any

      The input value.

    Returns string

    The value as string.

  • format(formatStr: string, ...args: any[]): string
  • Formats a string.

    example
    import { format } from "@marcelkloubert/strings"

    format("{1}, {0}", "Marcel", "Kloubert") // "Kloubert, Marcel"
    format("{1:upper}, {0:lower,trim}", "Marcel", " Kloubert ") // "kloubert, MARCEL"

    Parameters

    • formatStr: string

      The format string.

    • Rest ...args: any[]

    Returns string

    The formatted string.

  • formatArray(formatStr: string, argList: List<any>): string
  • Formats a string.

    example
    import { formatArray } from "@marcelkloubert/strings"

    formatArray("{1}, {0}", ["Marcel", "Kloubert"]) // "Kloubert, Marcel"
    formatArray("{1:upper}, {0:lower,trim}", ["Marcel", " Kloubert "]) // "kloubert, MARCEL"

    Parameters

    • formatStr: string

      The format string.

    • argList: List<any>

    Returns string

    The formatted string.

Generated using TypeDoc