Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

string-utils-lite is a tiny, dependency-free JavaScript library that makes common string transformations effortless and consistent across projects.

License

Notifications You must be signed in to change notification settings

jahirultusar/JavaScript-string-utils-lite

Repository files navigation

string-utils-lite

npm version npm downloads CI Release license

๐ŸŽฎ Live Playground

Try the library instantly in your browser:
๐Ÿ‘‰ Playground Demo

What is string-utils-lite?

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 rest
  • titleCase โ†’ Capitalises the first character of every word
  • toKebabCase โ†’ Converts text into kebab-case
  • toSnakeCase โ†’ Converts text into snake_case
  • toCamelCase โ†’ Converts text into camelCase
  • toPascalCase โ†’ Converts text into PascalCase

๐Ÿ’ก Why use this library?

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.

๐Ÿ“ฆ Installation

Using npm (recommended):

```bash
npm install string-utils-lite

๐Ÿš€ Usage

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>

๐Ÿ“š API Reference

| 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"` |

i๏ธ All functions are pure: they return a new string without mutating the input.

๐Ÿงช Running Tests

This project uses Vitest
npm test

๐Ÿ›  Development

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

๐Ÿค Contributing

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 

About

string-utils-lite is a tiny, dependency-free JavaScript library that makes common string transformations effortless and consistent across projects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /