Global

Methods

allToLower(values) → {Array.<string>}

Description:
  • Converts all elements in an array to lowercase. Each element is coerced into a String, if it's not already one. All undefined and null values will be removed from the output.

Source:
Example
allToLower(['Foo', null, 'bAr']); // ['foo', bar']
Parameters:
Name Type Description
values Array.<string> | string

The values to convert to lowercase. A single value will be wrapped in an array.

Returns:

All the passed values, down cased.

Type
Array.<string>

allToUpper(values) → {Array.<string>}

Description:
  • Converts all elements in an array to uppercase. Each element is coerced into a String, if it's not already one. All undefined, null or empty values will be removed from the output.

Source:
Example
allToUpper(['Foo', null, 'bAr']); // ['FOO', BAR']
Parameters:
Name Type Description
values Array.<string> | string

The values to convert to uppercase. A single value will be wrapped in an array.

Returns:

All the passed values, upper cased.

Type
Array.<string>

alwaysNew(value) → {function}

Description:
  • Returns a function that creates new instances of whatever argument is passed in each time it's called.

Source:
Example
const alwaysNewArray = alwaysNew([]);
 const a = alwaysNewArray(); // -> []
 const b = alwaysNewArray(); // -> []
 // a !== b
Parameters:
Name Type Description
value *

The value to create instances of on each call.

Returns:

A factory function that returns new instances of value each time it is called.

Type
function

applySpec(spec) → {function}

Description:
  • Given a spec object recursively mapping properties to functions, creates a function producing an object of the same structure, by mapping each property to the result of calling its associated function with the supplied arguments.

    The difference between R.applySpec and this implementation is that it also accepts literal values as part of the spec (e.g. applySpec({ value: 42 });).

Source:
Example
const getMetrics = applySpec({
       list: [R.add, 'value']
       sum: R.add,
       some: 'value',
       nested: { mul: R.multiply, any: 'value' }
     });
     getMetrics(2, 4); // => {  list: [6, 'value'], sum: 6, some: 'value', nested: { mul: 8, any: 'value' } }
Parameters:
Name Type Description
spec object | Array

a list or object recursively mapping properties or elements to functions for producing corresponding values.

Returns:

