CyrefJS
CCyrefJS
فا
Back to documentation
String/Since 1.38.0

kebabCase

Converts a string into kebab-case by tokenizing it, converting every word to lowercase, and joining the words with hyphens.

kebabCase(value):string

Behavior

kebabCase first tokenizes the input into words. Each word is converted to lowercase, and the resulting words are joined using a hyphen.

Tokenization

Word extraction is delegated to the internal tokenize utility. The exact word boundaries therefore depend on tokenize.

Lowercase conversion

Every token is converted entirely to lowercase before the tokens are joined.

Separator

The resulting tokens are joined with a single hyphen character.

Parameters

valuestringrequired

The string to convert to kebab-case.

Returns

string

The tokenized input converted to lowercase and joined with hyphens.

Examples

01

Basic usage

Convert a space-separated phrase to kebab-case.

TypeScript
import { kebabCase } from "@cyref/js";

kebabCase("hello world");
// "hello-world"
02

Multiple words

Each token is lowercased and separated with a hyphen.

TypeScript
kebabCase("Hello Beautiful World");
// "hello-beautiful-world"
03

Mixed case

The casing of every token is normalized to lowercase.

TypeScript
kebabCase("hello WoRLD TeST");
// "hello-world-test"
04

Single word

A single token is simply converted to lowercase.

TypeScript
kebabCase("HELLO");
// "hello"
05

Empty input

If tokenization produces no words, an empty string is returned.

TypeScript
kebabCase("");
// ""
06

Existing separators

The input is tokenized first, then the resulting words are joined with hyphens.

TypeScript
kebabCase("hello-world");
// "hello-world"
Built with@cyref/js·Official documentation