Class StringUtils

Constructors

Properties

camelCase: (input: string) => string = camelCase

Convert a string to camelCase

Type declaration

    • (input: string): string
    • Parameters

      • input: string

        The input string

      Returns string

      The camelCase string

displayArray: <T>(
    arr: T[],
    options: StringifyArrayOptions<T> & { emptyOutput: string },
) => string = displayArray

Utility wrapper for stringifyArray that handles empty arrays and displaying the number of truncated items

Type declaration

    • <T>(
          arr: T[],
          options: StringifyArrayOptions<T> & { emptyOutput: string },
      ): string
    • Type Parameters

      • T

      Parameters

      Returns string

      The displayed string

isUrl: (input: string) => boolean = isUrl

Check if a string is a valid URL

Type declaration

    • (input: string): boolean
    • Parameters

      • input: string

        The input string

      Returns boolean

      Whether the input is a valid URL

kebabCase: (input: string) => string = kebabCase

Convert a string to kebab-case

Type declaration

    • (input: string): string
    • Parameters

      • input: string

        The input string

      Returns string

      The kebab-case string

pascalCase: (input: string) => string = pascalCase

Convert a string to PascalCase

Type declaration

    • (input: string): string
    • Parameters

      • input: string

        The input string

      Returns string

      The PascalCase string

pluralize: (input: string, count: number) => string = pluralize

Pluralize a string based on a count

Type declaration

    • (input: string, count: number): string
    • Parameters

      • input: string

        The input string

      • count: number

        The count

      Returns string

      The pluralized string (e.g. 'apple' -> 'apples')

replaceTags: (input: string, placeholders: Record<string, string>) => string = replaceTags

Replace all available tags/placeholders in a string

Type declaration

    • (input: string, placeholders: Record<string, string>): string
    • Parameters

      • input: string

        The input string

      • placeholders: Record<string, string>

        A record of placeholders to replace, where the key is the placeholder and the value is the replacement

      Returns string

      A string that has had all placeholders replaced

snakeCase: (input: string) => string = snakeCase

Convert a string to snake_case

Type declaration

    • (input: string): string
    • Parameters

      • input: string

        The input string

      Returns string

      The snake_case string

splitOnUppercase: (input: string, splitChar?: string) => string = splitOnUppercase

Split a string on uppercase chars and join them back together

Type declaration

    • (input: string, splitChar?: string): string
    • Parameters

      • input: string

        The input string

      • splitChar: string = ' '

        The character to split on

      Returns string

      The split string

stringifyArray: <T>(
    arr: T[],
    options: StringifyArrayOptions<T>,
) => { result: string; truncatedItems: number } = stringifyArray

Truncate an array of items into a string

Type declaration

    • <T>(
          arr: T[],
          options: StringifyArrayOptions<T>,
      ): { result: string; truncatedItems: number }
    • Type Parameters

      • T

      Parameters

      Returns { result: string; truncatedItems: number }

      The truncated string

titleCase: (input: string) => string = titleCase

Converts a string to Title Case

Type declaration

    • (input: string): string
    • Parameters

      • input: string

        The input string

      Returns string

      The Title Case string

truncate: (input: string, length: number, suffix?: string) => string = truncate

Truncate a string to a certain length

Type declaration

    • (input: string, length: number, suffix?: string): string
    • Parameters

      • input: string

        The input string

      • length: number

        The maximum length

      • suffix: string = '...'

        The suffix to append if the string is truncated

      Returns string

      The truncated string