if-empty

1.0.0 • Public • Published

if-empty

NPM version Build Status Coveralls Status Dependency Status

If value (second argument) is empty return reason (first argument) otherwise return true

Install

npm install --save if-empty

Usage

import ifEmpty from 'if-empty';
 
ifEmpty('You have to provide name', '');    // "You have to provide name"
ifEmpty('You have to provide name', 'Ben'); // true, `value` is not empty

Also useful for validating inquirer prompts, as well as yeoman prompts

import inquirer from 'inquirer';
 
inquirer.prompt([{
  name: 'name',
  message: '☯ your name:',
  validate: ifEmpty('You have to provide name'), // curried
}], function(answers) {
  console.log(answers);
});

API

ifEmpty(reason, value)

// ifEmpty :: String -> String -> true | String`

reason

Required
Type: String

Reason for invalid value.

value

Required
Type: String

Value to validate.

License

MIT © Vladimir Starkov

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i if-empty

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • iamstarkov