@mongez/reinforcements 2.2.1 → 2.2.3
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 +917 -121
- package/cjs/array/countBy.d.ts +3 -1
- package/cjs/array/countBy.js +23 -0
- package/cjs/array/pushUnique.d.ts +1 -1
- package/cjs/array/unshiftUnique.d.ts +6 -0
- package/cjs/array/unshiftUnique.js +16 -0
- package/cjs/index.d.ts +3 -1
- package/cjs/index.js +6 -2
- package/cjs/mixed/shuffle/shuffle.d.ts +2 -2
- package/cjs/mixed/shuffle/shuffle.js +8 -6
- package/cjs/string/capitalize.js +1 -0
- package/cjs/string/extension.js +1 -0
- package/cjs/string/ltrim.js +1 -0
- package/cjs/string/readMoreChars.js +1 -0
- package/cjs/string/readMoreWords.js +1 -0
- package/cjs/string/removeFirst.js +1 -0
- package/cjs/string/removeLast.js +1 -0
- package/cjs/string/repeatsOf.js +1 -0
- package/cjs/string/replaceAll.js +1 -0
- package/cjs/string/replaceFirst.js +1 -0
- package/cjs/string/replaceLast.js +1 -0
- package/cjs/string/rtrim.js +1 -0
- package/cjs/string/startsWithArabic.d.ts +1 -1
- package/cjs/string/startsWithArabic.js +4 -3
- package/cjs/string/toCamelCase.js +1 -0
- package/cjs/string/toKebabCase.js +1 -0
- package/cjs/string/toSnakeCase.js +1 -0
- package/cjs/string/toStudlyCase.js +1 -0
- package/cjs/string/trim.js +1 -0
- package/cjs/string/ucfirst.js +1 -0
- package/esm/array/countBy.d.ts +3 -1
- package/esm/array/countBy.js +21 -0
- package/esm/array/pushUnique.d.ts +1 -1
- package/esm/array/unshiftUnique.d.ts +6 -0
- package/esm/array/unshiftUnique.js +14 -0
- package/esm/index.d.ts +3 -1
- package/esm/index.js +3 -1
- package/esm/mixed/shuffle/shuffle.d.ts +2 -2
- package/esm/mixed/shuffle/shuffle.js +8 -6
- package/esm/string/capitalize.js +1 -0
- package/esm/string/extension.js +1 -0
- package/esm/string/ltrim.js +1 -0
- package/esm/string/readMoreChars.js +1 -0
- package/esm/string/readMoreWords.js +1 -0
- package/esm/string/removeFirst.js +1 -0
- package/esm/string/removeLast.js +1 -0
- package/esm/string/repeatsOf.js +1 -0
- package/esm/string/replaceAll.js +1 -0
- package/esm/string/replaceFirst.js +1 -0
- package/esm/string/replaceLast.js +1 -0
- package/esm/string/rtrim.js +1 -0
- package/esm/string/startsWithArabic.d.ts +1 -1
- package/esm/string/startsWithArabic.js +4 -3
- package/esm/string/toCamelCase.js +1 -0
- package/esm/string/toKebabCase.js +1 -0
- package/esm/string/toSnakeCase.js +1 -0
- package/esm/string/toStudlyCase.js +1 -0
- package/esm/string/trim.js +1 -0
- package/esm/string/ucfirst.js +1 -0
- package/package.json +1 -1
- package/cjs/array/prependUnique.d.ts +0 -6
- package/cjs/object/obj.d.ts +0 -27
- package/cjs/object/obj.js +0 -30
- package/docs/VERSION-1.md +0 -1074
- package/esm/array/prependUnique.d.ts +0 -6
- package/esm/object/obj.d.ts +0 -27
- package/esm/object/obj.js +0 -28
package/cjs/array/countBy.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Count the occurrences of values in an array for the given key
|
|
3
3
|
*/
|
|
4
|
-
export default function countBy(array: any[], key: string):
|
|
4
|
+
export default function countBy(array: any[], key: string): {
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
};
|
|
5
7
|
//# sourceMappingURL=countBy.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var get = require("../object/get.js");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Count the occurrences of values in an array for the given key
|
|
7
|
+
*/
|
|
8
|
+
function countBy(array, key) {
|
|
9
|
+
if (!Array.isArray(array)) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
return array.reduce((result, item) => {
|
|
13
|
+
const value = get(item, key);
|
|
14
|
+
if (result[value]) {
|
|
15
|
+
result[value]++;
|
|
16
|
+
} else {
|
|
17
|
+
result[value] = 1;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = countBy;
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Push once one or more values to the array if and
|
|
3
3
|
* only if the value doesn't exists in the array
|
|
4
4
|
*/
|
|
5
|
-
export default function pushUnique<T>(array: T[], ...items: T[]): T[];
|
|
5
|
+
export default function pushUnique<T = any>(array: T[], ...items: T[]): T[];
|
|
6
6
|
//# sourceMappingURL=pushUnique.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prepend once one or more values to the array if and
|
|
5
|
+
* only if the value doesn't exists in the array
|
|
6
|
+
*/
|
|
7
|
+
function unshiftUnique(array, ...items) {
|
|
8
|
+
items.forEach(item => {
|
|
9
|
+
if (!array.includes(item)) {
|
|
10
|
+
array.unshift(item);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return array;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = unshiftUnique;
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as average, default as avg } from "./array/average";
|
|
2
2
|
export { default as chunk } from "./array/chunk";
|
|
3
3
|
export { default as count } from "./array/count";
|
|
4
|
+
export { default as countBy } from "./array/countBy";
|
|
4
5
|
export { default as even } from "./array/even";
|
|
5
6
|
export { default as evenIndexes } from "./array/evenIndexes";
|
|
6
7
|
export { default as groupBy } from "./array/groupBy";
|
|
@@ -13,6 +14,7 @@ export { default as pluck } from "./array/pluck";
|
|
|
13
14
|
export { default as pushUnique } from "./array/pushUnique";
|
|
14
15
|
export { default as sum } from "./array/sum";
|
|
15
16
|
export { default as unique } from "./array/unique";
|
|
17
|
+
export { default as unshiftUnique } from "./array/unshiftUnique";
|
|
16
18
|
export { default as areEqual } from "./mixed/areEqual/areEqual";
|
|
17
19
|
export { default as clone } from "./mixed/clone/clone";
|
|
18
20
|
export { default as shuffle } from "./mixed/shuffle/shuffle";
|
|
@@ -22,10 +24,10 @@ export { default as flatten } from "./object/flatten";
|
|
|
22
24
|
export { default as get } from "./object/get";
|
|
23
25
|
export { default as map } from "./object/map";
|
|
24
26
|
export { default as merge } from "./object/merge";
|
|
25
|
-
export { default as Obj } from "./object/obj";
|
|
26
27
|
export { default as only } from "./object/only";
|
|
27
28
|
export { default as set } from "./object/set";
|
|
28
29
|
export { default as sort } from "./object/sort";
|
|
30
|
+
export { default as unset } from "./object/unset";
|
|
29
31
|
export { default as Random } from "./Random/random";
|
|
30
32
|
export { default as capitalize } from "./string/capitalize";
|
|
31
33
|
export { default as extension } from "./string/extension";
|
package/cjs/index.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
var average = require("./array/average.js");
|
|
6
6
|
var chunk = require("./array/chunk.js");
|
|
7
7
|
var count = require("./array/count.js");
|
|
8
|
+
var countBy = require("./array/countBy.js");
|
|
8
9
|
var even = require("./array/even.js");
|
|
9
10
|
var evenIndexes = require("./array/evenIndexes.js");
|
|
10
11
|
var groupBy = require("./array/groupBy.js");
|
|
@@ -17,6 +18,7 @@ var pluck = require("./array/pluck.js");
|
|
|
17
18
|
var pushUnique = require("./array/pushUnique.js");
|
|
18
19
|
var sum = require("./array/sum.js");
|
|
19
20
|
var unique = require("./array/unique.js");
|
|
21
|
+
var unshiftUnique = require("./array/unshiftUnique.js");
|
|
20
22
|
var areEqual = require("./mixed/areEqual/areEqual.js");
|
|
21
23
|
var clone = require("./mixed/clone/clone.js");
|
|
22
24
|
var shuffle = require("./mixed/shuffle/shuffle.js");
|
|
@@ -26,10 +28,10 @@ var flatten = require("./object/flatten.js");
|
|
|
26
28
|
var get = require("./object/get.js");
|
|
27
29
|
var map = require("./object/map.js");
|
|
28
30
|
var merge = require("./object/merge.js");
|
|
29
|
-
var obj = require("./object/obj.js");
|
|
30
31
|
var only = require("./object/only.js");
|
|
31
32
|
var set = require("./object/set.js");
|
|
32
33
|
var sort = require("./object/sort.js");
|
|
34
|
+
var unset = require("./object/unset.js");
|
|
33
35
|
var random = require("./Random/random.js");
|
|
34
36
|
var capitalize = require("./string/capitalize.js");
|
|
35
37
|
var extension = require("./string/extension.js");
|
|
@@ -58,6 +60,7 @@ exports.average = average;
|
|
|
58
60
|
exports.avg = average;
|
|
59
61
|
exports.chunk = chunk;
|
|
60
62
|
exports.count = count;
|
|
63
|
+
exports.countBy = countBy;
|
|
61
64
|
exports.even = even;
|
|
62
65
|
exports.evenIndexes = evenIndexes;
|
|
63
66
|
exports.groupBy = groupBy;
|
|
@@ -70,6 +73,7 @@ exports.pluck = pluck;
|
|
|
70
73
|
exports.pushUnique = pushUnique;
|
|
71
74
|
exports.sum = sum;
|
|
72
75
|
exports.unique = unique;
|
|
76
|
+
exports.unshiftUnique = unshiftUnique;
|
|
73
77
|
exports.areEqual = areEqual;
|
|
74
78
|
exports.clone = clone;
|
|
75
79
|
exports.shuffle = shuffle;
|
|
@@ -79,10 +83,10 @@ exports.flatten = flatten;
|
|
|
79
83
|
exports.get = get;
|
|
80
84
|
exports.map = map;
|
|
81
85
|
exports.merge = merge;
|
|
82
|
-
exports.Obj = obj;
|
|
83
86
|
exports.only = only;
|
|
84
87
|
exports.set = set;
|
|
85
88
|
exports.sort = sort;
|
|
89
|
+
exports.unset = unset;
|
|
86
90
|
exports.Random = random;
|
|
87
91
|
exports.capitalize = capitalize;
|
|
88
92
|
exports.extension = extension;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shuffle array
|
|
2
|
+
* Shuffle value either it is a string or an array
|
|
3
3
|
*/
|
|
4
|
-
export default function shuffle(
|
|
4
|
+
export default function shuffle(value: any[] | string): any[] | string;
|
|
5
5
|
//# sourceMappingURL=shuffle.d.ts.map
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Shuffle array
|
|
4
|
+
* Shuffle value either it is a string or an array
|
|
5
5
|
*/
|
|
6
|
-
function shuffle(
|
|
7
|
-
if (typeof
|
|
8
|
-
return
|
|
6
|
+
function shuffle(value) {
|
|
7
|
+
if (!value || (!Array.isArray(value) && typeof value !== "string"))
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
return shuffle(value.split("")).join("");
|
|
9
11
|
}
|
|
10
|
-
if (!Array.isArray(
|
|
11
|
-
return
|
|
12
|
+
if (!Array.isArray(value)) return value;
|
|
13
|
+
return value.sort(() => Math.random() - 0.5);
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
module.exports = shuffle;
|
package/cjs/string/capitalize.js
CHANGED
package/cjs/string/extension.js
CHANGED
package/cjs/string/ltrim.js
CHANGED
|
@@ -9,6 +9,7 @@ var escapeRegex = require("../utils/escapeRegex.js");
|
|
|
9
9
|
* @return string
|
|
10
10
|
*/
|
|
11
11
|
function ltrim(string, needle = " ") {
|
|
12
|
+
if (!string) return "";
|
|
12
13
|
const pattern = "^" + escapeRegex(needle) + "+",
|
|
13
14
|
regex = new RegExp(pattern, "g");
|
|
14
15
|
return string.replace(regex, "");
|
package/cjs/string/removeLast.js
CHANGED
package/cjs/string/repeatsOf.js
CHANGED
package/cjs/string/replaceAll.js
CHANGED
package/cjs/string/rtrim.js
CHANGED
|
@@ -9,6 +9,7 @@ var escapeRegex = require("../utils/escapeRegex.js");
|
|
|
9
9
|
* @return string
|
|
10
10
|
*/
|
|
11
11
|
function rtrim(string, needle = " ") {
|
|
12
|
+
if (!string) return "";
|
|
12
13
|
const pattern = escapeRegex(needle) + "+$",
|
|
13
14
|
regex = new RegExp(pattern, "g");
|
|
14
15
|
return string.replace(regex, "");
|
|
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
var trim = require("./trim.js");
|
|
6
6
|
|
|
7
7
|
const ARABIC_PATTERN = /[\u0600-\u06FF]/;
|
|
8
|
-
function startsWithArabic(
|
|
8
|
+
function startsWithArabic(string, trimmed = true) {
|
|
9
|
+
if (!string) return false;
|
|
9
10
|
if (trimmed === true) {
|
|
10
|
-
|
|
11
|
+
string = trim(String(string));
|
|
11
12
|
}
|
|
12
|
-
return
|
|
13
|
+
return string.charAt(0).match(ARABIC_PATTERN) !== null;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
exports.ARABIC_PATTERN = ARABIC_PATTERN;
|
package/cjs/string/trim.js
CHANGED
package/cjs/string/ucfirst.js
CHANGED
package/esm/array/countBy.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Count the occurrences of values in an array for the given key
|
|
3
3
|
*/
|
|
4
|
-
export default function countBy(array: any[], key: string):
|
|
4
|
+
export default function countBy(array: any[], key: string): {
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
};
|
|
5
7
|
//# sourceMappingURL=countBy.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import get from "../object/get.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Count the occurrences of values in an array for the given key
|
|
5
|
+
*/
|
|
6
|
+
function countBy(array, key) {
|
|
7
|
+
if (!Array.isArray(array)) {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
return array.reduce((result, item) => {
|
|
11
|
+
const value = get(item, key);
|
|
12
|
+
if (result[value]) {
|
|
13
|
+
result[value]++;
|
|
14
|
+
} else {
|
|
15
|
+
result[value] = 1;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { countBy as default };
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Push once one or more values to the array if and
|
|
3
3
|
* only if the value doesn't exists in the array
|
|
4
4
|
*/
|
|
5
|
-
export default function pushUnique<T>(array: T[], ...items: T[]): T[];
|
|
5
|
+
export default function pushUnique<T = any>(array: T[], ...items: T[]): T[];
|
|
6
6
|
//# sourceMappingURL=pushUnique.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepend once one or more values to the array if and
|
|
3
|
+
* only if the value doesn't exists in the array
|
|
4
|
+
*/
|
|
5
|
+
function unshiftUnique(array, ...items) {
|
|
6
|
+
items.forEach(item => {
|
|
7
|
+
if (!array.includes(item)) {
|
|
8
|
+
array.unshift(item);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return array;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { unshiftUnique as default };
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as average, default as avg } from "./array/average";
|
|
2
2
|
export { default as chunk } from "./array/chunk";
|
|
3
3
|
export { default as count } from "./array/count";
|
|
4
|
+
export { default as countBy } from "./array/countBy";
|
|
4
5
|
export { default as even } from "./array/even";
|
|
5
6
|
export { default as evenIndexes } from "./array/evenIndexes";
|
|
6
7
|
export { default as groupBy } from "./array/groupBy";
|
|
@@ -13,6 +14,7 @@ export { default as pluck } from "./array/pluck";
|
|
|
13
14
|
export { default as pushUnique } from "./array/pushUnique";
|
|
14
15
|
export { default as sum } from "./array/sum";
|
|
15
16
|
export { default as unique } from "./array/unique";
|
|
17
|
+
export { default as unshiftUnique } from "./array/unshiftUnique";
|
|
16
18
|
export { default as areEqual } from "./mixed/areEqual/areEqual";
|
|
17
19
|
export { default as clone } from "./mixed/clone/clone";
|
|
18
20
|
export { default as shuffle } from "./mixed/shuffle/shuffle";
|
|
@@ -22,10 +24,10 @@ export { default as flatten } from "./object/flatten";
|
|
|
22
24
|
export { default as get } from "./object/get";
|
|
23
25
|
export { default as map } from "./object/map";
|
|
24
26
|
export { default as merge } from "./object/merge";
|
|
25
|
-
export { default as Obj } from "./object/obj";
|
|
26
27
|
export { default as only } from "./object/only";
|
|
27
28
|
export { default as set } from "./object/set";
|
|
28
29
|
export { default as sort } from "./object/sort";
|
|
30
|
+
export { default as unset } from "./object/unset";
|
|
29
31
|
export { default as Random } from "./Random/random";
|
|
30
32
|
export { default as capitalize } from "./string/capitalize";
|
|
31
33
|
export { default as extension } from "./string/extension";
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as average, default as avg } from "./array/average.js";
|
|
2
2
|
export { default as chunk } from "./array/chunk.js";
|
|
3
3
|
export { default as count } from "./array/count.js";
|
|
4
|
+
export { default as countBy } from "./array/countBy.js";
|
|
4
5
|
export { default as even } from "./array/even.js";
|
|
5
6
|
export { default as evenIndexes } from "./array/evenIndexes.js";
|
|
6
7
|
export { default as groupBy } from "./array/groupBy.js";
|
|
@@ -13,6 +14,7 @@ export { default as pluck } from "./array/pluck.js";
|
|
|
13
14
|
export { default as pushUnique } from "./array/pushUnique.js";
|
|
14
15
|
export { default as sum } from "./array/sum.js";
|
|
15
16
|
export { default as unique } from "./array/unique.js";
|
|
17
|
+
export { default as unshiftUnique } from "./array/unshiftUnique.js";
|
|
16
18
|
export { default as areEqual } from "./mixed/areEqual/areEqual.js";
|
|
17
19
|
export { default as clone } from "./mixed/clone/clone.js";
|
|
18
20
|
export { default as shuffle } from "./mixed/shuffle/shuffle.js";
|
|
@@ -22,10 +24,10 @@ export { default as flatten } from "./object/flatten.js";
|
|
|
22
24
|
export { default as get } from "./object/get.js";
|
|
23
25
|
export { default as map } from "./object/map.js";
|
|
24
26
|
export { default as merge } from "./object/merge.js";
|
|
25
|
-
export { default as Obj } from "./object/obj.js";
|
|
26
27
|
export { default as only } from "./object/only.js";
|
|
27
28
|
export { default as set } from "./object/set.js";
|
|
28
29
|
export { default as sort } from "./object/sort.js";
|
|
30
|
+
export { default as unset } from "./object/unset.js";
|
|
29
31
|
export { default as Random } from "./Random/random.js";
|
|
30
32
|
export { default as capitalize } from "./string/capitalize.js";
|
|
31
33
|
export { default as extension } from "./string/extension.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shuffle array
|
|
2
|
+
* Shuffle value either it is a string or an array
|
|
3
3
|
*/
|
|
4
|
-
export default function shuffle(
|
|
4
|
+
export default function shuffle(value: any[] | string): any[] | string;
|
|
5
5
|
//# sourceMappingURL=shuffle.d.ts.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shuffle array
|
|
2
|
+
* Shuffle value either it is a string or an array
|
|
3
3
|
*/
|
|
4
|
-
function shuffle(
|
|
5
|
-
if (typeof
|
|
6
|
-
return
|
|
4
|
+
function shuffle(value) {
|
|
5
|
+
if (!value || (!Array.isArray(value) && typeof value !== "string"))
|
|
6
|
+
return value;
|
|
7
|
+
if (typeof value === "string") {
|
|
8
|
+
return shuffle(value.split("")).join("");
|
|
7
9
|
}
|
|
8
|
-
if (!Array.isArray(
|
|
9
|
-
return
|
|
10
|
+
if (!Array.isArray(value)) return value;
|
|
11
|
+
return value.sort(() => Math.random() - 0.5);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export { shuffle as default };
|
package/esm/string/capitalize.js
CHANGED
package/esm/string/extension.js
CHANGED
package/esm/string/ltrim.js
CHANGED
|
@@ -7,6 +7,7 @@ import escapeRegex from "../utils/escapeRegex.js";
|
|
|
7
7
|
* @return string
|
|
8
8
|
*/
|
|
9
9
|
function ltrim(string, needle = " ") {
|
|
10
|
+
if (!string) return "";
|
|
10
11
|
const pattern = "^" + escapeRegex(needle) + "+",
|
|
11
12
|
regex = new RegExp(pattern, "g");
|
|
12
13
|
return string.replace(regex, "");
|
package/esm/string/removeLast.js
CHANGED
package/esm/string/repeatsOf.js
CHANGED
package/esm/string/replaceAll.js
CHANGED
package/esm/string/rtrim.js
CHANGED