Parse a string representation of a boolean.
- Parses "true" as
true
- Parses "false" as
false
- Case-insensitive
- Ignores leading and trailing whitespace
- Returns
null
(customizable) if the string does not represent a boolean - Throws an error if input is not a string
Installation
Node.js >= 6
is required. To install, type this at the command line:
npm install parse-string-boolean
Usage
parseBoolean(string[, defaultValue])
const parseBoolean = ; ; //-> true; //-> true; //-> false ; //-> null; //-> null; //-> null
Optionally, you can override the default value for strings that do not represent a boolean:
; //-> true