@xncn/simplecli
v1.0.5
Published
This package is a simple command line interface helper , you can ask a question and validate answer.That is very simple.
Downloads
7
Readme
SimpleCLI
This package is a simple command line interface helper , you can ask a question and validate answer.That is very simple.
How can i install?
npm install @xncn/simplecli
Let's do a simple example
const simplecli = require('@xncn/simplecli');
simplecli(
{ question: "What's your instagram username? :", },
(answer) => console.log(`https://www.instagram.com/${answer}`)
);
Customize
Let's do some customize.You can customize text color , just send color argument to simplecli.
simplecli(
{
question: "What's your instagram username? :",
color: 'cyan'
},
(answer) => console.log(`https://www.instagram.com/${answer}`)
);
Avaible colors : blue,green,red,yellow,magenta,cyan,white,crimson
And you can customize text weight and underline style.
{
...
bold: true,
//underline: true
},
Validation
Simplecli includes Validator library, you can validate your data it's so easy.Lets do a exampleİf you want do validation you pass second argument , you can use a callback function.Function includes two arguments they are user prompt and validation errors.
simplecli(
{
question: "How old are you? :",
color: 'cyan',
bold: true,
underline: true,
validationRules: 'required|numeric|max:50|min:18'
},
(answer, err) => {
if (err != true) { console.log(err); return; }
console.log(`Good you are ${answer} years old , you can do this action:)`);
}
);
Supported Validation Rules
See validation rule usage in Laravel Documentation
- accepted
- after (date)
- alpha
- alpha_num
- alpha_dash
- array
- before (date)
- between
- boolean
- confirmed
- date
- different
- digits
- digits_between
- filled
- in
- integer
- ip
- json
- max
- min
- not_in
- numeric
- present
- regex
- required
- required_if
- required_unless
- required_with
- required_with_all
- required_without
- required_without_all
- same
- size
- string
- url