Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

boolify

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    boolify

Convert true/false strings to booleans


Version published
Weekly downloads
373K
increased by14.72%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

boolify

Convert true/false strings to booleans

Build Status

Example

var boolify = require('boolify')

boolify('true')
// true

boolify('false')
// false

boolify('A string')
// "A string"

var obj = boolify({
  t: 'true',
  f: 'false',
  s: 'Another string',
  n: 5
})
// {
//   t: true,
//   f: false,
//   s: 'Another string',
//   n: 5
// }

boolify('TRUE')
// true

boolify('tRuE')
// true

Usage

boolify is case-insensitive and will convert any string of "true" or "false" in to the appropriate boolean.

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
})

boolify(object | string)

If provided an object, boolify will recursively convert all values.

var result = boolify({one: {fish: {two: {fish: 'true'}}}})
console.log(result.one.fish.two.fish)
// true

Install

With npm do:

npm install boolify

See also

  • yn supports additional values for booleans, both uppercase and lowercase, and returns null when a value is recognized is neither true or false

License

MIT

FAQs

Last updated on 18 May 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc