ez-string-toolkit
v1.0.2
Published
A simple and easy-to-use string utility library with essential string manipulation functions
Downloads
13
Maintainers
Readme
EZ String Toolkit
A simple and easy-to-use JavaScript string utility library with essential string manipulation functions.
Installation
npm install ez-string-toolkitUsage
const stringUtils = require('ez-string-toolkit');
// Capitalize first letter
console.log(stringUtils.capitalize('hello')); // Output: "Hello"
// Convert to camelCase
console.log(stringUtils.toCamelCase('hello world')); // Output: "helloWorld"
// Reverse string
console.log(stringUtils.reverse('hello')); // Output: "olleh"
// Count words
console.log(stringUtils.wordCount('hello world')); // Output: 2
// Truncate string
console.log(stringUtils.truncate('hello world', 5)); // Output: "he..."API Documentation
capitalize(str)
Capitalizes the first letter of a string.
- Parameter:
str(string) - The input string - Returns: (string) - String with first letter capitalized
Example:
capitalize('hello world'); // "Hello world"
capitalize('JAVASCRIPT'); // "Javascript"toCamelCase(str)
Converts a string to camelCase format.
- Parameter:
str(string) - The input string - Returns: (string) - The camelCase formatted string
Example:
toCamelCase('hello world'); // "helloWorld"
toCamelCase('user-name-field'); // "userNameField"
toCamelCase('my_variable_name'); // "myVariableName"reverse(str)
Reverses a string.
- Parameter:
str(string) - The input string - Returns: (string) - The reversed string
Example:
reverse('hello'); // "olleh"
reverse('JavaScript'); // "tpircSavaJ"wordCount(str)
Counts the number of words in a string.
- Parameter:
str(string) - The input string - Returns: (number) - The number of words
Example:
wordCount('hello world'); // 2
wordCount('JavaScript is awesome!'); // 3
wordCount(' spaced out words '); // 3truncate(str, maxLength, suffix)
Truncates a string to a specified length.
- Parameters:
str(string) - The input stringmaxLength(number) - The maximum lengthsuffix(string, optional) - The suffix to add (default: '...')
- Returns: (string) - The truncated string
Example:
truncate('This is a long sentence', 10); // "This is..."
truncate('Short text', 20); // "Short text"
truncate('Custom suffix', 10, ' →'); // "Custom →"Features
- ✅ Lightweight: Only 2.7 kB gzipped
- ✅ Zero dependencies: No external dependencies
- ✅ Well tested: Comprehensive test coverage
- ✅ TypeScript friendly: Works great with TypeScript projects
- ✅ Browser compatible: Works in both Node.js and browsers
Testing
Run the test suite:
npm testBrowser Usage
You can also use this library in the browser via CDN:
<script src="https://unpkg.com/ez-string-toolkit@latest/index.js"></script>
<script>
// Library is available as global variable
console.log(capitalize('hello world')); // "Hello world"
</script>License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.
