@mongez/reinforcements 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/cjs/Random/random.d.ts +35 -35
- package/cjs/Random/random.js +65 -67
- package/cjs/Random/random.test.d.ts +2 -0
- package/cjs/array/average.d.ts +6 -6
- package/cjs/array/average.js +12 -15
- package/cjs/array/average.test.d.ts +2 -0
- package/cjs/array/chunk.d.ts +4 -4
- package/cjs/array/chunk.js +13 -15
- package/cjs/array/chunk.test.d.ts +2 -0
- package/cjs/array/count.d.ts +4 -4
- package/cjs/array/count.js +14 -17
- package/cjs/array/count.test.d.ts +2 -0
- package/cjs/array/countBy.d.ts +6 -6
- package/cjs/array/countBy.js +20 -23
- package/cjs/array/countBy.test.d.ts +2 -0
- package/cjs/array/even.d.ts +6 -6
- package/cjs/array/even.js +15 -18
- package/cjs/array/even.test.d.ts +2 -0
- package/cjs/array/evenIndexes.d.ts +4 -4
- package/cjs/array/evenIndexes.js +9 -11
- package/cjs/array/evenIndexes.test.d.ts +2 -0
- package/cjs/array/groupBy.d.ts +7 -7
- package/cjs/array/groupBy.js +45 -48
- package/cjs/array/groupBy.test.d.ts +2 -0
- package/cjs/array/max.d.ts +6 -6
- package/cjs/array/max.js +20 -23
- package/cjs/array/max.test.d.ts +2 -0
- package/cjs/array/median.d.ts +6 -6
- package/cjs/array/median.js +25 -28
- package/cjs/array/median.test.d.ts +2 -0
- package/cjs/array/min.d.ts +6 -6
- package/cjs/array/min.js +20 -23
- package/cjs/array/min.test.d.ts +2 -0
- package/cjs/array/odd.d.ts +6 -6
- package/cjs/array/odd.js +15 -18
- package/cjs/array/odd.test.d.ts +2 -0
- package/cjs/array/oddIndexes.d.ts +4 -4
- package/cjs/array/oddIndexes.js +9 -11
- package/cjs/array/oddIndexes.test.d.ts +2 -0
- package/cjs/array/pluck.d.ts +8 -8
- package/cjs/array/pluck.js +23 -26
- package/cjs/array/pluck.test.d.ts +2 -0
- package/cjs/array/pushUnique.d.ts +5 -5
- package/cjs/array/pushUnique.js +14 -16
- package/cjs/array/pushUnique.test.d.ts +2 -0
- package/cjs/array/range.d.ts +4 -4
- package/cjs/array/range.js +21 -23
- package/cjs/array/range.test.d.ts +2 -0
- package/cjs/array/sum.d.ts +6 -6
- package/cjs/array/sum.js +28 -31
- package/cjs/array/sum.test.d.ts +2 -0
- package/cjs/array/unique.d.ts +4 -4
- package/cjs/array/unique.js +14 -17
- package/cjs/array/unique.test.d.ts +2 -0
- package/cjs/array/unshiftUnique.d.ts +5 -5
- package/cjs/array/unshiftUnique.js +14 -16
- package/cjs/array/unshiftUnique.test.d.ts +2 -0
- package/cjs/index.d.ts +56 -56
- package/cjs/index.js +56 -59
- package/cjs/mixed/areEqual/areEqual.d.ts +4 -4
- package/cjs/mixed/areEqual/areEqual.js +23 -25
- package/cjs/mixed/areEqual/areEqual.test.d.ts +2 -0
- package/cjs/mixed/clone/clone.d.ts +4 -4
- package/cjs/mixed/clone/clone.js +12 -18
- package/cjs/mixed/clone/clone.test.d.ts +2 -0
- package/cjs/mixed/shuffle/shuffle.d.ts +4 -4
- package/cjs/mixed/shuffle/shuffle.js +14 -16
- package/cjs/mixed/shuffle/shuffle.test.d.ts +2 -0
- package/cjs/number/round.d.ts +4 -4
- package/cjs/number/round.js +9 -11
- package/cjs/object/except.d.ts +4 -4
- package/cjs/object/except.js +12 -15
- package/cjs/object/except.test.d.ts +2 -0
- package/cjs/object/flatten.d.ts +4 -4
- package/cjs/object/flatten.js +38 -40
- package/cjs/object/flatten.test.d.ts +2 -0
- package/cjs/object/get.d.ts +4 -4
- package/cjs/object/get.js +24 -26
- package/cjs/object/get.test.d.ts +2 -0
- package/cjs/object/map.d.ts +4 -4
- package/cjs/object/map.js +10 -12
- package/cjs/object/merge.d.ts +1 -1
- package/cjs/object/merge.js +99 -104
- package/cjs/object/merge.test.d.ts +2 -0
- package/cjs/object/only.d.ts +4 -4
- package/cjs/object/only.js +17 -20
- package/cjs/object/only.test.d.ts +2 -0
- package/cjs/object/set.d.ts +5 -5
- package/cjs/object/set.js +28 -30
- package/cjs/object/set.test.d.ts +2 -0
- package/cjs/object/sort.d.ts +4 -4
- package/cjs/object/sort.js +15 -17
- package/cjs/object/unset.d.ts +4 -4
- package/cjs/object/unset.js +23 -26
- package/cjs/object/unset.test.d.ts +2 -0
- package/cjs/string/capitalize.d.ts +6 -6
- package/cjs/string/capitalize.js +15 -18
- package/cjs/string/extension.d.ts +4 -4
- package/cjs/string/extension.js +11 -13
- package/cjs/string/initials.d.ts +4 -4
- package/cjs/string/initials.js +15 -17
- package/cjs/string/initials.test.d.ts +2 -0
- package/cjs/string/ltrim.d.ts +7 -7
- package/cjs/string/ltrim.js +15 -18
- package/cjs/string/readMoreChars.d.ts +5 -5
- package/cjs/string/readMoreChars.js +11 -13
- package/cjs/string/readMoreWords.d.ts +5 -5
- package/cjs/string/readMoreWords.js +14 -16
- package/cjs/string/removeFirst.d.ts +7 -7
- package/cjs/string/removeFirst.js +13 -16
- package/cjs/string/removeLast.d.ts +7 -7
- package/cjs/string/removeLast.js +13 -16
- package/cjs/string/repeatsOf.d.ts +7 -7
- package/cjs/string/repeatsOf.js +17 -19
- package/cjs/string/replaceAll.d.ts +8 -8
- package/cjs/string/replaceAll.js +14 -17
- package/cjs/string/replaceFirst.d.ts +8 -8
- package/cjs/string/replaceFirst.js +14 -17
- package/cjs/string/replaceLast.d.ts +8 -8
- package/cjs/string/replaceLast.js +21 -23
- package/cjs/string/rtrim.d.ts +7 -7
- package/cjs/string/rtrim.js +15 -18
- package/cjs/string/startsWithArabic.d.ts +2 -2
- package/cjs/string/startsWithArabic.js +13 -17
- package/cjs/string/toCamelCase.d.ts +1 -1
- package/cjs/string/toCamelCase.js +11 -14
- package/cjs/string/toCamelCase.test.d.ts +2 -0
- package/cjs/string/toInputName.d.ts +5 -5
- package/cjs/string/toInputName.js +21 -24
- package/cjs/string/toKebabCase.d.ts +4 -4
- package/cjs/string/toKebabCase.js +10 -13
- package/cjs/string/toKebabCase.test.d.ts +2 -0
- package/cjs/string/toSnakeCase.d.ts +7 -7
- package/cjs/string/toSnakeCase.js +20 -22
- package/cjs/string/toSnakeCase.test.d.ts +2 -0
- package/cjs/string/toStudlyCase.d.ts +9 -9
- package/cjs/string/toStudlyCase.js +19 -22
- package/cjs/string/trim.d.ts +7 -7
- package/cjs/string/trim.js +19 -22
- package/cjs/string/ucfirst.d.ts +6 -6
- package/cjs/string/ucfirst.js +11 -13
- package/cjs/types.d.ts +1 -1
- package/cjs/utils/debounce.d.ts +8 -8
- package/cjs/utils/debounce.js +16 -18
- package/cjs/utils/escapeRegex.d.ts +4 -4
- package/cjs/utils/escapeRegex.js +8 -10
- package/cjs/utils/escapeRegex.test.d.ts +2 -0
- package/esm/Random/random.d.ts +35 -35
- package/esm/Random/random.js +64 -65
- package/esm/Random/random.test.d.ts +2 -0
- package/esm/array/average.d.ts +6 -6
- package/esm/array/average.js +11 -13
- package/esm/array/average.test.d.ts +2 -0
- package/esm/array/chunk.d.ts +4 -4
- package/esm/array/chunk.js +12 -13
- package/esm/array/chunk.test.d.ts +2 -0
- package/esm/array/count.d.ts +4 -4
- package/esm/array/count.js +13 -15
- package/esm/array/count.test.d.ts +2 -0
- package/esm/array/countBy.d.ts +6 -6
- package/esm/array/countBy.js +19 -21
- package/esm/array/countBy.test.d.ts +2 -0
- package/esm/array/even.d.ts +6 -6
- package/esm/array/even.js +14 -16
- package/esm/array/even.test.d.ts +2 -0
- package/esm/array/evenIndexes.d.ts +4 -4
- package/esm/array/evenIndexes.js +8 -9
- package/esm/array/evenIndexes.test.d.ts +2 -0
- package/esm/array/groupBy.d.ts +7 -7
- package/esm/array/groupBy.js +44 -46
- package/esm/array/groupBy.test.d.ts +2 -0
- package/esm/array/max.d.ts +6 -6
- package/esm/array/max.js +19 -21
- package/esm/array/max.test.d.ts +2 -0
- package/esm/array/median.d.ts +6 -6
- package/esm/array/median.js +24 -26
- package/esm/array/median.test.d.ts +2 -0
- package/esm/array/min.d.ts +6 -6
- package/esm/array/min.js +19 -21
- package/esm/array/min.test.d.ts +2 -0
- package/esm/array/odd.d.ts +6 -6
- package/esm/array/odd.js +14 -16
- package/esm/array/odd.test.d.ts +2 -0
- package/esm/array/oddIndexes.d.ts +4 -4
- package/esm/array/oddIndexes.js +8 -9
- package/esm/array/oddIndexes.test.d.ts +2 -0
- package/esm/array/pluck.d.ts +8 -8
- package/esm/array/pluck.js +22 -24
- package/esm/array/pluck.test.d.ts +2 -0
- package/esm/array/pushUnique.d.ts +5 -5
- package/esm/array/pushUnique.js +13 -14
- package/esm/array/pushUnique.test.d.ts +2 -0
- package/esm/array/range.d.ts +4 -4
- package/esm/array/range.js +20 -21
- package/esm/array/range.test.d.ts +2 -0
- package/esm/array/sum.d.ts +6 -6
- package/esm/array/sum.js +27 -29
- package/esm/array/sum.test.d.ts +2 -0
- package/esm/array/unique.d.ts +4 -4
- package/esm/array/unique.js +13 -15
- package/esm/array/unique.test.d.ts +2 -0
- package/esm/array/unshiftUnique.d.ts +5 -5
- package/esm/array/unshiftUnique.js +13 -14
- package/esm/array/unshiftUnique.test.d.ts +2 -0
- package/esm/index.d.ts +56 -56
- package/esm/mixed/areEqual/areEqual.d.ts +4 -4
- package/esm/mixed/areEqual/areEqual.js +22 -23
- package/esm/mixed/areEqual/areEqual.test.d.ts +2 -0
- package/esm/mixed/clone/clone.d.ts +4 -4
- package/esm/mixed/clone/clone.js +11 -16
- package/esm/mixed/clone/clone.test.d.ts +2 -0
- package/esm/mixed/shuffle/shuffle.d.ts +4 -4
- package/esm/mixed/shuffle/shuffle.js +13 -14
- package/esm/mixed/shuffle/shuffle.test.d.ts +2 -0
- package/esm/number/round.d.ts +4 -4
- package/esm/number/round.js +8 -9
- package/esm/object/except.d.ts +4 -4
- package/esm/object/except.js +11 -13
- package/esm/object/except.test.d.ts +2 -0
- package/esm/object/flatten.d.ts +4 -4
- package/esm/object/flatten.js +37 -38
- package/esm/object/flatten.test.d.ts +2 -0
- package/esm/object/get.d.ts +4 -4
- package/esm/object/get.js +23 -24
- package/esm/object/get.test.d.ts +2 -0
- package/esm/object/map.d.ts +4 -4
- package/esm/object/map.js +9 -10
- package/esm/object/merge.d.ts +1 -1
- package/esm/object/merge.js +94 -96
- package/esm/object/merge.test.d.ts +2 -0
- package/esm/object/only.d.ts +4 -4
- package/esm/object/only.js +16 -18
- package/esm/object/only.test.d.ts +2 -0
- package/esm/object/set.d.ts +5 -5
- package/esm/object/set.js +27 -28
- package/esm/object/set.test.d.ts +2 -0
- package/esm/object/sort.d.ts +4 -4
- package/esm/object/sort.js +14 -15
- package/esm/object/unset.d.ts +4 -4
- package/esm/object/unset.js +22 -24
- package/esm/object/unset.test.d.ts +2 -0
- package/esm/string/capitalize.d.ts +6 -6
- package/esm/string/capitalize.js +14 -16
- package/esm/string/extension.d.ts +4 -4
- package/esm/string/extension.js +10 -11
- package/esm/string/initials.d.ts +4 -4
- package/esm/string/initials.js +14 -15
- package/esm/string/initials.test.d.ts +2 -0
- package/esm/string/ltrim.d.ts +7 -7
- package/esm/string/ltrim.js +14 -16
- package/esm/string/readMoreChars.d.ts +5 -5
- package/esm/string/readMoreChars.js +10 -11
- package/esm/string/readMoreWords.d.ts +5 -5
- package/esm/string/readMoreWords.js +13 -14
- package/esm/string/removeFirst.d.ts +7 -7
- package/esm/string/removeFirst.js +12 -14
- package/esm/string/removeLast.d.ts +7 -7
- package/esm/string/removeLast.js +12 -14
- package/esm/string/repeatsOf.d.ts +7 -7
- package/esm/string/repeatsOf.js +16 -17
- package/esm/string/replaceAll.d.ts +8 -8
- package/esm/string/replaceAll.js +13 -15
- package/esm/string/replaceFirst.d.ts +8 -8
- package/esm/string/replaceFirst.js +13 -15
- package/esm/string/replaceLast.d.ts +8 -8
- package/esm/string/replaceLast.js +20 -21
- package/esm/string/rtrim.d.ts +7 -7
- package/esm/string/rtrim.js +14 -16
- package/esm/string/startsWithArabic.d.ts +2 -2
- package/esm/string/startsWithArabic.js +10 -12
- package/esm/string/toCamelCase.d.ts +1 -1
- package/esm/string/toCamelCase.js +10 -12
- package/esm/string/toCamelCase.test.d.ts +2 -0
- package/esm/string/toInputName.d.ts +5 -5
- package/esm/string/toInputName.js +20 -22
- package/esm/string/toKebabCase.d.ts +4 -4
- package/esm/string/toKebabCase.js +9 -11
- package/esm/string/toKebabCase.test.d.ts +2 -0
- package/esm/string/toSnakeCase.d.ts +7 -7
- package/esm/string/toSnakeCase.js +19 -20
- package/esm/string/toSnakeCase.test.d.ts +2 -0
- package/esm/string/toStudlyCase.d.ts +9 -9
- package/esm/string/toStudlyCase.js +18 -20
- package/esm/string/trim.d.ts +7 -7
- package/esm/string/trim.js +18 -20
- package/esm/string/ucfirst.d.ts +6 -6
- package/esm/string/ucfirst.js +10 -11
- package/esm/types.d.ts +1 -1
- package/esm/utils/debounce.d.ts +8 -8
- package/esm/utils/debounce.js +15 -16
- package/esm/utils/escapeRegex.d.ts +4 -4
- package/esm/utils/escapeRegex.js +7 -8
- package/esm/utils/escapeRegex.test.d.ts +2 -0
- package/package.json +1 -1
package/esm/array/average.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import sum from "./sum.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { average as default };
|
|
1
|
+
import sum from "./sum.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the average value of the given array or the given array of objects using the given key
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function average(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return 0;
|
|
9
|
+
return sum(array, key) / array.length;
|
|
10
|
+
}
|
|
11
|
+
export { average as default };
|
package/esm/array/chunk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chunk array|string by the given size
|
|
3
|
-
*/
|
|
4
|
-
export default function chunk(array: any[] | string, size: number): any[];
|
|
1
|
+
/**
|
|
2
|
+
* Chunk array|string by the given size
|
|
3
|
+
*/
|
|
4
|
+
export default function chunk(array: any[] | string, size: number): any[];
|
|
5
5
|
//# sourceMappingURL=chunk.d.ts.map
|
package/esm/array/chunk.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chunk array|string by the given size
|
|
3
|
-
*/
|
|
4
|
-
function chunk(array, size) {
|
|
5
|
-
if (!Array.isArray(array) && typeof array !== "string") return [];
|
|
6
|
-
const result = [];
|
|
7
|
-
for (let i = 0; i < array.length; i += size) {
|
|
8
|
-
result.push(array.slice(i, i + size));
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { chunk as default };
|
|
1
|
+
/**
|
|
2
|
+
* Chunk array|string by the given size
|
|
3
|
+
*/
|
|
4
|
+
function chunk(array, size) {
|
|
5
|
+
if (!Array.isArray(array) && typeof array !== "string") return [];
|
|
6
|
+
const result = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
result.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
export { chunk as default };
|
package/esm/array/count.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Count data by the given key or callback
|
|
3
|
-
*/
|
|
4
|
-
export default function count(data: any[], key: string | Parameters<typeof Array.prototype.filter>[0]): number;
|
|
1
|
+
/**
|
|
2
|
+
* Count data by the given key or callback
|
|
3
|
+
*/
|
|
4
|
+
export default function count(data: any[], key: string | Parameters<typeof Array.prototype.filter>[0]): number;
|
|
5
5
|
//# sourceMappingURL=count.d.ts.map
|
package/esm/array/count.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { count as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
const notFound = Symbol("notFound");
|
|
3
|
+
/**
|
|
4
|
+
* Count data by the given key or callback
|
|
5
|
+
*/
|
|
6
|
+
function count(data, key) {
|
|
7
|
+
if (!Array.isArray(data)) return 0;
|
|
8
|
+
if (typeof key === "string") {
|
|
9
|
+
return data.filter(item => get(item, key, notFound) !== notFound).length;
|
|
10
|
+
}
|
|
11
|
+
return data.filter(key).length;
|
|
12
|
+
}
|
|
13
|
+
export { count as default };
|
package/esm/array/countBy.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Count the occurrences of values in an array for the given key
|
|
3
|
-
*/
|
|
4
|
-
export default function countBy(array: any[], key: string): {
|
|
5
|
-
[key: string]: number;
|
|
6
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Count the occurrences of values in an array for the given key
|
|
3
|
+
*/
|
|
4
|
+
export default function countBy(array: any[], key: string): {
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
};
|
|
7
7
|
//# sourceMappingURL=countBy.d.ts.map
|
package/esm/array/countBy.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { countBy as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
/**
|
|
3
|
+
* Count the occurrences of values in an array for the given key
|
|
4
|
+
*/
|
|
5
|
+
function countBy(array, key) {
|
|
6
|
+
if (!Array.isArray(array)) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
return array.reduce((result, item) => {
|
|
10
|
+
const value = get(item, key);
|
|
11
|
+
if (result[value]) {
|
|
12
|
+
result[value]++;
|
|
13
|
+
} else {
|
|
14
|
+
result[value] = 1;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
export { countBy as default };
|
package/esm/array/even.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the even values of the given array or the given array of objects using the given key
|
|
3
|
-
*
|
|
4
|
-
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
-
*/
|
|
6
|
-
export default function even(array: any[], key?: string): any[];
|
|
1
|
+
/**
|
|
2
|
+
* Get the even values of the given array or the given array of objects using the given key
|
|
3
|
+
*
|
|
4
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
+
*/
|
|
6
|
+
export default function even(array: any[], key?: string): any[];
|
|
7
7
|
//# sourceMappingURL=even.d.ts.map
|
package/esm/array/even.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { even as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the even values of the given array or the given array of objects using the given key
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function even(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return [];
|
|
9
|
+
return array.filter(item => {
|
|
10
|
+
const value = key ? get(item, key) : item;
|
|
11
|
+
return typeof value !== "number" ? false : value % 2 === 0;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export { even as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the values of the given array by the even indexes or the given array of objects using the given key
|
|
3
|
-
*/
|
|
4
|
-
export default function evenIndexes(array: any[]): any[];
|
|
1
|
+
/**
|
|
2
|
+
* Get the values of the given array by the even indexes or the given array of objects using the given key
|
|
3
|
+
*/
|
|
4
|
+
export default function evenIndexes(array: any[]): any[];
|
|
5
5
|
//# sourceMappingURL=evenIndexes.d.ts.map
|
package/esm/array/evenIndexes.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the values of the given array by the even indexes or the given array of objects using the given key
|
|
3
|
-
*/
|
|
4
|
-
function evenIndexes(array) {
|
|
5
|
-
if (!Array.isArray(array)) return [];
|
|
6
|
-
return array.filter((_item, index) => index % 2 === 0);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { evenIndexes as default };
|
|
1
|
+
/**
|
|
2
|
+
* Get the values of the given array by the even indexes or the given array of objects using the given key
|
|
3
|
+
*/
|
|
4
|
+
function evenIndexes(array) {
|
|
5
|
+
if (!Array.isArray(array)) return [];
|
|
6
|
+
return array.filter((_item, index) => index % 2 === 0);
|
|
7
|
+
}
|
|
8
|
+
export { evenIndexes as default };
|
package/esm/array/groupBy.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GenericObject } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* Group the given array by the given key(s).
|
|
4
|
-
*
|
|
5
|
-
* The key(s) support dot notation.
|
|
6
|
-
*/
|
|
7
|
-
export default function groupBy(array: GenericObject[], groupByKey: string | string[], listAs?: string): GenericObject[];
|
|
1
|
+
import { GenericObject } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Group the given array by the given key(s).
|
|
4
|
+
*
|
|
5
|
+
* The key(s) support dot notation.
|
|
6
|
+
*/
|
|
7
|
+
export default function groupBy(array: GenericObject[], groupByKey: string | string[], listAs?: string): GenericObject[];
|
|
8
8
|
//# sourceMappingURL=groupBy.d.ts.map
|
package/esm/array/groupBy.js
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
import "../object/merge.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { groupBy as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
import "../object/merge.js";
|
|
3
|
+
/**
|
|
4
|
+
* Group the given array by the given key(s).
|
|
5
|
+
*
|
|
6
|
+
* The key(s) support dot notation.
|
|
7
|
+
*/
|
|
8
|
+
function groupBy(array, groupByKey, listAs = "data") {
|
|
9
|
+
const groupedData = {};
|
|
10
|
+
const groupByKeys =
|
|
11
|
+
typeof groupByKey === "string" ? [groupByKey] : groupByKey;
|
|
12
|
+
for (const item of array) {
|
|
13
|
+
const baseKeys = [];
|
|
14
|
+
for (const groupByKey of groupByKeys) {
|
|
15
|
+
const value = get(item, groupByKey);
|
|
16
|
+
if (!value) break;
|
|
17
|
+
baseKeys.push({
|
|
18
|
+
key: groupByKey,
|
|
19
|
+
value,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const dataKey = JSON.stringify(baseKeys);
|
|
23
|
+
if (!groupedData[dataKey]) {
|
|
24
|
+
const groupedDataList = {
|
|
25
|
+
data: [],
|
|
26
|
+
};
|
|
27
|
+
for (const groupByKeyData of baseKeys) {
|
|
28
|
+
groupedDataList[groupByKeyData.key] = groupByKeyData.value;
|
|
29
|
+
}
|
|
30
|
+
groupedData[dataKey] = groupedDataList;
|
|
31
|
+
}
|
|
32
|
+
groupedData[dataKey]?.data?.push(item);
|
|
33
|
+
}
|
|
34
|
+
const finalData = [];
|
|
35
|
+
for (const groupedKeyWithValue in groupedData) {
|
|
36
|
+
const { data, ...otherGroupedKeys } = groupedData[groupedKeyWithValue];
|
|
37
|
+
finalData.push({
|
|
38
|
+
...otherGroupedKeys,
|
|
39
|
+
[listAs]: data,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return finalData;
|
|
43
|
+
}
|
|
44
|
+
export { groupBy as default };
|
package/esm/array/max.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the max value of the given array or the given array of objects using the given key
|
|
3
|
-
*
|
|
4
|
-
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
-
*/
|
|
6
|
-
export default function max(array: any[], key?: string): number;
|
|
1
|
+
/**
|
|
2
|
+
* Get the max value of the given array or the given array of objects using the given key
|
|
3
|
+
*
|
|
4
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
+
*/
|
|
6
|
+
export default function max(array: any[], key?: string): number;
|
|
7
7
|
//# sourceMappingURL=max.d.ts.map
|
package/esm/array/max.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { max as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the max value of the given array or the given array of objects using the given key
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function max(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return 0;
|
|
9
|
+
let maxValue = 0;
|
|
10
|
+
for (let i = 0; i < array.length; i++) {
|
|
11
|
+
const value = key ? Number(get(array[i], key)) : Number(array[i]);
|
|
12
|
+
if (isNaN(value)) continue;
|
|
13
|
+
if (maxValue === 0 || value > maxValue) {
|
|
14
|
+
maxValue = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return maxValue;
|
|
18
|
+
}
|
|
19
|
+
export { max as default };
|
package/esm/array/median.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get median value of the array
|
|
3
|
-
*
|
|
4
|
-
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
-
*/
|
|
6
|
-
export default function median(array: any[], key?: string): number;
|
|
1
|
+
/**
|
|
2
|
+
* Get median value of the array
|
|
3
|
+
*
|
|
4
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
+
*/
|
|
6
|
+
export default function median(array: any[], key?: string): number;
|
|
7
7
|
//# sourceMappingURL=median.d.ts.map
|
package/esm/array/median.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import pluck from "./pluck.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { median as default };
|
|
1
|
+
import pluck from "./pluck.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get median value of the array
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function median(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return 0;
|
|
9
|
+
if (key) {
|
|
10
|
+
array = pluck(array, key);
|
|
11
|
+
if (!Array.isArray(array)) return 0;
|
|
12
|
+
}
|
|
13
|
+
// if array is not list of numbers then return 0
|
|
14
|
+
if (!array.every(item => typeof item === "number")) return 0;
|
|
15
|
+
const length = array.length;
|
|
16
|
+
if (length === 0) return 0;
|
|
17
|
+
array.sort((a, b) => a - b);
|
|
18
|
+
const middle = Math.floor(length / 2);
|
|
19
|
+
const value =
|
|
20
|
+
length % 2 ? array[middle] : (array[middle - 1] + array[middle]) / 2;
|
|
21
|
+
if (isNaN(value) || typeof value !== "number") return 0;
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export { median as default };
|
package/esm/array/min.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the min value of the given array or the given array of objects using the given key
|
|
3
|
-
*
|
|
4
|
-
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
-
*/
|
|
6
|
-
export default function min(array: any[], key?: string): number;
|
|
1
|
+
/**
|
|
2
|
+
* Get the min value of the given array or the given array of objects using the given key
|
|
3
|
+
*
|
|
4
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
+
*/
|
|
6
|
+
export default function min(array: any[], key?: string): number;
|
|
7
7
|
//# sourceMappingURL=min.d.ts.map
|
package/esm/array/min.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { min as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the min value of the given array or the given array of objects using the given key
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function min(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return 0;
|
|
9
|
+
let minValue = 0;
|
|
10
|
+
for (let i = 0; i < array.length; i++) {
|
|
11
|
+
const value = key ? Number(get(array[i], key)) : Number(array[i]);
|
|
12
|
+
if (isNaN(value)) continue;
|
|
13
|
+
if (minValue === 0 || value < minValue) {
|
|
14
|
+
minValue = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return minValue;
|
|
18
|
+
}
|
|
19
|
+
export { min as default };
|
package/esm/array/odd.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the odd values of the given array or the given array of objects using the given key
|
|
3
|
-
*
|
|
4
|
-
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
-
*/
|
|
6
|
-
export default function odd(array: any[], key?: string): any[];
|
|
1
|
+
/**
|
|
2
|
+
* Get the odd values of the given array or the given array of objects using the given key
|
|
3
|
+
*
|
|
4
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
5
|
+
*/
|
|
6
|
+
export default function odd(array: any[], key?: string): any[];
|
|
7
7
|
//# sourceMappingURL=odd.d.ts.map
|
package/esm/array/odd.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import get from "../object/get.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { odd as default };
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the odd values of the given array or the given array of objects using the given key
|
|
4
|
+
*
|
|
5
|
+
* The key supports dot notation. syntax: "key1.key2.key3"
|
|
6
|
+
*/
|
|
7
|
+
function odd(array, key) {
|
|
8
|
+
if (!Array.isArray(array)) return [];
|
|
9
|
+
return array.filter(item => {
|
|
10
|
+
const value = key ? Number(get(item, key)) : Number(item);
|
|
11
|
+
return isNaN(value) ? false : value % 2 !== 0;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export { odd as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the values of the given array by the odd indexes or the given array of objects using the given key
|
|
3
|
-
*/
|
|
4
|
-
export default function oddIndexes(array: any[]): any[];
|
|
1
|
+
/**
|
|
2
|
+
* Get the values of the given array by the odd indexes or the given array of objects using the given key
|
|
3
|
+
*/
|
|
4
|
+
export default function oddIndexes(array: any[]): any[];
|
|
5
5
|
//# sourceMappingURL=oddIndexes.d.ts.map
|