A function that returns an object of the same structure as `spec', with each property set to the value returned by calling its associated function with the supplied arguments.

Type
function

arrayPath(path, obj) → {Array.<*>}

Description:
  • Shorthand function to extract a property at a path from an object and cast its value to an array. If the value is already an array, it will be returned as is. Note that this function ensures that the returned value is always an Array - so null and undefined property values at path will return [null] and [undefined] respectively. Use compactPath instead if you need all falsey and empty values removed.

Source:
See:
Example
arrayPath(['foo', 'bar'], { foo: { bar: 'baz' } }); // -> ['baz']
 arrayPath(['foo'], { foo: [1, 2, 3] }); // -> [1, 2, 3]
 arrayPath(['foo', 'bar'], { foo: {} }); // -> [undefined]
Parameters:
Name Type Description
path Array.<string>

Path to the value on obj

obj object

Source of the extracted property

Returns:

The value of obj at path cast as an array.

Type
Array.<*>

arrayProp(propName, obj) → {Array.<*>}

Description:
  • Shorthand function to extract a property from an object and cast its value to an array. If the value is already an array, it will be returned as is. Note that this function ensures that the returned value is always an Array - so null and undefined properties will return [null] and [undefined] respectively. Use compactProp instead if you need all falsey and empty values removed.

Source:
See:
Example
arrayProp('foo', { foo: 'bar' }); // -> ['bar']
 arrayProp('foo', { foo: [1, 2, 3] }); // -> [1, 2, 3]
 arrayProp('foo', {}); // -> [undefined]
Parameters:
Name Type Description
propName string

Name of the property to extract.

obj object

Source of the extracted property

Returns:

The value of obj at propName cast as an array.

Type
Array.<*>

booleanProp(propName, obj) → {boolean}

Description:
  • Shorthand function to extract a property from an object and convert it to a boolean. Parsing of values to boolean follows yn logic.

Source:
See:
Example
booleanProp('foo', { foo: 'y' }); // -> true
 booleanProp('foo', { foo: 0 }); // -> false
Parameters:
Name Type Description
propName string

Name of the property to extract.

obj object

Source of the extracted property

Returns:

The value of obj at propName as a boolean.

Type
boolean

booleanPropOr(defaultValue, propName, obj) → {*}

Description:
  • Shorthand function to extract a property from an object and convert it to a Boolean. If boolean conversion would return null or undefined, it returns defaultValue, instead.

Source:
See:
Example
booleanPropOr(true, 'foo', { bar: 42 }); // -> true
 booleanPropOr(false, 'foo', { foo: 'y' }); // -> true
Parameters:
Name Type Description
defaultValue *

The value to return if propName does not exist in obj or is nil.

propName string

Name of the property to extract.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a boolean or defaultValue.

Type
*

capitalize(str) → {string}

Description:
  • Transforms a string so that the first letter is capitalized and the rest is lowercased (i.e.: 'uNibROw' -> 'Unibrow'). If the input is null or undefined, it's returned as is.

Source:
Parameters:
Name Type Description
str string

The string to capitalize

Returns:

The original string with the first letter capitalized.

Type
string

capitalizeWords(words) → {string}

Description:
  • Capitalizes each word in a sentence. A "word" is considered any token between space characters.

Source:
Example
capitalizeWords('I am selling these fine leather jackets');
 // I am Selling These Fine Leather Jackets
Parameters:
Name Type Description
words string

The sentence to capitalize.

Returns:

The original sentence with each word capitalized.

Type
string

castArray(value) → {Array}

Description:
  • Wraps any value in an Array if it's not already one.

Source:
See:
Example
castArray(42); // -> [42]
 castArray([42]); // -> [42]
 castArray(['foo', 'bar']); // -> ['foo', 'bar']
Parameters:
Name Type Description
value *

The value to wrap

Returns:

An Array containing the given value or the same input if it was already an Array.

Type
Array

coalesce(fns) → {function}

Description:
  • Creates a wrapping function that concatenates the result of each function in fns with an || operator, returning the first truthy value. This works as a falsy-coalescing operator.

Source:
See:
Example
coalesce([prop('foo'), prop('bar'), prop('baz')])({ bar: 42 }); // -> 42
Parameters:
Name Type Description
fns Array.<function()>

A list of functions to be chained together with an || operator returning the result of the first truthy value after their evaluation.

Returns:

A falsy-coalescing evaluator function. The arity of this resulting function matches the arity of the function in fns with the largest number of arguments.

Type
function

compact(list) → {Array.<*>}

Description:
  • Returns a new array with all falsey and empty values removed. The values false, null, 0, "", undefined, and NaN are falsey. [] and {} are considered empty.

Source:
See:
Example
compact([0, 1, false, 2, '', 3, {}]);
 // -> [1, 2, 3]
Parameters:
Name Type Description
list Array.<*>

The array to compact.

Returns:

Returns the new array of filtered values.

Type
Array.<*>

compactPath(path, obj) → {Array.<*>}

Description:
  • Shorthand function to extract a property from an object at path and cast its value to an array, removing all falsey and empty values from it. The values false, null, 0, "", undefined, and NaN are falsey. [] and {} are considered empty. If the value is already an array, this function behaves like calling compact with that same value. Note that this function ensures that the returned value is always an Array - so null and undefined properties will both return [] (an empty array).

Source:
See:
Example
compactPath(['foo'. 'bar'], { foo: { bar: 'baz' } }); // -> ['baz']
 compactPath(['foo'], { foo: [0, 1, 2, 3, null] }); // -> [1, 2, 3]
 compactPath(['foo', 'bar'], {}); // -> []
 compactPath(['foo'], { foo: null }); // -> []
 compactPath(['foo', 'bar'], { foo: {} }); // -> []
Parameters:
Name Type Description
path Array.<string>

Path to the value on obj

obj object

Source of the extracted property

Returns:

The value of obj at path cast as an array with all falsey and empty values removed.

Type
Array.<*>

compactProp(propName, obj) → {Array.<*>}

Description:
  • Shorthand function to extract a property from an object and cast its value to an array, removing all falsey and empty values from it. The values false, null, 0, "", undefined, and NaN are falsey. [] and {} are considered empty. If the value is already an array, this function behaves like calling compact with that same value. Note that this function ensures that the returned value is always an Array - so null and undefined properties will both return [] (an empty array).

Source:
See:
Example
compactProp('foo', { foo: 'bar' }); // -> ['bar']
 compactProp('foo', { foo: [0, 1, 2, 3, null] }); // -> [1, 2, 3]
 compactProp('foo', {}); // -> []
 compactProp('foo', { foo: null }); // -> []
 compactProp('foo', { foo: {} }); // -> []
Parameters:
Name Type Description
propName string

Name of the property to extract.

obj object

Source of the extracted property

Returns:

The value of obj at propName cast as an array with all falsey and empty values removed.

Type
Array.<*>

compactSpec(spec, value) → {object|undefined}

Description:
  • Given a spec object recursively mapping properties to functions, creates a function producing an object of the same structure, by mapping each property to the result of calling its associated function with the supplied arguments. If the outcome of applying the spec produces an object with all nil or empty values, it returns undefined instead.

Source:
See:
Example
compactSpec({ foo: o => o.bar }, { bar: null }); // -> undefined
Parameters:
Name Type Description
spec object

An object recursively mapping properties to functions for producing the values for these properties.

value object | Array

An object or array to apply the spec to.

Returns:

An spec matching object, or undefined if all of its properties are nil or empty.

Type
object | undefined

curry(fn) → {function}

Description:
  • Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. First, its arguments needn't be provided one at a time. If f is a ternary function and g is curry(f), the following are equivalent:

    • g(1)(2)(3)
    • g(1)(2, 3)
    • g(1, 2)(3)
    • g(1, 2, 3)

    Secondly, the special placeholder value R.__ (exported by ramda) may be used to specify "gaps", allowing partial application of any combination of arguments, regardless of their positions. If g is as above and _ is R.__, the following are equivalent:

    • g(1, 2, 3)
    • g(_, 2, 3)(1)
    • g(_, _, 3)(1)(2)
    • g(_, _, 3)(1, 2)
    • g(_, 2)(1)(3)
    • g(_, 2)(1, 3)
    • g(_, 2)(_, 3)(1)
Source:
Example
const addFourNumbers = (a, b, c, d) => a + b + c + d;

     const curriedAddFourNumbers = R.curry(addFourNumbers);
     const f = curriedAddFourNumbers(1, 2);
     const g = f(3);
     g(4); //=> 10
Parameters:
Name Type Description
fn function

The function to curry.

Returns:

A new, curried function.

Type
function

curryN(length, fn) → {function}

Description:
  • Returns a curried equivalent of the provided function, with the specified arity. The curried function has two unusual capabilities. First, its arguments needn't be provided one at a time. If g is R.curryN(3, f), the following are equivalent:

    • g(1)(2)(3)
    • g(1)(2, 3)
    • g(1, 2)(3)
    • g(1, 2, 3)

    Secondly, the special placeholder value R.__ may be used to specify "gaps", allowing partial application of any combination of arguments, regardless of their positions. If g is as above and _ is R.__, the following are equivalent:

    • g(1, 2, 3)
    • g(_, 2, 3)(1)
    • g(_, _, 3)(1)(2)
    • g(_, _, 3)(1, 2)
    • g(_, 2)(1)(3)
    • g(_, 2)(1, 3)
    • g(_, 2)(_, 3)(1)
Source:
Example
const sumArgs = (...args) => R.sum(args);

     const curriedAddFourNumbers = R.curryN(4, sumArgs);
     const f = curriedAddFourNumbers(1, 2);
     const g = f(3);
     g(4); //=> 10
Parameters:
Name Type Description
length number

The arity for the returned function.

fn function

The function to curry.

Returns:

A new, curried function.

Type
function

interpolate(template, context) → {string}

Description:
  • Replaces variables in a template enclosed by {}.

Source:
Example
interpolate('I am {name}', { name: 'Error' });
 // 'I am Error'
Parameters:
Name Type Description
template string

The template to interpolate.

context object

The values to replace in `template.

