1.0.1 • Published 5 years ago

boobool v1.0.1

Weekly downloads
716
License
MIT
Repository
github
Last release
5 years ago

boobool NPM Version Build Status

Convert a boolean from a string, keeping undefined and null values

  • Parses "true" as true
  • Parses "false" as false
  • Case-insensitive
  • Ignores leading and trailing whitespace
  • Parses undefined and null as undefined
  • Returns undefined when a boolean could not be found
  • Configurable defaultValue (replaces undefined)

Installation

npm install boobool

Usage

parseBoolean(string[, {defaultValue}])

const boobool = require('boobool');

boobool('true');  //-> true
boobool(' TRUE ');  //-> true
boobool('false');  //-> false

boobool('yes');  //-> undefined
boobool('1');  //-> undefined
boobool('');  //-> undefined
boobool(null);  //-> undefined
boobool(undefined);  //-> undefined

Optionally, you can override the default value:

boobool('', {defaultValue: true});  //-> true