isArrayWith # any-any → any-boolean

Return a function returning true if the accessed value is an array

Example

> isArrayWith(getValue)({key: 'a', value: [1, 2]})
true
@since 0.1.0
isNilWith # any-any → any-boolean

Return a function returning true if the accessed value is null or undefined

Example

> isNilWith(getValue)({key: 'a', value: null})
true
> isNilWith(getValue)({key: 'a'})
true
@since 0.1.0
isNotNaNWith # any-any → any-boolean

Return a function returning true if the accessed value is not NaN

Example

> isNotNaNWith(getValue)({key: 'a', value: 1})
true
@since 0.1.0
isNotNilWith # any-any → any-boolean

Return a function returning true if the accessed value is not null or undefined

Example

> isNotNilWith(getValue)({key: 'a', value: 1})
true
@since 0.1.0
isNotNullWith # any-any → any-boolean

Return a function returning true if the accessed value is not null

Example

> isNotNullWith(getValue)({key: 'a', value: 1})
true
@since 0.1.0
isNullWith # any-any → any-boolean

Return a function returning true if the accessed value is null

Example

> isNullWith(getValue)({key: 'a', value: null})
true
@since 0.1.0
isNumberWith # any-any → any-boolean

Return a function returning true if the accessed value is a number

Example

> isNumberWith(getValue)({key: 'a', value: 1})
true
> isNumberWith(getValue)({key: 'a', value: 'a'})
false
@since 0.1.0
isObjectWith # any-any → any-boolean

Return a function returning true if the accessed value is an object

Example

> isObjectWith(getValue)({key: 'a', value: {a: 1}})
true
> isObjectWith(getValue)({key: 'a', value: 'a'})
false
@since 0.1.0
isStringWith # any-any → any-boolean

Return a function returning true if the accessed value is a string

Example

> isStringWith(getValue)({key: 'a', value: 'a'})
true
> isStringWith(getValue)({key: 'a', value: 1})
false
@since 0.1.0
isToFloatValidNumberWith # any-any → any-boolean

Return a function returning true if the accessed value can be turned into a valid number via parseFloat()

Example

> isToFloatValidNumberWith(getValue)({key: 'a', value: [1]})
true
> isToFloatValidNumberWith(getValue)({key: 'a', value: []})
false
@since 0.1.0
isToNumberValidNumberWith # any-any → any-boolean

Return a function returning true if the accessed value can be turned into a valid number via Number()

Example

> isToNumberValidNumberWith(getValue)({key: 'a', value: '123'})
true
> isToNumberValidNumberWith(getValue)({key: 'a', value: '123px'})
false
@since 0.1.0
isUndefinedWith # any-any → any-boolean

Return a function returning true if the accessed value is undefined

Example

> isUndefinedWith(getValue)({key: 'a', value: 'a'})
false
> isUndefinedWith(getValue)({key: 'a', value: 1})
false
@since 0.1.0
isValidNumberWith # any-any → any-boolean

Return a function returning true if the accessed value is a valid number

Example

> isValidNumberWith(getValue)({key: 'a', value: 'a'})
false
> isValidNumberWith(getValue)({key: 'a', value: 1})
true
@since 0.1.0
areEqualWith # any-any → array-boolean

Return a function returning `true` if all the items of an array are equal once processed with the provided `fn`

Example

> areEqualByValue = areEqualWith(getValue)
> areEqualByValue([{key: 'a', value: 1}, {key: 'b', value: 1}])
true
> areEqualByValue([{key: 'a', value: 1}, {key: 'b', value: 2}])
false
> areEqualByValue([{key: 'a', value: 1}])
false
> areEqualByValue([])
false
@since 0.1.0
pairToKeyValueObjectWith # any-any → iterable-object

Return a function expecting a pair and returning a {key, value} object using the provided `fn` to get the `value`.

Example

> objectifySelfSum = pairToKeyValueObjectWith(x => x + x)

> objectifySelfSum('')
{key: undefined, value: undefined}
> objectifySelfSum('a')
{key: 'a', value: undefined}
> objectifySelfSum('ab')
{key: 'a', value: 'bb'}
> objectifySelfSum('abc')
{key: 'a', value: 'bb'}


> objectifyGetA = pairToKeyValueObjectWith(_.getKey('a'))

> objectifyGetA([])
{key: undefined, value: undefined}
> objectifyGetA([1])
{key: 1, value: undefined}
> objectifyGetA([1, {a: 2}])
{key: 1, value: 2}
> objectifyGetA([1, {a: 2}, 3])
{key: 1, value: 2}

> function func () {
	return objectifyGetA(arguments);
}
> func()
{key: undefined, value: undefined}
> func(1)
{key: 1, value: undefined}
> func(1, {a: 2})
{key: 1, value: 2}
> func(1, {a: 2}, 3)
{key: 1, value: 2}
@since 0.1.0
objectToKeyValueArrayWith # any-any → object-array

Return a function expecting an object and returning an array of {key, value} objects, using the provided `fn` to get the `value` of each object.

Example

> obj = {k1: {a: 1}, k2: {a: 2}}
> convertToArray = objectToKeyValueArrayWith(_.getKey('a'))
> convertToArray(obj)
[{key: 'k1', value: 1}, {key: 'k2', value: 2}]
@since 0.1.0
valuesWith # any-any → object-array

Return a function expecting an object and returning an array of its values processed with the provided function. The accessor receives (value, key) so keys can be used in the transformation.

Example

> triplicatedValues = valuesWith(_.add(3));
> triplicatedValues({a: 1, b: 2, c: 3})
[4, 5, 6]

> getFoos = valuesWith(_.getKey('foo'));
> getFoos({a: {foo: 1, bar: 2}, b: {foo: 15, bar: -3}})
[1, 15]

> keysAndValues = valuesWith((value, key) => `${value} (${key})`);
> keysAndValues({a: 3, b: 5})
['3 (a)', '5 (b)']
@since 0.1.0
areValuesEqualWith # any-any → object-boolean

Return a function expecting an object and returning `true` if its values, once processed with the provided `fn` function, are all equal.

Example

> areValuesEqual = areValuesEqualWith(getValue)
> areValuesEqual({a: {key: 'a', value: 1}, b: {key: 'b', value: 1}})
true
> areValuesEqual({a: {key: 'a', value: 1}, b: {key: 'b', value: 2}})
false
@since 0.1.0
groupValuesWith # any-any → object-object

Return a function expecting an object and returning an object grouping its values using the provided `fn`. Values that are arrays are flattened before grouping.

Example

> regroupedByX = groupValuesWith(obj => obj.x)
> regroupedByX({a: {x: 1, y: 2}, b: {x: 3, y: 4}, c: {x: 'a', y: 6}, d: {x: 1, y: 8}})
{1: [{x: 1, y: 2}, {x: 1, y: 8}], 3: [{x: 3, y: 4}], a: [{x: 'a', y: 6}]}
@since 0.1.0
indexValuesWith # any-any → object-object

Return a function expecting an object and returning an index of all its values using the provided `fn`. Use this if you're sure that applying the `fn` on the object values returns unique strings. Values that are arrays are flattened before indexing.

Example

> reindexedByX = indexValuesWith(obj => obj.x)
> reindexedByX({a: {x: 'u1', y: 2}, b: {x: 'u2', y: 4}})
{u1: {x: 'u1', y: 2}, u2: {x: 'u2', y: 4}}
@since 0.1.0
makeBiPermutationsWith # any-array

Return a function returning the pair-permutations of the items returned by the provided `fn`.

Example

> object = {
  key: 'foobars',
  value: [{foo: 'a'}, {foo: 'b'}, {bar: 'c'}, {bar: 'd'}]
}
> makeBiPermutations = makeBiPermutationsWith(getValue)
[
  [{foo: 'a'}, {foo: 'b'}],
  [{foo: 'a'}, {bar: 'c'}],
  [{foo: 'a'}, {bar: 'd'}],
  [{foo: 'b'}, {bar: 'c'}],
  [{foo: 'b'}, {bar: 'd'}],
  [{bar: 'c'}, {bar: 'd'}]
]
@since 0.1.0
makeArrayToObjectWith # any-array → array-object

Return a function expecting an array and returning an object with keys and values defined by the provided function, which expects a value and returns a pair [key, value].

Example

> valueToPair = x => [`${x}${x}`, `${x}${x}${x}`];
> arrayToObject1 = makeArrayToObjectWith(valueToPair)
> arrayToObject1(['a', 'b', 1])
{aa: 'aaa', bb: 'bbb', 11: '111'}

