UNPKG

ez-string-toolkit

Version:

A simple and easy-to-use string utility library with essential string manipulation functions

136 lines (97 loc) 3.63 kB
# EZ String Toolkit A simple and easy-to-use JavaScript string utility library with essential string manipulation functions. ## Installation ```bash npm install ez-string-toolkit ``` ## Usage ```javascript 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:** ```javascript 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:** ```javascript 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:** ```javascript 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:** ```javascript wordCount('hello world'); // 2 wordCount('JavaScript is awesome!'); // 3 wordCount(' spaced out words '); // 3 ``` ### `truncate(str, maxLength, suffix)` Truncates a string to a specified length. - **Parameters**: - `str` (string) - The input string - `maxLength` (number) - The maximum length - `suffix` (string, optional) - The suffix to add (default: '...') - **Returns**: (string) - The truncated string **Example:** ```javascript 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: ```bash npm test ``` ## Browser Usage You can also use this library in the browser via CDN: ```html <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. ## Changelog### v1.0.2- Added homepage URL: https://bgsiscript.com- Package metadata improvements### v1.0.1- Updated README with English documentation- Added more examples and improved documentation### v1.0.0- Initial release- Basic string utility functions: capitalize, toCamelCase, reverse, wordCount, truncate