@olan88/js-string-methods
v1.0.0
Published
A TypeScript library that extends the native `String` prototype with useful utility methods like camelCase conversion, reversing strings, and more.
Readme
@codebyolan/js-string-methods
A TypeScript library that extends the native String prototype with useful utility methods like camelCase conversion, reversing strings, and more.
Installation
Install the package via npm:
npm install @olan88/js-string-methodsUsage
Import the library in your TypeScript or JavaScript file:
import '@olan/js-string-methods';Example Methods
1. Convert to camelCase
console.log("hello_world-example".toCamelCase()); // Output: "helloWorldExample"2. Capitalize the first letter
console.log("hello world".capitalize()); // Output: "Hello world"3. Reverse a string
console.log("hello".reverse()); // Output: "olleh"4. Check if a string is a palindrome
console.log("A man a plan a canal Panama".isPalindrome()); // Output: true5. Count occurrences of a substring
console.log("hello world hello".countOccurrences("hello")); // Output: 26. Truncate a string
console.log("This is a long string".truncate(10)); // Output: "This is..."7. Convert to Title Case
console.log("this is a test".toTitleCase()); // Output: "This Is A Test"8. Remove all whitespace
console.log(" hello world ".removeWhitespace()); // Output: "helloworld"9. Mask a portion of a string
console.log("1234567890".mask(2, 8)); // Output: "12******90"10. Convert to a slug
console.log("Hello World!".toSlug()); // Output: "hello-world"11. Check if a string contains only specific characters
console.log("12345".containsOnly("0123456789")); // Output: trueContributing
Contributions are welcome! Open an issue or a pull request to suggest improvements.
License
This project is licensed under the MIT License.
