utilitish - v0.0.10
    Preparing search index...
    interface String {
        capitalize(): string;
        splitWords(): string[];
        camelCase(): string;
        kebabCase(): string;
        snakeCase(): string;
        truncate(n: number): string;
        reverse(): string;
        isEmpty(): boolean;
        slugify(): string;
        slugify(config: SlugifyConfig): string;
        replaceRange(start: number, end?: number, replaceString?: string): string;
        readonly [index: number]: string;
    }

    Hierarchy

    • RelativeIndexable<string>
      • String

    Indexable

    • readonly [index: number]: string
    Index

    Methods

    • Capitalizes the first character of the string (uppercase) and keeps the rest unchanged.

      Returns string

      A new string with the first character in uppercase

      'hello world'.capitalize(); // 'Hello world'
      'HELLO'.capitalize(); // 'HELLO'
      • Only affects the first character
      • Returns an empty string for empty input
      • Does not normalize the rest of the string
    • Splits the string into an array of words by detecting camelCase, kebab-case, snake_case, and spaces. Useful as a foundation for case conversion methods.

      Returns string[]

      An array of individual words extracted from the string

      'helloWorld'.splitWords(); // ['hello', 'World']
      'hello-world'.splitWords(); // ['hello', 'world']
      'hello_world'.splitWords(); // ['hello', 'world']
      'HelloWorld'.splitWords(); // ['Hello', 'World']
      • Handles transitions from lowercase to uppercase (camelCase)
      • Handles consecutive uppercase letters (HTMLParser → HTML Parser)
      • Treats spaces, hyphens, and underscores as word separators
      • Filters out empty strings
    • Converts the string to camelCase format.

      Returns string

      The camelCased version of the string

      'hello-world'.camelCase(); // 'helloWorld'
      'hello_world'.camelCase(); // 'helloWorld'
      'HelloWorld'.camelCase(); // 'helloWorld'
      • First word is lowercase, subsequent words have uppercase first letter
      • Uses splitWords() internally to handle various naming conventions
    • Converts the string to kebab-case format.

      Returns string

      The kebab-cased version of the string

      'helloWorld'.kebabCase(); // 'hello-world'
      'hello_world'.kebabCase(); // 'hello-world'
      'HelloWorld'.kebabCase(); // 'hello-world'
      • All letters are lowercase
      • Words are separated by hyphens
      • Uses splitWords() internally
    • Converts the string to snake_case format.

      Returns string

      The snake_cased version of the string

      'helloWorld'.snakeCase(); // 'hello_world'
      'hello-world'.snakeCase(); // 'hello_world'
      'HelloWorld'.snakeCase(); // 'hello_world'
      • All letters are lowercase
      • Words are separated by underscores
      • Uses splitWords() internally
    • Truncates the string to a maximum number of characters, appending '...' if truncated.

      Parameters

      • n: number

        Maximum length of the result (not including the '...')

      Returns string

      The truncated string with '...' appended if truncated, otherwise the original string

      If n is not a non-negative integer

      'hello world'.truncate(5); // 'hello...'
      'hello'.truncate(10); // 'hello'
      • The '...' is added after the truncated portion, so total length is n + 3
      • Negative or non-integer values throw an error
    • Reverses the characters in the string, properly handling Unicode surrogate pairs.

      Returns string

      The reversed string

      'hello'.reverse(); // 'olleh'
      '👋world'.reverse(); // 'dlrow👋'
      • Uses spread operator to properly handle Unicode characters
      • Works correctly with emoji and other multi-byte characters
    • Checks if the string is empty or contains only whitespace characters.

      Returns boolean

      True if the string is empty or whitespace-only, false otherwise

      ''.isEmpty(); // true
      ' '.isEmpty(); // true
      'hello'.isEmpty(); // false
      ' hello '.isEmpty(); // false
      • Uses trim() internally, so handles all whitespace characters
    • Converts the string into a URL-friendly slug format. Combines normalization, lowercasing, whitespace handling, and special character removal. Can be customized using global configuration or per-call options.

      Returns string

      A URL-safe slug version of the string

      // Basic usage (default config)
      'Hello World'.slugify(); // 'hello-world'
      'Héllo Wørld'.slugify(); // 'hello-world'
      'Hello World!!!'.slugify(); // 'hello-world'
      // Custom replacements
      'Test ♀'.slugify(SlugifyConfig.builder().withCustomReplacements({ "♀": "feminin" }).build()); // 'test-feminin'
      'User♂@domain.com'.slugify(SlugifyConfig.builder().withCustomReplacements({ "♂": "masculin", "@": "at" }).build()); // 'usermasculinatdomain-com'
      // Custom separator
      'Hello World'.slugify(SlugifyConfig.builder().withSeparator("_").build()); // 'hello_world'
      'Hello World'.slugify(SlugifyConfig.builder().withSeparator("--").build()); // 'hello--world'
      // Preserve accents
      'Éléphant'.slugify(SlugifyConfig.builder().withRemoveAccents(false).build()); // 'éléphant'
      // Disable lowercasing
      'Hello World'.slugify(SlugifyConfig.builder().withCase('default').build()); // 'Hello-World'
      // Max length
      'Very long string'.slugify(SlugifyConfig.builder().withMaxLength(8).build()); // 'very-lon'
      // Custom transformers
      'hello world'.slugify(SlugifyConfig.builder()
      .withTransformers([(str) => str.replace(/world/g, 'universe')])
      .build()); // 'hello-universe'
      • Uses global configuration by default (see setSlugifyConfig)
      • Normalizes Unicode characters (NFD decomposition) by default
      • Removes accents and diacritical marks by default
      • Converts to lowercase by default
      • Replaces spaces and special characters with separator (hyphen by default)
      • Removes leading/trailing separators
      • Collapses multiple consecutive separators into one
      • SlugifyConfig
      • setSlugifyConfig
      • getSlugifyConfig
      • resetSlugifyConfig
    • Parameters

      Returns string

    • Replaces a substring between start and end indices with a given string. Provides precise control over which portion of the string to replace.

      Parameters

      • start: number

        Start index of the replacement range (inclusive)

      • Optionalend: number

        End index of the replacement range (exclusive); defaults to start + 1

      • OptionalreplaceString: string

        The string to insert in place of the removed portion

      Returns string

      A new string with the range replaced

      'hello world'.replaceRange(0, 5, 'goodbye'); // 'goodbye world'
      'hello'.replaceRange(2, 2, 'XX'); // 'heXXllo'
      'hello'.replaceRange(1, 4); // 'ho'
      • If end is not provided, defaults to replacing only the character at start
      • If replaceString is not provided, the range is simply removed
      • Uses slice() internally for safe index handling