2024-07-22 00:49:57 +00:00
|
|
|
// 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).
|
|
|
|
*
|
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 06:55:17 +00:00
|
|
|
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
2024-07-22 00:49:57 +00:00
|
|
|
*
|
|
|
|
* @example Usage
|
|
|
|
* ```ts
|
2024-09-12 04:51:21 +00:00
|
|
|
* import { toConstantCase } from "@std/text/unstable-to-constant-case";
|
2024-07-22 00:49:57 +00:00
|
|
|
* 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();
|
|
|
|
}
|