Returns:

The result of resolving template interpolation with the given context.

Type
string

isNilOrEmpty(value) → {boolean}

Description:
  • Checks whether the given value is null, undefined or empty (definition of "empty" is type dependant).

Source:
See:
Example
isNilOrEmpty({}); // -> true
 isNilOrEmpty(null); // -> true
 isNilOrEmpty([]); // -> true
 isNilOrEmpty(''); // -> true
 isNilOrEmpty([42]); // -> false
Parameters:
Name Type Description
value *

The value to check

Returns:

true if value is either null, undefined or empty (such as "" for strings, {} for objects and [] for arrays); false, otherwise.

Type
boolean

isNotEmpty(value) → {boolean}

Description:
  • Checks whether the given value is not empty or not (definition of "empty" is type dependant).

Source:
See:
Example
isNotEmpty({}); // -> false
 isNotEmpty(null); // -> true
 isNotEmpty(undefined); // -> true
 isNotEmpty([]); // -> false
 isNotEmpty([42]); // -> true
 isNotEmpty(''); // -> false
Parameters:
Name Type Description
value *

The value to check

Returns:

true if value is not empty (such as "" for strings, {} for objects and [] for arrays); false, otherwise.

Type
boolean

isNotNil(value) → {boolean}

Description:
  • Checks whether the given value is neither null, nor undefined.

