adds typings for the 'vorpal' package (#28870)

This commit is contained in:
Daniel Byrne
2018-09-14 10:36:43 -07:00
committed by Ryan Cavanaugh
parent 192edcd269
commit e50bb9f556
4 changed files with 124 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
// Type definitions for vorpal 1.11
// Project: https://github.com/dthree/vorpal
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare class Vorpal {
parse(argv: ReadonlyArray<string>): 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<void>;
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<string>): this;
types(types: { string?: ReadonlyArray<string> }): this;
hidden(): this;
remove(): this;
help(value: (args: Args) => void): this;
validate(value: (args: Args) => boolean | string): this;
autocomplete(values: ReadonlyArray<string> | { data: () => Promise<ReadonlyArray<string>> }): 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<object>): Promise<object>;
delimiter(value: string): void;
}
}
export = Vorpal;
+23
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
+16
View File
@@ -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();