Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Schniz/cmd-ts. 💻 A type-driven command line argument parser cmd-ts.now.sh
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import stripAnsi from "strip-ansi";
/** * @ignore */export function padNoAnsi( str: string, length: number, place: "end" | "start",): string { const noAnsiStr = stripAnsi(str); if (length < noAnsiStr.length) return str; const pad = Array(length - noAnsiStr.length + 1).join(" "); if (place === "end") { return str + pad; } return pad + str;}
/** * Group an array by a function that returns the key * * @ignore */export function groupBy<A, B extends string>( objs: A[], f: (a: A) => B,): Record<B, A[]> { const result = {} as Record<B, A[]>; for (const obj of objs) { const key = f(obj); result[key] = result[key] ?? []; result[key].push(obj); } return result;}
/** * A better typed version of `Object.entries` * * @ignore */export function entries<Obj extends Record<string, any>>( obj: Obj,): { [key in keyof Obj]: [key, Obj[key]] }[keyof Obj][] { return Object.entries(obj);}
/** * Enumerate over a list, to get a pair of [index, value] * * @ignore */export function* enumerate<T>(arr: T[]): Generator<[number, T]> { for (let i = 0; i < arr.length; i++) { yield [i, arr[i]]; }}
/** * Array#flatMap polyfill * * @ignore */export function flatMap<A, B>(xs: A[], fn: (a: A) => B[]): B[] { const results: B[] = []; for (const x of xs) { results.push(...fn(x)); } return results;}
/** * Flatten an array * * @ignore */export function flatten<A>(xs: A[][]): A[] { const results: A[] = []; for (const x of xs) { results.push(...x); } return results;}
/** * Either the provided `T` or an empty object */export type AllOrNothing<T> = T | { [key in keyof T]?: never };