Comparing version 1.5.0 to 1.5.1
@@ -5,8 +5,10 @@ "use strict"; | ||
var purry_1 = require("./purry"); | ||
var _countBy = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
return ret + (value ? 1 : 0); | ||
}, 0); | ||
}; }; | ||
var _countBy = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
return ret + (value ? 1 : 0); | ||
}, 0); | ||
}; | ||
}; | ||
/** | ||
@@ -13,0 +15,0 @@ * Counts how many values of the collection pass the specified predicate. |
@@ -11,21 +11,25 @@ "use strict"; | ||
exports.filter = filter; | ||
var _filter = function (indexed) { return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? filter.lazyIndexed(fn) : filter.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!!valid === true) { | ||
var _filter = function (indexed) { | ||
return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? filter.lazyIndexed(fn) : filter.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!!valid === true) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
hasNext: false, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (filter) { | ||
@@ -32,0 +36,0 @@ function indexed() { |
@@ -11,18 +11,22 @@ "use strict"; | ||
exports.find = find; | ||
var _find = function (indexed) { return function (array, fn) { | ||
if (indexed) { | ||
return array.find(fn); | ||
} | ||
return array.find(function (x) { return fn(x); }); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
return { | ||
done: valid, | ||
hasNext: valid, | ||
next: value, | ||
var _find = function (indexed) { | ||
return function (array, fn) { | ||
if (indexed) { | ||
return array.find(fn); | ||
} | ||
return array.find(function (x) { return fn(x); }); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
return { | ||
done: valid, | ||
hasNext: valid, | ||
next: value, | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (find) { | ||
@@ -29,0 +33,0 @@ function indexed() { |
@@ -11,26 +11,30 @@ "use strict"; | ||
exports.findIndex = findIndex; | ||
var _findIndex = function (indexed) { return function (array, fn) { | ||
if (indexed) { | ||
return array.findIndex(fn); | ||
} | ||
return array.findIndex(function (x) { return fn(x); }); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
var i = 0; | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (valid) { | ||
var _findIndex = function (indexed) { | ||
return function (array, fn) { | ||
if (indexed) { | ||
return array.findIndex(fn); | ||
} | ||
return array.findIndex(function (x) { return fn(x); }); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
var i = 0; | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (valid) { | ||
return { | ||
done: true, | ||
hasNext: true, | ||
next: i, | ||
}; | ||
} | ||
i++; | ||
return { | ||
done: true, | ||
hasNext: true, | ||
next: i, | ||
done: false, | ||
hasNext: false, | ||
}; | ||
} | ||
i++; | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (findIndex) { | ||
@@ -37,0 +41,0 @@ function indexed() { |
@@ -9,9 +9,11 @@ "use strict"; | ||
exports.findLast = findLast; | ||
var _findLast = function (indexed) { return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return array[i]; | ||
var _findLast = function (indexed) { | ||
return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return array[i]; | ||
} | ||
} | ||
} | ||
}; }; | ||
}; | ||
}; | ||
(function (findLast) { | ||
@@ -18,0 +20,0 @@ function indexed() { |
@@ -9,10 +9,12 @@ "use strict"; | ||
exports.findLastIndex = findLastIndex; | ||
var _findLastIndex = function (indexed) { return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return i; | ||
var _findLastIndex = function (indexed) { | ||
return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return i; | ||
} | ||
} | ||
} | ||
return -1; | ||
}; }; | ||
return -1; | ||
}; | ||
}; | ||
(function (findLastIndex) { | ||
@@ -19,0 +21,0 @@ function indexed() { |
@@ -9,12 +9,14 @@ "use strict"; | ||
exports.flatMapToObj = flatMapToObj; | ||
var _flatMapToObj = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var items = indexed ? fn(element, index, array) : fn(element); | ||
items.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
}); | ||
return result; | ||
}, {}); | ||
}; }; | ||
var _flatMapToObj = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var items = indexed ? fn(element, index, array) : fn(element); | ||
items.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
}); | ||
return result; | ||
}, {}); | ||
}; | ||
}; | ||
(function (flatMapToObj) { | ||
@@ -21,0 +23,0 @@ function indexed() { |
@@ -11,20 +11,24 @@ "use strict"; | ||
exports.forEach = forEach; | ||
var _forEach = function (indexed) { return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
if (indexed) { | ||
fn(value, index, array); | ||
} | ||
else { | ||
fn(value); | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
var _forEach = function (indexed) { | ||
return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
if (indexed) { | ||
fn(value, index, array); | ||
} | ||
else { | ||
fn(value); | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (forEach) { | ||
@@ -31,0 +35,0 @@ function indexed() { |
@@ -9,14 +9,16 @@ "use strict"; | ||
exports.forEachObj = forEachObj; | ||
var _forEachObj = function (indexed) { return function (object, fn) { | ||
for (var key in object) { | ||
if (object.hasOwnProperty(key)) { | ||
var val = object[key]; | ||
if (indexed) | ||
fn(val, key, object); | ||
else | ||
fn(val); | ||
var _forEachObj = function (indexed) { | ||
return function (object, fn) { | ||
for (var key in object) { | ||
if (object.hasOwnProperty(key)) { | ||
var val = object[key]; | ||
if (indexed) | ||
fn(val, key, object); | ||
else | ||
fn(val); | ||
} | ||
} | ||
} | ||
return object; | ||
}; }; | ||
return object; | ||
}; | ||
}; | ||
(function (forEachObj) { | ||
@@ -23,0 +25,0 @@ function indexed() { |
@@ -20,14 +20,16 @@ "use strict"; | ||
exports.groupBy = groupBy; | ||
var _groupBy = function (indexed) { return function (array, fn) { | ||
var ret = {}; | ||
array.forEach(function (item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
if (!ret[key]) { | ||
ret[key] = []; | ||
} | ||
ret[key].push(item); | ||
}); | ||
return ret; | ||
}; }; | ||
var _groupBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = {}; | ||
array.forEach(function (item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
if (!ret[key]) { | ||
ret[key] = []; | ||
} | ||
ret[key].push(item); | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
(function (groupBy) { | ||
@@ -34,0 +36,0 @@ function indexed() { |
@@ -9,10 +9,12 @@ "use strict"; | ||
exports.indexBy = indexBy; | ||
var _indexBy = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
ret[key] = item; | ||
return ret; | ||
}, {}); | ||
}; }; | ||
var _indexBy = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
ret[key] = item; | ||
return ret; | ||
}, {}); | ||
}; | ||
}; | ||
(function (indexBy) { | ||
@@ -19,0 +21,0 @@ function indexed() { |
@@ -7,4 +7,3 @@ "use strict"; | ||
expect((0, intersection_1.intersection)([1, 2, 3], [2, 3, 5])).toEqual([ | ||
2, | ||
3, | ||
2, 3, | ||
]); | ||
@@ -16,6 +15,5 @@ }); | ||
expect((0, intersection_1.intersection)([2, 3, 5])([1, 2, 3])).toEqual([ | ||
2, | ||
3, | ||
2, 3, | ||
]); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ /** | ||
* ) // => 'a' | ||
* R.keys.strict({ a: 'x', b: 'y', c: 'z' } as const ) // => ['a', 'b', 'c'], typed Array<'a' | 'b' | 'c'> | ||
* R.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'> | ||
* @pipeable | ||
@@ -23,4 +23,6 @@ * @strict | ||
export declare namespace keys { | ||
function strict<T extends Record<PropertyKey, unknown>>(source: T): Array<keyof T>; | ||
function strict<T extends Record<PropertyKey, unknown>>(source: T): Array<{ | ||
[K in keyof T]: K extends string | number ? `${K}` : never; | ||
}[keyof T]>; | ||
} | ||
//# sourceMappingURL=keys.d.ts.map |
@@ -16,3 +16,3 @@ "use strict"; | ||
* ) // => 'a' | ||
* R.keys.strict({ a: 'x', b: 'y', c: 'z' } as const ) // => ['a', 'b', 'c'], typed Array<'a' | 'b' | 'c'> | ||
* R.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'> | ||
* @pipeable | ||
@@ -19,0 +19,0 @@ * @strict |
@@ -12,4 +12,4 @@ "use strict"; | ||
describe('strict', function () { | ||
var actual = keys_1.keys.strict({ a: 'x', b: 'y', c: 'z' }); | ||
expect(actual).toEqual(['a', 'b', 'c']); | ||
var actual = keys_1.keys.strict({ 5: 'x', b: 'y', c: 'z' }); | ||
expect(actual).toEqual(['5', 'b', 'c']); | ||
var result = true; | ||
@@ -16,0 +16,0 @@ expect(result).toEqual(true); |
@@ -11,14 +11,18 @@ "use strict"; | ||
exports.map = map; | ||
var _map = function (indexed) { return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? map.lazyIndexed(fn) : map.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: indexed ? fn(value, index, array) : fn(value), | ||
var _map = function (indexed) { | ||
return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? map.lazyIndexed(fn) : map.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: indexed ? fn(value, index, array) : fn(value), | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (map) { | ||
@@ -25,0 +29,0 @@ function indexed() { |
@@ -9,9 +9,11 @@ "use strict"; | ||
exports.mapToObj = mapToObj; | ||
var _mapToObj = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var _a = indexed ? fn(element, index, array) : fn(element), key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
return result; | ||
}, {}); | ||
}; }; | ||
var _mapToObj = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var _a = indexed ? fn(element, index, array) : fn(element), key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
return result; | ||
}, {}); | ||
}; | ||
}; | ||
(function (mapToObj) { | ||
@@ -18,0 +20,0 @@ function indexed() { |
@@ -5,14 +5,16 @@ "use strict"; | ||
var purry_1 = require("./purry"); | ||
var _maxBy = function (indexed) { return function (array, fn) { | ||
var ret = undefined; | ||
var retMax = undefined; | ||
array.forEach(function (item, i) { | ||
var max = indexed ? fn(item, i, array) : fn(item); | ||
if (retMax === undefined || max > retMax) { | ||
ret = item; | ||
retMax = max; | ||
} | ||
}); | ||
return ret; | ||
}; }; | ||
var _maxBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = undefined; | ||
var retMax = undefined; | ||
array.forEach(function (item, i) { | ||
var max = indexed ? fn(item, i, array) : fn(item); | ||
if (retMax === undefined || max > retMax) { | ||
ret = item; | ||
retMax = max; | ||
} | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
function maxBy() { | ||
@@ -19,0 +21,0 @@ return (0, purry_1.purry)(_maxBy(false), arguments); |
@@ -5,12 +5,14 @@ "use strict"; | ||
var purry_1 = require("./purry"); | ||
var _meanBy = function (indexed) { return function (array, fn) { | ||
if (array.length === 0) { | ||
return NaN; | ||
} | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
sum += indexed ? fn(item, i, array) : fn(item); | ||
}); | ||
return sum / array.length; | ||
}; }; | ||
var _meanBy = function (indexed) { | ||
return function (array, fn) { | ||
if (array.length === 0) { | ||
return NaN; | ||
} | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
sum += indexed ? fn(item, i, array) : fn(item); | ||
}); | ||
return sum / array.length; | ||
}; | ||
}; | ||
function meanBy() { | ||
@@ -17,0 +19,0 @@ return (0, purry_1.purry)(_meanBy(false), arguments); |
@@ -5,14 +5,16 @@ "use strict"; | ||
var purry_1 = require("./purry"); | ||
var _minBy = function (indexed) { return function (array, fn) { | ||
var ret = undefined; | ||
var retMin = undefined; | ||
array.forEach(function (item, i) { | ||
var min = indexed ? fn(item, i, array) : fn(item); | ||
if (retMin === undefined || min < retMin) { | ||
ret = item; | ||
retMin = min; | ||
} | ||
}); | ||
return ret; | ||
}; }; | ||
var _minBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = undefined; | ||
var retMin = undefined; | ||
array.forEach(function (item, i) { | ||
var min = indexed ? fn(item, i, array) : fn(item); | ||
if (retMin === undefined || min < retMin) { | ||
ret = item; | ||
retMin = min; | ||
} | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
function minBy() { | ||
@@ -19,0 +21,0 @@ return (0, purry_1.purry)(_minBy(false), arguments); |
@@ -9,10 +9,12 @@ "use strict"; | ||
exports.partition = partition; | ||
var _partition = function (indexed) { return function (array, fn) { | ||
var ret = [[], []]; | ||
array.forEach(function (item, index) { | ||
var matches = indexed ? fn(item, index, array) : fn(item); | ||
ret[matches ? 0 : 1].push(item); | ||
}); | ||
return ret; | ||
}; }; | ||
var _partition = function (indexed) { | ||
return function (array, fn) { | ||
var ret = [[], []]; | ||
array.forEach(function (item, index) { | ||
var matches = indexed ? fn(item, index, array) : fn(item); | ||
ret[matches ? 0 : 1].push(item); | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
(function (partition) { | ||
@@ -19,0 +21,0 @@ function indexed() { |
@@ -9,7 +9,9 @@ "use strict"; | ||
exports.reduce = reduce; | ||
var _reduce = function (indexed) { return function (items, fn, initialValue) { | ||
return items.reduce(function (acc, item, index) { | ||
return indexed ? fn(acc, item, index, items) : fn(acc, item); | ||
}, initialValue); | ||
}; }; | ||
var _reduce = function (indexed) { | ||
return function (items, fn, initialValue) { | ||
return items.reduce(function (acc, item, index) { | ||
return indexed ? fn(acc, item, index, items) : fn(acc, item); | ||
}, initialValue); | ||
}; | ||
}; | ||
(function (reduce) { | ||
@@ -16,0 +18,0 @@ function indexed() { |
@@ -11,21 +11,25 @@ "use strict"; | ||
exports.reject = reject; | ||
var _reject = function (indexed) { return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? reject.lazyIndexed(fn) : reject.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!valid === true) { | ||
var _reject = function (indexed) { | ||
return function (array, fn) { | ||
return (0, _reduceLazy_1._reduceLazy)(array, indexed ? reject.lazyIndexed(fn) : reject.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!valid === true) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
hasNext: false, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (reject) { | ||
@@ -32,0 +36,0 @@ function indexed() { |
@@ -40,6 +40,3 @@ "use strict"; | ||
expect((0, sortBy_1.sortBy)(objects, [function (x) { return x.date; }, 'desc']).map(function (x) { return x.id; })).toEqual([ | ||
4, | ||
3, | ||
2, | ||
1, | ||
4, 3, 2, 1, | ||
]); | ||
@@ -46,0 +43,0 @@ }); |
@@ -5,10 +5,12 @@ "use strict"; | ||
var purry_1 = require("./purry"); | ||
var _sumBy = function (indexed) { return function (array, fn) { | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
var summand = indexed ? fn(item, i, array) : fn(item); | ||
sum += summand; | ||
}); | ||
return sum; | ||
}; }; | ||
var _sumBy = function (indexed) { | ||
return function (array, fn) { | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
var summand = indexed ? fn(item, i, array) : fn(item); | ||
sum += summand; | ||
}); | ||
return sum; | ||
}; | ||
}; | ||
function sumBy() { | ||
@@ -15,0 +17,0 @@ return (0, purry_1.purry)(_sumBy(false), arguments); |
@@ -8,5 +8,3 @@ "use strict"; | ||
expect((0, takeWhile_1.takeWhile)([1, 2, 3, 4, 3, 2, 1], function (x) { return x !== 4; })).toEqual([ | ||
1, | ||
2, | ||
3, | ||
1, 2, 3, | ||
]); | ||
@@ -13,0 +11,0 @@ }); |
import { purry } from './purry'; | ||
var _countBy = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
return ret + (value ? 1 : 0); | ||
}, 0); | ||
}; }; | ||
var _countBy = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
return ret + (value ? 1 : 0); | ||
}, 0); | ||
}; | ||
}; | ||
/** | ||
@@ -9,0 +11,0 @@ * Counts how many values of the collection pass the specified predicate. |
@@ -7,21 +7,25 @@ import { purry } from './purry'; | ||
} | ||
var _filter = function (indexed) { return function (array, fn) { | ||
return _reduceLazy(array, indexed ? filter.lazyIndexed(fn) : filter.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!!valid === true) { | ||
var _filter = function (indexed) { | ||
return function (array, fn) { | ||
return _reduceLazy(array, indexed ? filter.lazyIndexed(fn) : filter.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!!valid === true) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
hasNext: false, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (filter) { | ||
@@ -28,0 +32,0 @@ function indexed() { |
@@ -7,18 +7,22 @@ import { purry } from './purry'; | ||
} | ||
var _find = function (indexed) { return function (array, fn) { | ||
if (indexed) { | ||
return array.find(fn); | ||
} | ||
return array.find(function (x) { return fn(x); }); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
return { | ||
done: valid, | ||
hasNext: valid, | ||
next: value, | ||
var _find = function (indexed) { | ||
return function (array, fn) { | ||
if (indexed) { | ||
return array.find(fn); | ||
} | ||
return array.find(function (x) { return fn(x); }); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
return { | ||
done: valid, | ||
hasNext: valid, | ||
next: value, | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (find) { | ||
@@ -25,0 +29,0 @@ function indexed() { |
@@ -7,26 +7,30 @@ import { purry } from './purry'; | ||
} | ||
var _findIndex = function (indexed) { return function (array, fn) { | ||
if (indexed) { | ||
return array.findIndex(fn); | ||
} | ||
return array.findIndex(function (x) { return fn(x); }); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
var i = 0; | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (valid) { | ||
var _findIndex = function (indexed) { | ||
return function (array, fn) { | ||
if (indexed) { | ||
return array.findIndex(fn); | ||
} | ||
return array.findIndex(function (x) { return fn(x); }); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
var i = 0; | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (valid) { | ||
return { | ||
done: true, | ||
hasNext: true, | ||
next: i, | ||
}; | ||
} | ||
i++; | ||
return { | ||
done: true, | ||
hasNext: true, | ||
next: i, | ||
done: false, | ||
hasNext: false, | ||
}; | ||
} | ||
i++; | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (findIndex) { | ||
@@ -33,0 +37,0 @@ function indexed() { |
@@ -5,9 +5,11 @@ import { purry } from './purry'; | ||
} | ||
var _findLast = function (indexed) { return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return array[i]; | ||
var _findLast = function (indexed) { | ||
return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return array[i]; | ||
} | ||
} | ||
} | ||
}; }; | ||
}; | ||
}; | ||
(function (findLast) { | ||
@@ -14,0 +16,0 @@ function indexed() { |
@@ -5,10 +5,12 @@ import { purry } from './purry'; | ||
} | ||
var _findLastIndex = function (indexed) { return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return i; | ||
var _findLastIndex = function (indexed) { | ||
return function (array, fn) { | ||
for (var i = array.length - 1; i >= 0; i--) { | ||
if (indexed ? fn(array[i], i, array) : fn(array[i])) { | ||
return i; | ||
} | ||
} | ||
} | ||
return -1; | ||
}; }; | ||
return -1; | ||
}; | ||
}; | ||
(function (findLastIndex) { | ||
@@ -15,0 +17,0 @@ function indexed() { |
@@ -5,12 +5,14 @@ import { purry } from './purry'; | ||
} | ||
var _flatMapToObj = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var items = indexed ? fn(element, index, array) : fn(element); | ||
items.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
}); | ||
return result; | ||
}, {}); | ||
}; }; | ||
var _flatMapToObj = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var items = indexed ? fn(element, index, array) : fn(element); | ||
items.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
}); | ||
return result; | ||
}, {}); | ||
}; | ||
}; | ||
(function (flatMapToObj) { | ||
@@ -17,0 +19,0 @@ function indexed() { |
@@ -7,20 +7,24 @@ import { purry } from './purry'; | ||
} | ||
var _forEach = function (indexed) { return function (array, fn) { | ||
return _reduceLazy(array, indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
if (indexed) { | ||
fn(value, index, array); | ||
} | ||
else { | ||
fn(value); | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
var _forEach = function (indexed) { | ||
return function (array, fn) { | ||
return _reduceLazy(array, indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
if (indexed) { | ||
fn(value, index, array); | ||
} | ||
else { | ||
fn(value); | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (forEach) { | ||
@@ -27,0 +31,0 @@ function indexed() { |
@@ -5,14 +5,16 @@ import { purry } from './purry'; | ||
} | ||
var _forEachObj = function (indexed) { return function (object, fn) { | ||
for (var key in object) { | ||
if (object.hasOwnProperty(key)) { | ||
var val = object[key]; | ||
if (indexed) | ||
fn(val, key, object); | ||
else | ||
fn(val); | ||
var _forEachObj = function (indexed) { | ||
return function (object, fn) { | ||
for (var key in object) { | ||
if (object.hasOwnProperty(key)) { | ||
var val = object[key]; | ||
if (indexed) | ||
fn(val, key, object); | ||
else | ||
fn(val); | ||
} | ||
} | ||
} | ||
return object; | ||
}; }; | ||
return object; | ||
}; | ||
}; | ||
(function (forEachObj) { | ||
@@ -19,0 +21,0 @@ function indexed() { |
@@ -16,14 +16,16 @@ import { purry } from './purry'; | ||
} | ||
var _groupBy = function (indexed) { return function (array, fn) { | ||
var ret = {}; | ||
array.forEach(function (item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
if (!ret[key]) { | ||
ret[key] = []; | ||
} | ||
ret[key].push(item); | ||
}); | ||
return ret; | ||
}; }; | ||
var _groupBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = {}; | ||
array.forEach(function (item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
if (!ret[key]) { | ||
ret[key] = []; | ||
} | ||
ret[key].push(item); | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
(function (groupBy) { | ||
@@ -30,0 +32,0 @@ function indexed() { |
@@ -5,10 +5,12 @@ import { purry } from './purry'; | ||
} | ||
var _indexBy = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
ret[key] = item; | ||
return ret; | ||
}, {}); | ||
}; }; | ||
var _indexBy = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (ret, item, index) { | ||
var value = indexed ? fn(item, index, array) : fn(item); | ||
var key = String(value); | ||
ret[key] = item; | ||
return ret; | ||
}, {}); | ||
}; | ||
}; | ||
(function (indexBy) { | ||
@@ -15,0 +17,0 @@ function indexed() { |
@@ -5,4 +5,3 @@ import { intersection } from './intersection'; | ||
expect(intersection([1, 2, 3], [2, 3, 5])).toEqual([ | ||
2, | ||
3, | ||
2, 3, | ||
]); | ||
@@ -14,6 +13,5 @@ }); | ||
expect(intersection([2, 3, 5])([1, 2, 3])).toEqual([ | ||
2, | ||
3, | ||
2, 3, | ||
]); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ /** | ||
* ) // => 'a' | ||
* R.keys.strict({ a: 'x', b: 'y', c: 'z' } as const ) // => ['a', 'b', 'c'], typed Array<'a' | 'b' | 'c'> | ||
* R.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'> | ||
* @pipeable | ||
@@ -23,4 +23,6 @@ * @strict | ||
export declare namespace keys { | ||
function strict<T extends Record<PropertyKey, unknown>>(source: T): Array<keyof T>; | ||
function strict<T extends Record<PropertyKey, unknown>>(source: T): Array<{ | ||
[K in keyof T]: K extends string | number ? `${K}` : never; | ||
}[keyof T]>; | ||
} | ||
//# sourceMappingURL=keys.d.ts.map |
@@ -15,3 +15,3 @@ /** | ||
* ) // => 'a' | ||
* R.keys.strict({ a: 'x', b: 'y', c: 'z' } as const ) // => ['a', 'b', 'c'], typed Array<'a' | 'b' | 'c'> | ||
* R.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'> | ||
* @pipeable | ||
@@ -18,0 +18,0 @@ * @strict |
@@ -10,4 +10,4 @@ import { keys } from './keys'; | ||
describe('strict', function () { | ||
var actual = keys.strict({ a: 'x', b: 'y', c: 'z' }); | ||
expect(actual).toEqual(['a', 'b', 'c']); | ||
var actual = keys.strict({ 5: 'x', b: 'y', c: 'z' }); | ||
expect(actual).toEqual(['5', 'b', 'c']); | ||
var result = true; | ||
@@ -14,0 +14,0 @@ expect(result).toEqual(true); |
@@ -7,14 +7,18 @@ import { purry } from './purry'; | ||
} | ||
var _map = function (indexed) { return function (array, fn) { | ||
return _reduceLazy(array, indexed ? map.lazyIndexed(fn) : map.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: indexed ? fn(value, index, array) : fn(value), | ||
var _map = function (indexed) { | ||
return function (array, fn) { | ||
return _reduceLazy(array, indexed ? map.lazyIndexed(fn) : map.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: indexed ? fn(value, index, array) : fn(value), | ||
}; | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (map) { | ||
@@ -21,0 +25,0 @@ function indexed() { |
@@ -5,9 +5,11 @@ import { purry } from './purry'; | ||
} | ||
var _mapToObj = function (indexed) { return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var _a = indexed ? fn(element, index, array) : fn(element), key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
return result; | ||
}, {}); | ||
}; }; | ||
var _mapToObj = function (indexed) { | ||
return function (array, fn) { | ||
return array.reduce(function (result, element, index) { | ||
var _a = indexed ? fn(element, index, array) : fn(element), key = _a[0], value = _a[1]; | ||
result[key] = value; | ||
return result; | ||
}, {}); | ||
}; | ||
}; | ||
(function (mapToObj) { | ||
@@ -14,0 +16,0 @@ function indexed() { |
import { purry } from './purry'; | ||
var _maxBy = function (indexed) { return function (array, fn) { | ||
var ret = undefined; | ||
var retMax = undefined; | ||
array.forEach(function (item, i) { | ||
var max = indexed ? fn(item, i, array) : fn(item); | ||
if (retMax === undefined || max > retMax) { | ||
ret = item; | ||
retMax = max; | ||
} | ||
}); | ||
return ret; | ||
}; }; | ||
var _maxBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = undefined; | ||
var retMax = undefined; | ||
array.forEach(function (item, i) { | ||
var max = indexed ? fn(item, i, array) : fn(item); | ||
if (retMax === undefined || max > retMax) { | ||
ret = item; | ||
retMax = max; | ||
} | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
export function maxBy() { | ||
@@ -15,0 +17,0 @@ return purry(_maxBy(false), arguments); |
import { purry } from './purry'; | ||
var _meanBy = function (indexed) { return function (array, fn) { | ||
if (array.length === 0) { | ||
return NaN; | ||
} | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
sum += indexed ? fn(item, i, array) : fn(item); | ||
}); | ||
return sum / array.length; | ||
}; }; | ||
var _meanBy = function (indexed) { | ||
return function (array, fn) { | ||
if (array.length === 0) { | ||
return NaN; | ||
} | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
sum += indexed ? fn(item, i, array) : fn(item); | ||
}); | ||
return sum / array.length; | ||
}; | ||
}; | ||
export function meanBy() { | ||
@@ -13,0 +15,0 @@ return purry(_meanBy(false), arguments); |
import { purry } from './purry'; | ||
var _minBy = function (indexed) { return function (array, fn) { | ||
var ret = undefined; | ||
var retMin = undefined; | ||
array.forEach(function (item, i) { | ||
var min = indexed ? fn(item, i, array) : fn(item); | ||
if (retMin === undefined || min < retMin) { | ||
ret = item; | ||
retMin = min; | ||
} | ||
}); | ||
return ret; | ||
}; }; | ||
var _minBy = function (indexed) { | ||
return function (array, fn) { | ||
var ret = undefined; | ||
var retMin = undefined; | ||
array.forEach(function (item, i) { | ||
var min = indexed ? fn(item, i, array) : fn(item); | ||
if (retMin === undefined || min < retMin) { | ||
ret = item; | ||
retMin = min; | ||
} | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
export function minBy() { | ||
@@ -15,0 +17,0 @@ return purry(_minBy(false), arguments); |
@@ -5,10 +5,12 @@ import { purry } from './purry'; | ||
} | ||
var _partition = function (indexed) { return function (array, fn) { | ||
var ret = [[], []]; | ||
array.forEach(function (item, index) { | ||
var matches = indexed ? fn(item, index, array) : fn(item); | ||
ret[matches ? 0 : 1].push(item); | ||
}); | ||
return ret; | ||
}; }; | ||
var _partition = function (indexed) { | ||
return function (array, fn) { | ||
var ret = [[], []]; | ||
array.forEach(function (item, index) { | ||
var matches = indexed ? fn(item, index, array) : fn(item); | ||
ret[matches ? 0 : 1].push(item); | ||
}); | ||
return ret; | ||
}; | ||
}; | ||
(function (partition) { | ||
@@ -15,0 +17,0 @@ function indexed() { |
@@ -5,7 +5,9 @@ import { purry } from './purry'; | ||
} | ||
var _reduce = function (indexed) { return function (items, fn, initialValue) { | ||
return items.reduce(function (acc, item, index) { | ||
return indexed ? fn(acc, item, index, items) : fn(acc, item); | ||
}, initialValue); | ||
}; }; | ||
var _reduce = function (indexed) { | ||
return function (items, fn, initialValue) { | ||
return items.reduce(function (acc, item, index) { | ||
return indexed ? fn(acc, item, index, items) : fn(acc, item); | ||
}, initialValue); | ||
}; | ||
}; | ||
(function (reduce) { | ||
@@ -12,0 +14,0 @@ function indexed() { |
@@ -7,21 +7,25 @@ import { purry } from './purry'; | ||
} | ||
var _reject = function (indexed) { return function (array, fn) { | ||
return _reduceLazy(array, indexed ? reject.lazyIndexed(fn) : reject.lazy(fn), indexed); | ||
}; }; | ||
var _lazy = function (indexed) { return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!valid === true) { | ||
var _reject = function (indexed) { | ||
return function (array, fn) { | ||
return _reduceLazy(array, indexed ? reject.lazyIndexed(fn) : reject.lazy(fn), indexed); | ||
}; | ||
}; | ||
var _lazy = function (indexed) { | ||
return function (fn) { | ||
return function (value, index, array) { | ||
var valid = indexed ? fn(value, index, array) : fn(value); | ||
if (!valid === true) { | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: true, | ||
next: value, | ||
hasNext: false, | ||
}; | ||
} | ||
return { | ||
done: false, | ||
hasNext: false, | ||
}; | ||
}; | ||
}; }; | ||
}; | ||
(function (reject) { | ||
@@ -28,0 +32,0 @@ function indexed() { |
@@ -38,6 +38,3 @@ import { sortBy } from './sortBy'; | ||
expect(sortBy(objects, [function (x) { return x.date; }, 'desc']).map(function (x) { return x.id; })).toEqual([ | ||
4, | ||
3, | ||
2, | ||
1, | ||
4, 3, 2, 1, | ||
]); | ||
@@ -44,0 +41,0 @@ }); |
import { purry } from './purry'; | ||
var _sumBy = function (indexed) { return function (array, fn) { | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
var summand = indexed ? fn(item, i, array) : fn(item); | ||
sum += summand; | ||
}); | ||
return sum; | ||
}; }; | ||
var _sumBy = function (indexed) { | ||
return function (array, fn) { | ||
var sum = 0; | ||
array.forEach(function (item, i) { | ||
var summand = indexed ? fn(item, i, array) : fn(item); | ||
sum += summand; | ||
}); | ||
return sum; | ||
}; | ||
}; | ||
export function sumBy() { | ||
@@ -11,0 +13,0 @@ return purry(_sumBy(false), arguments); |
@@ -6,5 +6,3 @@ import { takeWhile } from './takeWhile'; | ||
expect(takeWhile([1, 2, 3, 4, 3, 2, 1], function (x) { return x !== 4; })).toEqual([ | ||
1, | ||
2, | ||
3, | ||
1, 2, 3, | ||
]); | ||
@@ -11,0 +9,0 @@ }); |
{ | ||
"name": "remeda", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "A utility library for JavaScript and Typescript.", | ||
@@ -13,3 +13,3 @@ "main": "dist/commonjs/index.js", | ||
"marked": "^0.4.0", | ||
"prettier": "^2.1.2", | ||
"prettier": "^2.8.0", | ||
"ts-jest": "^26.4.1", | ||
@@ -16,0 +16,0 @@ "ts-node": "^8.4.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
711384
16276