Source:
See:
Example
isNotNil({}); // -> true
 isNotNil(null); // -> false
 isNotNil([42]); // -> true
 isNotNil(undefined); // -> false
 isNotNil(''); // -> true
Parameters:
Name Type Description
value *

The value to check

Returns:

true if value is neither null nor undefined; false, otherwise.

Type
boolean

isNotNilOrEmpty(value) → {boolean}

Description:
  • Checks whether the given value is neither null, undefined nor empty (definition of "empty" is type dependant).

Source:
See:
Example
isNotNilOrEmpty({}); // -> false
 isNotNilOrEmpty(null); // -> false
 isNotNilOrEmpty([]); // -> false
 isNotNilOrEmpty(''); // -> false
 isNotNilOrEmpty([42]); // -> true
Parameters:
Name Type Description
value *

The value to check

Returns:

true if value is neither null, undefined nor empty (such as "" for strings, {} for objects and [] for arrays); false, otherwise.

Type
boolean

isNotOneOf(firstSet, secondSet) → {boolean}

Description:
  • Checks if a string value (or set of values) is not present in another. The comparison between elements is case insensitive. null and undefined values are ignored.

Source:
See:
Example
const isNotVeggie = isNotOneOf(['carrot', 'cucumber', 'parsnip']);
 isNotVeggie('tuna'); //=> true

 const areAllDomestic = isNotOneOf(['tiger', 'lion', 'panther']);
 areAllDomestic(['dog', 'cat']); //=> true
 areAllDomestic(['tiger', 'cat']); //=> false
Parameters:
Name Type Description
firstSet Array.<string> | string

The first set of elements (or single element) to check.

secondSet Array.<string> | string

The second set of elements (or single element) to check.

Returns:

true if no one element on firstSet is present in secondSet.

Type
boolean

isOneOf(firstSet, secondSet) → {boolean}

Description:
  • Checks if a string value (or set of values) is present in another. The comparison between elements is case insensitive. null and undefined values are ignored.

Source:
See:
Example
const isVeggie = isOneOf(['carrot', 'cucumber', 'parsnip']);
 isVeggie('tuna'); //=> false

 const anyWild = isOneOf(['tiger', 'lion', 'panther']);
 anyWild(['dog', 'cat']); //=> false
 anyWild(['tiger', 'cat']); //=> true
Parameters:
Name Type Description
firstSet Array.<string> | string

The first set of elements (or single element) to check.

secondSet Array.<string> | string

The second set of elements (or single element) to check.

Returns:

true if at least one element on firstSet is present in secondSet.

Type
boolean

joinFrom(separator, fns, elem) → {string}

Description:
  • Joins together using a separator strings returned from an array of fns functions that are applied to an obj element.

Source:
Example
joinFrom('-', [prop('firstName'), prop('lastName')], {
   firstName: 'Fred',
   lastName: 'Astaire'
 }); // -> Fred Astaire
Parameters:
Name Type Description
separator string

String to use to join together all other strings.

fns Array.<function()>

Set of string returning functions that will be applied to obj.

elem *

Value that will become the single argument for each function in fns.

Returns:

The result of joining together each string returned by functions in fns with separator.

Type
string

lowerEquals(first, second) → {boolean}

Description:
  • Compares two elements and returns true if they are the same after transforming their stringified value to lower case and trimming spaces; false otherwise.

