Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@qui-cli/validators

@qui-cli Plugin: Input validators

npm version Module type: ESM

Install

npm install @qui-cli/validators @qui-cli/core @inquirer/prompts

If developing a reusable plugin:

npm install --save-peer  @qui-cli/validators@>=3

Usage

import { Core } from '@qui-cli/core';
import { Validators } from '@qui-cli/validators';
import { input } from '@inquirer/prompts'

// load user-provided command-line arguments
await Core.run();

const word = await input({
  message: 'Enter a decently long word'
  default: 'quetzlcoatl',
  validate: Validators.lengthBetween(8, 100)
})

Configuration

Validators provides no configuration options.

Options

Validators adds no user-configurable command line options.

Initialization

Validators requires no initialization

API

import { Validators } from '@qui-cli/validators';

Validators.notEmpty(value?): boolean | string

Require a non-empty string. Returns true if valid, an error message if invalid.

Validators.minLength(minLength): Validator

Returns a validator that requires a string of at least minLength.

Validators.maxLength(maxLength): Validator

Returns a validator that requires a string of no more than maxLength.

Validators.lengthBetween(min, max): Validator

Returns a validator that requires a string between min and max characters.

Validators.match(regExp): Validator

Returns a validator that requires a string that matches regExp.

Validators.email(): Validator

Returns a validator that requires a valid email address.

Validators.cron(value?): boolean | string

Requires a valid cron schedule string. Returns true if valid, an error message if invalid.

Validators.isHostname(): Validator

Returns a validator that requires a valid hostname.

Validators.isPath(value?): boolean | string

Require a file path string. Returns true if valid, an error message if invalid.

Validators.pathExists(root?): Validator

Returns a validator that requires a file path string that exists (relative to root, if root is undefined, falls back to Root.path()).

Validators.combine(...validators: Validator[]): Validator

Returns a validator that combines any number of other validators (all must be met to valididate, first validator to fail returns an error message).