@lpm.dev/neo.case

Pool

case

Modern, comprehensive case conversion library - zero dependencies, TypeScript-first, tree-shakeable. Convert between camelCase, snake_case, kebab-case, and 7 more cases. 100% backward compatible with camelcase package.

install @lpm.dev/neo.case@v1.0.1

@lpm.dev/neo.case

Modern, comprehensive case conversion library - zero dependencies, TypeScript-first, tree-shakeable

Convert between camelCase, snake_case, kebab-case, and 7 more cases. 100% backward compatible with the popular camelcase package (90M+ downloads/week).

Features

✅ 10 case types - camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, dot.case, path/case, Sentence case, Title Case, Train-Case ✅ Zero dependencies - No external runtime dependencies ✅ Tree-shakeable - Import only what you need (~1.3 KB all cases, tree-shake to ~300-400 bytes per case) ✅ TypeScript-first - Built with TypeScript, full type safety ✅ 100% backward compatible - Drop-in replacement for camelcase package ✅ Fast - Competitive performance (0.9-1.2M ops/sec for camelCase) ✅ Unicode support - Handles international characters ✅ Modern - ESM + CJS, Node.js 18+, modern browsers

Install

lpm install @lpm.dev/neo.case

Usage

Basic Usage

import { camelCase, snakeCase, kebabCase } from "@lpm.dev/neo.case";

camelCase("foo-bar"); // 'fooBar'
snakeCase("fooBar"); // 'foo_bar'
kebabCase("FooBar"); // 'foo-bar'

All Case Types

import {
  camelCase,
  pascalCase,
  snakeCase,
  kebabCase,
  constantCase,
  dotCase,
  pathCase,
  sentenceCase,
  titleCase,
  trainCase,
} from "@lpm.dev/neo.case";

const input = "foo-bar-baz";

camelCase(input); // 'fooBarBaz'
pascalCase(input); // 'FooBarBaz'
snakeCase(input); // 'foo_bar_baz'
kebabCase(input); // 'foo-bar-baz'
constantCase(input); // 'FOO_BAR_BAZ'
dotCase(input); // 'foo.bar.baz'
pathCase(input); // 'foo/bar/baz'
sentenceCase(input); // 'Foo bar baz'
titleCase(input); // 'Foo Bar Baz'
trainCase(input); // 'Foo-Bar-Baz'

Backward Compatible with camelcase

import { camelCase } from "@lpm.dev/neo.case";

// All camelcase package features work identically
camelCase("foo-bar"); // 'fooBar'
camelCase("foo_bar"); // 'fooBar'
camelCase(["foo", "bar"]); // 'fooBar'
camelCase("foo-bar", { pascalCase: true }); // 'FooBar'
camelCase("розовый_пушистый"); // 'розовыйПушистый'

Tree-Shaking

Import only what you need for minimal bundle size:

// Import single case (~300-400 bytes gzipped)
import { camelCase } from "@lpm.dev/neo.case";

// Import multiple cases (~600-800 bytes gzipped)
import { camelCase, snakeCase, kebabCase } from "@lpm.dev/neo.case";

// Import all cases (~1.3 KB gzipped)
import * as cases from "@lpm.dev/neo.case";

API

Case Conversion Functions

camelCase(input, options?)

Convert to camelCase

camelCase("foo-bar"); // 'fooBar'
camelCase("foo_bar"); // 'fooBar'
camelCase("FooBar"); // 'fooBar'
camelCase(["foo", "bar"]); // 'fooBar'

// Options (backward compatible with camelcase package)
camelCase("foo-bar", { pascalCase: true }); // 'FooBar'
camelCase("foo-BAR", { preserveConsecutiveUppercase: true }); // 'fooBAR'
camelCase("lorem-ipsum", { locale: "tr-TR" }); // 'loremİpsum'

Options:

  • pascalCase?: boolean - Uppercase the first character (default: false)
  • preserveConsecutiveUppercase?: boolean - Preserve consecutive uppercase letters (default: false)
  • capitalizeAfterNumber?: boolean - Capitalize letters after numbers (default: true)
  • locale?: string | string[] | false - Locale for case conversion (default: host environment locale)
