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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import 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; } else { 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 };