sp-string-kit
v1.0.1
Published
A small collection of handy string utility functions - capitalize, palindrome check, camelCase/snakeCase/kebabCase conversion, slugify, and more.
Maintainers
Readme
sp-string-kit
A small collection of handy string utility functions — capitalize, palindrome check, case conversions (camelCase/snake_case/kebab-case), slugify, and more.
Installation
npm install sp-string-kitUsage
const {
capitalize,
isPalindrome,
reverse,
truncate,
toCamelCase,
toSnakeCase,
toKebabCase,
countWords,
countVowels,
removeWhitespace,
isEmpty,
randomString,
slugify,
} = require('sp-string-kit');
capitalize('hello'); // 'Hello'
isPalindrome('Madam'); // true
reverse('hello'); // 'olleh'
truncate('Hello World', 5); // 'Hello...'
toCamelCase('hello world'); // 'helloWorld'
toSnakeCase('Hello World'); // 'hello_world'
toKebabCase('Hello World'); // 'hello-world'
countWords('The quick brown fox'); // 4
countVowels('Hello World'); // 3
removeWhitespace('a b c d'); // 'abcd'
isEmpty(' '); // true
randomString(8); // random 8-character string
slugify('Hello World!'); // 'hello-world'API
| Function | Description |
|---|---|
| capitalize(str) | Capitalizes the first letter of a string |
| isPalindrome(str) | Checks if a string is a palindrome (ignores case, spaces, punctuation) |
| reverse(str) | Reverses a string |
| truncate(str, length) | Shortens a string and appends ... if it exceeds length |
| toCamelCase(str) | Converts a string to camelCase |
| toSnakeCase(str) | Converts a string to snake_case |
| toKebabCase(str) | Converts a string to kebab-case |
| countWords(str) | Counts the number of words in a string |
| countVowels(str) | Counts the number of vowels in a string |
| removeWhitespace(str) | Strips all whitespace from a string |
| isEmpty(str) | Checks if a string is empty or contains only whitespace |
| randomString(length) | Generates a random alphanumeric string of a given length |
| slugify(str) | Converts a string into a URL-friendly slug |
License
MIT
