deno.land / std@0.224.0 / text / case.ts

View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { capitalizeWord, splitToWords } from "./_util.ts";
/** * Converts a string into camelCase. * * @example * ```ts * import { toCamelCase } from "https://deno.land/std@$STD_VERSION/text/case.ts"; * * toCamelCase("deno is awesome"); // "denoIsAwesome" * ``` * * @param input The string that is going to be converted into camelCase * @returns The string as camelCase */export function toCamelCase(input: string): string { input = input.trim(); const [first = "", ...rest] = splitToWords(input); return [first.toLocaleLowerCase(), ...rest.map(capitalizeWord)].join("");}
/** * Converts a string into kebab-case. * * @example * ```ts * import { toKebabCase } from "https://deno.land/std@$STD_VERSION/text/case.ts"; * * 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();}
/** * Converts a string into PascalCase. * * @example * ```ts * import { toPascalCase } from "https://deno.land/std@$STD_VERSION/text/case.ts"; * * toPascalCase("deno is awesome"); // "DenoIsAwesome" * ``` * * @param input The string that is going to be converted into PascalCase * @returns The string as PascalCase */export function toPascalCase(input: string): string { input = input.trim(); return splitToWords(input).map(capitalizeWord).join("");}
/** * Converts a string into snake_case. * * @example * ```ts * import { toSnakeCase } from "https://deno.land/std@$STD_VERSION/text/case.ts"; * toSnakeCase("deno is awesome"); // "deno_is_awesome" * ``` * * @param input The string that is going to be converted into snake_case * @returns The string as snake_case */export function toSnakeCase(input: string): string { input = input.trim(); return splitToWords(input).join("_").toLocaleLowerCase();}
std

Version Info

Tagged at
6 months ago