Socket
Socket
Sign inDemoInstall

boolify

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boolify

Convert true/false strings to booleans


Version published
Weekly downloads
412K
increased by8.88%
Maintainers
1
Weekly downloads
 
Created
Source

boolify

Convert true/false strings to booleans

Build Status

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.t === true)
console.log(obj.f === false)
console.log(obj.s === 'Another string')
console.log(obj.n === 5)

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

app.put('/users/:username', function(req, res) {
  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

FAQs

Package last updated on 12 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc