-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from samchon/features/primitive
Close #511 - `random()` became customizable
- Loading branch information
Showing
21 changed files
with
418 additions
and
241 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
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,16 +1,16 @@ | ||
export interface IRandomGenerator { | ||
boolean(): boolean; | ||
int(minimum?: number, maximum?: number): number; | ||
integer(minimum?: number, maximum?: number): number; | ||
number(minimum?: number, maximum?: number): number; | ||
bigint(minimum?: bigint, maximum?: bigint): bigint; | ||
string(length?: number): string; | ||
array<T>(closure: (index: number) => T, count?: number): T[]; | ||
|
||
uuid?(): string; | ||
email?(): string; | ||
url?(): string; | ||
ipv4?(): string; | ||
ipv6?(): string; | ||
pattern?(regex: RegExp): string; | ||
date?(): string; | ||
uuid(): string; | ||
email(): string; | ||
url(): string; | ||
ipv4(): string; | ||
ipv6(): string; | ||
pattern(regex: RegExp): string; | ||
date(): string; | ||
} |
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,89 @@ | ||
import type CommanderModule from "commander"; | ||
import type * as InquirerModule from "inquirer"; | ||
import path from "path"; | ||
|
||
import { PackageManager } from "./PackageManager"; | ||
|
||
export namespace ArgumentParser { | ||
export type Inquiry<T> = ( | ||
pack: PackageManager, | ||
command: CommanderModule.Command, | ||
prompt: ( | ||
opt?: InquirerModule.StreamOptions, | ||
) => InquirerModule.PromptModule, | ||
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>, | ||
) => Promise<T>; | ||
|
||
export const parse = | ||
(pack: PackageManager) => | ||
(erase: boolean) => | ||
async <T>( | ||
inquiry: ( | ||
pack: PackageManager, | ||
command: CommanderModule.Command, | ||
prompt: ( | ||
opt?: InquirerModule.StreamOptions, | ||
) => InquirerModule.PromptModule, | ||
action: ( | ||
closure: (options: Partial<T>) => Promise<T>, | ||
) => Promise<T>, | ||
) => Promise<T>, | ||
): Promise<T> => { | ||
// INSTALL TEMPORARY PACKAGES | ||
const newbie = { | ||
commander: pack.install({ | ||
dev: true, | ||
modulo: "commander", | ||
version: "10.0.0", | ||
silent: true, | ||
}), | ||
inquirer: pack.install({ | ||
dev: true, | ||
modulo: "inquirer", | ||
version: "8.2.5", | ||
silent: true, | ||
}), | ||
}; | ||
|
||
// LOAD INSTALLED MODULES | ||
const { program: command }: typeof CommanderModule = await import( | ||
path.join(pack.directory, "node_modules", "commander") | ||
); | ||
const { createPromptModule: prompt }: typeof InquirerModule = | ||
await import( | ||
path.join(pack.directory, "node_modules", "inquirer") | ||
); | ||
|
||
// TAKE OPTIONS | ||
const action = (closure: (options: Partial<T>) => Promise<T>) => | ||
new Promise<T>((resolve, reject) => { | ||
command.action(async (options) => { | ||
try { | ||
resolve(await closure(options)); | ||
} catch (exp) { | ||
reject(exp); | ||
} | ||
}); | ||
command.parseAsync().catch(reject); | ||
}); | ||
const output: T | Error = await (async () => { | ||
try { | ||
return await inquiry(pack, command, prompt, action); | ||
} catch (error) { | ||
return error as Error; | ||
} | ||
})(); | ||
|
||
// REMOVE TEMPORARY PACKAGES | ||
if (erase === true) { | ||
if (newbie.commander) | ||
pack.erase({ modulo: "commander", silent: true }); | ||
if (newbie.inquirer) | ||
pack.erase({ modulo: "inquirer", silent: true }); | ||
} | ||
|
||
// RETURNS | ||
if (output instanceof Error) throw output; | ||
return output; | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.