StringUtils: {
    camelCaseToSentence: ((str) => string);
    camelize: ((str) => string);
    capitalize: ((str) => string);
    capitalizeWords: ((str) => string);
    contains: ((haystack, needle) => boolean);
    formatBytes: ((bytes, decimals?) => string);
    isString: ((value) => value is string);
    length: ((str) => number);
    middleEllipsify: ((str?, maxLength?) => string);
    pad: ((str, length, char, right?) => string);
    replaceAll: ((str, find, replace) => string);
    sort: ((val1, val2, direction?) => number);
    sortAsc: ((val1, val2) => number);
    sortDesc: ((val1, val2) => number);
    toLowerCase: ((val) => string);
    toNumbers: ((val) => string);
    toString: ((val) => string);
    truncateWithEllipsis: ((str, maxLength?) => string);
    uncapitalize: ((str) => string);
} = ...

Type declaration

  • camelCaseToSentence: ((str) => string)

    Converts a camelCase string to a sentence with proper capitalization.

    Returns

    The converted sentence with proper spacing and capitalization

    Example

    StringUtils.camelCaseToSentence('myVariableName'); // Returns "My Variable Name"
    StringUtils.camelCaseToSentence('XMLHttpRequest'); // Returns "XML Http Request"
      • (str): string
      • Parameters

        • str: string

          The camelCase string to convert

        Returns string

  • camelize: ((str) => string)

    Converts a string to camelCase format.

    Returns

    The camelCased string

    Example

    StringUtils.camelize('hello world'); // Returns "helloWorld"
    StringUtils.camelize('my-variable-name'); // Returns "myVariableName"
      • (str): string
      • Parameters

        • str: string

          The string to convert to camelCase

        Returns string

  • capitalize: ((str) => string)

    Capitalizes the first letter of a string.

    Returns

    The string with the first letter capitalized

    Example

    StringUtils.capitalize('hello'); // Returns "Hello"
    StringUtils.capitalize('WORLD'); // Returns "WORLD"
      • (str): string
      • Parameters

        • str: string

          The string to capitalize

        Returns string

  • capitalizeWords: ((str) => string)

    Capitalizes the first letter of each word in a string.

    Returns

    The string with each word capitalized

    Example

    StringUtils.capitalizeWords('hello world'); // Returns "Hello World"
    StringUtils.capitalizeWords('the quick brown fox'); // Returns "The Quick Brown Fox"
      • (str): string
      • Parameters

        • str: string

          The string to convert to title case

        Returns string

  • contains: ((haystack, needle) => boolean)

    Checks if a string contains another string (case-insensitive).

    Returns

    True if the haystack contains the needle, false otherwise

    Example

    StringUtils.contains('Hello World', 'world'); // Returns true
    StringUtils.contains('JavaScript', 'script'); // Returns true
    StringUtils.contains('TypeScript', 'python'); // Returns false
      • (haystack, needle): boolean
      • Parameters

        • haystack: unknown

          The string to search in

        • needle: unknown

          The string to search for

        Returns boolean

  • formatBytes: ((bytes, decimals?) => string)

    Formats a number of bytes into a human-readable string with appropriate units.

    Returns

    A formatted string with appropriate byte units

    Example

    StringUtils.formatBytes(1024); // Returns "1 KB"
    StringUtils.formatBytes(1536, 1); // Returns "1.5 KB"
    StringUtils.formatBytes(1048576); // Returns "1 MB"
      • (bytes, decimals?): string
      • Parameters

        • bytes: number

          The number of bytes to format

        • decimals: number = 0

          The number of decimal places to include (default: 0)

        Returns string

  • isString: ((value) => value is string)

    Type guard to check if a value is a string.

    Returns

    True if the value is a string, false otherwise

    Example

    StringUtils.isString('hello'); // Returns true
    StringUtils.isString(123); // Returns false
    StringUtils.isString(null); // Returns false
      • (value): value is string
      • Parameters

        • value: unknown

          The value to check

        Returns value is string

  • length: ((str) => number)

    Gets the length of a string safely.

    Returns

    The length of the string, or 0 if the string is null/undefined

    Example

    StringUtils.length('hello'); // Returns 5
    StringUtils.length(''); // Returns 0
    StringUtils.length(null); // Returns 0
      • (str): number
      • Parameters

        • str: string

          The string to measure

        Returns number

  • middleEllipsify: ((str?, maxLength?) => string)

    Truncates a string in the middle with ellipsis if it exceeds the maximum length.

    Returns

    The truncated string with ellipsis in the middle

    Example

    StringUtils.middleEllipsify('verylongfilename.txt', 15); // Returns "veryl...me.txt"
    StringUtils.middleEllipsify('short.txt', 20); // Returns "short.txt"
      • (str?, maxLength?): string
      • Parameters

        • str: string = ""

          The string to truncate (default: empty string)

        • maxLength: number = 20

          The maximum length before truncation (default: 20)

        Returns string

  • pad: ((str, length, char, right?) => string)

    Pads a string with a specified character to reach a target length.

    Returns

    The padded string

    Example

    StringUtils.pad('5', 3, '0'); // Returns "005"
    StringUtils.pad('hello', 8, '*', true); // Returns "hello***"
      • (str, length, char, right?): string
      • Parameters

        • str: string | number

          The string or number to pad

        • length: number

          The target length after padding

        • char: string

          The character to use for padding

        • right: boolean = false

          Whether to pad on the right side (default: false, pads left)

        Returns string

  • replaceAll: ((str, find, replace) => string)

    Replaces all occurrences of a substring in a string.

    Returns

    The modified string with all occurrences replaced

    Example

    StringUtils.replaceAll('hello world hello', 'hello', 'hi'); // Returns "hi world hi"
    StringUtils.replaceAll('foo-bar-baz', '-', '_'); // Returns "foo_bar_baz"
      • (str, find, replace): string
      • Parameters

        • str: string

          The string to modify

        • find: string

          The substring to find and replace

        • replace: string

          The substring to replace with

        Returns string

  • sort: ((val1, val2, direction?) => number)

    Sorts two values as strings with specified direction.

    Returns

    A number indicating the sort order (-1, 0, or 1)

    Example

    StringUtils.sort('apple', 'banana'); // Returns -1 (apple comes before banana)
    StringUtils.sort('zebra', 'apple', 'desc'); // Returns -1 (zebra comes before apple in desc order)
      • (val1, val2, direction?): number
      • Parameters

        • val1: unknown

          The first value to compare

        • val2: unknown

          The second value to compare

        • direction: "asc" | "desc" = "asc"

          The sort direction: 'asc' for ascending, 'desc' for descending (default: 'asc')

        Returns number

  • sortAsc: ((val1, val2) => number)

    Sorts two values as strings in ascending order.

    Returns

    A number indicating the sort order (-1, 0, or 1)

    Example

    StringUtils.sortAsc('banana', 'apple'); // Returns 1
    
      • (val1, val2): number
      • Parameters

        • val1: unknown

          The first value to compare

        • val2: unknown

          The second value to compare

        Returns number

  • sortDesc: ((val1, val2) => number)

    Sorts two values as strings in descending order.

    Returns

    A number indicating the sort order (-1, 0, or 1)

    Example

    StringUtils.sortDesc('apple', 'banana'); // Returns 1
    
      • (val1, val2): number
      • Parameters

        • val1: unknown

          The first value to compare

        • val2: unknown

          The second value to compare

        Returns number

  • toLowerCase: ((val) => string)

    Converts a value to lowercase string.

    Returns

    The lowercase string representation, or empty string if not a string

    Example

    StringUtils.toLowerCase('HELLO WORLD'); // Returns "hello world"
    StringUtils.toLowerCase('MixedCase'); // Returns "mixedcase"
    StringUtils.toLowerCase(123); // Returns ""
      • (val): string
      • Parameters

        • val: unknown

          The value to convert to lowercase

        Returns string

  • toNumbers: ((val) => string)

    Extracts only numeric characters from a string.

    Returns

    A string containing only the numeric characters

    Example

    StringUtils.toNumbers('abc123def456'); // Returns "123456"
    StringUtils.toNumbers('phone: (555) 123-4567'); // Returns "5551234567"
    StringUtils.toNumbers('no numbers here'); // Returns ""
      • (val): string
      • Parameters

        • val: unknown

          The string to extract numbers from

        Returns string

  • toString: ((val) => string)

    Converts any value to its string representation.

    Returns

    The string representation of the value

    Example

    StringUtils.toString(123); // Returns "123"
    StringUtils.toString(true); // Returns "true"
    StringUtils.toString(null); // Returns "null"
      • (val): string
      • Parameters

        • val: unknown

          The value to convert to string

        Returns string

  • truncateWithEllipsis: ((str, maxLength?) => string)

    Truncates a string with ellipsis if it exceeds the maximum length.

    Returns

    The truncated string with ellipsis appended if needed

    Example

    StringUtils.truncateWithEllipsis('This is a very long string', 10); // Returns "This is..."
    StringUtils.truncateWithEllipsis('Short', 10); // Returns "Short"
      • (str, maxLength?): string
      • Parameters

        • str: string

          The string to truncate

        • maxLength: number = 100

          The maximum length before truncation (default: 100)

        Returns string

  • uncapitalize: ((str) => string)

    Converts the first letter of a string to lowercase.

    Returns

    The string with the first letter in lowercase

    Example

    StringUtils.uncapitalize('Hello World'); // Returns "hello World"
    StringUtils.uncapitalize('UPPERCASE'); // Returns "uPPERCASE"
      • (str): string
      • Parameters

        • str: string

          The string to convert

        Returns string