Node Parcel Merchant

    boolify-string
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/boolify-string package

    2.0.2 • Public • Published

    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.

    Install

    npm i boolify-string

    DownloadsWeekly Downloads

    210

    Version

    2.0.2

    License

    MIT

    Last publish

    Collaborators

    • sanemat