Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 15, 2023
1 parent 9242c33 commit 3e4cd49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export function isUppercase(char = ""): boolean | undefined {
export function splitByCase<T extends string>(string_: T): SplitByCase<T>;
export function splitByCase<
T extends string,
Separator extends readonly string[]
Separator extends readonly string[],
>(string_: T, separators: Separator): SplitByCase<T, Separator[number]>;
export function splitByCase<
T extends string,
Separator extends readonly string[]
Separator extends readonly string[],
>(string_: T, separators?: Separator) {
const splitters = separators ?? STR_SPLITTERS;
const parts: string[] = [];
Expand Down Expand Up @@ -91,7 +91,7 @@ export function lowerFirst<S extends string>(string_: S): Uncapitalize<S> {

export function pascalCase(): "";
export function pascalCase<T extends string | readonly string[]>(
string_: T
string_: T,
): PascalCase<T>;
export function pascalCase<T extends string | readonly string[]>(string_?: T) {
return string_
Expand All @@ -103,23 +103,23 @@ export function pascalCase<T extends string | readonly string[]>(string_?: T) {

export function camelCase(): "";
export function camelCase<T extends string | readonly string[]>(
string_: T
string_: T,
): CamelCase<T>;
export function camelCase<T extends string | readonly string[]>(string_?: T) {
return lowerFirst(pascalCase(string_ || "")) as CamelCase<T>;
}

export function kebabCase(): "";
export function kebabCase<T extends string | readonly string[]>(
string_: T
string_: T,
): KebabCase<T>;
export function kebabCase<
T extends string | readonly string[],
Joiner extends string
Joiner extends string,
>(string_: T, joiner: Joiner): KebabCase<T, Joiner>;
export function kebabCase<
T extends string | readonly string[],
Joiner extends string
Joiner extends string,
>(string_?: T, joiner?: Joiner) {
return string_
? ((Array.isArray(string_) ? string_ : splitByCase(string_ as string))
Expand All @@ -130,7 +130,7 @@ export function kebabCase<

export function snakeCase(): "";
export function snakeCase<T extends string | readonly string[]>(
string_: T
string_: T,
): SnakeCase<T>;
export function snakeCase<T extends string | readonly string[]>(string_?: T) {
return kebabCase(string_ || "", "_") as SnakeCase<T>;
Expand Down
19 changes: 9 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ export type SplitByCase<
type JoinByCase<T, Joiner extends string> = string extends T
? string
: string[] extends T
? string
: T extends string
? SplitByCase<T> extends readonly string[]
? JoinLowercaseWords<SplitByCase<T>, Joiner>
: never
: T extends readonly string[]
? JoinLowercaseWords<T, Joiner>
: never;
? string
: T extends string
? SplitByCase<T> extends readonly string[]
? JoinLowercaseWords<SplitByCase<T>, Joiner>
: never
: T extends readonly string[]
? JoinLowercaseWords<T, Joiner>
: never;

export type PascalCase<T> = string extends T
? string
Expand All @@ -129,10 +129,9 @@ export type CamelCase<T> = string extends T
? string
: Uncapitalize<PascalCase<T>>;


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

export type SnakeCase<T extends string | readonly string[]> = JoinByCase<
Expand Down

0 comments on commit 3e4cd49

Please sign in to comment.