object

Source:

Methods

(static) hasRequiredProps(required) → {function}

Description:
  • Checks object has required properties

Source:
Example
const testProps = hasRequiredProps(["name", "date"]);
   if (testProps(userConfiguration)) {
     // Stuff
   }
Parameters:
Name Type Description
required Array.<String>

Array of properties to check for

Returns:

Function for user to use to test, fn(object) returns boolean whether all properties are set

Type
function

(static) includeIf(cond, value) → {Object|Array}

Description:
  • Returns an object or array if the condition is truthy, otherwise returns a new empty array or object.

    • Primary use is for keeping configuration objects clean adding conditions inline
    • Useful for conditionally adding properties to an object or elements to an array via spreading.
Source:
Examples
// Conditionally add properties to an object
const config = {
  name: "My App",
  ...includeIf(isAdmin, { canDelete: true })
};
// Conditionally add elements to an array in a config
const settings = {
  plugins: [
    "plugin-a",
    ...includeIf(isPro, ["plugin-pro-b", "plugin-pro-c"])
  ]
};
Parameters:
Name Type Description
cond *

The condition to evaluate.

value Object | Array

The object or array to return if the condition is truthy.

Returns:

Returns value if cond is truthy, otherwise returns [] if value was an array, or {}.

Type
Object | Array