pascalCase(input, options?)

Convert to PascalCase. Alias for camelCase with pascalCase: true.

pascalCase("foo-bar"); // 'FooBar'
pascalCase("fooBar"); // 'FooBar'
snakeCase(input)

Convert to snake_case

snakeCase("fooBar"); // 'foo_bar'
snakeCase("FooBar"); // 'foo_bar'
kebabCase(input)

Convert to kebab-case

kebabCase("fooBar"); // 'foo-bar'
kebabCase("FooBar"); // 'foo-bar'
constantCase(input)

Convert to CONSTANT_CASE

constantCase("fooBar"); // 'FOO_BAR'
constantCase("foo-bar"); // 'FOO_BAR'
dotCase(input)

Convert to dot.case

dotCase("fooBar"); // 'foo.bar'
dotCase("foo-bar"); // 'foo.bar'
pathCase(input)

Convert to path/case

pathCase("fooBar"); // 'foo/bar'
pathCase("foo-bar"); // 'foo/bar'
sentenceCase(input)

Convert to Sentence case

sentenceCase("fooBar"); // 'Foo bar'
sentenceCase("foo-bar"); // 'Foo bar'
titleCase(input)

Convert to Title Case

titleCase("fooBar"); // 'Foo Bar'
titleCase("foo-bar"); // 'Foo Bar'
trainCase(input)

Convert to Train-Case

trainCase("fooBar"); // 'Foo-Bar'
trainCase("foo-bar"); // 'Foo-Bar'

Advanced API

split(input: string): string[]

Split a string into words

import { split } from "@lpm.dev/neo.case";

split("fooBar"); // ['foo', 'Bar']
split("foo-bar"); // ['foo', 'bar']
split("FOO_BAR"); // ['FOO', 'BAR']
split("foo2Bar"); // ['foo', '2', 'Bar']
transform(words: string[], options: TransformOptions): string

Transform an array of words with custom options

import { transform } from "@lpm.dev/neo.case";

transform(["foo", "bar"], {
  case: "lower",
  separator: "-",
}); // 'foo-bar'

transform(["foo", "bar"], {
  case: "capital",
  separator: " ",
}); // 'Foo Bar'

Migration from camelcase

@lpm.dev/neo.case is 100% backward compatible with the camelcase package. Simply replace the import:

- import camelCase from 'camelcase'
+ import { camelCase } from '@lpm.dev/neo.case'

// All existing code works identically
camelCase('foo-bar')  // 'fooBar'

Benefits of switching:

  • ✅ Same API - Zero code changes needed
  • ✅ More cases - Get 9 additional case types for free
  • ✅ Smaller bundle - Tree-shake to only what you need
  • ✅ TypeScript - Native TypeScript types (no @types package needed)

Performance

Benchmarks vs camelcase package (higher is better):

Operation neo.case original Comparison
camelCase('foo-bar') 1.24M ops/s 1.94M ops/s 0.64x
camelCase('FooBar') 1.07M ops/s 1.00M ops/s 1.07x faster ✅
camelCase with consecutive uppercase 1.12M ops/s 1.00M ops/s 1.11x faster ✅
camelCase with numbers 0.96M ops/s 0.90M ops/s 1.06x faster ✅

Summary: neo.case is competitive with camelcase for simple cases, and faster for complex cases (consecutive uppercase, numbers). Performance is excellent across all operations (0.9-1.2M ops/sec).

Bundle Size

Import Size (gzipped) Comparison
Full package (all 10 cases) ~1.33 KB 57% smaller than target
Single case (tree-shaken) ~300-400 bytes Tiny!
Three cases (camel + snake + kebab) ~600-800 bytes Very small

Comparison:

  • camelcase: ~2 KB minified (2 cases)
  • @lpm.dev/neo.case: ~1.33 KB gzipped (10 cases) ✅

Requirements

  • Node.js >= 18
  • Modern browsers (ES2022+)

TypeScript

Full TypeScript support with strict types:

import { camelCase, type CaseOptions } from "@lpm.dev/neo.case";

const options: CaseOptions = {
  pascalCase: true,
  locale: "en-US",
};

const result: string = camelCase("foo-bar", options);

License

MIT