Skip to content

Commit

Permalink
feat: add SnakeCase and KebabCase helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 23, 2023
1 parent fd47cf9 commit 1a6ba3a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ export function camelCase<T extends string | readonly string[]>(string_?: T) {
return lowerFirst(pascalCase(string_ || "")) as CamelCase<T>;
}

export type KebabCase<T extends string | readonly string[]> = JoinByCase<T, "-">

export function kebabCase(): "";
export function kebabCase<T extends string | readonly string[]>(
string_: T
): JoinByCase<T, "-">;
): KebabCase<T>;
export function kebabCase<
T extends string | readonly string[],
Joiner extends string
Expand All @@ -124,10 +126,12 @@ export function kebabCase<
.join(joiner ?? "-") as JoinByCase<T, Joiner>);
}

export type SnakeCase<T extends string | readonly string[]> = JoinByCase<T, "_">

export function snakeCase(): "";
export function snakeCase<T extends string | readonly string[]>(
string_: T
): JoinByCase<T, "_">;
): SnakeCase<T>;
export function snakeCase<T extends string | readonly string[]>(string_?: T) {
return kebabCase(string_ || "", "_") as JoinByCase<T, "_">;
return kebabCase(string_ || "", "_") as SnakeCase<T>;
}

0 comments on commit 1a6ba3a

Please sign in to comment.