diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts new file mode 100644 index 0000000000..152d6326e8 --- /dev/null +++ b/types/prompts/index.d.ts @@ -0,0 +1,76 @@ +// Type definitions for prompts 1.1 +// Project: https://github.com/terkelg/prompts +// Definitions by: Berkay GURSOY +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export = prompts; + +declare function prompts(questions: prompts.PromptObject | prompts.PromptObject[], options?: prompts.Options): any; + +declare namespace prompts { + // Circular reference from prompts + const prompt: any; + + function inject(obj: any): void; + + namespace inject { + const prototype: { + }; + } + + namespace prompts { + function autocomplete(args: PromptObject): any; + + function confirm(args: PromptObject): void; + + function invisible(args: PromptObject): any; + + function list(args: PromptObject): any; + + function multiselect(args: PromptObject): any; + + function number(args: PromptObject): void; + + function password(args: PromptObject): any; + + function select(args: PromptObject): void; + + function text(args: PromptObject): void; + + function toggle(args: PromptObject): void; + } + + interface Choice { + title: string; + value: string; + } + + interface Options { + onSubmit: (prompt: PromptObject, answer: any, answers: any[]) => void; + onCancel: (prompt: PromptObject, answers: any) => void; + } + + interface PromptObject { + type: string | ((prev: any, values: any, prompt: PromptObject) => void); + name: string | ((prev: any, values: any, prompt: PromptObject) => void); + message?: string | ((prev: any, values: any, prompt: PromptObject) => void); + initial?: string; + style?: string; + format?: ((prev: any, values: any, prompt: PromptObject) => void); + validate?: ((prev: any, values: any, prompt: PromptObject) => void); + onState?: ((prev: any, values: any, prompt: PromptObject) => void); + min?: number; + max?: number; + float?: boolean; + round?: number; + increment?: number; + seperator?: string; + active?: string; + inactive?: string; + choices?: Choice[]; + hint?: string; + suggest?: ((prev: any, values: any, prompt: PromptObject) => void); + limit?: number; + } +} diff --git a/types/prompts/prompts-tests.ts b/types/prompts/prompts-tests.ts new file mode 100644 index 0000000000..0b89cb3721 --- /dev/null +++ b/types/prompts/prompts-tests.ts @@ -0,0 +1,8 @@ +import prompts = require("prompts"); + +const response = prompts({ + type: 'number', + name: 'value', + message: 'Input value to double:', + validate: (value: any) => value < 0 ? `Cant be less than zero` : true +}); diff --git a/types/prompts/tsconfig.json b/types/prompts/tsconfig.json new file mode 100644 index 0000000000..e8a46be254 --- /dev/null +++ b/types/prompts/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", + "prompts-tests.ts" + ] +} \ No newline at end of file diff --git a/types/prompts/tslint.json b/types/prompts/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/prompts/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file