From 1a6ba3a1c25eb18a50306454c4652e8be97c21ff Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 23 Oct 2023 22:59:49 +0900 Subject: [PATCH] feat: add `SnakeCase` and `KebabCase` helpers --- src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7180c57..21ea5dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -105,10 +105,12 @@ export function camelCase(string_?: T) { return lowerFirst(pascalCase(string_ || "")) as CamelCase; } +export type KebabCase = JoinByCase + export function kebabCase(): ""; export function kebabCase( string_: T -): JoinByCase; +): KebabCase; export function kebabCase< T extends string | readonly string[], Joiner extends string @@ -124,10 +126,12 @@ export function kebabCase< .join(joiner ?? "-") as JoinByCase); } +export type SnakeCase = JoinByCase + export function snakeCase(): ""; export function snakeCase( string_: T -): JoinByCase; +): SnakeCase; export function snakeCase(string_?: T) { - return kebabCase(string_ || "", "_") as JoinByCase; + return kebabCase(string_ || "", "_") as SnakeCase; }