Skip to content

Commit 527a815

Browse files
committed
make format function async
1 parent 964eb23 commit 527a815

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const { prompt } = require('./lib');
77
{
88
type: 'text',
99
name: 'twitter',
10-
message: `What's your twitter handle?`
10+
message: `What's your twitter handle?`,
11+
format: v => `@${v}`
1112
},
1213
{
1314
type: 'password',

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
4545

4646
try {
4747
answer = await prompts[type](question);
48-
answers[name] = answer = question.format ? question.format(answer, answers) : answer;
48+
answers[name] = answer = question.format ? await question.format(answer, answers) : answer;
4949
quit = onSubmit(question, answer);
5050
} catch (err) {
5151
quit = onCancel(question);

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Almost all prompt objects have the following properties:
247247
name: String || Function,
248248
message: String || Function,
249249
initial: String || Function || Async Function
250-
format: Function,
250+
format: Function || Async Function,
251251
onState: Function
252252
}
253253
```

0 commit comments

Comments
 (0)