Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ts): move and tsify most of root yargs.js to lib/yargs (#1670)
- Loading branch information
Showing
16 changed files
with
2,060 additions
and
1,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,48 @@ | ||
import { notStrictEqual } from 'assert' | ||
import { notStrictEqual, strictEqual } from 'assert' | ||
|
||
/** | ||
* An object whose all properties have the same type. | ||
*/ | ||
export type Dictionary<T = any> = { [key: string]: T } | ||
|
||
/** | ||
* Returns the keys of T that match Dictionary<U> and are not arrays. | ||
*/ | ||
export type DictionaryKeyof<T, U = any> = Exclude<KeyOf<T, Dictionary<U>>, KeyOf<T, any[]>> | ||
|
||
/** | ||
* Returns the keys of T that match U. | ||
*/ | ||
export type KeyOf<T, U> = Exclude<{ [K in keyof T]: T[K] extends U ? K : never }[keyof T], undefined> | ||
|
||
/** | ||
* An array whose first element is not undefined. | ||
*/ | ||
export type NotEmptyArray<T = any> = [T, ...T[]] | ||
|
||
export function assertNotTrue<T = any> (actual: T | true): asserts actual is T { | ||
notStrictEqual(actual, true) | ||
/** | ||
* Returns the type of a Dictionary or array values. | ||
*/ | ||
export type ValueOf<T> = T extends (infer U)[] ? U : T[keyof T]; | ||
|
||
/** | ||
* Typing wrapper around assert.notStrictEqual() | ||
*/ | ||
export function assertNotStrictEqual<N, T> (actual: T|N, expected: N, message ?: string | Error) | ||
: asserts actual is Exclude<T, N> { | ||
notStrictEqual(actual, expected, message) | ||
} | ||
|
||
/** | ||
* Asserts actual is a single key, not a key array or a key map. | ||
*/ | ||
export function assertSingleKey (actual: string | string[] | Dictionary): asserts actual is string { | ||
strictEqual(typeof actual, 'string') | ||
} | ||
|
||
export function assertNotUndefined<T = any> (actual: T | undefined): asserts actual is T { | ||
notStrictEqual(actual, undefined) | ||
/** | ||
* Typing wrapper around Object.keys() | ||
*/ | ||
export function objectKeys<T> (object: T) { | ||
return Object.keys(object) as (keyof T)[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// TODO: either create @types/require-main-filename or or convert require-main-filename to typescript | ||
|
||
/** | ||
* Returns the entry point of the current application. | ||
* | ||
* `require.main.filename` is great for figuring out the entry point for the current application. | ||
* This can be combined with a module like pkg-conf to, as if by magic, load top-level configuration. | ||
* | ||
* Unfortunately, `require.main.filename` sometimes fails when an application is executed | ||
* with an alternative process manager, e.g., iisnode. | ||
* | ||
* `require-main-filename` is a shim that addresses this problem. | ||
* | ||
* @param _require require function | ||
* @returns hash of modules in specified directory | ||
*/ | ||
declare function requireMainFilename(_require: NodeRequire): string; | ||
|
||
declare module 'require-main-filename' { | ||
export = requireMainFilename; | ||
} |
Oops, something went wrong.