boolify-string
Check a string whether truthy or falsy.
Last updated 5 years ago by sanemat .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install boolify-string 
SYNC missed versions from official npm registry.

boolify-string

NPM version Build Status Appveyor Status Dependency Status

Check a string whether truthy or falsy.

Use case

Read from environment variable, sometimes these are 'True', 'false', '1', '', undefined, etc.

if (boolifyString(process.env.CI)){
  something_do();
}

Install

$ npm install --save boolify-string

Usage

var boolifyString = require('boolify-string');

boolifyString('true');// #=> true
boolifyString('TRUE');// #=> true
boolifyString('True');// #=> true
boolifyString('false');// #=> false

boolifyString('{}');// #=> true
boolifyString('foo');// #=> true
boolifyString('');// #=> false
boolifyString('1');// #=> true
boolifyString('-1');// #=> true
boolifyString('0');// #=> false
boolifyString('[]');// #=> true
boolifyString('undefined');// #=> false
boolifyString('null');// #=> false

// primitive values as is
boolifyString(true);// #=> true
boolifyString(false);// #=> false
boolifyString({});// #=> true
boolifyString(1);// #=> true
boolifyString(-1);// #=> true
boolifyString(0);// #=> false
boolifyString([]);// #=> true
boolifyString(undefined);// #=> false
boolifyString(null);// #=> false

// string constructor
boolifyString(new String('true'));// #=> true
boolifyString(new String('false'));// #=> false

// YAML's specification
// http://yaml.org/type/bool.html
// y|Y|yes|Yes|YES|n|N|no|No|NO
// |true|True|TRUE|false|False|FALSE
// |on|On|ON|off|Off|OFF
boolifyString('y');// #=> true
boolifyString('Y');// #=> true
boolifyString('yes');// #=> true
boolifyString('Yes');// #=> true
boolifyString('YES');// #=> true
boolifyString('n');// #=> false
boolifyString('N');// #=> false
boolifyString('no');// #=> false
boolifyString('No');// #=> false
boolifyString('NO');// #=> false
boolifyString('true');// #=> true
boolifyString('True');// #=> true
boolifyString('TRUE');// #=> true
boolifyString('false');// #=> false
boolifyString('False');// #=> false
boolifyString('FALSE');// #=> false
boolifyString('on');// #=> true
boolifyString('On');// #=> true
boolifyString('ON');// #=> true
boolifyString('off');// #=> false
boolifyString('Off');// #=> false
boolifyString('OFF');// #=> false

Simular

Changelog

changelog

License

Copyright (c) 2014-2015 sanemat. Licensed under the MIT license.

Current Tags

  • 2.0.2                                ...           latest (5 years ago)

6 Versions

  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |