diff --git a/lib/string/typecast.js b/lib/string/typecast.js index 57c4954..80436d3 100644 --- a/lib/string/typecast.js +++ b/lib/string/typecast.js @@ -8,8 +8,8 @@ module.exports = function typecast(value) { if (value === 'null' || value === null) return null if (value === 'undefined' || value === undefined) return undefined - if (value === 'true') return true - if (value === 'false') return false + if (value === 'true' || value === true) return true + if (value === 'false' || value === false) return false if (value === '' || isNaN(value)) return value if (isFinite(value)) return parseFloat(value) return value diff --git a/test/unit/string.js b/test/unit/string.js index 7951137..aa134a2 100644 --- a/test/unit/string.js +++ b/test/unit/string.js @@ -168,6 +168,13 @@ test('string', async (t) => { }, { value: 'false' , expected: false + }, { + value: true + , expected: true + }, { + value: false + , expected: false + }, { }, { value: '123' , expected: 123