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.
An array of individual words extracted from the string
Converts the string to camelCase format.
The camelCased version of the string
Converts the string to kebab-case format.
The kebab-cased version of the string
Converts the string to snake_case format.
The snake_cased version of the string
Truncates the string to a maximum number of characters, appending '...' if truncated.
Maximum length of the result (not including the '...')
The truncated string with '...' appended if truncated, otherwise the original string
Reverses the characters in the string, properly handling Unicode surrogate pairs.
The reversed string
Checks if the string is empty or contains only whitespace characters.
True if the string is empty or whitespace-only, false otherwise
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.
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'
Replaces a substring between start and end indices with a given string.
Provides precise control over which portion of the string to replace.
Start index of the replacement range (inclusive)
Optionalend: numberEnd index of the replacement range (exclusive); defaults to start + 1
OptionalreplaceString: stringThe string to insert in place of the removed portion
A new string with the range replaced
Capitalizes the first character of the string (uppercase) and keeps the rest unchanged.