0.3.2 • Published 10 years ago
schinquirer v0.3.2
schinquirer
JSON-Schema Prompt Inquirer
What's up?
Hey there! This is a simple json-schema inquirer (jsonschemainquirer), based on famous prompt inquirer and is-my-json-valid validator.
Getting started
npm install --save schinquirerUsage
var schinquirer = require("schinquirer");
schinquirer.prompt(
{
name: {
type: "string",
pattern: "\d-\d"
},
car: {
type: "string",
enum: ["audi", "bmw", "mercedes", "volkswagen"],
message: "Which car?",
default: "mercedes"
}
},
function(answers) {
console.log(answers.name, "drives", answers.car);
}
);API
prompt(schema: Object , callback: Function(answers: Object)): Promise
Asks questions by given schema, validates the answers and then invoke callback with them.
Returns native Promise (in node < 0.12 - user tiny Promise/A+ compatible library promiscuous).
Note, that
schemaobject is a value ofschema.propertiesproperty.
Extensions to schema
You could use these fields additionally to your schema object:
- message
string- message (question) to show, if not present property name will printed; - default
*- default value; - when
Object{key: string, equal: *}- ask question, when some answer withkeyequal toequal; - formatter
string["number"]- determine which formatter to apply for the input (available is:number); - formatter
Function -> *- formatter, applying to the value, returning formatted value.