Hackinet/is-camel-case

★ 0Forks 0TypeScriptGitHub ↗Compare

README

is-camel-case

npm version npm downloads bundle size license

Check if a string is camelCase

A tiny, zero-dependency utility that returns true if a string is valid camelCase (starts lowercase, with uppercase letters separating words). Built with TypeScript — types included out of the box.

What is camelCase?

camelCase is a naming convention where the first word is lowercase and subsequent words are capitalized with no separators:

  • helloWorld — camelCase
  • getElementById — camelCase
  • HelloWorld — not camelCase (PascalCase)
  • hello-world — not camelCase (kebab-case)
  • hello_world — not camelCase (snake_case)

Install

npm install is-camel-case

Usage

import { isCamelCase } from "is-camel-case";

isCamelCase("fooBar");          // true
isCamelCase("helloWorld");      // true
isCamelCase("getElementById");  // true
isCamelCase("parseJSON");       // true
isCamelCase("getV2Api");        // true

isCamelCase("foo");             // false (no uppercase letter)
isCamelCase("FooBar");          // false (PascalCase)
isCamelCase("foo-bar");         // false (kebab-case)
isCamelCase("foo_bar");         // false (snake_case)
isCamelCase("FOO_BAR");         // false (SCREAMING_CASE)
isCamelCase("");                // false (empty string)
isCamelCase("1fooBar");         // false (starts with number)

CommonJS

const { isCamelCase } = require("is-camel-case");

TypeScript

Types are included — no need to install @types/is-camel-case.

import { isCamelCase } from "is-camel-case";
// isCamelCase(str: string) => boolean

Related

License

MIT - Piyush Jha

Contributors

Hackinet

Issues