UNPKG

@bitblit/ratchet-common

Version:

Common tools for general use

46 lines 1.29 kB
import { NumberRatchet } from './number-ratchet.js'; export class BooleanRatchet { static allTrue(vals, emptyArraysReturn = false) { let rval = null; if (vals) { if (vals.length > 0) { rval = vals.reduce((a, i) => a && i, true); } else { rval = emptyArraysReturn; } } else { rval = false; } return rval; } static anyTrue(vals, emptyArraysReturn = false) { let rval = null; if (vals) { if (vals.length > 0) { rval = vals.reduce((a, i) => a || i, false); } else { rval = emptyArraysReturn; } } else { rval = false; } return rval; } static parseBool(val) { return val === true || (val !== null && val !== undefined && typeof val === 'string' && val.toLowerCase() === 'true'); } static intToBool(val) { if (val === null || val === undefined) { return false; } return NumberRatchet.safeNumber(val) !== 0; } static boolToInt(val) { return BooleanRatchet.parseBool(val) ? 1 : 0; } } //# sourceMappingURL=boolean-ratchet.js.map