@technobuddha/library
Version:
A large library of useful functions
16 lines (15 loc) • 617 B
JavaScript
import toEnumeration from '../toEnumeration';
const defaultTrue = ['true', 'yes', 'y', 'on', '1'];
const defaultFalse = ['false', 'no', 'n', 'off', '0'];
/**
* Convert a string to a boolean value
*
* @param input The string to convert
* @parm __namedParameters see {@link Options}
* @defaults trueValues 'true', 'yes', 'y', 'on', or '1'
* @defaults falseValues 'false', 'no', 'n', 'off', '0'
*/
export function toBoolean(input, { trueValues = defaultTrue, falseValues = defaultFalse } = {}) {
return [true, false, undefined][toEnumeration(input, trueValues, falseValues) ?? 2];
}
export default toBoolean;