camel-kit
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

camel-kit

npm package

NPM version NPM Downloads jsdelivr

A lightweight and feature-rich utility library for bidirectional conversion between camelCase and snake_case.


Core Features

  • Bidirectional Conversion: Supports seamless conversion between camelCasesnake_case.
  • Flexible Configuration: Customize behavior with options (e.g., preserve consecutive uppercase letters, custom separators).
  • Unicode Support: Compatible with multilingual characters (e.g., Greek letters, Japanese).
  • Zero Dependencies: Only ~2KB (gzipped).

Documentation

For detailed usage instructions and API references, please visit the official documentation:

👉 View Full Documentation


Quick Start

import { camelize, decamelize } from 'camel-kit';

// Snake to Camel
console.log(camelize('snake_case_example')); // Output: snakeCaseExample

// Camel to Snake
console.log(decamelize('camelCaseExample')); // Output: camel_case_example

Advanced Features

1. Configuration Options

camelize Options

// Convert to PascalCase (uppercase first letter)
console.log(camelize('hello_world', { pascalCase: true })); // Output: HelloWorld

// Preserve consecutive uppercase letters (e.g., 'HTTPRequest' → 'http_Request')
console.log(camelize('HTTP_Request', { preserveConsecutiveUppercase: true })); // Output: hTTP_Request

decamelize Options

// Custom separator (e.g., kebab-case)
console.log(decamelize('camelCase', { separator: '-' })); // Output: camel-case

// Preserve consecutive uppercase letters (e.g., 'FOOBar' → 'FOO_Bar')
console.log(decamelize('FOOBar', { preserveConsecutiveUppercase: true })); // Output: FOO_Bar

2. Array Input Handling

console.log(camelize(['hello', 'world'])); // Output: helloWorld
console.log(decamelize('helloWorld', { separator: '_' })); // Output: hello_world

3. Unicode Support

// Process multilingual characters
console.log(camelize('üser_näme')); // Output: üserNäme
console.log(decamelize('üserNäme')); // Output: üser_näme

Contributing

We welcome contributions from the community! If you find a bug or want to suggest an improvement, feel free to open an issue or submit a pull request.

How to Contribute

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Submit a pull request with a clear description of your changes.

License

This project is licensed under the MIT License.


Browser Support

Chrome Firefox Safari Opera Edge
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔

Package Sidebar

Install

npm i camel-kit

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

22.7 kB

Total Files

13

Last publish

Collaborators

  • fengxinming