https://github.com/gobwas/schinquirer
schinquirer
https://github.com/gobwas/schinquirer
Last synced: 18 days ago
JSON representation
schinquirer
- Host: GitHub
- URL: https://github.com/gobwas/schinquirer
- Owner: gobwas
- Created: 2015-05-29T14:13:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-28T16:10:48.000Z (almost 5 years ago)
- Last Synced: 2025-03-25T02:43:32.349Z (about 1 month ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# schinquirer
[](http://badge.fury.io/js/schinquirer)
> [JSON-Schema](http://json-schema.org/) Prompt Inquirer
## What's up?
Hey there! This is a simple json-schema inquirer ([json]sch[ema]inquirer), based on famous prompt [inquirer](https://github.com/SBoudrias/Inquirer.js) and [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid) validator.
## Getting started
```shell
npm install --save schinquirer
```## Usage
```js
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 `schema` object is a value of `schema.properties` property.
## 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 with `key` equal to `equal`;
+ formatter `string["number"]` - determine which formatter to apply for the input (available is: `number`);
+ formatter `Function -> *` - formatter, applying to the value, returning formatted value.