es-toolkit/docs/reference/string/kebabCase.md
2024-07-14 16:06:42 +09:00

723 B

kebabCase

Converts a string to kebab case.

Kebab case is the naming convention in which each word is written in lowercase and separated by an dash (-) character. For example, kebab-case.

Signature

function kebabCase(str: string): string;

Parameters

  • str (string): The string that is to be changed to kebab case.

Returns

(string) The converted string to kebab case.

Examples

import { kebabCase } from 'es-toolkit/string';

kebabCase('camelCase'); // returns 'camel-case'
kebabCase('some whitespace'); // returns 'some-whitespace'
kebabCase('hyphen-text'); // returns 'hyphen-text'
kebabCase('HTTPRequest'); // returns 'http-request'