string-toolbelt
v1.0.0
Published
A lightweight utility library for common string operations
Downloads
87
Readme
string-toolbelt
A lightweight utility library for common string operations.
Installation
npm install string-toolbeltUsage
const { titleCase, truncate, slugify, wordCount, reverse, isPalindrome } = require('string-toolbelt');API
| Function | Description | Example |
|---|---|---|
| titleCase(str) | Capitalizes the first letter of each word | titleCase("hello world") → "Hello World" |
| truncate(str, maxLength, suffix?) | Truncates to max length with a suffix (default "...") | truncate("Hello World", 5) → "Hello..." |
| slugify(str) | Converts to a URL-friendly slug | slugify("Hello World!") → "hello-world" |
| wordCount(str) | Counts the number of words | wordCount("hello world foo") → 3 |
| reverse(str) | Reverses the string | reverse("hello") → "olleh" |
| isPalindrome(str) | Checks if the string is a palindrome (case/space insensitive) | isPalindrome("racecar") → true |
Examples
const t = require('string-toolbelt');
t.titleCase('the quick brown fox'); // "The Quick Brown Fox"
t.truncate('Hello World', 5); // "Hello..."
t.truncate('Hello', 3, '!'); // "Hel!"
t.slugify('My Blog Post! 2024'); // "my-blog-post-2024"
t.wordCount('one two three'); // 3
t.reverse('abcd'); // "dcba"
t.isPalindrome('A man a plan a canal Panama'); // trueLicense
MIT
