BREAKING(text): align to single-export file pattern (#5428)

This commit is contained in:
Yoshiya Hinosawa 2024-07-16 12:39:39 +09:00 committed by GitHub
parent df388b18e3
commit 63912921b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 102 additions and 84 deletions

View File

@ -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();
}

View File

@ -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(""), "");

View File

@ -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"
}
}

View File

@ -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";

24
text/to_camel_case.ts Normal file
View File

@ -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("");
}

23
text/to_kebab_case.ts Normal file
View File

@ -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();
}

23
text/to_pascal_case.ts Normal file
View File

@ -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("");
}

23
text/to_snake_case.ts Normal file
View File

@ -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();
}