Skip to content

Commit c895c57

Browse files
committed
Merge branch 'main' of https://github.com/so1ve/clerc
2 parents 7f9ebe0 + 9bd272a commit c895c57

File tree

3 files changed

+194
-181
lines changed

3 files changed

+194
-181
lines changed

packages/core/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export class Clerc<C extends Commands = {}> {
488488
*/
489489
runMatchedCommand() {
490490
this.#callWithErrorHandling(() => this.#runMatchedCommand());
491+
process.title = this.#name;
491492
return this;
492493
}
493494
}

packages/utils/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@ export type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<ToArray<E>
1414

1515
export const toArray = <T>(a: MaybeArray<T>) => Array.isArray(a) ? a : [a];
1616

17-
export type CamelCase<T extends string> = (T extends `${infer Prefix}-${infer Suffix}` | `${infer Prefix} ${infer Suffix}` ? `${Prefix}${Capitalize<CamelCase<Suffix>>}` : T);
18-
export const camelCase = <T extends string>(s: T) => s.replace(/[-_ ](\w)/g, (_, c) => c.toUpperCase()) as CamelCase<T>;
17+
type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
18+
type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
19+
type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
20+
21+
export type CamelCase<Word extends string> = (
22+
Word extends `${infer FirstCharacter}${infer Rest}`
23+
? (
24+
FirstCharacter extends AlphaNumeric
25+
? `${FirstCharacter}${CamelCase<Rest>}`
26+
: Capitalize<CamelCase<Rest>>
27+
)
28+
: Word
29+
);
30+
export const camelCase = (word: string) => word.replace(/[\W_]([a-z\d])?/gi, (_, c) => (c ? c.toUpperCase() : ""));
1931

2032
export type KebabCase<T extends string, A extends string = ""> = T extends `${infer Prefix}${infer Suffix}`
2133
? KebabCase<Suffix, `${A}${Prefix extends Lowercase<Prefix> ? "" : "-"}${Lowercase<Prefix>}`>

0 commit comments

Comments
 (0)