General

General Utilities module.

Methods

(inner) containNils(…args) → {boolean}

Verifies whether any of the arguments provided is nil.

Example
containNils(1, 0, NaN, false, null); //=> true
containNils(1, 0, NaN, false, undefined); //=> true
containNils(1, 0, NaN, false); //=> false
Parameters:
Name Type Attributes Description
args * <repeatable>

Arguments of any type.

Returns:
Type
boolean

(inner) flow(functions, value) → {*}

Creates a pipe with all the functions provided, where the output of each function will served as the input of the next function

The final result is the input value with all the transformations provided applied in order

Note:

  • This is a composed function, so check the example to know how to call it
Example
//generate random positive or negative percentage
const pipeline = [
  x => x * 100, // multiply it by 100
  x => x.toFixed(2), // fix number to 2 fixed-points
  x => (Math.random() > 0.5 ? "+" : "-") + x, // add a random sign
  x => x + " %" // add postfix
];
flow(pipeline)(Math.random()); //=> -45.23 %
flow(pipeline)(Math.random()); //=> +89.92 %
Parameters:
Name Type Description
functions Array

Array of functions to be applied in the pipeline

value *

Value to apply pipeline

Returns:
  • fnN(...fn2(fn1(value)))
Type
*

(inner) formatIfExist(fn, placeholder, value) → {*|placeholder}

Composed function that returns

  • A string placeholder if the value is not truthy or
  • A fn(value) formatted value

Note:

  • 0 is considered a truthy value
  • This is a composed function, so check the example to know how to call it
Example
// format the content of a variable. If the variable has a truthy content, run a formatter on it,
 var amount = api.getAmount(); //=> 0.6778
 formatIfExist(toPercentage)('-')(amount); //=> "67.78 %"

// if not, return '-'
 var amount = api.getAmount(); //=> undefined
 formatIfExist(toPercentage)('-')(amount); //=> "-"
Parameters:
Name Type Description
fn function

Formatter to be applied if value is truthy

placeholder string | number

Placeholder to return if value is not truthy

value string | number

Value to be judged and transformed if truthy

Returns:
  • Whatever the formatter returns or the placeholder
Type
* | placeholder

(inner) isNil(value) → {boolean}

Checks if value is null or undefined

Parameters:
Name Type Description
value *

Value

Returns:
Type
boolean

(inner) isTruthy(value) → {boolean}

Checks if value is truthy. This means not undefined, not null, not 0, not infinite

Parameters:
Name Type Description
value *

Value

Returns:
Type
boolean

(inner) isUndefined(value) → {boolean}

Checks if value is undefined You might want this ¯\_(ツ)_/¯

Parameters:
Name Type Description
value *

Value

Returns:
Type
boolean

(inner) isValidVarName(value) → {boolean}

Run a validation to know if the name of a variable is valid or not

Example
isVarNameValid("valid_var_name"); //=> true
isVarNameValid("do"); //=> false
Parameters:
Name Type Description
value string

The suggested name of a variable

Returns:
Type
boolean

(inner) toFixed(digits, value) → {string}

A functional interface of toFixed

Note:

  • This is a composed function, so check the example to know how to call it
Example
toFixed()(0.1234); //=> "0.12"
toFixed(1)(0.1234); //=> "0.1"
toFixed(2)(0.1234); //=> "0.12"
Parameters:
Name Type Default Description
digits number 2

Number of floating points to be used

value number

Floating precision number to be fixed

Returns:
Type
string