Try the library instantly in your browser:
👉 Playground Demo
string-utils-lite
is a tiny, dependency-free JavaScript library that makes common string transformations effortless and consistent across projects.
It provides simple helper functions for everyday string formatting needs:
capitalize
→ Uppercases the first character, lowercases the resttitleCase
→ Capitalises the first character of every wordtoKebabCase
→ Converts text intokebab-case
toSnakeCase
→ Converts text intosnake_case
toCamelCase
→ Converts text intocamelCase
toPascalCase
→ Converts text intoPascalCase
JavaScript lacks built-in utilities for string case transformations (unlike Python’s .title()
or .capitalize()
).
While you could write ad-hoc functions, string-utils-lite
saves time by offering:
- ✅ Consistency — same results across all projects
- ✅ Zero dependencies — lightweight, no bloat
- ✅ Dual support — works with both ESM and CommonJS
- ✅ Tree-shakable — import only what you need
Whether you’re cleaning up user input, formatting identifiers, or ensuring consistency in APIs, this library provides a clear and minimal solution.
Using npm (recommended):
```bash
npm install string-utils-lite
You can use string-utils-lite in multiple environments:
ES Modules:
import { capitalize, titleCase, toKebabCase } from 'string-utils-lite';
console.log(capitalize('hELLo')); // "Hello"
console.log(titleCase('hELLO woRLD')); // "Hello World"
console.log(toKebabCase('Hello World')); // "hello-world"
CommonJS:
const { capitalize, titleCase } = require('string-utils-lite');
console.log(capitalize('hELLo')); // "Hello"
console.log(titleCase('foo bar')); // "Foo Bar"
CDN (Direct Browser Use):
No installation required! Load from a CDN like esm.sh and use in the browser. For example:
<script type="module">
import { capitalize, titleCase } from "https://esm.sh/string-utils-lite";
console.log(capitalize("hELLo")); // "Hello"
console.log(titleCase("hELLO woRLD")); // "Hello World");
</script>
| Function | Description | Example Input | Example Output |
|-------------------|--------------------------------------------------|-----------------|-----------------|
| `capitalize(str)` | Uppercases the first letter, lowercases the rest | `"hELLo"` | `"Hello"` |
| `titleCase(str)` | Capitalises the first letter of each word | `"hELLO woRLD"` | `"Hello World"` |
| `toKebabCase(str)`| Converts string to kebab-case | `"Hello World"` | `"hello-world"` |
| `toSnakeCase(str)`| Converts string to snake_case | `"Hello World"` | `"hello_world"` |
| `toCamelCase(str)`| Converts string to camelCase | `"Hello World"` | `"helloWorld"` |
| `toPascalCase(str)`| Converts string to PascalCase | `"Hello World"` | `"HelloWorld"` |
ℹ️ All functions are pure: they return a new string without mutating the input.
This project uses Vitest
npm test
Clone the repo and install dependencies:
git clone https://github.com/jahirultusar/JavaScript-string-utils-lite.git
cd string-utils-lite
npm install
Build the package:
npm run build
Contributions are welcome! 🎉
Fork the repository
Create a feature branch (git checkout -b feature/my-feature)
Commit your changes (git commit -m 'feat: add new feature')
Push to the branch (git push origin feature/my-feature)
Open a Pull Request
Please follow Conventional Commits for commit messages.
📄 License
MIT © 2025 Jahirul Tusar