import ecmaToBoolean from './ecmaToBoolean'
const matchTrue = /^("|')?(true)("|')?$/i
const matchFalse = /^("|')?(false)("|')?$/i
// @todo need to export
const isTruish = (x: any): x is true | 'true' | '"true"' | `'true'` =>
x === true || (typeof x === 'string' && matchTrue.test(x))
const isFalsish = (x): x is false | 'false' | '"false"' | `'false'` =>
x === false || (typeof x === 'string' && matchFalse.test(x))
const fromIshToBoolean = (x: any): boolean => {
if (isTruish(x)) {
return true
} else if (isFalsish(x)) {
return false
} else {
return ecmaToBoolean(x)
}
}
export { fromIshToBoolean }
export default fromIshToBoolean