From 2661fd4a9a50906a55bd3896f97226504e4fa060 Mon Sep 17 00:00:00 2001 From: Dan Spencer Date: Wed, 11 Dec 2013 12:15:34 +0000 Subject: [PATCH] Added definition file for Promptly --- promptly/promptly-tests.ts | 86 ++++++++++++++++++++++++++++++++++++++ promptly/promptly.d.ts | 34 +++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 promptly/promptly-tests.ts create mode 100644 promptly/promptly.d.ts diff --git a/promptly/promptly-tests.ts b/promptly/promptly-tests.ts new file mode 100644 index 0000000000..b18578be53 --- /dev/null +++ b/promptly/promptly-tests.ts @@ -0,0 +1,86 @@ +/// +/// + +import promptly = require('promptly'); + +process.stdin + +// Options +var options: promptly.Options = {} +options = { + default: 'value' +} +options = { + trim: false +} +options = { + retry: false +} +options = { + silent: false +} +options = { + input: process.stdin +} +options = { + output: process.stdout +} + +// Validator +options = { + validator: () => {} +} +options = { + validator: (value: string) => {} +} +options = { + validator: (value: string) => { + return 'result'; + } +} +options = { + validator: [ + (value: string) => { return 'result' }, + (value: string) => { return 'result' } + ] +} + +// Prompt +promptly.prompt('hello world'); +promptly.prompt('hello world', options); +promptly.prompt('hello world', () => { + +}); +promptly.prompt('hello world', options, (err: Error, value: string) => { + +}); + +// Password +promptly.password('hello world'); +promptly.password('hello world', options); +promptly.password('hello world', () => { + +}); +promptly.password('hello world', options, (err: Error, value: string) => { + +}); + +// Confirm +promptly.confirm('hello world'); +promptly.confirm('hello world', options); +promptly.confirm('hello world', () => { + +}); +promptly.confirm('hello world', options, (err: Error, value: string) => { + +}); + +// Choose +promptly.choose('hello world', ['test1', 'test2']); +promptly.choose('hello world', ['test1', 'test2'], options); +promptly.choose('hello world', ['test1', 'test2'], () => { + +}); +promptly.choose('hello world', ['test1', 'test2'], options, (err: Error, value: string) => { + +}); \ No newline at end of file diff --git a/promptly/promptly.d.ts b/promptly/promptly.d.ts new file mode 100644 index 0000000000..2ad8f33100 --- /dev/null +++ b/promptly/promptly.d.ts @@ -0,0 +1,34 @@ +// Type definitions for node-promptly 1.1.1 +// Project: https://github.com/IndigoUnited/node-promptly +// Definitions by: Dan Spencer +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "promptly" { + + interface Callback { + (err: Error, value: string): void; + } + + export interface Options { + default?: string; + trim?: boolean; + validator?: any; + retry?: boolean; + silent?: boolean; + input?: ReadableStream; + output?: WritableStream; + } + + export function prompt(message: string, fn?: Callback); + export function prompt(message: string, opts: Options, fn?: Callback); + + export function password(message: string, fn?: Callback); + export function password(message: string, opts: Options, fn?: Callback); + + export function confirm(message: string, fn?: Callback); + export function confirm(message: string, opts: Options, fn?: Callback); + + export function choose(message: string, choices: string[], fn?: Callback); + export function choose(message: string, choices: string[], opts: Options, fn?: Callback); + +} \ No newline at end of file