Useful string manipulation helpers with runtime validation, Unicode normalization, and flexible padding options.
import atomix from '@nasriya/atomix';
const strings = atomix.dataTypes.string;| API | Description |
|---|---|
| capitalizeFirstLetter | Capitalizes the first letter |
| guard | Provides validation methods for strings. |
| countOccurrences | Counts substring occurrences |
| endsWithIgnoreCase | Case-insensitive endsWith check |
| pad | Pads string with fill or random chars on any side |
| padEnd | Pads string at end |
| padStart | Pads string at start |
| removeWhitespace | Removes all whitespace |
| reverse | Reverses the string characters |
| startsWithIgnoreCase | Case-insensitive startsWith check |
| stripHTMLTags | Removes all HTML tags |
| slugify | Converts string to a URL-friendly slug |
| toCamelCase | Converts string to camelCase |
| toKebabCase | Converts string to kebab-case |
| toSnakeCase | Converts string to snake_case |
| truncate | Truncates string and adds ellipsis if needed |
Signature: capitalizeFirstLetter(str: string): string
Capitalizes the first letter of the given string.
const result = strings.capitalizeFirstLetter('hello world');
console.log(result); // "Hello world"Signature: countOccurrences(str: string, substr: string): number
Counts the number of times a substring occurs in a string.
const count = strings.countOccurrences('banana', 'an');
console.log(count); // 2Signature: endsWithIgnoreCase(str: string, suffix: string): boolean
Checks if the string ends with the specified suffix, ignoring case.
const result = strings.endsWithIgnoreCase('HelloWorld', 'WORLD');
console.log(result); // trueSignature: pad(str: string, maxLength: number, options?: StringPaddingOptions): string
Pads the string to a certain length, optionally using random characters or filling on specified sides.
const padded = strings.pad('abc', 6, { side: 'both', fillChar: '-' });
console.log(padded); // "--abc-"Signature: padEnd(str: string, maxLength: number, options?: Omit<StringPaddingOptions, 'side'>): string
Pads the end of the string to the specified length.
const paddedEnd = strings.padEnd('abc', 5, { fillChar: '.' });
console.log(paddedEnd); // "abc.."Signature: padStart(str: string, maxLength: number, options?: Omit<StringPaddingOptions, 'side'>): string
Pads the start of the string to the specified length.
const paddedStart = strings.padStart('abc', 5, { fillChar: '.' });
console.log(paddedStart); // "..abc"Signature: removeWhitespace(str: string): string
Removes all whitespace characters from the string.
const noSpaces = strings.removeWhitespace(' a b \n c\t');
console.log(noSpaces); // "abc"Signature: reverse(str: string): string
Reverses the characters of the string.
const reversed = strings.reverse('abc');
console.log(reversed); // "cba"Signature: startsWithIgnoreCase(str: string, prefix: string): boolean
Checks if the string starts with the specified prefix, ignoring case.
const result = strings.startsWithIgnoreCase('HelloWorld', 'hello');
console.log(result); // trueSignature: stripHTMLTags(str: string): string
Removes all HTML tags from the string.
const clean = strings.stripHTMLTags('<p>Hello <strong>world</strong></p>');
console.log(clean); // "Hello world"Signature: slugify(str: string): string
Converts a string into a slug suitable for URLs.
const slug = strings.slugify('Café del Mar!');
console.log(slug); // "cafe-del-mar"Signature: toCamelCase(str: string): string
Converts a string to camelCase.
const camel = strings.toCamelCase('hello world example');
console.log(camel); // "helloWorldExample"Signature: toKebabCase(str: string): string
Converts a string to kebab-case.
const kebab = strings.toKebabCase('helloWorldExample');
console.log(kebab); // "hello-world-example"Signature: toSnakeCase(str: string): string
Converts a string to snake_case.
const snake = strings.toSnakeCase('helloWorldExample');
console.log(snake); // "hello_world_example"Signature: truncate(str: string, length: number): string
Truncates a string to a specified length, adding ellipsis if truncated.
const truncated = strings.truncate('Hello world example', 8);
console.log(truncated); // "Hello wo..."