boolify-string
v2.0.2
Published
Check a string whether truthy or falsy.
Downloads
2,848
Maintainers
Readme
boolify-string
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
License
Copyright (c) 2014-2015 sanemat. Licensed under the MIT license.