falsify

Helps you deny the existence of specified truthy values (e.g. 'someString', aParticularObject)

Usage no npm install needed!

<script type="module">
  import falsify from 'https://cdn.skypack.dev/falsify';
</script>

README

falsify

This node module helps you deny the existence of specified truthy values (e.g. 'some string', aParticularObject)

Install

$ npm install falsify

Usage

var falsify = require('falsify')

Now falsify is a function that, when called, will return to you a function. falsify expects to be passed 0 or more arguments. These are the values that you would like your new function to consider falsy. The new function accepts an argument that it will attempt to match against the values you originally supplied to falsify. If such a match is found, the new function will return false. 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
  falsify = require('falsify')
, isTruthyButNotTheBooleanLiteralTrue = falsify(true)
, someObject = {}
, isTruthyButNotHelloOrSomeObject = falsify('hello', someObject)


console.log(isTruthyButNotTheBooleanLiteralTrue(true))        // false
console.log(isTruthyButNotTheBooleanLiteralTrue(0))           // false
console.log(isTruthyButNotTheBooleanLiteralTrue(undefined))   // false
console.log(isTruthyButNotTheBooleanLiteralTrue(NaN))         // false
console.log(isTruthyButNotTheBooleanLiteralTrue(null))        // false
console.log(isTruthyButNotTheBooleanLiteralTrue(''))          // false
console.log(isTruthyButNotTheBooleanLiteralTrue(false))       // false
console.log(isTruthyButNotTheBooleanLiteralTrue('hi'))        // true
console.log(isTruthyButNotTheBooleanLiteralTrue({}))          // true
console.log(isTruthyButNotTheBooleanLiteralTrue([]))          // true


console.log(isTruthyButNotHelloOrSomeObject('hello'))         // false
console.log(isTruthyButNotHelloOrSomeObject(someObject))      // false
console.log(isTruthyButNotHelloOrSomeObject(0))               // false
console.log(isTruthyButNotHelloOrSomeObject(undefined))       // false
console.log(isTruthyButNotHelloOrSomeObject(NaN))             // false
console.log(isTruthyButNotHelloOrSomeObject(null))            // false
console.log(isTruthyButNotHelloOrSomeObject(''))              // false
console.log(isTruthyButNotHelloOrSomeObject(false))           // false
console.log(isTruthyButNotHelloOrSomeObject('hi'))            // true
console.log(isTruthyButNotHelloOrSomeObject({}))              // true
console.log(isTruthyButNotHelloOrSomeObject([]))              // true

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.