qoa icon indicating copy to clipboard operation
qoa copied to clipboard

Input validation

Open sbencoding opened this issue 5 years ago • 0 comments

Input validation. Fixes #5 Hello! This is a pull request implementing an input validation feature for, input, hidden, secure prompts.
I ran npm run test, and there were no errors, I also updated the API documentation in the readme.md file.
If there's anything I need to change let me know 😉 .

Example

const qoa = require('qoa');
const validator = {
    name: 'start_with_underscore',
    validate: (answer) => answer.startsWith('_'),
};

const input = {
    type: 'input', query: 'input test:', handle: 'input_result', validate: [validator]
};

qoa.prompt([input]).then(res => console.log(res));

Executing this code would have the following result:

$ node test
input test: username
{ input_result: 'username',
  input_result_validators: { start_with_underscore: false } }

$

sbencoding avatar Jun 10 '19 12:06 sbencoding