Source:
See:
Parameters:
Name Type Description
first *

The first value to compare.

second *

The second value to compare.

Returns:

true if first and second are the same value after lower casing and trimming.

Type
boolean

lowerPath(path, obj) → {*}

Description:
  • Extracts the value of an object at the given path. The individual keys on the path are transformed to lowercase before extracting the actual value.

Source:
See:
Example
lowerPath(['country', 'IE'], {country: { ie: '&#133662110186;' } });
 // -> '&#133662110186;'
Parameters:
Name Type Description
path Array.<string>

The path to the value (items in here will be lowercased).

obj object

The source of the value to extract.

Returns:

The value of obj at path after lower casing keys.

Type
*

lowerPathSatisfies(pred, path, obj) → {boolean}

Description:
  • Returns true if the specified object property at given path satisfies the given predicate; false otherwise. The individual keys on the path are transformed to lowercase before checking the actual value.

Source:
See:
Example
lowerPathSatisfies(isNil, ['country', 'IE'], {country: { ie: '&#133662110186;' } });
 // -> false
Parameters:
Name Type Description
pred function

The predicate to check the value.

path Array.<string>

The path to the value (items in here will be lowercased).

obj object

The source of the value to extract.

Returns:

True if the object property at given path satisfies the given predicate.

Type
boolean

lowerTrim(value) → {string}

Description:
  • Trims and transforms text to lower case. null and undefined values are returned as is.

Source:
Parameters:
Name Type Description
value string

The string to trim and convert to lowercase.

Returns:

The value after trimming and lowercasing.

Type
string

mapKeys(fn, obj) → {object}

Description:
  • Map keys on an objects by running a mapping function to each one.

Source:
Parameters:
Name Type Description
fn function

Mapping function. Receives a key and must return a new key name.

obj object

The object to map keys from.

Returns:

The resulting object after mapping its keys.

Type
object

mergeInto(propNames, arrayPropName, obj) → {object}

Description:
  • Given an object containing an array move selected properties outside the array to each element on it.

Source:
Example
const o = { foo: 'bar', items: [{ id: 1 }, { id: 2 }] };
 mergeInto('foo', 'items');
 // -> { foo: 'bar', items: [{ id: 1, foo: 'bar' }, { id: 2, foo: 'bar' }] }
Parameters:
Name Type Description
propNames string | Object

List of property names to merge into each element in the arrayProp (supports sending a single name).

arrayPropName string

Name of the array property on obj.

obj object

The object to apply the transformation to.

Returns:

The object with propNames properties merged into elements of arrayPropName array.

Type
object

mergeSpec(spec, obj) → {object}

Description:
  • Recursively applies functions on the spec object to produce a new object matching its definition, which is then merged with the original object. If a key exists in both objects, the value from the result of applying the spec will take precedence.

Source:
See:
Example
mergeSpec({ bar: o => o.num + 40 }, { num: 2 });
 // -> { bar: 42, num: 2 }
Parameters:
Name Type Description
spec object

An object recursively mapping properties to functions for producing corresponding values.

obj object

The object to apply the spec to and onto which the result will be merged.

Returns:

A new object containing all properties coming from applying the spec to obj plus all or of obj own properties.

Type
object

nAry(n, fn) → {function}

Description:
  • Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. Any extraneous parameters will not be passed to the supplied function.

Source:
Example
const takesTwoArgs = (a, b) => [a, b];

     takesTwoArgs.length; //=> 2
     takesTwoArgs(1, 2); //=> [1, 2]

     const takesOneArg = R.nAry(1, takesTwoArgs);
     takesOneArg.length; //=> 1
     // Only `n` arguments are passed to the wrapped function
     takesOneArg(1, 2); //=> [1, undefined]
Parameters:
Name Type Description
n number

The desired arity of the new function.

fn function

The function to wrap.

Returns:

A new function wrapping fn. The new function is guaranteed to be of arity n.

Type
function

notEquals(A, B) → {boolean}

Description:
  • Returns false if its arguments are equivalent, true otherwise. Handles cyclical data structures.

Source:
See:
Example
notEquals(1, 2) //=> true
  notEquals({ a: 1 }, { a: 1 }) //=> false
Parameters:
Name Type Description
A any

The first object to compare

B any

The second object to compare

