Methods
(static) defaultWhenEquals(checkVal, defaultVal, val) → {*}
- Source:
- Since:
- See:
Returns the second argument if the third argument
is equal (in R.equals
terms) to the first argument,
otherwise returns the third argument.
Example
const defaultWhenEqualsZero = PHI.defaultWhenEquals('zero', 0)
defaultWhenEqualsZero('zero') //=> 0
defaultWhenEqualsZero(0) //=> 0
defaultWhenEqualsZero('one') //=> 'one'
defaultWhenEqualsZero(1) //=> 1
Parameters:
Name | Type | Description |
---|---|---|
checkVal |
* | The value to check equality against |
defaultVal |
* | The value to return if the other arguments are equal |
val |
* | The value to return if it is not equal to |
Returns:
Either val
or defaultVal
- Type
- *
(static) entries(arrnon-null) → (non-null) {Array}
- Source:
- Since:
- See:
Shortcut for Object.entries
.
Returns an array whose elements are arrays corresponding to
the enumerable property [key, value]
pairs found directly upon an object.
Example
PHI.entries({foo: 'bar', baz: 42})
//=> [['foo', 'bar'], ['baz', 42]]
Parameters:
Name | Type | Description |
---|---|---|
arr |
Object | The object for which to return entries |
Returns:
The array of entries
- Type
- Array
(static) findMax(arrnon-null) → (non-null) {number}
- Source:
- Since:
- See:
Finds the maximum value in a list.
Returns -Infinity
for empty lists.
Example
PHI.findMax([5, 4, -7, -2, 10, 5]) //=> 10
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | The list to search |
Returns:
The maximum value
- Type
- number
(static) findMin(arrnon-null) → (non-null) {number}
- Source:
- Since:
- See:
Finds the minimum value in a list.
Returns Infinity
for empty lists.
Example
PHI.findMin([5, 4, -7, -2, 10, 5]) //=> -7
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | The list to search |
Returns:
The minimum value
- Type
- number
(static) mapPath(pathnon-null, fnnon-null, objnon-null) → (non-null) {Object}
- Source:
- Since:
- See:
Maps over the value at the end of a path.
Example
PHI.mapPath(['a', 'b', 'c'], R.inc, {a: {b: {c: 3}}}) //=> {a: {b: {c: 4}}}
PHI.mapPath(['a', 'z'], R.always(10), {a: {b: {c: 3}}}) //=> {a: {z: 10, b: {c: 3}}}
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The path to map |
fn |
function | The function that transforms the value |
obj |
Object | The object with the path to map |
Returns:
The object with the mapped path
- Type
- Object
(static) nOf(val, nnon-null) → (non-null) {Array}
- Source:
- Since:
- See:
Returns an array of length n filled with the value provided.
Example
const nOfFoo = PHI.nOf('foo')
nOfFoo(5)
//=> ['foo', 'foo', 'foo', 'foo', 'foo']
Parameters:
Name | Type | Description |
---|---|---|
val |
* | Value to assign to each element |
n |
number | The length of the array |
Returns:
The new array
- Type
- Array
(static) objFromKeys(fnnon-null, keysnon-null) → (non-null) {Object}
- Source:
- Since:
Returns an object created from a list of keys with values derived from them.
Example
PHI.objFromKeys(R.toUpper, ['a', 'b', 'c'])
//=> {a: 'A', b: 'B', c: 'C'}
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | Function to map key to value |
keys |
string | number | Keys to include in object |
Returns:
The new object
- Type
- Object
(static) objOfKeys(val, keysnon-null) → (non-null) {Object}
- Source:
- Since:
- See:
Returns an object containing the provided keys with all keys assigned the same provided value.
Example
const objOfFoo = PHI.objOfKeys('foo')
objOfFoo(['a', 'b'])
//=> {a: 'foo', b: 'foo'}
Parameters:
Name | Type | Description |
---|---|---|
val |
* | Value to assign to each property |
keys |
Array | Keys to include in object |
Returns:
The new object
- Type
- Object
(static) sleeP(ms) → (non-null) {Promise}
Returns a promise which resolves after the specified number of milliseconds. This should not be relied on for ms accurate timing: the promise may resolve later then requested, but should not resolve before.
Example
PHI.sleeP(100) //=> Promise(null)
Parameters:
Name | Type | Description |
---|---|---|
ms |
Number | Number of milliseconds to sleep (default 0) |
Returns:
Promise which resolves to null after specified delay
- Type
- Promise
(static) sortByPath(pathnon-null, arrnon-null) → (non-null) {Array}
- Source:
- Since:
- See:
Sorts the list by the supplied property path.
Example
const sortByABC = PHI.sortByPath(['a', 'b', 'c'])
sortByABC([{a: {b: {c: 'joe'}}}, {a: {b: {c: 'alice'}}}])
//=> [{a: {b: {c: 'alice'}}}, {a: {b: {c: 'joe'}}}]
Parameters:
Name | Type | Description |
---|---|---|
path |
Array.<(string|number)> | The property path to sort by |
arr |
Array | The list to sort |
Returns:
The sorted list
- Type
- Array
(static) sortByProp(propnon-null, arrnon-null) → (non-null) {Array}
- Source:
- Since:
- See:
Sorts the list by the supplied property.
Example
const sortByFirstItem = PHI.sortByProp(0)
const pairs = [[-1, 1], [-2, 2], [-3, 3]]
sortByFirstItem(pairs) //=> [[-3, 3], [-2, 2], [-1, 1]]
const sortByName = PHI.sortByProp('name')
const people = [{name: 'joe'}, {name: 'alice'}]
sortByName(people) //=> [{name: 'alice'}, {name: 'joe'}]
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | number | The property to sort by |
arr |
Array | The list to sort |
Returns:
The sorted list
- Type
- Array