> valueIndexToPair = (x, i) => [`${i}${i}`, `${x}${x}${x}`];
> arrayToObject2 = makeArrayToObjectWith(valueIndexToPair)
> arrayToObject2(['a', 'b', 1])
{'00': 'aaa', '11': 'bbb', '22': '111'}
@since 0.1.0
raiseWith # any-boolean → array-array

Return a function expecting an array and returning a new array with all items satisfying the provided predicate in the tail, in the same relative order they were in the input array.

Example

> raiseOdds = raiseWith(x => x % 2 === 1);
> raiseOdds([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
[0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
@since 0.1.0
findValueWith # any-boolean → object-generic

Return a function expecting an object and returning the first of its values satisfying the provided predicate.

Example

> findFirstOdd = findValueWith(x => x % 2 === 1);
> findFirstOdd({a: 2, b: 4, c: 3, d: 6, e: 7})
3
> findItem = findValueWith(isKeyValue(['max', 10]))
> findItem({a: {id: 'foo', min: 1, max: 2}, b: {id: 'bar', min: -1, max: 10}, c: {id: 'baz', min: -4, max: 10}})
{id: 'bar', min: -1, max: 10}
@since 0.1.0
arrayMaxWith # any-number → array-number

Return a function expecting an array and returning the max of results of applying the provided function on all of the array items.

Example

> maxWithAbsSin = arrayMaxWith(_.pipe([Math.sin, Math.abs]))
> maxWithAbsSin([-Math.PI/2, -Math.PI/4])
1
> maxWithAbsSin([Math.PI/4, Math.PI/6])
0.7071067811865475
@since 0.1.0
arrayMinWith # any-number → array-number

Return a function expecting an array and returning the min of results of applying the provided function on all of the array items.

Example

> minWithAbsSin = arrayMinWith(_.pipe([Math.sin, Math.abs]))
> minWithAbsSin([-Math.PI/2, -Math.PI/4])
0.7071067811865475
> minWithAbsSin([Math.PI/4, Math.PI/6])
0.49999999999999994
@since 0.1.0
arraySumWith # any-number → array-number

Return a function expecting an array and summing the numbers obtained from applying the provided `fn` to the array items.

Example

> sumValues = arraySumWith(_.getKey('a'))
> sumValues([{a: 1}, {a: 2}, {a: 3}])
6
> sumValues([])
0
@since 0.1.0
makeAverageWith # any-number → array-number

Return a function expecting an array and returning the average of the numbers obtained by applying the provided `fn` to the array items.

Example

> makeAverageOfA = makeAverageWith(_.getKey('a'));
> makeAverageOfA([{a: 1, b: 2}, {a: 10, b: 7}, {a: 7, b: 9}])
6
> makeAverageOfA([])
0
@since 0.1.0
valuesMaxWith # any-number → object-number

Return a function expecting an object, applying the provided function to its values and returning the largest of the results.

Example

> maxWithAbsSin = valuesMaxWith(_.pipe([Math.sin, Math.abs]))
> maxWithAbsSin({a: -Math.PI/2, b: -Math.PI/4})
1
> maxWithAbsSin({a: -Math.PI/4, b: -Math.PI/6})
0.7071067811865475
@since 0.1.0
valuesMinWith # any-number → object-number

Return a function expecting an object, applying the provided function to its values and returning the lowest of the results.

Example

> minWithAbsSin = valuesMinWith(_.pipe([Math.sin, Math.abs]))
> minWithAbsSin({a: -Math.PI/2, b: -Math.PI/4})
0.7071067811865475
> minWithAbsSin({a: -Math.PI/4, b: -Math.PI/6})
0.49999999999999994
@since 0.1.0
makeAllOccurrencesWith # any-object → array-object

Return a function expecting an array and returning an object of occurrences of all the keys contained in the property reachable with the provided `fn` in the items of the provided array.

Example

> items = [
  {foo: 1, bar: {a: 1}},
  {foo: 1, bar: {a: 6, b: -1}},
  {foo: 1, bar: {a: 2, b: 0, c: 1}},
  {foo: 1, bar: {c: 4, e: 2}},
]
> makeAllOccurrences = makeAllOccurrencesWith(_.getKey('bar'))
> makeAllOccurrences(items)
{a: 3, b: 2, c: 2, e: 1}
@since 0.1.0
getFirstAndLast # array

Return an array containing the first and the last element of the provided array.

Example

> getFirstAndLast([0, 1, 2, 3, 4])
[0, 4]
> getFirstAndLast([0])
[0, 0]
> getFirstAndLast([])
[undefined, undefined]
@since 0.1.0
inclusiveRange # array

Return the range within the provided limits, both limits being included.

Example

> inclusiveRange([2, 5])
[2, 3, 4, 5]
> inclusiveRange([2, 12, 2])
[2, 4, 6, 8, 10, 12]
> inclusiveRange([])
[]
@since 0.1.0
makeBiPermutations # array

Return the permutations of pairs of the provided items.

Example

> makeBiPermutations([{foo: 'a'}, {foo: 'b'}, {bar: 'c'}])
[[{foo: 'a'}, {foo: 'b'}], [{foo: 'a'}, {bar: 'c'}], [{foo: 'b'}, {bar: 'c'}]]
@since 0.1.0
pluckKey # array

Pluck the `key` property value from an array of objects.

Example

> pluckKey([{key: 'John', value: 'Foo'}, {key: 'Jane', value: 'Bar'}])
['John', 'Jane']
@since 0.1.0
pluckValue # array

Pluck the `value` property value from an array of objects.

Example

> pluckValue([{key: 'John', value: 'Foo'}, {key: 'Jane', value: 'Bar'}])
['Foo', 'Bar']
@since 0.1.0
sortDesc # array

Return a copy of the provided array sorted in descending order.

Example

> sortDesc([3, 1, 2])
[3, 2, 1]
@since 0.3.0
sortKeyAsc # array

Return a copy of the provided array of key-value objects sorted by `key` (ascending).

Example

> sortKeyAsc([{key: 'b', value: 1}, {key: 'a', value: 2}])
[{key: 'a', value: 2}, {key: 'b', value: 1}]
@since 0.3.0
sortKeyDesc # array

Return a copy of the provided array of key-value objects sorted by `key` (descending).

Example

> sortKeyDesc([{key: 'a', value: 1}, {key: 'c', value: 2}, {key: 'b', value: 3}])
[{key: 'c', value: 2}, {key: 'b', value: 3}, {key: 'a', value: 1}]
@since 0.3.0
sortValueAsc # array

Return a copy of the provided array of key-value objects sorted by `value` (ascending).

Example

> sortValueAsc([{key: 'a', value: 3}, {key: 'b', value: 1}, {key: 'c', value: 2}])
[{key: 'b', value: 1}, {key: 'c', value: 2}, {key: 'a', value: 3}]
@since 0.3.0
sortValueAscKeyAsc # array

Return a copy of the provided array with items sorted by `value` (ascending) then by `key` (ascending)

@since 0.1.0
sortValueAscKeyDesc # array

Return a copy of the provided array with items sorted by `value` (ascending) then by `key` (descending)

@since 0.3.0
sortValueDesc # array

Return a copy of the provided array of key-value objects sorted by `value` (descending).

Example

> sortValueDesc([{key: 'a', value: 1}, {key: 'b', value: 3}, {key: 'c', value: 2}])
[{key: 'b', value: 3}, {key: 'c', value: 2}, {key: 'a', value: 1}]
@since 0.3.0
sortValueDescKeyAsc # array

Return a copy of the provided array with items sorted by `value` (descending) then by `key` (ascending)

@since 0.3.0
sortValueDescKeyDesc # array

Return a copy of the provided array with items sorted by `value` (descending) then by `key` (descending)

@since 0.3.0
sortValueDescLabelAsc # array

Return a copy of the provided array sorted by `value` (descending) then `label` (ascending).

Example

> sortValueDescLabelAsc([{key: 'a', label: 'z', value: 1}, {key: 'b', label: 'a', value: 1}])
[{key: 'b', label: 'a', value: 1}, {key: 'a', label: 'z', value: 1}]
@since 0.3.0
sortValueDescLabelDesc # array

Return a copy of the provided array sorted by `value` (descending) then `label` (descending).

Example

> sortValueDescLabelDesc([{key: 'a', label: 'a', value: 1}, {key: 'b', label: 'z', value: 1}])
[{key: 'b', label: 'z', value: 1}, {key: 'a', label: 'a', value: 1}]
@since 0.3.0
sortValueDescLabelLowercaseAsc # array

Return a copy of the provided array sorted by `value` (descending) then `label` lowercase (ascending).

Example

> sortValueDescLabelLowercaseAsc([{key: 'a', label: 'Z', value: 1}, {key: 'b', label: 'a', value: 1}])
[{key: 'b', label: 'a', value: 1}, {key: 'a', label: 'Z', value: 1}]
@since 0.3.0
sortValueDescLabelLowercaseDesc # array

Return a copy of the provided array sorted by `value` (descending) then `label` lowercase (descending).

Example

> sortValueDescLabelLowercaseDesc([{key: 'a', label: 'a', value: 1}, {key: 'b', label: 'Z', value: 1}])
[{key: 'b', label: 'Z', value: 1}, {key: 'a', label: 'a', value: 1}]
@since 0.3.0
makeArrayTransformer # array → array-array

Return a function expecting an array and applying the provided transforms to its elements. The result array length equals the length of the shorter of the two arrays.

Example

> transformer = makeArrayTransformer([x => x * 20, x => x + 3])
> transformer([2, 2])
[40, 5]
@since 0.1.0
pluckKeys # array → array-array

Return a function plucking the provided keys from each object in the expected array.

Example

> select = pluckKeys(['a', 'k'])
> select([
  {a: 1, b: 2, c: 3, k: 4},
  {a: 5, b: 8},
])
[{a: 1, k: 4}, {a: 5}]
@since 0.1.0
removeAt # array → array-array

Return a function expecting an array and removing items at the provided indices.

Example

> removeIndices = removeAt([3, 4, 8])
> removeIndices([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
[0, 1, 2, 5, 6, 7, 9]
@since 0.1.0
makeWithKeys # array → array-object

Return a function expecting an array of values and returning an object assigning the values to the provided keys.

Example

> makeWithLatLng = makeWithKeys(['lng', 'lat'])
> makeWithLatLng([1, 2])
{lng: 1, lat: 2}
> makeWithLatLng([10, 20])
{lng: 10, lat: 20}
@since 0.1.0
makeWithValues # array → array-object

Return a function expecting an array of keys and returning an object assigning the keys to the provided values.

Example

> makeWithTheseValues = makeWithValues([1, 2])
> makeWithTheseValues(['lng', 'lat'])
{lng: 1, lat: 2}
> makeWithTheseValues(['foo', 'bar'])
{foo: 1, bar: 2}
@since 0.1.0
areAllTruthy # array → boolean

Return true if all elements of the provided array are truthy

Example

> areAllTruthy([true, true])
true
> areAllTruthy([1, [], [1, 2], {}, {a: 1}, 'a'])
true
> areAllTruthy([false, true])
false
> areAllTruthy([0, {a: 1}])
false
@since 0.1.0
areEqual # array → boolean

Return `true` if items in the provided array are equal

Example

> areEqual([false, false, false])
true
> areEqual([true, false, false])
false
> areEqual([])
false
> areEqual([1])
false
@since 0.1.0
areSomeTruthy # array → boolean

Return true if some elements of the provided array are truthy

Example

> areSomeTruthy([false, true])
true
> areSomeTruthy([0, ''])
false
@since 0.1.0
getRandomItemOf # array → generic

Return a random item of the passed array

Example

> getRandomItemOf([0, 1, 2, 3])
2
> getRandomItemOf([0, 1, 2, 3])
1
> getRandomItemOf([{a: 0}, {a: 1}, {a: 2}, {a: 3}])
{a: 3}
> getRandomItemOf([{a: 0}, {a: 1}, {a: 2}, {a: 3}])
{a: 0}
@since 0.1.0
makeIsIncluded # array → generic-boolean

Return a function returning true if the passed (primitive) value is found in the provided array. To check non-primitive values use makeOccursIn instead.

Example

> isIncluded = makeIsIncluded([1, 2, 3])
> isIncluded(1)
true
> isIncluded(4)
false
@since 0.1.0
makeOccursIn # array → generic-boolean

Return a function returning true if the passed value is found in the provided array. This function is ideal to check the presence of arrays or objects. To check primitive values use makeIsIncluded instead.

Example

> isOneOfThoseArrays = makeOccursIn([
  [1, 2, 3], [1, 2, 3, 4], [5, 6, 7, 6, 5]
])
> isOneOfThoseArrays([1, 2, 3])
true
> isOneOfThoseArrays([1, 2])
false
@since 0.1.0
truthynessTo # array → generic-generic

Return a function that maps the input to the first or the second element of the provided pair: the first if its truthy, the second otherwise.

Example

> boolToNum = truthynessTo([0, 1])
> boolToNum(true)
0
> boolToNum(false)
1

> boolToString = truthynessTo(['OK!', 'Sorry!'])
> boolToString(true)
'OK!'
> boolToString(false)
'Sorry!'
@since 0.1.0
makeWith # array → generic-object

Return a function returning an object by assigning the results of the provided functions to the provided keys.

Example

> makeCircle = makeWith([
  ['radius', 'perimeter', 'area'],
  [_.identity, r => 2 * Math.PI * r, r => Math.PI * Math.pow(r, 2)]
])
> makeCircle(3)
{radius: 3, perimeter: 18.85, area: 28.27}
> makeCircle(4)
{radius: 4, perimeter: 25.13, area: 50.27}
@since 0.1.0
getShorter # array → iterable

Return the shorter iterable of the provided array of iterables. Returns the first one in case of equal length. Returns undefined for an empty input.

Example

> getShorter([[1, 2], [1], [1, 2, 3], ['a']])
[1]
> getShorter(['abc', 'a', [1]])
'a'
> getShorter(['b', 'a'])
'b'
> getShorter([])
undefined
@since 0.1.0
arrayAverage # array → number

Return the average of the numbers in the provided array

Example

> arrayAverage([1, 23, 6])
10
> arrayAverage([])
0
@since 0.1.0
arrayMax # array → number

Return the max of the numbers in the provided array

Example

> arrayMax([-1, -2, 0, 1, 2])
2
@since 0.1.0
arrayMin # array → number

Return the min of the numbers in the provided array

Example

> arrayMin([-1, -2, 0, 1, 2])
-2
@since 0.1.0
arraySum # array → number

Return the sum of the numbers in the provided array

Example

> arraySum([1, -2, 3, -4, 5])
3
> arraySum([])
0
@since 0.1.0
getRandomIndexOf # array → number

Return the index of a random item of the passed array

Example

> getRandomIndexOf([0, 1, 2, 3])
2
> getRandomIndexOf([0, 1, 2, 3])
1
@since 0.1.0
keyValueArrayAverage # array → number

Return the average of values of a {key, value}[] array

Example

> keyValueArrayAverage([
  {key: 'a', value: 1},
  {key: 'b', value: 23},
  {key: 'c', value: 6},
])
10
> keyValueArrayAverage([])
0
@since 0.1.0
makeRandomNumInRange # array → number

Return a random number in the specified range.

Example

> makeRandomNumInRange([1.2, 7.4])
4.2
@since 0.1.0
permutationsCount # array → number

Calculate the number of combinations (permutations without repetition) of `n` items taken in groups of size `g`. Useful for sizing matrices of scatterplots / heatmaps. Formula: C(n,g) = n! / (g! × (n-g)!)

Example

> permutationsCount([4, 2])
6
> permutationsCount([5, 2])
10
@since 0.3.0
sumValue # array → number

Return the sum of the `value` properties from the provided array of key-value objects.

Example

> sumValue([{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}])
6
> sumValue([])
0
@since 0.3.0
makeIsWithinRange # array → number-boolean

Return a function expecting a number and returning true if the number is within the provided range (inclusive on both ends).

Example

> isWithinRange = makeIsWithinRange([0, 5])
> isWithinRange(2)
true
> isWithinRange(5)
true
> isWithinRange(8)
false
@since 0.1.0
makePolynomial # array → number-number

Return a function that computes the polynomial of the input number using the provided coefficients. The exponent corresponds to the coefficient's index.

Example

> // x => 2 x + 4 x^3
> poly = makePolynomial([0, 2, 0, 4])
> poly(2)
36
> poly(5)
510
@since 0.1.0
keyValueArrayToObject # array → object

Return an object built using 'key's and 'value's from the objects in the provided array

Example

> keyValueArrayToObject([
  {key: 'ITA', value: 0},
  {key: 'FRA', value: 0},
])
{ ITA: 0, FRA: 0 }
@since 0.1.0
makeAllOccurrences # array → object

Return an object of occurrences of all the keys contained in the objects in the provided array

Example

> makeAllOccurrences([{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}, {c: 4, e: 2}])
{a: 3, b: 2, c: 2, e: 1}
@since 0.1.0
makeIndexByKey # array → object

Return an object with the provided array elements as keys and all values equal to their index in the array

Example

> makeIndexByKey(['a', 'b'])
{a: 0, b: 1}
> makeIndexByKey([2, -4])
{'2': 0, '-4': 1}
@since 0.1.0
makeKeyedEmptyArray # array → object

Return an object with the provided array elements as keys and all values equal to `[]`

Example

> makeKeyedEmptyArray(['a', 'b'])
{a: [], b: []}
@since 0.3.0
makeKeyedFalse # array → object

Return an object with the provided array elements as keys and all values equal to `false`

Example

> makeKeyedFalse(['a', 'b'])
{a: false, b: false}
@since 0.1.0
makeKeyedNull # array → object

Return an object with the provided array elements as keys and all values equal to `null`

Example

> makeKeyedNull(['a', 'b'])
{a: null, b: null}
@since 0.3.0
makeKeyedTrue # array → object

Return an object with the provided array elements as keys and all values equal to `true`

Example

> makeKeyedTrue(['a', 'b'])
{a: true, b: true}
@since 0.1.0
makeKeyedZeroes # array → object

Return an object with the provided array elements as keys and all values equal to zero

Example

> makeKeyedZeroes(['a', 'b'])
{a: 0, b: 0}
> makeKeyedZeroes([1, 2])
{1: 0, 2: 0}
@since 0.1.0
mergeObjects # array → object

Merge all the objects in the provided array. The result depends on the order of the objects in the array.

Example

> mergeObjects([{a: 1}, {a: 6, b: -1}, {b: 1}])
{a: 6, b: 1}
@since 0.1.0
pairToKeyValueObject # array → object

Return the {key, value} object from a pair

Example

> pairToKeyValueObject(['a', 2])
{key: 'a', value: 2}
> pairToKeyValueObject([1, 2, 3])
{key: 1, value: 2}
> pairToKeyValueObject([])
{key: undefined, value: undefined}
@since 0.1.0
pairToKeyValuesObject # array → object

Return the {key, values} object from a pair

Example

> pairToKeyValuesObject(['a', [1, 2]])
{key: 'a', values: [1, 2]}
> pairToKeyValuesObject([1, [1, 2], 3])
{key: 1, values: [1, 2]}
@since 0.1.0
makeKeysGetter # array → object-array

pickAndConcatValues # array → object-array

Return a function expecting an object and concatenating values in the provided list of keys.

Example

> getProducts = pickAndConcatValues(['food', 'beverage'])
> getProducts({
    food: ['bread', 'cheese', 'ham'],
    beverage: ['wine', 'water'],
    id: 'area1',
    value: 32.1,
  })
['bread', 'cheese', 'ham', 'wine', 'water']
@since 0.1.0
isKeyValue # array → object-boolean

Return a predicate expecting an object and returning `true` if the value at the provided `key` is the same as the provided `value`.

Example

> isUSA = isKeyValue(['country_id', 'US'])
> isUSA({country_id: 'GB', id: 123})
false
> isUSA({country_id: 'US', id: 456})
true
@since 0.1.0
isNotKeyValue # array → object-boolean

Return a predicate expecting an object and returning `true` if the value at the provided `key` is not the same as the provided `value`.

Example

> isNotUSA = isNotKeyValue(['country_id', 'US'])
> isNotUSA({country_id: 'GB', id: 123})
true
> isNotUSA({country_id: 'US', id: 456})
false
@since 0.1.0
isNotPathValue # array → object-boolean

Return a predicate expecting an object and returning `true` if the value at the provided `path` is not the same as the provided `value`.

Example

> isNotDefaultStatus = isNotPathValue(['item.status', 'default'])
> isNotDefaultStatus({item: {status: 'active'}, id: 123})
true
> isNotDefaultStatus({item: {status: 'default'}, id: 456})
false
@since 0.1.0
isPathValue # array → object-boolean

Return a predicate expecting an object and returning `true` if the value at the provided `path` is the same as the provided `value`.

Example

> isDefaultStatus = isPathValue(['item.status', 'default'])
> isDefaultStatus({item: {status: 'active'}, id: 123})
false
> isDefaultStatus({item: {status: 'default'}, id: 456})
true
@since 0.1.0
applyTransformsSequence # array → object-object

Return a function that expects an object and applies the provided sequence of transforms to the values of the correspondent paths to the input object. Note that transforms to the same path can be repeated.

Example

> transform = applyTransformsSequence([
    ['a.a2.a22', _.pipe([Number, Math.sqrt])],
    ['a.a3', parseInt],
  ])
> transform({a: {a2: {a22: '9'}, a3: '3px'}})
{a: {a2: {a22: 3}, a3: 3}}
@since 0.1.0
pluckValuesKeys # array → object-object

Return a function plucking the provided keys from the expected object values.

Example

> let select = pluckValuesKeys(['a', 'k'])
> select({
    foo: {a: 1, b: 2, c: 3, k: 4},
    bar: {a: 5, b: 8}
  })
{foo: {a: 1, k: 4}, bar: {a: 5}}
@since 0.1.0
remapWith # array → object-object

Return a function expecting an object and returning an object having keys and values defined by applying the provided array of two functions to the input object keys and values.

Example

> remap = remapWith([key => `${key}${key}`, value => 3 * value])
> remap({a: 1, b: 2})
{aa: 3, bb: 6}
@since 0.1.0
joinWithBlank # array → string

Return a string joining the provided array items with a blank

Example

> joinWithBlank(['a', 'b', 'c'])
'a b c'
@since 0.1.0
joinWithColon # array → string

Return a string joining the provided array items with a colon

Example

> joinWithColon(['a', 'b', 'c'])
'a:b:c'
@since 0.1.0
joinWithDash # array → string

Return a string joining the provided array items with a dash

Example

> joinWithDash(['a', 'b', 'c'])
'a-b-c'
@since 0.1.0
joinWithNewline # array → string

Return a string joining the provided array items with a return

Example

> joinWithNewline([1, 2, 3])
'1\n2\n3'
> joinWithNewline(['a', 'b', 'c'])
'a\nb\nc'
@since 0.1.0
joinWithSemicolon # array → string

Return a string joining the provided array items with a semicolon

Example

> joinWithSemicolon(['a', 'b', 'c'])
'a;b;c'
@since 0.1.0
containsOneOf # array → string-boolean

Return a function that checks if a string contains one of the provided strings.

Example

> isWeight = containsOneOf(['(g)', '(mg)', '(mcg)'])
> ['id', 'Energy (kcal)', 'Protein (g)', 'Cholesterol (mg)', 'Selenium (mcg)'].filter(isWeight)
['Protein (g)', 'Cholesterol (mg)', 'Selenium (mcg)']
@since 0.1.0
sliceStringAt # array → string-string

Return a function extracting the portion of a string between the provided indices (first included, second excluded). Note that indices can be negative.

Example

> slicerPosPos = sliceStringAt([3, 5])
> slicerPosPos('0123456789')
'34'

> slicerPosImplicit = sliceStringAt([3])
> slicerPosImplicit('0123456789')
'3456789'

> slicerPosNeg = sliceStringAt([1, -3])
> slicerPosNeg('0123456789')
'123456'

> slicerNegPos = sliceStringAt([-6, 6])
> slicerNegPos('0123456789')
'45'
@since 0.1.0
isEqualTo # generic → any-boolean

Return a function that returns true if the input value is equal to the provided value. This can be used to compare objects and arrays.

Example

> isEqualToObj = isEqualTo({a: 1, b: [1,2]})
> isEqualToObj({a: 1, b: [1, 2]})
true
> isEqualToObj({a: 1, b: [1, 2, 3]})
false
@since 0.1.0
isNot # generic → any-boolean

Return a function that returns true if the input is different from the provided value.

Example

> isNotTwo = isNot(2)
> isNotTwo(3)
true
> isNotTwo(2)
false
@since 0.1.0
makeKeyed # generic → array-object

Return a function expecting an array of keys and returning an object with the provided value as value of those keys.

Example

> makeKeyedEmptyArray = makeKeyed([])
> makeKeyedEmptyArray([1, 2])
{1: [], 2: []}
> makeKeyedEmptyArray(['a', 'b'])
{a: [], b: []}
@since 0.1.0
isArguments # generic → boolean

Return true if the input is an arguments list.

@since 0.1.0
isArray # generic → boolean

Return true if the input is an array.

@since 0.1.0
isFunction # generic → boolean

Return true if the input is a function.

@since 0.1.0
isNotNaN # generic → boolean

Return true if the input is not a NaN.

@since 0.1.0
isNotNil # generic → boolean

Return true if the input is not undefined or null.

@since 0.1.0
isNotNull # generic → boolean

Return true if the input is not null.

@since 0.1.0
isNumber # generic → boolean

Return true if the input is a number (including NaN and Infinity).

@since 0.1.0
isObject # generic → boolean

Return true if the input is a plain object.

@since 0.1.0
isPromise # generic → boolean

Return true if the input is a promise.

@since 0.1.0
isString # generic → boolean

Return true if the input is a string.

@since 0.1.0
isValidNumber # generic → boolean

Return true if the input is a valid number (including not being NaN).

@since 0.1.0
negate # generic → boolean

Return the negated input.

@since 0.1.0
toFloatIsValidNumber # generic → boolean

Return true if the input, parsed to float, is a valid number.

@since 0.1.0
toNumberisValidNumber # generic → boolean

Return true if the input, converted to Number, is indeed a number.

@since 0.1.0
makeEmptyArrayIfUndefined # generic

Return an empty array if the input is undefined, identity otherwise.

Example

> makeEmptyArrayIfUndefined(undefined)
[]
> makeEmptyArrayIfUndefined([1, 2, 3])
[1, 2, 3]
@since 0.1.0
sanitize # generic

Return a copy of the input after stringifying and parsing it. Useful to strip `undefined` values for JSON comparison.

Example

> sanitize({a: 1, b: undefined})
{a: 1}
> sanitize([1, undefined])
[1, null]
@since 0.1.0
toFloatOrIdentity # generic

Return a number if the input can be converted to float, identity otherwise.

Example

> toFloatOrIdentity('2')
2
> toFloatOrIdentity('h2o')
'h2o'
@since 0.1.0
hasValue # generic → object-boolean

Return a function that returns true if at least one of the input object properties has the provided value.

Example

> hasTwo = hasValue(2)
> hasTwo({a: 1, b: 2})
true
> hasTwo({a: 1, b: 3})
false
@since 0.1.0
stringify # generic → string

Return a string representation of the input with indentation = 2.

Example

> stringify([{a: 1}, {a: 2}])
'[\n  {\n    "a": 1\n  },\n  {\n    "a": 2\n  }\n]'
@since 0.1.0
noop # generic → undefined

A function that does nothing.

Example

> noop()
undefined
@since 0.1.0
hasIterableLength1 # iterable → boolean

Return true if the iterable has exactly one element

Example

> hasIterableLength1('a')
true
> hasIterableLength1([1])
true
> hasIterableLength1([1, 2])
false
@since 0.1.0
isIterableEmpty # iterable → boolean

Return true if the iterable is empty

Example

> isIterableEmpty('')
true
> isIterableEmpty([])
true
> isIterableEmpty([1, 2])
false
@since 0.1.0
isIterableLongerThan1 # iterable → boolean

Return true if the iterable has more than one element

Example

> isIterableLongerThan1('ab')
true
> isIterableLongerThan1([1, 2])
true
> isIterableLongerThan1([1])
false
@since 0.1.0
isIterableNotEmpty # iterable → boolean

Return true if the iterable is not empty

Example

> isIterableNotEmpty('a')
true
> isIterableNotEmpty([1, 2])
true
> isIterableNotEmpty([])
false
@since 0.1.0
getLength # iterable → number

Get the length of the iterable

Example

> getLength('a')
1
> getLength('two')
3
> getLength([10])
1
> getLength([3, 7])
2
@since 0.1.0
is0 # number → boolean

Return `true` if the input number is 0.

Example

> is0(0)
true
> is0(2)
false
@since 0.1.0
is1 # number → boolean

Return `true` if the input number is 1.

Example

> is1(1)
true
> is1(2)
false
@since 0.1.0
isGT0 # number → boolean

Return `true` if the input number is greater than 0.

Example

> isGT0(-1)
false
> isGT0(2)
true
@since 0.1.0
isGT1 # number → boolean

Return `true` if the input number is greater than 1.

Example

> isGT1(0)
false
> isGT1(2)
true
@since 0.1.0
factorial # number

Return the factorial of a number.

Example

> factorial(0)
1
> factorial(5)
120
@since 0.3.0
roundTo # number → number-number

Return a function that rounds the input number to the provided number of digits.

Example

> roundTo2 = roundTo(2)
> roundTo2(2.41285)
2.41
> roundTo2(2.41785)
2.42
@since 0.1.0
plural # number → string

Return an empty string if the provided number is 1, otherwise return 's'. Useful for building pluralized labels.

Example

> plural(1)
''
> plural(2)
's'
> plural(0)
's'
> plural(-1)
's'
@since 0.3.0
concatValues # object → array

Concatenate the values of the provided object.

Example

> concatValues({a: [1, 2, 3], b: [4, 5, 6]})
[1, 2, 3, 4, 5, 6]
@since 0.1.0
getTruthyValuesKeys # object → array

Return the keys of the provided object with a truthy value.

Example

> getTruthyValuesKeys({a: true, b: true, c: false})
['a', 'b']
> getTruthyValuesKeys({a: 1, b: 0, c: false})
['a']
> getTruthyValuesKeys({a: [1, 2], b: {a: 1}, c: false})
['a', 'b']
@since 0.1.0
makeKeyedValuesPermutations # object → array

Return an array of the permutations of the provided object values items, by key. Note that this function assumes the provided object values are arrays.

Example

> makeKeyedValuesPermutations({a: [0, 1], b: [2, 3], c: [4, 5]})
[
  {a: 0, b: 2, c: 4}, {a: 1, b: 2, c: 4},
  {a: 0, b: 3, c: 4}, {a: 1, b: 3, c: 4},
  {a: 0, b: 2, c: 5}, {a: 1, b: 2, c: 5},
  {a: 0, b: 3, c: 5}, {a: 1, b: 3, c: 5}
]
@since 0.1.0
objectToKeyValueArray # object → array

Return an array of {key, value} objects from an object.

Example

> objectToKeyValueArray({k1: 'v1', k2: 'v2'})
[{key: 'k1', value: 'v1'}, {key: 'k2', value: 'v2'}]
@since 0.1.0
objectToKeyValuesArray # object → array

Return an array of {key, values} objects from an object.

Example

> objectToKeyValuesArray({k1: ['a', 'b'], k2: ['c', 'd']})
[{key: 'k1', values: ['a', 'b']}, {key: 'k2', values: ['c', 'd']}]
@since 0.1.0
objectToValueDescKeyAsc # object → array

Convert an object to a key-value array sorted by `value` (descending) then `key` (ascending).

Example

> objectToValueDescKeyAsc({b: 1, a: 3, c: 1})
[{key: 'a', value: 3}, {key: 'b', value: 1}, {key: 'c', value: 1}]
@since 0.3.0
areAllValuesTruthy # object → boolean

Return `true` if all values of the provided object are truthy.

Example

> areAllValuesTruthy({a: 1, b: 'hello', c: true})
true
> areAllValuesTruthy({a: 1, b: 0, c: true})
false
@since 0.3.0
areSomeValuesTruthy # object → boolean

Return `true` if at least one value of the provided object is truthy.

Example

> areSomeValuesTruthy({a: 0, b: 1, c: false})
true
> areSomeValuesTruthy({a: 0, b: false, c: null})
false
@since 0.3.0
areValuesEqual # object → boolean

Return `true` if all values of the provided object are equal.

Example

> areValuesEqual({a: 1, b: 1, c: 1})
true
> areValuesEqual({a: [1, 2], b: [1, 2], c: [1, 2]})
true
> areValuesEqual({a: 1, b: 2, c: 3})
false
> areValuesEqual({})
false
@since 0.1.0
hasObjSize1 # object → boolean

Return `true` if the provided object has exactly one key.

Example

> hasObjSize1({})
false
> hasObjSize1({a: 1})
true
> hasObjSize1({a: 1, b: 2})
false
@since 0.1.0
hasSomeNullValues # object → boolean

Return true if some of the provided object properties are `null`.

Example

> hasSomeNullValues({a: 1})
false
> hasSomeNullValues({a: 1, b: undefined})
false
> hasSomeNullValues({a: 1, b: undefined, c: null})
true
@since 0.1.0
isObjEmpty # object → boolean

Return `true` if the object is empty.

Example

> isObjEmpty({})
true
> isObjEmpty({a: 1})
false
@since 0.1.0
isObjNotEmpty # object → boolean

Return `true` if the object is not empty.

Example

> isObjNotEmpty({a: 1})
true
> isObjNotEmpty({})
false
@since 0.1.0
getId # object → generic

Retrieve the 'id' property of the provided object.

Example

> getId({id: 'foo', name: 'bar'})
'foo'
@since 0.1.0
getKey # object → generic

Retrieve the 'key' property of the provided object.

Example

> getKey({key: 'foo', value: 'bar'})
'foo'
@since 0.1.0
getValue # object → generic

Retrieve the 'value' property of the provided object.

Example

> getValue({key: 'foo', value: 'bar'})
'bar'
@since 0.1.0
getValues # object → generic

Retrieve the 'values' property of the provided object.

Example

> getValues({key: 'foo', values: [0, 1, 2, 3]})
[0, 1, 2, 3]
@since 0.1.0
applyFnMap # object → generic-object

Return a function expecting any kind of input to be used as the argument of the provided functions

Example

> array = [
    {fname: 'John', lname: 'Woo', lng: 1, lat: 2},
    {fname: 'John', lname: 'Foo', lng: 7, lat: 8}
];
> format = applyFnMap({
    coords: _.collect([_.getKey('lng'), _.getKey('lat')]),
    fullname: _.pipe([
        _.collect([_.getKey('fname'), _.getKey('lname')]),
        _.joinWith(' ')
    ]),
});
> formatted = _.map(raw, format)
[
    {coords: [1, 2], fullname: 'John Woo'},
    {coords: [7, 8], fullname: 'John Foo'}
]
@since 0.1.0
getObjSize # object → number

Return the size of the provided object.

Example

> getObjSize({a: 1, b: 2})
2
@since 0.1.0
valuesMax # object → number

Return the max of the provided object values.

Example

> valuesMax({a: -3, b: 2, c: 1})
2
@since 0.1.0
valuesMin # object → number

Return the min of the provided object values.

Example

> valuesMin({a: -3, b: 2, c: 1})
-3
@since 0.1.0
countValues # object

Return an object counting the occurrences of each unique value in the provided object.

Example

> countValues({a: 'x', b: 'y', c: 'x', d: 'z', e: 'y'})
{x: 2, y: 2, z: 1}
@since 0.3.0
mapValuesToFloat # object

Return a copy of the object with values converted to float.

Example

> mapValuesToFloat({a: '1.2px', b: '20px'})
{a: 1.2, b: 20}
> mapValuesToFloat({a: '1.2', b: 'h2o'})
{a: 1.2, b: NaN}
@since 0.1.0
mapValuesToFloatPossibly # object

Return the object with values converted to numbers where possible.

Example

> mapValuesToFloatPossibly({a: '1.2', b: '2px', c: 'h2o'})
{a: 1.2, b: 2, c: 'h2o'}
@since 0.1.0
mapValuesToNumber # object

Return a copy of the object with values converted to numbers.

Example

> mapValuesToNumber({a: '1.2', b: '2'})
{a: 1.2, b: 2}
> mapValuesToNumber({a: '1.2', b: '2s'})
{a: 1.2, b: NaN}
@since 0.1.0
pickIfTruthy # object

Return a copy of the object without falsy values.

Example

> pickIfTruthy({a: true, b: true, c: false})
{a: true, b: true}
> pickIfTruthy({a: 1, b: 0, c: false})
{a: 1}
> pickIfTruthy({a: [1, 2], b: {a: 1}, c: false})
{a: [1, 2], b: {a: 1}}
@since 0.1.0
sortObjectKeysAsc # object

Return a copy of the input object with enumerable properties sorted in ascending order.

Example

> sortObjectKeysAsc({c: 1, a: 2, b: 15})
{a: 2, b: 15, c: 1}
@since 0.1.0
sortObjectKeysDesc # object

Return a copy of the input object with enumerable properties sorted in descending order.

Example

> sortObjectKeysDesc({c: 1, a: 2, b: 15})
{c: 1, b: 15, a: 2}
@since 0.1.0
swapKeyValue # object

Return an object with swapped keys and values. If there are duplicate values, the last occurrence wins.

Example

> swapKeyValue({a: 1, b: 2, c: 'd'})
{1: 'a', 2: 'b', d: 'c'}
> swapKeyValue({a: 1, b: 2, c: 'd', e: 1})
{2: 'b', d: 'c', 1: 'e'}
@since 0.1.0
makeMergeAppliedFnMap # object → object-object

Return a function that applies the provided map to the expected object and merges the result to the object. This is useful to add new properties to an object, eventually modifying existing ones by using keys expected to be in the input objects.

Example

> enhancer = makeMergeAppliedFnMap({
    coords: _.collect([_.getKey('lng'), _.getKey('lat')]),
    fullname: _.pipe([
        _.collect([_.getKey('fname'), _.getKey('lname')]),
        _.joinWith(' ')
    ]),
    lat: obj => roundTo2(obj.lat),
    lng: obj => roundTo2(obj.lng),
})
> enhancer({fname: 'John', lat: 2.345434, lname: 'Woo', lng: 10.3425})
{coords: [10.3425, 2.345434], fname: 'John', fullname: 'John Woo', lat: 2.35, lname: 'Woo', lng: 10.34}
@since 0.1.0
mergeObj # object → object-object

Return a function expecting an object to merge with the input object.

Example

> mergeB = mergeObj({b: 2})
> mergeB({a: 1})
{a: 1, b: 2}
> mergeB({a: 1, b: 1})
{a: 1, b: 2}
@since 0.1.0
transformPaths # object → object-object

Return a function that expects an object and applies the functions in the values of the input object to the values of the provided object found in the paths in the correspondent keys.

Example

> transform = transformPaths({
    'a.a2.a22': _.pipe([Number, Math.sqrt]),
    'a.a3': parseInt,
    'b.b2': parseInt,
})
> transform({a: {a1: 'a1', a2: {a21: 'a21', a22: '9'}, a3: '3px', a4: '2'}, b: {b1: 'b1', b2: '4px'}})
{a: {a1: 'a1', a2: {a21: 'a21', a22: 3}, a3: 3, a4: '2'}, b: {b1: 'b1', b2: 4}}
@since 0.1.0
transformValues # object → object-object

Return a function that expects an object and applies the functions in the values of the input object to the correspondent values of the provided object. Since 0.6.0 it assumes identity for missing keys.

Example

> conversionFn = transformValues({
    name: _.identity,
    a: _.pipe([Number, Math.sqrt]),
    b: Number,
    width: parseFloat
})
> conversionFn({name: 'foo', a: '9', b: '2', width: '10px'})
{name: 'foo', a: 3, b: 2, width: 10}
@since 0.1.0
updateKeys # object → object-object

Return a function that expects an object and applies the provided updater function to the values correspondent to the provided keys, leaving the other properties unchanged.

Example

> update = updateKeys({keys: ['a', 'k', 'm'], updater: x => x * 2})
> update({a: 1, b: 2, d: 4, k: 7, m: 2})
{a: 2, b: 2, d: 4, k: 14, m: 4}
> update({a: 1, b: 2, d: 4})
{a: 2, b: 2, d: 4}
> update({b: 2, d: 4})
{b: 2, d: 4}
@since 0.1.0
getLabel # object → string

Retrieve the 'label' property of the provided object.

Example

> getLabel({label: 'foo', value: 42})
'foo'
@since 0.3.0
getLabelLowercase # object → string

Retrieve the 'label' property of the provided object, lowercased. Returns an empty string if label is undefined.

Example

> getLabelLowercase({label: 'Foo', value: 42})
'foo'
> getLabelLowercase({value: 42})
''
@since 0.3.0
isKeyOf # object → string-boolean

Return a function that checks if the expected string is a key of the provided object.

Example

> isKeyOfObj = isKeyOf({a: 1, b: 2})
> isKeyOfObj('a')
true
> isKeyOfObj('c')
false
@since 0.1.0
isRegexpEmpty # regexp → boolean

Returns true if the provided RegExp is empty

Example

> isRegexpEmpty(/(?:)/u)
true
> isRegexpEmpty(/^a/u)
false
@since 0.1.0
isRegexpNotEmpty # regexp → boolean

Returns true if the provided RegExp is not empty

Example

> isRegexpNotEmpty(/^a/u)
true
> isRegexpNotEmpty(/(?:)/u)
false
@since 0.1.0
sorterKeyDesc # sorters

A descending sorter for arrays of objects with a `key` property. Use with `_.sortWith` to sort by `key` descending.

Example

> _.sortWith([sorterKeyDesc])([{key: 'b', value: 1}, {key: 'c', value: 2}])
[{key: 'c', value: 2}, {key: 'b', value: 1}]
@since 0.3.0
sorterLabelDesc # sorters

A descending sorter for arrays of objects with a `label` property. Use with `_.sortWith` to sort by `label` descending.

Example

> _.sortWith([sorterLabelDesc])([{label: 'a'}, {label: 'c'}, {label: 'b'}])
[{label: 'c'}, {label: 'b'}, {label: 'a'}]
@since 0.3.0
sorterValueDesc # sorters

A descending sorter for arrays of objects with a `value` property. Use with `_.sortWith` to sort by `value` descending.

Example

> _.sortWith([sorterValueDesc])([{key: 'a', value: 1}, {key: 'b', value: 3}])
[{key: 'b', value: 3}, {key: 'a', value: 1}]
@since 0.3.0
hasKeyWith # string-boolean → object-boolean

Return a function expecting an object and returning `true` if the input object has a key satisfying the provided predicate

Example

> const hasA = hasKeyWith(x => x === 'a')
> hasA({a: 2, b: 4, c: 3})
true
> hasA({b: 4, c: 3})
false
@since 0.1.0
pickIfKeyWith # string-boolean → object-object

Return a function expecting an object and returning a new object with only the keys satisfying the provided predicate

Example

> const keysStartWithA = pickIfKeyWith(key => key.startsWith('a'))
> keysStartWithA({a: 1, aa: 2, b: 0, c: 0})
{a: 1, aa: 2}
> keysStartWithA({b: 0, c: 0})
{}
@since 0.3.0
skipIfKeyWith # string-boolean → object-object

Return a function expecting an object and returning a new object without the keys satisfying the provided predicate

Example

> const keysDontStartWithA = skipIfKeyWith(key => key.startsWith('a'))
> keysDontStartWithA({a: 1, aa: 2, b: 0, c: 0})
{b: 0, c: 0}
> keysDontStartWithA({b: 0, c: 0})
{b: 0, c: 0}
@since 0.3.0
renameKeysWith # string-string → object-object

Return a function expecting an object and returning a new object with keys renamed with the provided function.

Example

> const rename = renameKeysWith(key => `--${key}`)
> rename({foo: 1, bar: 2})
{'--foo': 1, '--bar': 2}
@since 0.1.0
makeLines # string → array

Return lines in a string (trimmed, split by newline)

Example

> makeLines('A,B\n1,2\n3,4\n')
['A,B', '1,2', '3,4']
@since 0.1.0
makeRows # string → array

Return rows in a string excluding the first line (the header). Useful for CSVs.

Example

> makeRows('A,B\n1,2\n3,4\n')
['1,2', '3,4']
@since 0.1.0
ndjsonToArray # string → array

Return an array from a ndjson string

Example

> ndjsonToArray('{"a":1}\n{"b":2}\n\n')
[{a: 1}, {b: 2}]
@since 0.1.0
splitByDot # string → array

Return an array by splitting by '.'

Example

> splitByDot('a.b.c')
['a', 'b', 'c']
@since 0.1.0
splitByEOL # string → array

Return an array by splitting by '\n'

Example

> splitByEOL('a\nb\nc')
['a', 'b', 'c']
@since 0.1.0
splitBySemiColon # string → array

Return an array by splitting by ';'

Example

> splitBySemiColon('A;B;C')
['A', 'B', 'C']
@since 0.1.0
pluckPath # string → array-array

Return a function expecting an array of objects and plucking the provided array with the input path

Example

> getABs = pluckPath('a.b')
> getABs([{a: {b: -1, label: 'foo'}}, {a: {b: 4, label: 'bar'}}])
[-1, 4]
> getABs([{a: {label: 'foo'}}, {a: {b: 2}}])
[undefined, 2]
@since 0.1.0
pluckUniques # string → array-array

Return a function expecting an array of objects and returning an array of unique values for the provided key.

Example

> pluckUniquesByA = pluckUniques('a')
> pluckUniquesByA([{a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 2}])
[1, 2]
@since 0.3.0
setIndexAsKey # string → array-array

Return a copy of the provided array of objects assigning each object index to a property with the provided key (defaulting to `index`)

Example

> setIndexAsKey()([{a: 2}, {c: 5}])
[{a: 2, index: 0}, {c: 5, index: 1}]
> setIndexAsKey('idx')([{a: 2}, {c: 5}])
[{a: 2, idx: 0}, {c: 5, idx: 1}]
@since 0.1.0
arrayMaxBy # string → array-number

Return a function expecting an array of objects and returning the max of values by the provided key. The same can be done by `arrayMaxWith(_.getKey(key))` but here we avoid invoking a function for all the items.

Example

> maxByA = arrayMaxBy('a')
> maxByA([{a: -1, b: -1}, {a: 0, b: 0}])
0
> maxByA([{a: 1, b: 1}, {a: 2, b: -2}])
2
@since 0.1.0
arrayMinBy # string → array-number

Return a function expecting an array of objects and returning the min of values by the provided key. The same can be done by `arrayMinWith(_.getKey(key))` but here we avoid invoking a function for all the items.

Example

> minByA = arrayMinBy('a')
> minByA([{a: -1, b: -1}, {a: 0, b: 0}])
-1
> minByA([{a: 1, b: 1}, {a: 2, b: -2}])
1
@since 0.1.0
countByKey # string → array-object

Return a function expecting an array of objects and counting their values for the provided key.

Example

> countA = countByKey('a')
> countA([{a: 1, b: 2}, {a: 1, b: 4}, {a: 'foo', b: 6}, {a: 'bar', b: 7}])
{'1': 2, 'foo': 1, 'bar': 1}
@since 0.3.0
endsWithNewLine # string → boolean

Return true if the string ends with a newline

Example

> endsWithNewLine('abc')
false
> endsWithNewLine('abc\n')
true
> endsWithNewLine('abc\r\n')
true
@since 0.1.0
isTrimmedNotEmpty # string → boolean

Return true if the trimmed string is not empty

Example

> isTrimmedNotEmpty('  foo  ')
true
> isTrimmedNotEmpty('  ')
false
@since 0.1.0
exportedJsObjToAny # string → generic

Parse a JS module string (possibly prefixed with `export default `) and return the resulting value.

Example

> exportedJsObjToAny('export default {"a":1}')
{a: 1}
> exportedJsObjToAny('{"a":1}')
{a: 1}
@since 0.1.0
getEndOfLineLength # string → number

Return the length of the end of line, if any.

Example

> getEndOfLineLength('hello')
0
> getEndOfLineLength('hello\n')
1
> getEndOfLineLength('hello\r\n')
2
@since 0.1.0
valuesMaxBy # string → object-number

Return a function expecting an object of objects and returning the max of values by the provided key. The same can be done by `valuesMaxWith(_.getKey(key))` but here we avoid invoking a function for all the items.

Example

> maxByK1 = valuesMaxBy('k1')
> maxByK1({a: {k1: 1, k2: 20}, b: {k1: 3, k2: 2}})
3
> maxByK1({a: {k1: 9, k2: 12}, b: {k1: 7, k2: 2}})
9
@since 0.1.0
valuesMinBy # string → object-number

Return a function expecting an object of objects and returning the min of values by the provided key. The same can be done by `valuesMinWith(_.getKey(key))` but here we avoid invoking a function for all the items.

Example

> minByK1 = valuesMinBy('k1')
> minByK1({a: {k1: 1, k2: 20}, b: {k1: 3, k2: 2}})
1
> minByK1({a: {k1: 9, k2: 12}, b: {k1: 7, k2: 2}})
7
@since 0.1.0
regexOf # string → regexp

Return a regular expression based on the given string

Example

> regexOf('foo')
/foo/giu
@since 0.1.0
safeRegexOf # string → regexp

Return a safe regular expression based on the given string, with any special characters escaped

Example

> safeRegexOf('foo+bar')
/foo\+bar/giu
@since 0.1.0
capitalize # string

Capitalise the input string

Example

> capitalize('hello')
'Hello'
@since 0.1.0
decapitalize # string

Decapitalise the input string (makes the first letter lowercase)

Example

> decapitalize('Hello')
'hello'
> decapitalize('HELLO')
'hELLO'
@since 0.1.0
trim # string

Return a copy of the provided string with whitespace trimmed from both ends.

Example

> trim(' abc \n ')
'abc'
@since 0.1.0
trimLastNewline # string

Trim the last char of the provided string if it's a newline

Example

> trimLastNewline('a\nb\nc')
'a\nb\nc'
> trimLastNewline('a\nb\nc\n')
'a\nb\nc'
> trimLastNewline('a\nb\nc\n\n')
'a\nb\nc\n'
> trimLastNewline('a\nb\nc\r\n')
'a\nb\nc'
> trimLastNewline('a\nb\nc\n\r\n')
'a\nb\nc\n'
@since 0.1.0
makeSplitBy # string → string-array

Return a function expecting a string to be split using the provided separator or regex

Example

> splitByDoubleDot = makeSplitBy('..')
> splitByDoubleDot('aa...a..a.a.aa.....aa..')
['aa', '.a', 'a.a.aa', '', '.aa', '']
@since 0.1.0
makeSplitStringBy # string → string-array

Return a function expecting a separator or regex to split the provided string

Example

> splitStringBy = makeSplitStringBy('a.b-c,d:e')
> splitStringBy(':')
['a.b-c,d', 'e']
> splitStringBy('-')
['a.b', 'c,d:e']
@since 0.1.0
makeTrimmedSplitBy # string → string-array

Return a function that splits the expected string and trims all the elements of the returned array

Example

> trimSplitByDoubleDot = makeTrimmedSplitBy('..')
> trimSplitByDoubleDot('  aa ..	a\n..a')
['aa', 'a', 'a']
@since 0.1.0
makeEndsWith # string → string-boolean

Return a function expecting a base string and checking if it ends with the provided search string.

Example

> endsWithExclamationMark = makeEndsWith('!')
> endsWithExclamationMark('Hi!')
true
> endsWithExclamationMark('Who?')
false
@since 0.1.0
makeStartsWith # string → string-boolean

Return a function expecting a base string and checking if it starts with the provided search string.

Example

> startsWithHash = makeStartsWith('#')
> startsWithHash('# this is a bash comment')
true
> startsWithHash('This is not')
false
@since 0.1.0
makeStringEndsWith # string → string-boolean

Return a function expecting a search string and checking if the provided base string ends with the search string.

Example

> stringEndsWith = makeStringEndsWith('Hi!')
> stringEndsWith('!')
true
> stringEndsWith('?')
false
@since 0.1.0
makeStringStartsWith # string → string-boolean

Return a function expecting a search string and checking if the provided base string starts with the search string.

Example

> stringStartsWith = makeStringStartsWith('Hi!')
> stringStartsWith('H')
true
> stringStartsWith('h')
false
@since 0.1.0
makeRegexOf # string → string-regexp

Creates a regular expression using the flags provided

Example

> const regex = makeRegexOf('giu')('foo+bar')
/foo+bar/giu
@since 0.1.0
makeSafeRegexOf # string → string-regexp

Creates an escaped regular expression using the flags provided to prevent regexp injections from source strings

Example

> regex = makeSafeRegexOf('giu')('foo+bar')
/foo\+bar/giu
@since 0.1.0
makePostfixed # string → string-string

Return a function that appends the provided string to the input string

Example

> postfixed = makePostfixed('---')
> postfixed('A')
'A---'
> postfixed('B')
'B---'
@since 0.1.0
makePrefixed # string → string-string

Return a function that prepends the provided string to the input string

Example

> prefixed = makePrefixed('---')
> prefixed('A')
'---A'
> prefixed('B')
'---B'
@since 0.1.0
chunkArray # arity-gt-1

Split an array into chunks of the specified size.

Example

> chunkArray([1, 2, 3, 4, 5], 2)
[[1, 2], [3, 4], [5]]
> chunkArray([1, 2, 3], 3)
[[1, 2, 3]]
@since 0.3.0
concat # arity-gt-1

Return an array by concatenating the provided arrays.

Example

> concat([0, 1, 2], [3, 4], [5, 6])
[0, 1, 2, 3, 4, 5, 6]
@since 0.1.0
endsWith # arity-gt-1

Return true if the input string ends with the test string.

Example

> endsWith('Ping', 'ing')
true
> endsWith('Pong', 'ing')
false
@since 0.1.0
exportedObjBufferToAny # arity-gt-1

Decode a TypedArray buffer and parse it as a JS object, stripping any `export default` prefix.

Example

> encoder = new TextEncoder()
> buffer = encoder.encode('export default {"a": 1}')
> exportedObjBufferToAny(buffer)
{a: 1}
@since 0.1.0
includes # arity-gt-1

Return true if the provided value is included in the provided array.

Example

> includes([0, 1, 2], 2)
true
> includes([0, 1, 2], 3)
false
@since 0.1.0
join # arity-gt-1

Return a string by joining the provided array with the provided separator.

Example

> join([0, 1, 2], '-')
'0-1-2'
@since 0.1.0
jsonBufferToAny # arity-gt-1

Decode a TypedArray buffer and parse it as JSON.

Example

> encoder = new TextEncoder()
> buffer = encoder.encode('{"a": 1}')
> jsonBufferToAny(buffer)
{a: 1}
@since 0.1.0
makeMergeKeyValue # arity-gt-1

Return a function that merges the provided value on the provided key of the expected object.

Example

> mergeFooValue = makeMergeKeyValue('foo', {b: -2, c: -3})
> mergeFooValue({foo: {a: 1, b: 2}, bar: {k: 1}})
{foo: {a: 1, b: -2, c: -3}, bar: {k: 1}}
> mergeFooValue({bar: {k: 1}})
{foo: {b: -2, c: -3}, bar: {k: 1}}
@since 0.1.0
makeOccurrences # arity-gt-1

Return an object of occurrences of keys in the provided array containing the provided keys

Example

> makeOccurrences([{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}], ['a', 'b'])
{a: 3, b: 2}
@since 0.1.0
mergeWith # arity-gt-1

Return a function expecting two objects to merge using the provided merge function.

Example

> mergeWithSubtract = mergeWith(_.subtract)
> mergeWithSubtract({a: 8, b: 3}, {a: 5, b: 2, c: 7})
{a: 3, b: 1, c: 7}
@since 0.1.0
mergeWithAppendTo # arity-gt-1

Return the merge of two objects appending values of correspondent keys.

Example

> obj1 = {a: [1, 2, 3], b: [4, 5, 6]}
> obj2 = {a: 4, b: [7]}
> mergeWithAppendTo(obj1, obj2)
{a: [1, 2, 3, 4], b: [4, 5, 6, [7]]}
@since 0.1.0
mergeWithConcat # arity-gt-1

Return the merge of two objects concatenating values of correspondent keys.

Example

> obj1 = {a: [1, 2, 3], b: [4, 5, 6]}
> obj2 = {a: [1, 2, 3], b: [4, 5, 6]}
> mergeWithConcat(obj1, obj2)
{a: [1, 2, 3, 1, 2, 3], b: [4, 5, 6, 4, 5, 6]}
@since 0.1.0
mergeWithMerge # arity-gt-1

Return the merge of two objects merging values of correspondent keys.

Example

> obj1 = {A: {a: 1}, B: {b: 1}}
> obj2 = {A: {b: 10}, B: {a: 10}}
> mergeWithMerge(obj1, obj2)
{A: {a: 1, b: 10}, B: {a: 10, b: 1}}
@since 0.1.0
mergeWithSum # arity-gt-1

Return the merge of two objects adding values of correspondent keys.

Example

> mergeWithSum({a: 1, b: 2}, {a: 10, c: 1})
{a: 11, b: 2, c: 1}
@since 0.1.0
pluckUniquesFrom # arity-gt-1

Pluck unique values for the given key from the provided array of objects.

Example

> pluckUniquesFrom([{a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 2}], 'a')
[1, 2]
@since 0.3.0
sliceString # arity-gt-1

Return the portion of the provided string between the provided indices (first included, second excluded). Indices can be negative.

Example

> sliceString('0123456789', 3)
'3456789'
> sliceString('0123456789', 3, 5)
'34'
> sliceString('0123456789', 3, -1)
'345678'
@since 0.1.0
split # arity-gt-1

Return an array by splitting the input string with the provided separator.

Example

> split('a-b-c', '-')
['a', 'b', 'c']
@since 0.1.0
startsWith # arity-gt-1

Return true if the input string starts with the test string.

Example

> startsWith('Ping', 'Pin')
true
> startsWith('Pong', 'Pin')
false
@since 0.1.0
swap # arity-gt-1

Return a copy of the array with values at the provided indices swapped

Example

> swap([0, 1, 2, 3, 4, 5], 1, 4)
[0, 4, 2, 3, 1, 5]
@since 0.1.0
toggleItem # arity-gt-1

Return a copy of the provided array without all instances of the provided item if the item is in the array, or appending the item otherwise.

Example

> toggleItem([0, 1, 2, 0], 0)
[1, 2]
> toggleItem([1, 2], 0)
[1, 2, 0]
@since 0.1.0
© mindrones · datakit