Returns:

The result of the compare

Type
boolean

numberPath(propPath, obj) → {number}

Description:
  • Shorthand function to extract a nested property from an object and convert it to a number. Note that this behaves somewhat different to regular number parsing using Number constructor: if the property is null or undefined it will be returned as is; if the property is an empty string (''), NaN will be returned.

Source:
See:
Example
numberPath(['life', 'meaning'], { life: { meaning: '42' }}); // 42
Parameters:
Name Type Description
propPath string | Object

Path to the property to extract. Also accepts a property name as a single string.

obj object

Source of the extracted property.

Returns:

The value of obj at propPath as a number or NaN.

Type
number

numberPathOr(defaultValue, propPath, obj) → {*}

Description:
  • Extract a nested property from an object and convert it to a number. If property is absent, null, undefined or cannot be coerced into a Number, the default value will be returned instead. Note that number coercing behaves somewhat different than using the Number constructor: an empty string ('') or null would return the defaultValue instead of 0.

Source:
See:
Example
numberPathOr(42, ['life', 'meaning'], { foo: 'bar' }); // 42
Parameters:
Name Type Description
defaultValue *

The value to return if propPath does not exist in obj or its value is nil or NaN.

propPath string | Object

Path to the property to extract. Also accepts a property name as a single string.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a number or defaultValue.

Type
*

numberProp(propName, obj) → {number}

Description:
  • Shorthand function to extract a property from an object and convert it to a number. Note that this behaves somewhat different to regular number parsing using Number constructor: if the property is null or undefined it will be returned as is; if the property is an empty string (''), NaN will be returned.

Source:
See:
Parameters:
Name Type Description
propName string

Name of the property to extract.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a number or NaN.

Type
number

numberPropOr(defaultValue, propName, obj) → {*}

Description:
  • Extract a property from an object and convert it to a number. If property is absent, null, undefined or cannot be coerced into a Number, the default value will be returned instead. Note that number coercing behaves somewhat different than using the Number constructor: an empty string ('') or null would return the defaultValue instead of 0.

Source:
See:
Parameters:
Name Type Description
defaultValue *

The value to return if propName does not exist in obj or is nil.

propName string

Name of the property to extract.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a number or defaultValue.

Type
*

propOf(obj, propName) → {*}

Description:
  • Returns the value of obj at the given propName.

Source:
See:
Example
propOf({ name: 'Alexander' }, 'name') //=> 'Alexander'
  propOf({ name: 'Alexander' }, 'age') //=> undefined
Parameters:
Name Type Description
obj object

The object to query

propName string

The property name

Returns:

The value at obj[propName].

Type
*

rejectNil(functor) → {object|Object}

Description:
  • Iterates over a functor a removes any elements that are either null or undefined.

Source:
See:
Example
rejectNil(null); // -> null
 rejectNil([42, undefined, 'life']); // -> [42, 'life']
 rejectNil({ foo: null, life: 42 }); // -> { life: 42 }
Parameters:
Name Type Description
functor object | Object

The iterable to remove nil values from.

Returns:

The original iterable without null or undefined values.

Type
object | Object

rejectNilOrEmpty(functor) → {object|Object}

Description:
  • Iterates over a functor a removes any elements that are either null, undefined. or empty ([], {}).

Source:
See:
Example
rejectNilOrEmpty(null); // -> null
 rejectNilOrEmpty([42, undefined, {}, 'life']); // -> [42, 'life']
 rejectNilOrEmpty({ foo: null, bar: [], life: 42 }); // -> { life: 42 }
Parameters:
Name Type Description
functor object | Object

The iterable to remove nil or empty values from.

Returns:

The original iterable without null, undefined or empty values.

Type
object | Object

renameKeys(keysMap, obj) → {object}

Description:
  • Creates a new object with the own properties of the provided object, but the keys renamed according to the keysMap object as {oldKey: newKey}. When some key is not found in the keysMap, then it's passed as-is.

Source:
See:
Example
renameKeys({ foo: 'life' }, { foo: 42 }); // -> { life: 42 }
Parameters:
Name Type Description
keysMap object

Mapping of current key names to new names.

obj object

Object whose keys are to be renamed

Returns:

A new object based on obj with renamed keys.

Type
object

round(decimals, value) → {number}

