Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including prose_is with all npm packages installed. Try it out:

var proseIs = require("prose_is")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

prose_is v2.0.6

A logic Utility. Nil is: null or undefined. Make writing node easier, prettier and less error prone. Writes and reads more like prose

prose_is

Copyright (c) 2020 Seán D. Murray SEE MIT LICENSE FILE

A logic Utility. Nil is: null or undefined. Make writing node easier, prettier and less error prone. Writes and reads more like prose.

Notes

A new concept of Nil has been added. Nil is anything that is either undefined or null.

Usage

const is = require('prose_is');

/**
 True if the item passed in is nil.
 Nil is either null or undefined.
 True if nothing passed in.
**/
is.nil(obj);

/**
 False if the item passed in is not nil.
 Nil is either null or undefined.
 False if nothing passed in.
**/
is.notNil(obj);

/**
 True if all the items passed in are nil.
 Nil is either null or undefined.
 True if nothing passed in.
**/
is.allNil(obj1, obj2);

/**
 True if any of the items passed in is nil.
 Nil is either null or undefined.
 True if nothing passed in.
**/
is.anyNil(obj1, obj2);

// Example
const someList = someCallReturningList();
// use the ... operator to decompose the list into arguments.
if(is.allNil(...someList)) {
  // Do stuff here
  // as the list is empty or all the values are null or undefined.
}

// use the ... operator to decompose the list into arguments.
if(is.anyNil(...someList)) {
  // Do other stuff here
  // as the list is empty or all the values are null or undefined.
}

/**
 Returns the logical opposit of the input.
 Returns false for input of true.
 Returns true for input of false.
 Returns true if nothing passed in.
 Returns true if null is passed in.
 Returns true if undefined is passed in.
 You never have to use the ! operator again!
**/
is.not(true); // False
is.not(false); // True

/**
 True if the item passed in is defined.
 False if nothing passed in.
**/
is.defined(obj);

/**
 False if the item passed in is defined.
 True if nothing passed in.
**/
is.notDefined(obj);

/**
 True if the all items passed in are defined.
 False if nothing passed in.
**/
is.allDefined(obj1, obj2);

/**
 True if the any one item passed in is defined.
 False if nothing passed in.
**/
is.anyDefined(obj1, obj2);

/**
 True if item passed in is null.
 False if item passed in is undefined.
 False if nothing passed in.
**/
is.null(obj);

/**
 True if the item passed in is not null.
 True if nothing passed in.
**/
is.notNull(obj);

/**
 True if all of the items passed in are null.
 False if nothing passed in.
**/
is.allNul(obj1, obj2);

/**
 True if all any of the items passed in are null.
 False if nothing passed in.
**/
is.anyNull(obj1, obj2);

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free