Merge pull request #1427 from danrspencer/master

Added definition file for Promptly
This commit is contained in:
Basarat Ali Syed
2013-12-11 04:19:01 -08:00
2 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
///<reference path="../node/node.d.ts"/>
///<reference path="promptly.d.ts"/>
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) => {
});

34
promptly/promptly.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
// Type definitions for node-promptly 1.1.1
// Project: https://github.com/IndigoUnited/node-promptly
// Definitions by: Dan Spencer <https://github.com/danrspencer>
// 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);
}