This package was generated by ChatGPT 4o mini.
A lightweight utility library that extends JavaScript's String.prototype with powerful and convenient methods for string manipulation.
Install the package using NPM:
npm install @bhar2254/string-utilsTo load the custom string methods:
const { loadStringPrototypes } = require('@bhar2254/string-utils');
// Load custom prototypes
loadStringPrototypes();
// Now you can use the extended String.prototype methods!
console.log("hello world".toCamelCase()); // "helloWorld"
console.log("hello_world".replaceUnderscoreWith(' ')); // "hello world"Converts a string to camelCase.
console.log("hello_world example".toCamelCase()); // "helloWorldExample"Converts a string to snake_case.
console.log("helloWorld example".toSnakeCase()); // "hello_world_example"Converts a string to kebab-case.
console.log("helloWorld example".toKebabCase()); // "hello-world-example"Truncates a string to the specified length and appends ... if truncated.
console.log("This is a long string".truncate(10)); // "This is..."Checks if a string is a palindrome (ignores case, spaces, and punctuation).
console.log("racecar".isPalindrome()); // true
console.log("A man, a plan, a canal: Panama".isPalindrome()); // trueChecks if a string contains only alphabetical characters.
console.log("HelloWorld".containsOnlyLetters()); // true
console.log("Hello123".containsOnlyLetters()); // falsePads a string to the specified length with a given character (default: space).
console.log("hello".pad(10, '-')); // "--hello---"Reverses the string.
console.log("example".reverse()); // "elpmaxe"Counts the number of words in a string.
console.log("hello world this is a test".wordCount()); // 6Alias for capitalizeFirst. Capitalizes the first character of the string.
console.log("hello world".capitalize()); // "Hello world"Capitalizes the first character of the string.
console.log("hello world".capitalizeFirst()); // "Hello world"Capitalizes the first letter of each word.
console.log("hello world".capitalizeWords()); // "Hello World"Removes all vowels from the string.
console.log("hello world".removeVowels()); // "hll wrld"Replaces all spaces with the specified character.
console.log("hello world".replaceSpacesWith('-')); // "hello-world"Replaces all underscores with the specified character.
console.log("hello_world".replaceUnderscoreWith(' ')); // "hello world"Removes all HTML tags from the string.
console.log("<p>Hello <b>World</b></p>".stripHtml()); // "Hello World"Contributions are welcome! Please open an issue or submit a pull request for any new features, bug fixes, or improvements.
This package is licensed under the GPL-3.0 license. See the LICENSE file for details.
Feel free to modify or extend this as needed for your specific project. π