Return a function returning true if the accessed value is an array
Example
> isArrayWith(getValue)({key: 'a', value: [1, 2]})
trueReturn a function returning true if the accessed value is an array
> isArrayWith(getValue)({key: 'a', value: [1, 2]})
trueReturn a function returning true if the accessed value is null or undefined
> isNilWith(getValue)({key: 'a', value: null})
true
> isNilWith(getValue)({key: 'a'})
trueReturn a function returning true if the accessed value is not NaN
> isNotNaNWith(getValue)({key: 'a', value: 1})
trueReturn a function returning true if the accessed value is not null or undefined
> isNotNilWith(getValue)({key: 'a', value: 1})
trueReturn a function returning true if the accessed value is not null
> isNotNullWith(getValue)({key: 'a', value: 1})
trueReturn a function returning true if the accessed value is null
> isNullWith(getValue)({key: 'a', value: null})
trueReturn a function returning true if the accessed value is a number
> isNumberWith(getValue)({key: 'a', value: 1})
true
> isNumberWith(getValue)({key: 'a', value: 'a'})
falseReturn a function returning true if the accessed value is an object
> isObjectWith(getValue)({key: 'a', value: {a: 1}})
true
> isObjectWith(getValue)({key: 'a', value: 'a'})
falseReturn a function returning true if the accessed value is a string
> isStringWith(getValue)({key: 'a', value: 'a'})
true
> isStringWith(getValue)({key: 'a', value: 1})
falseReturn a function returning true if the accessed value can be turned into a valid number via parseFloat()
> isToFloatValidNumberWith(getValue)({key: 'a', value: [1]})
true
> isToFloatValidNumberWith(getValue)({key: 'a', value: []})
falseReturn a function returning true if the accessed value can be turned into a valid number via Number()
> isToNumberValidNumberWith(getValue)({key: 'a', value: '123'})
true
> isToNumberValidNumberWith(getValue)({key: 'a', value: '123px'})
falseReturn a function returning true if the accessed value is undefined
> isUndefinedWith(getValue)({key: 'a', value: 'a'})
false
> isUndefinedWith(getValue)({key: 'a', value: 1})
falseReturn a function returning true if the accessed value is a valid number
> isValidNumberWith(getValue)({key: 'a', value: 'a'})
false
> isValidNumberWith(getValue)({key: 'a', value: 1})
trueReturn a function returning `true` if all the items of an array are equal once processed with the provided `fn`
> 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([])
falseReturn a function expecting a pair and returning a {key, value} object using the provided `fn` to get the `value`.
> 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}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.
> obj = {k1: {a: 1}, k2: {a: 2}}
> convertToArray = objectToKeyValueArrayWith(_.getKey('a'))
> convertToArray(obj)
[{key: 'k1', value: 1}, {key: 'k2', value: 2}]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.
> 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)']Return a function expecting an object and returning `true` if its values, once processed with the provided `fn` function, are all equal.
> 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}})
falseReturn a function expecting an object and returning an object grouping its values using the provided `fn`. Values that are arrays are flattened before grouping.
> 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}]}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.
> 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}}Return a function returning the pair-permutations of the items returned by the provided `fn`.
> 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'}]
]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].
> 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'}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.
> 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]Return a function expecting an object and returning the first of its values satisfying the provided predicate.
> 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}Return a function expecting an array and returning the max of results of applying the provided function on all of the array items.
> maxWithAbsSin = arrayMaxWith(_.pipe([Math.sin, Math.abs]))
> maxWithAbsSin([-Math.PI/2, -Math.PI/4])
1
> maxWithAbsSin([Math.PI/4, Math.PI/6])
0.7071067811865475Return a function expecting an array and returning the min of results of applying the provided function on all of the array items.
> minWithAbsSin = arrayMinWith(_.pipe([Math.sin, Math.abs]))
> minWithAbsSin([-Math.PI/2, -Math.PI/4])
0.7071067811865475
> minWithAbsSin([Math.PI/4, Math.PI/6])
0.49999999999999994Return a function expecting an array and summing the numbers obtained from applying the provided `fn` to the array items.
> sumValues = arraySumWith(_.getKey('a'))
> sumValues([{a: 1}, {a: 2}, {a: 3}])
6
> sumValues([])
0Return a function expecting an array and returning the average of the numbers obtained by applying the provided `fn` to the array items.
> makeAverageOfA = makeAverageWith(_.getKey('a'));
> makeAverageOfA([{a: 1, b: 2}, {a: 10, b: 7}, {a: 7, b: 9}])
6
> makeAverageOfA([])
0Return a function expecting an object, applying the provided function to its values and returning the largest of the results.
> 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.7071067811865475Return a function expecting an object, applying the provided function to its values and returning the lowest of the results.
> 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.49999999999999994Return 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.
> 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}Return an array containing the first and the last element of the provided array.
> getFirstAndLast([0, 1, 2, 3, 4])
[0, 4]
> getFirstAndLast([0])
[0, 0]
> getFirstAndLast([])
[undefined, undefined]Return the range within the provided limits, both limits being included.
> inclusiveRange([2, 5])
[2, 3, 4, 5]
> inclusiveRange([2, 12, 2])
[2, 4, 6, 8, 10, 12]
> inclusiveRange([])
[]Return the permutations of pairs of the provided items.
> makeBiPermutations([{foo: 'a'}, {foo: 'b'}, {bar: 'c'}])
[[{foo: 'a'}, {foo: 'b'}], [{foo: 'a'}, {bar: 'c'}], [{foo: 'b'}, {bar: 'c'}]]Pluck the `key` property value from an array of objects.
> pluckKey([{key: 'John', value: 'Foo'}, {key: 'Jane', value: 'Bar'}])
['John', 'Jane']Pluck the `value` property value from an array of objects.
> pluckValue([{key: 'John', value: 'Foo'}, {key: 'Jane', value: 'Bar'}])
['Foo', 'Bar']Return a copy of the provided array sorted in descending order.
> sortDesc([3, 1, 2])
[3, 2, 1]Return a copy of the provided array of key-value objects sorted by `key` (ascending).
> sortKeyAsc([{key: 'b', value: 1}, {key: 'a', value: 2}])
[{key: 'a', value: 2}, {key: 'b', value: 1}]Return a copy of the provided array of key-value objects sorted by `key` (descending).
> 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}]Return a copy of the provided array of key-value objects sorted by `value` (ascending).
> 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}]Return a copy of the provided array with items sorted by `value` (ascending) then by `key` (ascending)
@since 0.1.0Return a copy of the provided array with items sorted by `value` (ascending) then by `key` (descending)
@since 0.3.0Return a copy of the provided array of key-value objects sorted by `value` (descending).
> 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}]Return a copy of the provided array with items sorted by `value` (descending) then by `key` (ascending)
@since 0.3.0Return a copy of the provided array with items sorted by `value` (descending) then by `key` (descending)
@since 0.3.0Return a copy of the provided array sorted by `value` (descending) then `label` (ascending).
> 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}]Return a copy of the provided array sorted by `value` (descending) then `label` (descending).
> 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}]Return a copy of the provided array sorted by `value` (descending) then `label` lowercase (ascending).
> 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}]Return a copy of the provided array sorted by `value` (descending) then `label` lowercase (descending).
> 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}]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.
> transformer = makeArrayTransformer([x => x * 20, x => x + 3])
> transformer([2, 2])
[40, 5]Return a function plucking the provided keys from each object in the expected array.
> select = pluckKeys(['a', 'k'])
> select([
{a: 1, b: 2, c: 3, k: 4},
{a: 5, b: 8},
])
[{a: 1, k: 4}, {a: 5}]Return a function expecting an array and removing items at the provided indices.
> removeIndices = removeAt([3, 4, 8])
> removeIndices([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
[0, 1, 2, 5, 6, 7, 9]Return a function expecting an array of values and returning an object assigning the values to the provided keys.
> makeWithLatLng = makeWithKeys(['lng', 'lat'])
> makeWithLatLng([1, 2])
{lng: 1, lat: 2}
> makeWithLatLng([10, 20])
{lng: 10, lat: 20}Return a function expecting an array of keys and returning an object assigning the keys to the provided values.
> makeWithTheseValues = makeWithValues([1, 2])
> makeWithTheseValues(['lng', 'lat'])
{lng: 1, lat: 2}
> makeWithTheseValues(['foo', 'bar'])
{foo: 1, bar: 2}Return true if all elements of the provided array are truthy
> areAllTruthy([true, true])
true
> areAllTruthy([1, [], [1, 2], {}, {a: 1}, 'a'])
true
> areAllTruthy([false, true])
false
> areAllTruthy([0, {a: 1}])
falseReturn `true` if items in the provided array are equal
> areEqual([false, false, false])
true
> areEqual([true, false, false])
false
> areEqual([])
false
> areEqual([1])
falseReturn true if some elements of the provided array are truthy
> areSomeTruthy([false, true])
true
> areSomeTruthy([0, ''])
falseReturn a random item of the passed array
> 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}Return a function returning true if the passed (primitive) value is found in the provided array. To check non-primitive values use makeOccursIn instead.
> isIncluded = makeIsIncluded([1, 2, 3])
> isIncluded(1)
true
> isIncluded(4)
falseReturn 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.
> isOneOfThoseArrays = makeOccursIn([
[1, 2, 3], [1, 2, 3, 4], [5, 6, 7, 6, 5]
])
> isOneOfThoseArrays([1, 2, 3])
true
> isOneOfThoseArrays([1, 2])
falseReturn 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.
> boolToNum = truthynessTo([0, 1])
> boolToNum(true)
0
> boolToNum(false)
1
> boolToString = truthynessTo(['OK!', 'Sorry!'])
> boolToString(true)
'OK!'
> boolToString(false)
'Sorry!'Return a function returning an object by assigning the results of the provided functions to the provided keys.
> 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}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.
> getShorter([[1, 2], [1], [1, 2, 3], ['a']])
[1]
> getShorter(['abc', 'a', [1]])
'a'
> getShorter(['b', 'a'])
'b'
> getShorter([])
undefinedReturn the average of the numbers in the provided array
> arrayAverage([1, 23, 6])
10
> arrayAverage([])
0Return the max of the numbers in the provided array
> arrayMax([-1, -2, 0, 1, 2])
2Return the min of the numbers in the provided array
> arrayMin([-1, -2, 0, 1, 2])
-2Return the sum of the numbers in the provided array
> arraySum([1, -2, 3, -4, 5])
3
> arraySum([])
0Return the index of a random item of the passed array
> getRandomIndexOf([0, 1, 2, 3])
2
> getRandomIndexOf([0, 1, 2, 3])
1Return the average of values of a {key, value}[] array
> keyValueArrayAverage([
{key: 'a', value: 1},
{key: 'b', value: 23},
{key: 'c', value: 6},
])
10
> keyValueArrayAverage([])
0Return a random number in the specified range.
> makeRandomNumInRange([1.2, 7.4])
4.2Calculate 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)!)
> permutationsCount([4, 2])
6
> permutationsCount([5, 2])
10Return the sum of the `value` properties from the provided array of key-value objects.
> sumValue([{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}])
6
> sumValue([])
0Return a function expecting a number and returning true if the number is within the provided range (inclusive on both ends).
> isWithinRange = makeIsWithinRange([0, 5])
> isWithinRange(2)
true
> isWithinRange(5)
true
> isWithinRange(8)
falseReturn a function that computes the polynomial of the input number using the provided coefficients. The exponent corresponds to the coefficient's index.
> // x => 2 x + 4 x^3
> poly = makePolynomial([0, 2, 0, 4])
> poly(2)
36
> poly(5)
510Return an object built using 'key's and 'value's from the objects in the provided array
> keyValueArrayToObject([
{key: 'ITA', value: 0},
{key: 'FRA', value: 0},
])
{ ITA: 0, FRA: 0 }Return an object of occurrences of all the keys contained in the objects in the provided array
> 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}Return an object with the provided array elements as keys and all values equal to their index in the array
> makeIndexByKey(['a', 'b'])
{a: 0, b: 1}
> makeIndexByKey([2, -4])
{'2': 0, '-4': 1}Return an object with the provided array elements as keys and all values equal to `[]`
> makeKeyedEmptyArray(['a', 'b'])
{a: [], b: []}Return an object with the provided array elements as keys and all values equal to `false`
> makeKeyedFalse(['a', 'b'])
{a: false, b: false}Return an object with the provided array elements as keys and all values equal to `null`
> makeKeyedNull(['a', 'b'])
{a: null, b: null}Return an object with the provided array elements as keys and all values equal to `true`
> makeKeyedTrue(['a', 'b'])
{a: true, b: true}Return an object with the provided array elements as keys and all values equal to zero
> makeKeyedZeroes(['a', 'b'])
{a: 0, b: 0}
> makeKeyedZeroes([1, 2])
{1: 0, 2: 0}Merge all the objects in the provided array. The result depends on the order of the objects in the array.
> mergeObjects([{a: 1}, {a: 6, b: -1}, {b: 1}])
{a: 6, b: 1}Return the {key, value} object from a pair
> pairToKeyValueObject(['a', 2])
{key: 'a', value: 2}
> pairToKeyValueObject([1, 2, 3])
{key: 1, value: 2}
> pairToKeyValueObject([])
{key: undefined, value: undefined}Return the {key, values} object from a pair
> pairToKeyValuesObject(['a', [1, 2]])
{key: 'a', values: [1, 2]}
> pairToKeyValuesObject([1, [1, 2], 3])
{key: 1, values: [1, 2]}Return a function expecting an object and concatenating values in the provided list of keys.
> getProducts = pickAndConcatValues(['food', 'beverage'])
> getProducts({
food: ['bread', 'cheese', 'ham'],
beverage: ['wine', 'water'],
id: 'area1',
value: 32.1,
})
['bread', 'cheese', 'ham', 'wine', 'water']Return a predicate expecting an object and returning `true` if the value at the provided `key` is the same as the provided `value`.
> isUSA = isKeyValue(['country_id', 'US'])
> isUSA({country_id: 'GB', id: 123})
false
> isUSA({country_id: 'US', id: 456})
trueReturn a predicate expecting an object and returning `true` if the value at the provided `key` is not the same as the provided `value`.
> isNotUSA = isNotKeyValue(['country_id', 'US'])
> isNotUSA({country_id: 'GB', id: 123})
true
> isNotUSA({country_id: 'US', id: 456})
falseReturn a predicate expecting an object and returning `true` if the value at the provided `path` is not the same as the provided `value`.
> isNotDefaultStatus = isNotPathValue(['item.status', 'default'])
> isNotDefaultStatus({item: {status: 'active'}, id: 123})
true
> isNotDefaultStatus({item: {status: 'default'}, id: 456})
falseReturn a predicate expecting an object and returning `true` if the value at the provided `path` is the same as the provided `value`.
> isDefaultStatus = isPathValue(['item.status', 'default'])
> isDefaultStatus({item: {status: 'active'}, id: 123})
false
> isDefaultStatus({item: {status: 'default'}, id: 456})
trueReturn 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.
> 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}}Return a function plucking the provided keys from the expected object values.
> 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}}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.
> remap = remapWith([key => `${key}${key}`, value => 3 * value])
> remap({a: 1, b: 2})
{aa: 3, bb: 6}Return a string joining the provided array items with a blank
> joinWithBlank(['a', 'b', 'c'])
'a b c'Return a string joining the provided array items with a colon
> joinWithColon(['a', 'b', 'c'])
'a:b:c'Return a string joining the provided array items with a dash
> joinWithDash(['a', 'b', 'c'])
'a-b-c'Return a string joining the provided array items with a return
> joinWithNewline([1, 2, 3])
'1\n2\n3'
> joinWithNewline(['a', 'b', 'c'])
'a\nb\nc'Return a string joining the provided array items with a semicolon
> joinWithSemicolon(['a', 'b', 'c'])
'a;b;c'Return a function that checks if a string contains one of the provided strings.
> isWeight = containsOneOf(['(g)', '(mg)', '(mcg)'])
> ['id', 'Energy (kcal)', 'Protein (g)', 'Cholesterol (mg)', 'Selenium (mcg)'].filter(isWeight)
['Protein (g)', 'Cholesterol (mg)', 'Selenium (mcg)']Return a function extracting the portion of a string between the provided indices (first included, second excluded). Note that indices can be negative.
> 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'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.
> isEqualToObj = isEqualTo({a: 1, b: [1,2]})
> isEqualToObj({a: 1, b: [1, 2]})
true
> isEqualToObj({a: 1, b: [1, 2, 3]})
falseReturn a function that returns true if the input is different from the provided value.
> isNotTwo = isNot(2)
> isNotTwo(3)
true
> isNotTwo(2)
falseReturn a function expecting an array of keys and returning an object with the provided value as value of those keys.
> makeKeyedEmptyArray = makeKeyed([])
> makeKeyedEmptyArray([1, 2])
{1: [], 2: []}
> makeKeyedEmptyArray(['a', 'b'])
{a: [], b: []}Return true if the input is an arguments list.
@since 0.1.0Return true if the input is an array.
@since 0.1.0Return true if the input is a function.
@since 0.1.0Return true if the input is not a NaN.
@since 0.1.0Return true if the input is not undefined or null.
@since 0.1.0Return true if the input is not null.
@since 0.1.0Return true if the input is a number (including NaN and Infinity).
@since 0.1.0Return true if the input is a plain object.
@since 0.1.0Return true if the input is a promise.
@since 0.1.0Return true if the input is a string.
@since 0.1.0Return true if the input is a valid number (including not being NaN).
@since 0.1.0Return the negated input.
@since 0.1.0Return true if the input, parsed to float, is a valid number.
@since 0.1.0Return true if the input, converted to Number, is indeed a number.
@since 0.1.0Return an empty array if the input is undefined, identity otherwise.
> makeEmptyArrayIfUndefined(undefined)
[]
> makeEmptyArrayIfUndefined([1, 2, 3])
[1, 2, 3]Return a copy of the input after stringifying and parsing it. Useful to strip `undefined` values for JSON comparison.
> sanitize({a: 1, b: undefined})
{a: 1}
> sanitize([1, undefined])
[1, null]Return a number if the input can be converted to float, identity otherwise.
> toFloatOrIdentity('2')
2
> toFloatOrIdentity('h2o')
'h2o'Return a function that returns true if at least one of the input object properties has the provided value.
> hasTwo = hasValue(2)
> hasTwo({a: 1, b: 2})
true
> hasTwo({a: 1, b: 3})
falseReturn a string representation of the input with indentation = 2.
> stringify([{a: 1}, {a: 2}])
'[\n {\n "a": 1\n },\n {\n "a": 2\n }\n]'A function that does nothing.
> noop()
undefinedReturn true if the iterable has exactly one element
> hasIterableLength1('a')
true
> hasIterableLength1([1])
true
> hasIterableLength1([1, 2])
falseReturn true if the iterable is empty
> isIterableEmpty('')
true
> isIterableEmpty([])
true
> isIterableEmpty([1, 2])
falseReturn true if the iterable has more than one element
> isIterableLongerThan1('ab')
true
> isIterableLongerThan1([1, 2])
true
> isIterableLongerThan1([1])
falseReturn true if the iterable is not empty
> isIterableNotEmpty('a')
true
> isIterableNotEmpty([1, 2])
true
> isIterableNotEmpty([])
falseGet the length of the iterable
> getLength('a')
1
> getLength('two')
3
> getLength([10])
1
> getLength([3, 7])
2Return `true` if the input number is 0.
> is0(0)
true
> is0(2)
falseReturn `true` if the input number is 1.
> is1(1)
true
> is1(2)
falseReturn `true` if the input number is greater than 0.
> isGT0(-1)
false
> isGT0(2)
trueReturn `true` if the input number is greater than 1.
> isGT1(0)
false
> isGT1(2)
trueReturn the factorial of a number.
> factorial(0)
1
> factorial(5)
120Return a function that rounds the input number to the provided number of digits.
> roundTo2 = roundTo(2)
> roundTo2(2.41285)
2.41
> roundTo2(2.41785)
2.42Return an empty string if the provided number is 1, otherwise return 's'. Useful for building pluralized labels.
> plural(1)
''
> plural(2)
's'
> plural(0)
's'
> plural(-1)
's'Concatenate the values of the provided object.
> concatValues({a: [1, 2, 3], b: [4, 5, 6]})
[1, 2, 3, 4, 5, 6]Return the keys of the provided object with a truthy value.
> 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']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.
> 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}
]Return an array of {key, value} objects from an object.
> objectToKeyValueArray({k1: 'v1', k2: 'v2'})
[{key: 'k1', value: 'v1'}, {key: 'k2', value: 'v2'}]Return an array of {key, values} objects from an object.
> objectToKeyValuesArray({k1: ['a', 'b'], k2: ['c', 'd']})
[{key: 'k1', values: ['a', 'b']}, {key: 'k2', values: ['c', 'd']}]Convert an object to a key-value array sorted by `value` (descending) then `key` (ascending).
> objectToValueDescKeyAsc({b: 1, a: 3, c: 1})
[{key: 'a', value: 3}, {key: 'b', value: 1}, {key: 'c', value: 1}]Return `true` if all values of the provided object are truthy.
> areAllValuesTruthy({a: 1, b: 'hello', c: true})
true
> areAllValuesTruthy({a: 1, b: 0, c: true})
falseReturn `true` if at least one value of the provided object is truthy.
> areSomeValuesTruthy({a: 0, b: 1, c: false})
true
> areSomeValuesTruthy({a: 0, b: false, c: null})
falseReturn `true` if all values of the provided object are equal.
> 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({})
falseReturn `true` if the provided object has exactly one key.
> hasObjSize1({})
false
> hasObjSize1({a: 1})
true
> hasObjSize1({a: 1, b: 2})
falseReturn true if some of the provided object properties are `null`.
> hasSomeNullValues({a: 1})
false
> hasSomeNullValues({a: 1, b: undefined})
false
> hasSomeNullValues({a: 1, b: undefined, c: null})
trueReturn `true` if the object is empty.
> isObjEmpty({})
true
> isObjEmpty({a: 1})
falseReturn `true` if the object is not empty.
> isObjNotEmpty({a: 1})
true
> isObjNotEmpty({})
falseRetrieve the 'id' property of the provided object.
> getId({id: 'foo', name: 'bar'})
'foo'Retrieve the 'key' property of the provided object.
> getKey({key: 'foo', value: 'bar'})
'foo'Retrieve the 'value' property of the provided object.
> getValue({key: 'foo', value: 'bar'})
'bar'Retrieve the 'values' property of the provided object.
> getValues({key: 'foo', values: [0, 1, 2, 3]})
[0, 1, 2, 3]Return a function expecting any kind of input to be used as the argument of the provided functions
> 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'}
]Return the size of the provided object.
> getObjSize({a: 1, b: 2})
2Return the max of the provided object values.
> valuesMax({a: -3, b: 2, c: 1})
2Return the min of the provided object values.
> valuesMin({a: -3, b: 2, c: 1})
-3Return an object counting the occurrences of each unique value in the provided object.
> countValues({a: 'x', b: 'y', c: 'x', d: 'z', e: 'y'})
{x: 2, y: 2, z: 1}Return a copy of the object with values converted to float.
> mapValuesToFloat({a: '1.2px', b: '20px'})
{a: 1.2, b: 20}
> mapValuesToFloat({a: '1.2', b: 'h2o'})
{a: 1.2, b: NaN}Return the object with values converted to numbers where possible.
> mapValuesToFloatPossibly({a: '1.2', b: '2px', c: 'h2o'})
{a: 1.2, b: 2, c: 'h2o'}Return a copy of the object with values converted to numbers.
> mapValuesToNumber({a: '1.2', b: '2'})
{a: 1.2, b: 2}
> mapValuesToNumber({a: '1.2', b: '2s'})
{a: 1.2, b: NaN}Return a copy of the object without falsy values.
> 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}}Return a copy of the input object with enumerable properties sorted in ascending order.
> sortObjectKeysAsc({c: 1, a: 2, b: 15})
{a: 2, b: 15, c: 1}Return a copy of the input object with enumerable properties sorted in descending order.
> sortObjectKeysDesc({c: 1, a: 2, b: 15})
{c: 1, b: 15, a: 2}Return an object with swapped keys and values. If there are duplicate values, the last occurrence wins.
> 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'}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.
> 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}Return a function expecting an object to merge with the input object.
> mergeB = mergeObj({b: 2})
> mergeB({a: 1})
{a: 1, b: 2}
> mergeB({a: 1, b: 1})
{a: 1, b: 2}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.
> 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}}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.
> 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}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.
> 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}Retrieve the 'label' property of the provided object.
> getLabel({label: 'foo', value: 42})
'foo'Retrieve the 'label' property of the provided object, lowercased. Returns an empty string if label is undefined.
> getLabelLowercase({label: 'Foo', value: 42})
'foo'
> getLabelLowercase({value: 42})
''Return a function that checks if the expected string is a key of the provided object.
> isKeyOfObj = isKeyOf({a: 1, b: 2})
> isKeyOfObj('a')
true
> isKeyOfObj('c')
falseReturns true if the provided RegExp is empty
> isRegexpEmpty(/(?:)/u)
true
> isRegexpEmpty(/^a/u)
falseReturns true if the provided RegExp is not empty
> isRegexpNotEmpty(/^a/u)
true
> isRegexpNotEmpty(/(?:)/u)
falseA descending sorter for arrays of objects with a `key` property. Use with `_.sortWith` to sort by `key` descending.
> _.sortWith([sorterKeyDesc])([{key: 'b', value: 1}, {key: 'c', value: 2}])
[{key: 'c', value: 2}, {key: 'b', value: 1}]A descending sorter for arrays of objects with a `label` property. Use with `_.sortWith` to sort by `label` descending.
> _.sortWith([sorterLabelDesc])([{label: 'a'}, {label: 'c'}, {label: 'b'}])
[{label: 'c'}, {label: 'b'}, {label: 'a'}]A descending sorter for arrays of objects with a `value` property. Use with `_.sortWith` to sort by `value` descending.
> _.sortWith([sorterValueDesc])([{key: 'a', value: 1}, {key: 'b', value: 3}])
[{key: 'b', value: 3}, {key: 'a', value: 1}]Return a function expecting an object and returning `true` if the input object has a key satisfying the provided predicate
> const hasA = hasKeyWith(x => x === 'a')
> hasA({a: 2, b: 4, c: 3})
true
> hasA({b: 4, c: 3})
falseReturn a function expecting an object and returning a new object with only the keys satisfying the provided predicate
> 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})
{}Return a function expecting an object and returning a new object without the keys satisfying the provided predicate
> 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}Return a function expecting an object and returning a new object with keys renamed with the provided function.
> const rename = renameKeysWith(key => `--${key}`)
> rename({foo: 1, bar: 2})
{'--foo': 1, '--bar': 2}Return lines in a string (trimmed, split by newline)
> makeLines('A,B\n1,2\n3,4\n')
['A,B', '1,2', '3,4']Return rows in a string excluding the first line (the header). Useful for CSVs.
> makeRows('A,B\n1,2\n3,4\n')
['1,2', '3,4']Return an array from a ndjson string
> ndjsonToArray('{"a":1}\n{"b":2}\n\n')
[{a: 1}, {b: 2}]Return an array by splitting by '.'
> splitByDot('a.b.c')
['a', 'b', 'c']Return an array by splitting by '\n'
> splitByEOL('a\nb\nc')
['a', 'b', 'c']Return an array by splitting by ';'
> splitBySemiColon('A;B;C')
['A', 'B', 'C']Return a function expecting an array of objects and plucking the provided array with the input path
> 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]Return a function expecting an array of objects and returning an array of unique values for the provided key.
> pluckUniquesByA = pluckUniques('a')
> pluckUniquesByA([{a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 2}])
[1, 2]Return a copy of the provided array of objects assigning each object index to a property with the provided key (defaulting to `index`)
> 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}]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.
> maxByA = arrayMaxBy('a')
> maxByA([{a: -1, b: -1}, {a: 0, b: 0}])
0
> maxByA([{a: 1, b: 1}, {a: 2, b: -2}])
2Return 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.
> minByA = arrayMinBy('a')
> minByA([{a: -1, b: -1}, {a: 0, b: 0}])
-1
> minByA([{a: 1, b: 1}, {a: 2, b: -2}])
1Return a function expecting an array of objects and counting their values for the provided key.
> 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}Return true if the string ends with a newline
> endsWithNewLine('abc')
false
> endsWithNewLine('abc\n')
true
> endsWithNewLine('abc\r\n')
trueReturn true if the trimmed string is not empty
> isTrimmedNotEmpty(' foo ')
true
> isTrimmedNotEmpty(' ')
falseParse a JS module string (possibly prefixed with `export default `) and return the resulting value.
> exportedJsObjToAny('export default {"a":1}')
{a: 1}
> exportedJsObjToAny('{"a":1}')
{a: 1}Return the length of the end of line, if any.
> getEndOfLineLength('hello')
0
> getEndOfLineLength('hello\n')
1
> getEndOfLineLength('hello\r\n')
2Return 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.
> 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}})
9Return 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.
> 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}})
7Return a regular expression based on the given string
> regexOf('foo')
/foo/giuReturn a safe regular expression based on the given string, with any special characters escaped
> safeRegexOf('foo+bar')
/foo\+bar/giuCapitalise the input string
> capitalize('hello')
'Hello'Decapitalise the input string (makes the first letter lowercase)
> decapitalize('Hello')
'hello'
> decapitalize('HELLO')
'hELLO'Return a copy of the provided string with whitespace trimmed from both ends.
> trim(' abc \n ')
'abc'Trim the last char of the provided string if it's a newline
> 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'Return a function expecting a string to be split using the provided separator or regex
> splitByDoubleDot = makeSplitBy('..')
> splitByDoubleDot('aa...a..a.a.aa.....aa..')
['aa', '.a', 'a.a.aa', '', '.aa', '']Return a function expecting a separator or regex to split the provided string
> splitStringBy = makeSplitStringBy('a.b-c,d:e')
> splitStringBy(':')
['a.b-c,d', 'e']
> splitStringBy('-')
['a.b', 'c,d:e']Return a function that splits the expected string and trims all the elements of the returned array
> trimSplitByDoubleDot = makeTrimmedSplitBy('..')
> trimSplitByDoubleDot(' aa .. a\n..a')
['aa', 'a', 'a']Return a function expecting a base string and checking if it ends with the provided search string.
> endsWithExclamationMark = makeEndsWith('!')
> endsWithExclamationMark('Hi!')
true
> endsWithExclamationMark('Who?')
falseReturn a function expecting a base string and checking if it starts with the provided search string.
> startsWithHash = makeStartsWith('#')
> startsWithHash('# this is a bash comment')
true
> startsWithHash('This is not')
falseReturn a function expecting a search string and checking if the provided base string ends with the search string.
> stringEndsWith = makeStringEndsWith('Hi!')
> stringEndsWith('!')
true
> stringEndsWith('?')
falseReturn a function expecting a search string and checking if the provided base string starts with the search string.
> stringStartsWith = makeStringStartsWith('Hi!')
> stringStartsWith('H')
true
> stringStartsWith('h')
falseCreates a regular expression using the flags provided
> const regex = makeRegexOf('giu')('foo+bar')
/foo+bar/giuCreates an escaped regular expression using the flags provided to prevent regexp injections from source strings
> regex = makeSafeRegexOf('giu')('foo+bar')
/foo\+bar/giuReturn a function that appends the provided string to the input string
> postfixed = makePostfixed('---')
> postfixed('A')
'A---'
> postfixed('B')
'B---'Return a function that prepends the provided string to the input string
> prefixed = makePrefixed('---')
> prefixed('A')
'---A'
> prefixed('B')
'---B'Split an array into chunks of the specified size.
> chunkArray([1, 2, 3, 4, 5], 2)
[[1, 2], [3, 4], [5]]
> chunkArray([1, 2, 3], 3)
[[1, 2, 3]]Return an array by concatenating the provided arrays.
> concat([0, 1, 2], [3, 4], [5, 6])
[0, 1, 2, 3, 4, 5, 6]Return true if the input string ends with the test string.
> endsWith('Ping', 'ing')
true
> endsWith('Pong', 'ing')
falseDecode a TypedArray buffer and parse it as a JS object, stripping any `export default` prefix.
> encoder = new TextEncoder()
> buffer = encoder.encode('export default {"a": 1}')
> exportedObjBufferToAny(buffer)
{a: 1}Return true if the provided value is included in the provided array.
> includes([0, 1, 2], 2)
true
> includes([0, 1, 2], 3)
falseReturn a string by joining the provided array with the provided separator.
> join([0, 1, 2], '-')
'0-1-2'Decode a TypedArray buffer and parse it as JSON.
> encoder = new TextEncoder()
> buffer = encoder.encode('{"a": 1}')
> jsonBufferToAny(buffer)
{a: 1}Return a function that merges the provided value on the provided key of the expected object.
> 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}}Return an object of occurrences of keys in the provided array containing the provided keys
> makeOccurrences([{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}], ['a', 'b'])
{a: 3, b: 2}Return a function expecting two objects to merge using the provided merge function.
> mergeWithSubtract = mergeWith(_.subtract)
> mergeWithSubtract({a: 8, b: 3}, {a: 5, b: 2, c: 7})
{a: 3, b: 1, c: 7}Return the merge of two objects appending values of correspondent keys.
> 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]]}Return the merge of two objects concatenating values of correspondent keys.
> 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]}Return the merge of two objects merging values of correspondent keys.
> 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}}Return the merge of two objects adding values of correspondent keys.
> mergeWithSum({a: 1, b: 2}, {a: 10, c: 1})
{a: 11, b: 2, c: 1}Pluck unique values for the given key from the provided array of objects.
> pluckUniquesFrom([{a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 2}], 'a')
[1, 2]Return the portion of the provided string between the provided indices (first included, second excluded). Indices can be negative.
> sliceString('0123456789', 3)
'3456789'
> sliceString('0123456789', 3, 5)
'34'
> sliceString('0123456789', 3, -1)
'345678'Return an array by splitting the input string with the provided separator.
> split('a-b-c', '-')
['a', 'b', 'c']Return true if the input string starts with the test string.
> startsWith('Ping', 'Pin')
true
> startsWith('Pong', 'Pin')
falseReturn a copy of the array with values at the provided indices swapped
> swap([0, 1, 2, 3, 4, 5], 1, 4)
[0, 4, 2, 3, 1, 5]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.
> toggleItem([0, 1, 2, 0], 0)
[1, 2]
> toggleItem([1, 2], 0)
[1, 2, 0]