# text-camel-case

> Convert into a text with the separator denoted by the next word capitalized

Latest version **1.2.11** (published 2026-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install text-camel-case
pnpm add text-camel-case
yarn add text-camel-case
bun add text-camel-case
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.11 |
| Published | 2026-05-19 |
| First published | 2020-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Dmitry Selikhov |
| Maintainers | dimetrix |
| Keywords | camel, case, camelcase, camel-case, convert, transform, identifier |

## Links

- npm: https://www.npmjs.com/package/text-camel-case
- Repository: https://github.com/idimetrix/text-case
- Homepage: https://github.com/idimetrix/text-case/tree/master/packages/camel-case#readme
- Issues: https://github.com/idimetrix/text-case/issues
- npm.io page: https://npm.io/package/text-camel-case

## Dependencies (1)

- [text-pascal-case](https://npm.io/package/text-pascal-case.md) ^1.2.11

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.2.11 (latest) — 2026-05-19
- 1.2.10 — 2026-01-15
- 1.2.9 — 2025-09-25
- 1.2.8 — 2025-09-25
- 1.2.7 — 2025-09-25
- 1.2.5 — 2025-09-25
- 1.2.4 — 2025-06-03
- 1.2.3 — 2025-06-02
- 1.2.0 — 2025-06-02
- 1.0.2 — 2020-10-07
- 1.0.0 — 2020-01-03

## README

# Camel Case

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Bundle size][bundlephobia-image]][bundlephobia-url]
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)

> Transform text into **camelCase** format where the first letter is lowercase and subsequent words have their first letter capitalized with no separators.

## 🚀 Features

- **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

## 📦 Installation

```bash
# npm
npm install text-camel-case

# yarn
yarn add text-camel-case

# pnpm
pnpm add text-camel-case

# bun
bun add 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

### ES Modules (Recommended)

```javascript
import { camelCase } from "text-camel-case";

console.log(camelCase("hello world")); // "helloWorld"
```

### CommonJS

```javascript
const { camelCase } = require("text-camel-case");

console.log(camelCase("hello world")); // "helloWorld"
```

### TypeScript

```typescript
import { camelCase, camelCaseTransformMerge, Options } from "text-camel-case";

const result: string = camelCase("hello world");
console.log(result); // "helloWorld"
```

## 🔄 Transformation Examples

### Basic Transformations

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

### Advanced Options

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

### JavaScript Variables

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

### CSS Properties to JavaScript

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

### Database Columns to Object Properties

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

### Object Key Transformation

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

### `camelCase(input, options?)`

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[];
}
```

### `camelCaseTransformMerge`

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

### Custom Word Splitting

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

### Custom Character Stripping

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

### Custom Transform Functions

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

# Run tests in watch mode
pnpm test --watch

# Run tests with coverage
pnpm test --coverage

# Type checking
pnpm typecheck

# Linting
pnpm lint
```

## 🔗 Related Packages

- [`text-capital-case`](https://www.npmjs.com/package/text-capital-case) - Convert to Capital Case
- [`text-constant-case`](https://www.npmjs.com/package/text-constant-case) - Convert to CONSTANT_CASE
- [`text-dot-case`](https://www.npmjs.com/package/text-dot-case) - Convert to dot.case
- [`text-header-case`](https://www.npmjs.com/package/text-header-case) - Convert to Header-Case
- [`text-is-lower-case`](https://www.npmjs.com/package/text-is-lower-case) - Check if text is lower case
- [`text-case`](https://www.npmjs.com/package/text-case) - All case transformations in one package

## 📜 License

[MIT](LICENSE) © [Dmitry Selikhov](https://github.com/idimetrix)

## 🤝 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`)
5. Open a Pull Request

## 🆘 Support

- 📧 **Email**: [selikhov.dmitrey@gmail.com](mailto:selikhov.dmitrey@gmail.com)
- 🐛 **Issues**: [GitHub Issues](https://github.com/idimetrix/text-case/issues)
- 💬 **Discussions**: [GitHub Discussions](https://github.com/idimetrix/text-case/discussions)
- 📖 **Documentation**: [Full Documentation](https://github.com/idimetrix/text-case#readme)

---

**Made with ❤️ by [Dmitry Selikhov](https://github.com/idimetrix)**

[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

---
_Source: https://npm.io/package/text-camel-case · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