Description:
  • Rounds a given number to the next largest number for positives and the next smallest for negatives.

Source:
Example
round(2, 2.151) // returns 2.15
round(1, -2.63) // returns -2.7
round(0, 2.8) // returns 3
Parameters:
Name Type Description
decimals number

number of decimals to round to

value number

number to be rounded

Returns:

rounded number

Type
number

spreadProp(prop, obj) → {object}

Description:
  • Spreads object under property onto provided object.

Source:
See:
Example
spreadProp('b', { a: 1, b: { c: 3, d: 4 } }); // => { a: 1, c: 3, d: 4 };
Parameters:
Name Type Description
prop string | Number

The property to spread

obj object

The provided object

Returns:

The result of the spread

Type
object

stringPath(propPath, obj) → {string}

Description:
  • Shorthand function to extract a nested property from an object and convert it to a string. If the property is null or undefined it will be returned as is; if the property is an empty string (''), null will be returned.

Source:
See:
Example
stringPath(['life', 'count'], { life: { count: 1 }}); // '1'
Parameters:
Name Type Description
propPath string | Object

Path to the property to extract. Also accepts a property name as a single string.

obj object

Source of the extracted property.

Returns:

The value of obj at propPath as a string or null.

Type
string

stringPathOr(defaultValue, propPath, obj) → {*}

Description:
  • Extract a nested property from an object and convert it to a string. If property is absent, null, undefined or empty, the default value will be returned instead.

Source:
See:
Example
stringPathOr('default', ['life', 'reason'], { foo: 'bar' }); // 'default'
Parameters:
Name Type Description
defaultValue *

The value to return if propPath does not exist in obj or its value is nil or empty.

propPath string | Object

Path to the property to extract. Also accepts a property name as a single string.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a string or defaultValue.

Type
*

stringProp(propName, obj) → {string}

Description:
  • Shorthand function to extract a property from an object and convert it to a string. If the property is null or undefined it will be returned as is; if the property is an empty string (''), null will be returned.

Source:
See:
Parameters:
Name Type Description
propName string

Name of the property to extract.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a string or null string.

Type
string

stringPropOr(defaultValue, propName, obj) → {*}

Description:
  • Extract a property from an object and convert it to a string. If property is absent, null, undefined or empty, the default value will be returned instead.

Source:
See:
Parameters:
Name Type Description
defaultValue *

The value to return if propName does not exist in obj or is nil.

propName string

Name of the property to extract.

obj object

Source of the extracted property.

Returns:

The value of obj at propName as a string or defaultValue.

Type
*

sumProp(precision, propName, values) → {number}

Description:
  • Sums the values at propName present in each element of an array. Works as a single-pass version of compose(sum, map(Number), pluck(propName)).

Source:
Example
sumProp(2, 'amount', [{amount:'40'}, {amount:'2'}]); // 42
Parameters:
Name Type Description
precision string

Number of decimal places used in rounding the final value.

propName string

Name of the property to pluck values from.

values Array.<object>

The elements to extract the propName values from. Value may be either a Number or a numerical String.

Returns:

The total sum of all values at propName.

Type
number

thenThrowErrorWith(message, data)

Description:
  • Returns a function that, when invoked, throws an Error with the given message extended with additional properties on data.

Source:
Example
const explode = thenThrowErrorWith('boom', { code: 500 });
 explode(); // Throw `new Error('boom')`
Parameters:
Name Type Description
message string

The error message

data object

Additional properties to attach to the thrown error

Throws:
Error

throwErrorWith(message, data)

Description:
  • Immediately throws an Error with the given message extended with additional properties on data.

Source:
Example
throwErrorWith('boom', { code: 500 }); // Throw `new Error('boom')`
Parameters:
Name Type Description
message string

The error message

data object

Additional properties to attach to the thrown error

Throws:
Error

truncate(maxLength, value) → {string}

Description:
  • Truncates the given string value so its total length does not exceed maxLength length, adding an ellipsis (...) at the end.

Source:
Example
truncate(15, 'I am selling these fine leather jackets');
 // 'I am selling...'
Parameters:
Name Type Description
maxLength number

Length threshold above which value will be truncated.

value *

The text to truncate (will be coerced into a String and trimmed).

Returns:

The truncated string containing an ellipsis (...) at the end.

Type
string