From 372a44a4d2d5339cf62f8c8aea8268f270d4e24f Mon Sep 17 00:00:00 2001 From: Adam Voss Date: Thu, 20 Jul 2017 17:18:15 -0500 Subject: [PATCH 1/2] Add TypeScript type declaration file This provides completion information for users of both JavaScript and TypeScript with supported editors. This also allows TypeScript users to have type checking and be able to use the library when strict checking is enabled (which is the default for new TS projects). --- lib/dashdash.d.ts | 261 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 262 insertions(+) create mode 100644 lib/dashdash.d.ts diff --git a/lib/dashdash.d.ts b/lib/dashdash.d.ts new file mode 100644 index 0000000..6535444 --- /dev/null +++ b/lib/dashdash.d.ts @@ -0,0 +1,261 @@ +// Type definitions for dashdash 1.14 +// Project: https://github.com/trentm/node-dashdash#readme + +/// + +export class Parser { + constructor(config: ParseConfiguration); + + bashCompletion(args: BashCompletionConfiguration): string; + + help(config?: HelpConfiguration): string; + + parse(inputs?: string[]): Results; +} + +export function addOptionType(optionType: OptionType): void; + +export function bashCompletionFromOptions(args: BashCompletionConfiguration): string; + +export function bashCompletionSpecFromOptions(args: BashCompletionSpecConfiguration): string; + +export function createParser(config: ParseConfiguration): Parser; + +export function getOptionType(name: string): OptionType; + +export function parse(config: ParseConfiguration): Results; + +export interface Results { + [key: string]: any; + _order: Arg[]; + _args: string[]; +} + +export interface Arg { + name: string; + value: any; + from: string; +} + +/** + * Used by node-cmdln to put together a synopsis of options for a command + */ +export function synopsisFromOpt(o: Option): string; + +export type Option = OptionWithoutAliases | OptionWithAliases; + +export interface ParseConfiguration { + /** + * The argv to parse. Defaults to `process.argv`. + */ + argv?: string[]; + + /** + * The index into argv at which options/args begin. Default is 2, as appropriate for `process.argv`. + */ + slice?: number; + + /** + * The env to use for 'env' entries in the option specs. Defaults to `process.env`. + */ + env?: NodeJS.ProcessEnv; + + options?: Array