From e50bb9f5566d9ee4255cf0cf0c419e1f0d190912 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Fri, 14 Sep 2018 10:36:43 -0700 Subject: [PATCH] adds typings for the 'vorpal' package (#28870) --- types/vorpal/index.d.ts | 82 ++++++++++++++++++++++++++++++++++++ types/vorpal/tsconfig.json | 23 ++++++++++ types/vorpal/tslint.json | 3 ++ types/vorpal/vorpal-tests.ts | 16 +++++++ 4 files changed, 124 insertions(+) create mode 100644 types/vorpal/index.d.ts create mode 100644 types/vorpal/tsconfig.json create mode 100644 types/vorpal/tslint.json create mode 100644 types/vorpal/vorpal-tests.ts diff --git a/types/vorpal/index.d.ts b/types/vorpal/index.d.ts new file mode 100644 index 0000000000..ee2bf2ac42 --- /dev/null +++ b/types/vorpal/index.d.ts @@ -0,0 +1,82 @@ +// Type definitions for vorpal 1.11 +// Project: https://github.com/dthree/vorpal +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare class Vorpal { + parse(argv: ReadonlyArray): this; + delimiter(value: string): this; + show(): this; + hide(): this; + find(command: string): Vorpal.Command; + exec(command: string): Promise<{}>; + execSync(command: string): Promise<{}>; + log(value: string, ...values: string[]): this; + history(id: string): this; + localStorage(id: string): object; + help(value: (cmd: string) => string): this; + pipe(value: (stdout: string) => string): this; + use(extension: Vorpal.Extension): this; + catch(command: string, description?: string): Vorpal.Catch; + command(command: string, description?: string): Vorpal.Command; + version(version: string): this; + sigint(value: () => void): this; + ui: Vorpal.UI; + activeCommand: Vorpal.CommandInstance; +} + +declare namespace Vorpal { + interface Args { + [key: string]: any; + options: { + [key: string]: any; + }; + } + + type Action = (args: Args) => Promise; + type Cancel = () => void; + + class Command { + _name: string; + _fn: Action; + _cancel: Cancel | undefined; + alias(command: string): this; + parse(value: (command: string, args: Args) => string): this; + option(option: string, description: string, autocomplete?: ReadonlyArray): this; + types(types: { string?: ReadonlyArray }): this; + hidden(): this; + remove(): this; + help(value: (args: Args) => void): this; + validate(value: (args: Args) => boolean | string): this; + autocomplete(values: ReadonlyArray | { data: () => Promise> }): this; + action(action: Action): this; + cancel(cancel: Cancel): this; + allowUnknownOptions(): this; + } + + class Catch extends Command { } + + class Extension { } + + class UI { + delimiter(text?: string): string; + input(text?: string): string; + imprint(): void; + submit(command: string): string; + cancel(): void; + redraw: { + (text: string, ...texts: string[]): void; + clear(): void; + done(): void; + }; + } + + class CommandInstance { + log(value: string, ...values: string[]): void; + prompt(prompt: object | ReadonlyArray): Promise; + delimiter(value: string): void; + } +} + +export = Vorpal; diff --git a/types/vorpal/tsconfig.json b/types/vorpal/tsconfig.json new file mode 100644 index 0000000000..8c44d56707 --- /dev/null +++ b/types/vorpal/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vorpal-tests.ts" + ] +} diff --git a/types/vorpal/tslint.json b/types/vorpal/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/vorpal/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/vorpal/vorpal-tests.ts b/types/vorpal/vorpal-tests.ts new file mode 100644 index 0000000000..4499365fd0 --- /dev/null +++ b/types/vorpal/vorpal-tests.ts @@ -0,0 +1,16 @@ +import Vorpal = require('vorpal'); + +// example from README + +const vorpal = new Vorpal(); + +vorpal + .command('foo', 'Outputs "bar".') + .action((action) => { + vorpal.log('bar'); + return Promise.resolve(); + }); + +vorpal + .delimiter('myapp$') + .show();