1.38.0kebabCase
Converts a string into kebab-case by tokenizing it, converting every word to lowercase, and joining the words with hyphens.
kebabCase(value):stringBehavior
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
valuestringrequiredThe string to convert to kebab-case.
Returns
stringThe tokenized input converted to lowercase and joined with hyphens.
Examples
Basic usage
Convert a space-separated phrase to kebab-case.
import { kebabCase } from "@cyref/js";
kebabCase("hello world");
// "hello-world"Multiple words
Each token is lowercased and separated with a hyphen.
kebabCase("Hello Beautiful World");
// "hello-beautiful-world"Mixed case
The casing of every token is normalized to lowercase.
kebabCase("hello WoRLD TeST");
// "hello-world-test"Single word
A single token is simply converted to lowercase.
kebabCase("HELLO");
// "hello"Empty input
If tokenization produces no words, an empty string is returned.
kebabCase("");
// ""Existing separators
The input is tokenized first, then the resulting words are joined with hyphens.
kebabCase("hello-world");
// "hello-world"