boolify

Convert true/false strings to booleans

boolify

Convert true/false strings to booleans

example

var boolify = require('../index.js')
 
var trueString = boolify('true')
var falseString = boolify('false')
var aString = boolify('A string')
var obj = boolify({
  t: 'true',
  f: 'false',
  s: 'Another string',
  n: 5
})
 
console.log(trueString === true)
console.log(falseString === false)
console.log(aString === 'A string')
console.log(obj.=== true)
console.log(obj.=== false)
console.log(obj.=== 'Another string')
console.log(obj.=== 5)

This is helpful for handling checkboxes in express' req.body

app.put('/users/:username', function(reqres) {
  console.log(req.body.someCheckbox) // 'true' 
  req.body = boolify(req.body)
  console.log(req.body.someCheckbox) // true 
})

install

With npm do:

npm install boolify

license

MIT