boobool
v1.0.1
Published
Convert a boolean from a string, keeping undefined and null values, to be able to use defaultsTo
Downloads
700
Keywords
Readme
boobool
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
andnull
asundefined
- Returns
undefined
when a boolean could not be found - Configurable
defaultValue
(replacesundefined
)
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