Skip to content

Commit 2661fd4

Browse files
Dan SpencerDan Spencer
Dan Spencer
authored and
Dan Spencer
committed
Added definition file for Promptly
1 parent 4df0598 commit 2661fd4

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

promptly/promptly-tests.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
///<reference path="../node/node.d.ts"/>
2+
///<reference path="promptly.d.ts"/>
3+
4+
import promptly = require('promptly');
5+
6+
process.stdin
7+
8+
// Options
9+
var options: promptly.Options = {}
10+
options = {
11+
default: 'value'
12+
}
13+
options = {
14+
trim: false
15+
}
16+
options = {
17+
retry: false
18+
}
19+
options = {
20+
silent: false
21+
}
22+
options = {
23+
input: process.stdin
24+
}
25+
options = {
26+
output: process.stdout
27+
}
28+
29+
// Validator
30+
options = {
31+
validator: () => {}
32+
}
33+
options = {
34+
validator: (value: string) => {}
35+
}
36+
options = {
37+
validator: (value: string) => {
38+
return 'result';
39+
}
40+
}
41+
options = {
42+
validator: [
43+
(value: string) => { return 'result' },
44+
(value: string) => { return 'result' }
45+
]
46+
}
47+
48+
// Prompt
49+
promptly.prompt('hello world');
50+
promptly.prompt('hello world', options);
51+
promptly.prompt('hello world', () => {
52+
53+
});
54+
promptly.prompt('hello world', options, (err: Error, value: string) => {
55+
56+
});
57+
58+
// Password
59+
promptly.password('hello world');
60+
promptly.password('hello world', options);
61+
promptly.password('hello world', () => {
62+
63+
});
64+
promptly.password('hello world', options, (err: Error, value: string) => {
65+
66+
});
67+
68+
// Confirm
69+
promptly.confirm('hello world');
70+
promptly.confirm('hello world', options);
71+
promptly.confirm('hello world', () => {
72+
73+
});
74+
promptly.confirm('hello world', options, (err: Error, value: string) => {
75+
76+
});
77+
78+
// Choose
79+
promptly.choose('hello world', ['test1', 'test2']);
80+
promptly.choose('hello world', ['test1', 'test2'], options);
81+
promptly.choose('hello world', ['test1', 'test2'], () => {
82+
83+
});
84+
promptly.choose('hello world', ['test1', 'test2'], options, (err: Error, value: string) => {
85+
86+
});

promptly/promptly.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Type definitions for node-promptly 1.1.1
2+
// Project: https://github.com/IndigoUnited/node-promptly
3+
// Definitions by: Dan Spencer <https://github.com/danrspencer>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare module "promptly" {
7+
8+
interface Callback {
9+
(err: Error, value: string): void;
10+
}
11+
12+
export interface Options {
13+
default?: string;
14+
trim?: boolean;
15+
validator?: any;
16+
retry?: boolean;
17+
silent?: boolean;
18+
input?: ReadableStream;
19+
output?: WritableStream;
20+
}
21+
22+
export function prompt(message: string, fn?: Callback);
23+
export function prompt(message: string, opts: Options, fn?: Callback);
24+
25+
export function password(message: string, fn?: Callback);
26+
export function password(message: string, opts: Options, fn?: Callback);
27+
28+
export function confirm(message: string, fn?: Callback);
29+
export function confirm(message: string, opts: Options, fn?: Callback);
30+
31+
export function choose(message: string, choices: string[], fn?: Callback);
32+
export function choose(message: string, choices: string[], opts: Options, fn?: Callback);
33+
34+
}

0 commit comments

Comments
 (0)