@clerc/utils
Version:
26 lines (23 loc) • 2.4 kB
TypeScript
import * as _clerc_core from '@clerc/core';
import { I18N, Commands, CommandType, TranslateFn, Command, RootType, Root } from '@clerc/core';
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
type Dict<T> = Record<string, T>;
type ToArray<T> = T extends any[] ? T : [T];
type MaybeArray<T> = T | T[];
declare const toArray: <T>(a: MaybeArray<T>) => T[];
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";
type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
type CamelCase<Word extends string> = Word extends `${infer FirstCharacter}${infer Rest}` ? FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>> : Word;
declare const camelCase: (word: string) => string;
type KebabCase<T extends string, A extends string = ""> = T extends `${infer Prefix}${infer Suffix}` ? KebabCase<Suffix, `${A}${Prefix extends Lowercase<Prefix> ? "" : "-"}${Lowercase<Prefix>}`> : A;
declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
declare const gracefulFlagName: (n: string) => string;
declare const gracefulVersion: (v: string) => string;
declare function arrayEquals<T>(arr1: T[], arr2: T[]): boolean;
declare function arrayStartsWith<T>(arr: T[], start: T[]): boolean;
declare function semanticArray(arr: string[], { add, t }: I18N): string;
declare function resolveCommandStrict(commands: Commands, name: CommandType | string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
declare function resolveSubcommandsByParent(commands: Commands, parent: string | string[], depth?: number): Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
declare const resolveRootCommands: (commands: Commands) => Command<string, _clerc_core.CommandOptions<string[], MaybeArray<string | typeof Root>, _clerc_core.Flags>>[];
export { CamelCase, Dict, Equals, KebabCase, MaybeArray, ToArray, arrayEquals, arrayStartsWith, camelCase, gracefulFlagName, gracefulVersion, kebabCase, resolveCommandStrict, resolveRootCommands, resolveSubcommandsByParent, semanticArray, toArray };