Package Exports
- curslo-string-utilities
- curslo-string-utilities/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (curslo-string-utilities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Curslo String Utilities
A lightweight utility package for string manipulations in JavaScript and TypeScript.
🚀 Installation
Install via npm, yarn or pnpm:
npm install curslo-string-utilities
OR yarn
yarn add curslo-string-utilities
OR pnpm
pnpm add curslo-string-utilities
📖 Usage
Import the package in your JavaScript or TypeScript project:
const {
capitalize,
toCamelCase,
toSnakeCase,
toKebabCase,
reverseString,
truncateString,
isPalindrome,
removeWhitespace,
countWords,
toTitleCase,
maskString,
randomString,
} = require("curslo-string-utilities");
OR in TypeScript:
import {
capitalize,
toCamelCase,
toSnakeCase,
toKebabCase,
reverseString,
truncateString,
isPalindrome,
removeWhitespace,
countWords,
toTitleCase,
maskString,
randomString,
} from "curslo-string-utilities";
🔥 Functions & Examples
1️⃣ capitalize(word)
Converts the first letter of a word to uppercase.
console.log(capitalize("hello world")); // "Hello world"
2️⃣ toCamelCase(str)
Converts a string to camelCase.
console.log(toCamelCase("hello world")); // "helloWorld"
3️⃣ toSnakeCase(str)
Converts a string to snake_case.
console.log(toSnakeCase("hello world")); // "hello_world"
4️⃣ toKebabCase(str)
Converts a string to kebab-case.
console.log(toKebabCase("hello world")); // "hello-world"
5️⃣ reverseString(str)
Reverses the given string.
console.log(reverseString("hello")); // "olleh"
6️⃣ truncateString(str, length)
Truncates a string to a given length and adds "..." at the end.
console.log(truncateString("Hello World", 5)); // "Hello..."
7️⃣ isPalindrome(str)
Checks if a string is a palindrome.
console.log(isPalindrome("racecar")); // true
console.log(isPalindrome("hello")); // false
8️⃣ removeWhitespace(str)
Removes all whitespace from a string.
console.log(removeWhitespace("Hello World")); // "HelloWorld"
9️⃣ countWords(str)
Counts the number of words in a string.
console.log(countWords("This is a test")); // 4
🔟 toTitleCase(str)
Converts a string to title case.
console.log(toTitleCase("hello world")); // "Hello World"
1️⃣1️⃣ maskString(str, visibleChars = 4)
Masks all but the last visibleChars characters in a string.
console.log(maskString("1234567890")); // "**\*\***7890"
console.log(maskString("secretPassword", 3)); // "\***\*\*\*\*\*\*\***ord"
1️⃣2️⃣ randomString(length)
Generates a random alphanumeric string of the given length.
console.log(randomString(8)); // Example output: "A1B2C3D4"
✅ Testing
Run tests using Jest:
npm test
👨💻 Contributing
Contributions are welcome!
Fork the repository Make your changes Open a pull request
🔨 Development
If you want to contribute or modify this package:
- Clone the repository:
git clone https://github.com/Curslo/curslo-string-utilities.git cd curslo-string-utilities
- Install dependencies:
npm install
- Build the package:
npm run build
Run tests:sh npm test
🌟 Support
If you like this package, please ⭐ star the repository on GitHub!
📜 License
This project is licensed under the MIT License.
📢 Changelog
- v2.1.3 (Latest)
- Converted to TypeScript for better type safety.
- Updated package exports for ES Module & CommonJS compatibility.
- Added more string utilities
- Can Build, run test with jest and its the most stable version
- v2.1.0
- Initial release with string utility functions.
- Converted to TypeScript for better type safety.
- Updated package exports for ES Module & CommonJS compatibility.