std/text/to_constant_case.ts
Asher Gomez dea7d7701a
docs(archive,assert,cache,cli,encoding,html,http,net,streams,text): remove unstable Markdown alert (#5672)
* docs(archive,cli,html,http,net,streams,text): remove unstable Markdown alert

* update

* fix

* update

* fmt

* fix
2024-08-22 02:55:17 -04:00

26 lines
795 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 CONSTANT_CASE (also known as SCREAMING_SNAKE_CASE).
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @example Usage
* ```ts
* import { toConstantCase } from "@std/text/to-constant-case";
* import { assertEquals } from "@std/assert/equals";
*
* assertEquals(toConstantCase("deno is awesome"), "DENO_IS_AWESOME");
* ```
*
* @param input The string that is going to be converted into CONSTANT_CASE
* @returns The string as CONSTANT_CASE
*/
export function toConstantCase(input: string): string {
input = input.trim();
return splitToWords(input).join("_").toLocaleUpperCase();
}