mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
BREAKING(text): align to single-export file pattern (#5428)
This commit is contained in:
parent
df388b18e3
commit
63912921b3
81
text/case.ts
81
text/case.ts
@ -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();
|
||||
}
|
@ -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(""), "");
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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
24
text/to_camel_case.ts
Normal 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
23
text/to_kebab_case.ts
Normal 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
23
text/to_pascal_case.ts
Normal 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
23
text/to_snake_case.ts
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user