String Utils Helper
A lightweight and efficient collection of string manipulation and validation utilities for JavaScript.
Installation
npm install string-utils-helper
Usage
String Manipulation
const { toCamelCase, toSnakeCase, truncate, toTitleCase, removeWhitespace, reverse, countOccurrences } = require('string-utils-helper');
toCamelCase('hello-world');
toCamelCase('hello_world');
toCamelCase('Hello World');
toSnakeCase('helloWorld');
toSnakeCase('hello world');
toSnakeCase('hello-world');
truncate('hello world', 8);
truncate('short', 10);
toTitleCase('hello world');
toTitleCase('HELLO WORLD');
removeWhitespace('hello world');
removeWhitespace(' hello world ');
reverse('hello');
reverse('hello world');
countOccurrences('hello hello world', 'hello');
countOccurrences('world', 'hello');
String Validation
const { isValidEmail, isValidUrl, isAlphanumeric } = require('string-utils-helper/validation');
isValidEmail('user@example.com');
isValidEmail('invalid-email');
isValidUrl('https://example.com');
isValidUrl('not-a-url');
isAlphanumeric('abc123');
isAlphanumeric('hello world');
API
String Manipulation
toCamelCase(str)
Converts a string to camelCase format.
toSnakeCase(str)
Converts a string to snake_case format.
truncate(str, length)
Truncates a string to the specified length, adding '...' if truncated.
toTitleCase(str)
Capitalizes the first letter of each word in a string.
removeWhitespace(str)
Removes all whitespace from a string.
reverse(str)
Reverses a string.
countOccurrences(str, substr)
Counts the number of occurrences of a substring in a string.
String Validation
isValidEmail(email)
Checks if a string is a valid email address.
isValidUrl(url)
Checks if a string is a valid URL.
isAlphanumeric(str)
Checks if a string contains only alphanumeric characters.
Testing
Run the tests:
npm test
License
MIT