mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
24 lines
669 B
TypeScript
24 lines
669 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
import { splitToWords } from "./_util.ts";
|
|
|
|
/**
|
|
* Converts a string into kebab-case.
|
|
*
|
|
* @example Usage
|
|
* ```ts
|
|
* import { toKebabCase } from "@std/text/to-kebab-case";
|
|
* import { assertEquals } from "@std/assert";
|
|
*
|
|
* assertEquals(toKebabCase("deno is awesome"), "deno-is-awesome");
|
|
* ```
|
|
*
|
|
* @param input The string that is going to be converted into kebab-case
|
|
* @returns The string as kebab-case
|
|
*/
|
|
export function toKebabCase(input: string): string {
|
|
input = input.trim();
|
|
return splitToWords(input).join("-").toLocaleLowerCase();
|
|
}
|