Convert into a text with the separator denoted by the next word capitalized
npm install text-camel-case[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Bundle size][bundlephobia-image]][bundlephobia-url]


> Transform text into camelCase format where the first letter is lowercase and subsequent words have their first letter capitalized with no separators.
- Lightweight - Only ~450B minified + gzipped
- Type-safe - Full TypeScript support with comprehensive type definitions
- Zero dependencies - No external dependencies
- Tree-shakeable - ES modules support
- Universal - Works in browsers, Node.js, and serverless environments
- Well-tested - Comprehensive test suite with edge cases
- Customizable - Flexible options for advanced use cases
``bashnpm
npm install text-camel-case
๐ฏ Quick Start
`javascript
import { camelCase } from "text-camel-case";console.log(camelCase("hello world")); // "helloWorld"
console.log(camelCase("user_profile_data")); // "userProfileData"
console.log(camelCase("background-color")); // "backgroundColor"
`๐ Usage
$3
`javascript
import { camelCase } from "text-camel-case";console.log(camelCase("hello world")); // "helloWorld"
`$3
`javascript
const { camelCase } = require("text-camel-case");console.log(camelCase("hello world")); // "helloWorld"
`$3
`typescript
import { camelCase, camelCaseTransformMerge, Options } from "text-camel-case";const result: string = camelCase("hello world");
console.log(result); // "helloWorld"
`๐ Transformation Examples
$3
`javascript
import { camelCase } from "text-camel-case";// From different cases
camelCase("hello world"); // "helloWorld"
camelCase("Hello World"); // "helloWorld"
camelCase("HELLO WORLD"); // "helloWorld"
camelCase("snake_case"); // "snakeCase"
camelCase("kebab-case"); // "kebabCase"
camelCase("dot.case"); // "dotCase"
camelCase("PascalCase"); // "pascalCase"
camelCase("CONSTANT_CASE"); // "constantCase"
// Complex examples
camelCase("XMLHttpRequest"); // "xmlHttpRequest"
camelCase("iPhone"); // "iPhone"
camelCase("version 1.2.3"); // "version123"
camelCase("user-profile-data"); // "userProfileData"
`$3
`javascript
import { camelCase, camelCaseTransformMerge } from "text-camel-case";// Custom transform to merge numbers without separator
camelCase("version 1.2.3", {
transform: camelCaseTransformMerge,
}); // "version123"
// Custom word splitting
camelCase("XMLHttpRequest", {
splitRegexp: /([a-z])([A-Z])/g,
}); // "xmlHttpRequest"
// Custom character stripping
camelCase("hello@world.com", {
stripRegexp: /[@.]/g,
}); // "helloWorldCom"
// Custom transformation function
camelCase("api-v2-endpoint", {
transform: (word, index) => {
if (word === "api") return "API";
if (word === "v2") return "V2";
return word;
},
}); // "APIV2Endpoint"
`๐ Real-World Examples
$3
`javascript
import { camelCase } from "text-camel-case";// API field names
camelCase("first_name"); // "firstName"
camelCase("email_address"); // "emailAddress"
camelCase("created_at"); // "createdAt"
camelCase("user_id"); // "userId"
camelCase("access_token"); // "accessToken"
`$3
`javascript
import { camelCase } from "text-camel-case";// CSS properties
camelCase("background-color"); // "backgroundColor"
camelCase("font-family"); // "fontFamily"
camelCase("border-radius"); // "borderRadius"
camelCase("margin-top"); // "marginTop"
camelCase("z-index"); // "zIndex"
`$3
`javascript
import { camelCase } from "text-camel-case";// Database columns
camelCase("user_profile"); // "userProfile"
camelCase("last_login_date"); // "lastLoginDate"
camelCase("is_active"); // "isActive"
camelCase("created_by_user_id"); // "createdByUserId"
`$3
`javascript
import { camelCase } from "text-camel-case";// Transform object keys from snake_case to camelCase
const dbUser = {
first_name: "John",
last_name: "Doe",
email_address: "john@example.com",
created_at: "2023-01-01",
};
const jsUser = Object.fromEntries(
Object.entries(dbUser).map(([key, value]) => [camelCase(key), value]),
);
console.log(jsUser);
// {
// firstName: "John",
// lastName: "Doe",
// emailAddress: "john@example.com",
// createdAt: "2023-01-01"
// }
`๐ API Reference
$3
Converts a string to camelCase.
#### Parameters
-
input (string): The string to convert
- options (Options, optional): Configuration options#### Returns
-
string: The camelCase formatted string#### Options
`typescript
interface Options {
// Custom transform function for word processing
transform?: (word: string, index: number, words: string[]) => string; // Regex to strip characters before processing
stripRegexp?: RegExp;
// Custom split function
split?: (value: string) => string[];
}
`$3
A transform function that merges numeric characters without separation.
`javascript
import { camelCase, camelCaseTransformMerge } from "text-camel-case";camelCase("version 1.2.3", { transform: camelCaseTransformMerge }); // "version123"
`๐ง Advanced Configuration
$3
`javascript
import { camelCase } from "text-camel-case";// Split on specific patterns
camelCase("XMLHttpRequest", {
splitRegexp: /([a-z])([A-Z])/g,
}); // "xmlHttpRequest"
// Split on numbers
camelCase("user123data", {
splitRegexp: /([a-zA-Z])(\d)/g,
}); // "user123Data"
`$3
`javascript
import { camelCase } from "text-camel-case";// Strip specific characters
camelCase("hello@world.com", {
stripRegexp: /[@.]/g,
}); // "helloWorldCom"
// Strip all non-alphanumeric
camelCase("hello!@#world", {
stripRegexp: /[^a-zA-Z0-9]/g,
}); // "helloWorld"
`$3
`javascript
import { camelCase } from "text-camel-case";// Preserve acronyms
camelCase("xml-http-request", {
transform: (word, index) => {
const acronyms = ["xml", "http", "api", "url"];
if (acronyms.includes(word.toLowerCase())) {
return word.toUpperCase();
}
return word;
},
}); // "XMLHTTPRequest"
// Custom business logic
camelCase("user-v2-api", {
transform: (word, index) => {
if (word === "v2") return "V2";
if (word === "api") return "API";
return word;
},
}); // "userV2API"
`๐ Bundle Size
This package is optimized for minimal bundle size:
- Minified: ~450B
- Gzipped: ~250B
- Tree-shakeable: Yes
- Side effects: None
๐ Browser Support
- Modern browsers: ES2015+ (Chrome 51+, Firefox 54+, Safari 10+)
- Node.js: 12+
- TypeScript: 4.0+
- Bundle formats: UMD, ESM, CommonJS
๐งช Testing
`bash
Run tests
pnpm testRun tests in watch mode
pnpm test --watchRun tests with coverage
pnpm test --coverageType checking
pnpm typecheckLinting
pnpm lint
`๐ Related Packages
text-capital-case - Convert to Capital Case
- text-constant-case - Convert to CONSTANT_CASE
- text-dot-case - Convert to dot.case
- text-header-case - Convert to Header-Case
- text-is-lower-case - Check if text is lower case
- text-case - All case transformations in one package๐ License
๐ค Contributing
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature`)- ๐ง Email: selikhov.dmitrey@gmail.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: Full Documentation
---
Made with โค๏ธ by Dmitry Selikhov
[npm-image]: https://img.shields.io/npm/v/text-camel-case.svg?style=flat
[npm-url]: https://npmjs.org/package/text-camel-case
[downloads-image]: https://img.shields.io/npm/dm/text-camel-case.svg?style=flat
[downloads-url]: https://npmjs.org/package/text-camel-case
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/text-camel-case.svg
[bundlephobia-url]: https://bundlephobia.com/result?p=text-camel-case