Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@xncn/simplecli

1.0.5 • Public • Published

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}`)
);

Example1

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}`)
);

Color

Avaible colors : blue,green,red,yellow,magenta,cyan,white,crimson

And you can customize text weight and underline style.

{
    ...
        bold: true,
        //underline: true
},

bold

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:)`);
    }
);

validation

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
  • email
  • 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

Install

npm i @xncn/simplecli

DownloadsWeekly Downloads

12

Version

1.0.5

License

ISC

Unpacked Size

4.5 kB

Total Files

5

Last publish

Collaborators

  • avatar