String Utilities
Description
The string utilities module provides a collection of functions for manipulating and transforming strings, including case conversions, HTML escaping, and key manipulation.
camelToDash
Converts camelCase strings to dash-case.
import { camelToDash } from '../src/utils/string.js';
camelToDash('camelCase'); // "camel-case"
dashToCamel
Converts dash-case strings to camelCase.
import { dashToCamel } from '../src/utils/string.js';
dashToCamel('dash-case'); // "dashCase"
isCamelCase
Checks if a string is in camelCase format.
import { isCamelCase } from '../src/utils/string.js';
isCamelCase('camelCase'); // true
isCamelCase('dash-case'); // false
getCase
Returns an object with both camel and dash versions of the string.
import { getCase } from '../src/utils/string.js';
getCase('camelCase'); // { camel: "camelCase", dash: "camel-case" }
getCase('dash-case'); // { camel: "dashCase", dash: "dash-case" }
escapeHTML
Escapes HTML special characters in a string.
import { escapeHTML } from '../src/utils/string.js';
escapeHTML('<script>'); // "<script>"
unescapeHTML
Unescapes HTML entities in a string.
import { unescapeHTML } from '../src/utils/string.js';
unescapeHTML('<script>'); // "<script>"
trim
Trims specified characters from the start and end of a string.
import { trim } from '../src/utils/string.js';
trim('.key.value.', '.'); // "key.value"
compoundKey
Joins an array of keys into a compound key string.
import { compoundKey } from '../src/utils/string.js';
compoundKey(['a', 'b', 'c']); // "a.b.c"
toTitleCase
Converts strings to title case format, handling camelCase, snake_case, kebab-case, and regular text.
import { toTitleCase } from '../src/utils/string.js';
toTitleCase('helloWorld'); // "Hello World"
toTitleCase('hello-world'); // "Hello World"
toTitleCase('hello_world'); // "Hello World"