truthify

1.0.0 • Public • Published

truthify

This node module helps you confirm the existence of specified falsy values (0, NaN, null...)

Install

$ npm install truthify

Usage

var truthify = require('truthify')

Now truthify is a function that, when called, will return to you a function. truthify expects to be passed 0 or more arguments. These are the values that you would like your new function to consider truthy. The new function accepts an argument that it will attempt to match against the values you originally supplied to truthify. If such a match is found, the new function will return true. If a match is not found, the new function will return the standard 'truthiness' of the argument.

The examples below (and the tests within test/test.js) should serve to clarify any questions you may have.

Example

const
  truthify = require('truthify')
, isTruthyOrZero = truthify(0)
, isTruthyOrNullOrNaN = truthify(null, NaN)


console.log(isTruthyOrZero(0))       // true
console.log(isTruthyOrZero(true))    // true
console.log(isTruthyOrZero({}))      // true
console.log(isTruthyOrZero(false))   // false
console.log(isTruthyOrZero(NaN))     // false
console.log(isTruthyOrZero(null))    // false


console.log(isTruthyOrNullOrNaN(null))       // true
console.log(isTruthyOrNullOrNaN(NaN))        // true
console.log(isTruthyOrNullOrNaN(true))       // true
console.log(isTruthyOrNullOrNaN({}))         // true
console.log(isTruthyOrNullOrNaN(0))          // false
console.log(isTruthyOrNullOrNaN(undefined))  // false

ISC License (ISC)

Copyright 2015, Instancetype

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i truthify

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • instancetype