diff --git a/text/case.ts b/text/case.ts deleted file mode 100644 index dfab12916..000000000 --- a/text/case.ts +++ /dev/null @@ -1,81 +0,0 @@ -// 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 Usage - * ```ts - * import { toCamelCase } from "@std/text/case"; - * import { assertEquals } from "@std/assert"; - * - * assertEquals(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 Usage - * ```ts - * import { toKebabCase } from "@std/text/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(); -} - -/** - * Converts a string into PascalCase. - * - * @example Usage - * ```ts - * import { toPascalCase } from "@std/text/case"; - * import { assertEquals } from "@std/assert"; - * - * assertEquals(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 Usage - * ```ts - * import { toSnakeCase } from "@std/text/case"; - * import { assertEquals } from "@std/assert"; - * - * assertEquals(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(); -} diff --git a/text/case_test.ts b/text/case_test.ts index 5d0e04cd9..39d2ef57d 100644 --- a/text/case_test.ts +++ b/text/case_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { assertEquals } from "@std/assert"; -import { toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./case.ts"; +import { toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./mod.ts"; Deno.test("toCamelCase() handles an empty string", () => { assertEquals(toCamelCase(""), ""); diff --git a/text/deno.json b/text/deno.json index e6abbeba9..0aea8d9ac 100644 --- a/text/deno.json +++ b/text/deno.json @@ -3,10 +3,13 @@ "version": "1.0.0-rc.3", "exports": { ".": "./mod.ts", - "./case": "./case.ts", "./closest-string": "./closest_string.ts", "./compare-similarity": "./compare_similarity.ts", "./levenshtein-distance": "./levenshtein_distance.ts", + "./to-camel-case": "./to_camel_case.ts", + "./to-kebab-case": "./to_kebab_case.ts", + "./to-pascal-case": "./to_pascal_case.ts", + "./to-snake-case": "./to_snake_case.ts", "./word-similarity-sort": "./word_similarity_sort.ts" } } diff --git a/text/mod.ts b/text/mod.ts index 65e4efd52..41914de6e 100644 --- a/text/mod.ts +++ b/text/mod.ts @@ -23,4 +23,7 @@ export * from "./levenshtein_distance.ts"; export * from "./closest_string.ts"; export * from "./compare_similarity.ts"; export * from "./word_similarity_sort.ts"; -export * from "./case.ts"; +export * from "./to_camel_case.ts"; +export * from "./to_kebab_case.ts"; +export * from "./to_pascal_case.ts"; +export * from "./to_snake_case.ts"; diff --git a/text/to_camel_case.ts b/text/to_camel_case.ts new file mode 100644 index 000000000..8e8c8ce44 --- /dev/null +++ b/text/to_camel_case.ts @@ -0,0 +1,24 @@ +// 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 Usage + * ```ts + * import { toCamelCase } from "@std/text/to-camel-case"; + * import { assertEquals } from "@std/assert"; + * + * assertEquals(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(""); +} diff --git a/text/to_kebab_case.ts b/text/to_kebab_case.ts new file mode 100644 index 000000000..a749d2da9 --- /dev/null +++ b/text/to_kebab_case.ts @@ -0,0 +1,23 @@ +// 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(); +} diff --git a/text/to_pascal_case.ts b/text/to_pascal_case.ts new file mode 100644 index 000000000..8c1386e35 --- /dev/null +++ b/text/to_pascal_case.ts @@ -0,0 +1,23 @@ +// 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 PascalCase. + * + * @example Usage + * ```ts + * import { toPascalCase } from "@std/text/to-pascal-case"; + * import { assertEquals } from "@std/assert"; + * + * assertEquals(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(""); +} diff --git a/text/to_snake_case.ts b/text/to_snake_case.ts new file mode 100644 index 000000000..609fdddd2 --- /dev/null +++ b/text/to_snake_case.ts @@ -0,0 +1,23 @@ +// 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 snake_case. + * + * @example Usage + * ```ts + * import { toSnakeCase } from "@std/text/to-snake-case"; + * import { assertEquals } from "@std/assert"; + * + * assertEquals(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(); +}