is-kebab-case
v1.0.3
Published
Check if a string is kebab-case
Maintainers
Readme
is-kebab-case
Check if a string is kebab-case
A tiny, zero-dependency utility that returns true if a string is valid kebab-case (lowercase words separated by hyphens). Built with TypeScript — types included out of the box.
What is kebab-case?
Kebab-case is a naming convention where words are lowercase and separated by hyphens:
hello-world— kebab-casemy-component-name— kebab-casehelloWorld— not kebab-case (camelCase)hello_world— not kebab-case (snake_case)HelloWorld— not kebab-case (PascalCase)
Install
npm install is-kebab-caseUsage
import { isKebabCase } from "is-kebab-case";
isKebabCase("foo-bar"); // true
isKebabCase("foo-bar-baz"); // true
isKebabCase("hello"); // true
isKebabCase("h1-heading"); // true
isKebabCase("fooBar"); // false (camelCase)
isKebabCase("foo_bar"); // false (snake_case)
isKebabCase("FooBar"); // false (PascalCase)
isKebabCase("FOO-BAR"); // false (uppercase)
isKebabCase(""); // false (empty string)
isKebabCase("-foo"); // false (leading hyphen)
isKebabCase("foo-"); // false (trailing hyphen)
isKebabCase("foo--bar"); // false (consecutive hyphens)
isKebabCase("123-bar"); // false (starts with number)CommonJS
const { isKebabCase } = require("is-kebab-case");TypeScript
Types are included — no need to install @types/is-kebab-case.
import { isKebabCase } from "is-kebab-case";
// isKebabCase(str: string) => booleanRelated
- is-camel-case — Check if a string is camelCase
License
MIT - Piyush Jha
