@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.
Files changed (67) hide show
  1. package/README.md +917 -121
  2. package/cjs/array/countBy.d.ts +3 -1
  3. package/cjs/array/countBy.js +23 -0
  4. package/cjs/array/pushUnique.d.ts +1 -1
  5. package/cjs/array/unshiftUnique.d.ts +6 -0
  6. package/cjs/array/unshiftUnique.js +16 -0
  7. package/cjs/index.d.ts +3 -1
  8. package/cjs/index.js +6 -2
  9. package/cjs/mixed/shuffle/shuffle.d.ts +2 -2
  10. package/cjs/mixed/shuffle/shuffle.js +8 -6
  11. package/cjs/string/capitalize.js +1 -0
  12. package/cjs/string/extension.js +1 -0
  13. package/cjs/string/ltrim.js +1 -0
  14. package/cjs/string/readMoreChars.js +1 -0
  15. package/cjs/string/readMoreWords.js +1 -0
  16. package/cjs/string/removeFirst.js +1 -0
  17. package/cjs/string/removeLast.js +1 -0
  18. package/cjs/string/repeatsOf.js +1 -0
  19. package/cjs/string/replaceAll.js +1 -0
  20. package/cjs/string/replaceFirst.js +1 -0
  21. package/cjs/string/replaceLast.js +1 -0
  22. package/cjs/string/rtrim.js +1 -0
  23. package/cjs/string/startsWithArabic.d.ts +1 -1
  24. package/cjs/string/startsWithArabic.js +4 -3
  25. package/cjs/string/toCamelCase.js +1 -0
  26. package/cjs/string/toKebabCase.js +1 -0
  27. package/cjs/string/toSnakeCase.js +1 -0
  28. package/cjs/string/toStudlyCase.js +1 -0
  29. package/cjs/string/trim.js +1 -0
  30. package/cjs/string/ucfirst.js +1 -0
  31. package/esm/array/countBy.d.ts +3 -1
  32. package/esm/array/countBy.js +21 -0
  33. package/esm/array/pushUnique.d.ts +1 -1
  34. package/esm/array/unshiftUnique.d.ts +6 -0
  35. package/esm/array/unshiftUnique.js +14 -0
  36. package/esm/index.d.ts +3 -1
  37. package/esm/index.js +3 -1
  38. package/esm/mixed/shuffle/shuffle.d.ts +2 -2
  39. package/esm/mixed/shuffle/shuffle.js +8 -6
  40. package/esm/string/capitalize.js +1 -0
  41. package/esm/string/extension.js +1 -0
  42. package/esm/string/ltrim.js +1 -0
  43. package/esm/string/readMoreChars.js +1 -0
  44. package/esm/string/readMoreWords.js +1 -0
  45. package/esm/string/removeFirst.js +1 -0
  46. package/esm/string/removeLast.js +1 -0
  47. package/esm/string/repeatsOf.js +1 -0
  48. package/esm/string/replaceAll.js +1 -0
  49. package/esm/string/replaceFirst.js +1 -0
  50. package/esm/string/replaceLast.js +1 -0
  51. package/esm/string/rtrim.js +1 -0
  52. package/esm/string/startsWithArabic.d.ts +1 -1
  53. package/esm/string/startsWithArabic.js +4 -3
  54. package/esm/string/toCamelCase.js +1 -0
  55. package/esm/string/toKebabCase.js +1 -0
  56. package/esm/string/toSnakeCase.js +1 -0
  57. package/esm/string/toStudlyCase.js +1 -0
  58. package/esm/string/trim.js +1 -0
  59. package/esm/string/ucfirst.js +1 -0
  60. package/package.json +1 -1
  61. package/cjs/array/prependUnique.d.ts +0 -6
  62. package/cjs/object/obj.d.ts +0 -27
  63. package/cjs/object/obj.js +0 -30
  64. package/docs/VERSION-1.md +0 -1074
  65. package/esm/array/prependUnique.d.ts +0 -6
  66. package/esm/object/obj.d.ts +0 -27
  67. package/esm/object/obj.js +0 -28
@@ -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): any;
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,6 @@
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
+ export default function unshiftUnique<T = any>(array: T[], ...items: T[]): T[];
6
+ //# sourceMappingURL=unshiftUnique.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 items
2
+ * Shuffle value either it is a string or an array
3
3
  */
4
- export default function shuffle(array: any[] | string): any[] | string;
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 items
4
+ * Shuffle value either it is a string or an array
5
5
  */
6
- function shuffle(array) {
7
- if (typeof array === "string") {
8
- return shuffle(array.split("")).join("");
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(array)) return array;
11
- return array.sort(() => Math.random() - 0.5);
12
+ if (!Array.isArray(value)) return value;
13
+ return value.sort(() => Math.random() - 0.5);
12
14
  }
13
15
 
14
16
  module.exports = shuffle;
@@ -8,6 +8,7 @@ var ucfirst = require("./ucfirst.js");
8
8
  * @return string
9
9
  */
10
10
  function capitalize(string) {
11
+ if (!string) return "";
11
12
  return string
12
13
  .split(" ")
13
14
  .map(word => ucfirst(word))
@@ -4,6 +4,7 @@
4
4
  * Get the extension of the file name
5
5
  */
6
6
  function extension(string) {
7
+ if (!string) return "";
7
8
  const regex = /(?:\.([^.]+))?$/,
8
9
  extension = regex.exec(string);
9
10
  return extension ? extension[1] : "";
@@ -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, "");
@@ -5,6 +5,7 @@
5
5
  *
6
6
  */
7
7
  function readMoreChars(string, length, readMoreDots = "...") {
8
+ if (!string) return "";
8
9
  if (string.length <= length) return string;
9
10
  return string.substring(0, length) + readMoreDots;
10
11
  }
@@ -5,6 +5,7 @@
5
5
  *
6
6
  */
7
7
  function readMoreWords(string, length, readMoreDots = "...") {
8
+ if (!string) return "";
8
9
  const wordsList = string.split(" ");
9
10
  const words = wordsList.slice(0, length);
10
11
  return (
@@ -9,6 +9,7 @@ var replaceFirst = require("./replaceFirst.js");
9
9
  * @return string
10
10
  */
11
11
  function removeFirst(string, needle) {
12
+ if (!string) return "";
12
13
  return replaceFirst(string, needle, "");
13
14
  }
14
15
 
@@ -9,6 +9,7 @@ var replaceLast = require("./replaceLast.js");
9
9
  * @return string
10
10
  */
11
11
  function removeLast(string, needle) {
12
+ if (!string) return "";
12
13
  return replaceLast(string, needle, "");
13
14
  }
14
15
 
@@ -7,6 +7,7 @@
7
7
  * @return int
8
8
  */
9
9
  function repeatsOf(string, needle, caseSensitive = true) {
10
+ if (!string) return 0;
10
11
  let flags = "g";
11
12
  if (caseSensitive === false) {
12
13
  flags += "i";
@@ -10,6 +10,7 @@ var escapeRegex = require("../utils/escapeRegex.js");
10
10
  * @returns string
11
11
  */
12
12
  function replaceAll(string, searchText, replacement) {
13
+ if (!string) return "";
13
14
  return string.replace(new RegExp(escapeRegex(searchText), "g"), replacement);
14
15
  }
15
16
 
@@ -10,6 +10,7 @@ var escapeRegex = require("../utils/escapeRegex.js");
10
10
  * @return string
11
11
  */
12
12
  function replaceFirst(string, needle, replacement) {
13
+ if (!string) return "";
13
14
  return string.replace(escapeRegex(needle), replacement);
14
15
  }
15
16
 
@@ -8,6 +8,7 @@
8
8
  * @return string
9
9
  */
10
10
  function replaceLast(string, needle, replacement) {
11
+ if (!string) return "";
11
12
  const lastIndex = string.lastIndexOf(needle);
12
13
  if (lastIndex < 0) {
13
14
  return string;
@@ -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, "");
@@ -1,3 +1,3 @@
1
1
  export declare const ARABIC_PATTERN: RegExp;
2
- export default function startsWithArabic(text: string, trimmed?: boolean): boolean;
2
+ export default function startsWithArabic(string: string, trimmed?: boolean): boolean;
3
3
  //# sourceMappingURL=startsWithArabic.d.ts.map
@@ -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(text, trimmed = true) {
8
+ function startsWithArabic(string, trimmed = true) {
9
+ if (!string) return false;
9
10
  if (trimmed === true) {
10
- text = trim(String(text));
11
+ string = trim(String(string));
11
12
  }
12
- return text.charAt(0).match(ARABIC_PATTERN) !== null;
13
+ return string.charAt(0).match(ARABIC_PATTERN) !== null;
13
14
  }
14
15
 
15
16
  exports.ARABIC_PATTERN = ARABIC_PATTERN;
@@ -3,6 +3,7 @@
3
3
  var capitalize = require("./capitalize.js");
4
4
 
5
5
  function toCamelCase(string, separator = "\\s+|-|/|_|\\.") {
6
+ if (!string) return "";
6
7
  const regex = new RegExp(separator + "|(?=[A-Z])", "g");
7
8
  return string
8
9
  .split(regex)
@@ -6,6 +6,7 @@ var toSnakeCase = require("./toSnakeCase.js");
6
6
  * Convert current string to kebab case
7
7
  */
8
8
  function toKebabCase(string, lowerAll = true) {
9
+ if (!string) return "";
9
10
  return toSnakeCase(string, "-", lowerAll);
10
11
  }
11
12
 
@@ -7,6 +7,7 @@
7
7
  * @return string
8
8
  */
9
9
  function toSnakeCase(string, separator = "_", lowerAll = true) {
10
+ if (!string) return "";
10
11
  return string
11
12
  .replace(/(-|\/|\s|([A-Z]))+/g, function (_match, _v2, matchedUpperLetter) {
12
13
  if (!matchedUpperLetter) return separator;
@@ -11,6 +11,7 @@ var capitalize = require("./capitalize.js");
11
11
  * @see String.capitalize
12
12
  */
13
13
  function toStudlyCase(string, separator = "-|\\.|_|/|\\s") {
14
+ if (!string) return "";
14
15
  const regex = new RegExp(separator, "g");
15
16
  return string
16
17
  .split(regex)
@@ -9,6 +9,7 @@ var escapeRegex = require("../utils/escapeRegex.js");
9
9
  * @return string
10
10
  */
11
11
  function trim(string, needle = " ") {
12
+ if (!string) return "";
12
13
  if (needle === " ") {
13
14
  return string.replace(/^\s+|\s+$/g, "");
14
15
  }
@@ -6,6 +6,7 @@
6
6
  * @return string
7
7
  */
8
8
  function ucfirst(string) {
9
+ if (!string) return "";
9
10
  return string.charAt(0).toUpperCase() + string.slice(1);
10
11
  }
11
12
 
@@ -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): any;
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,6 @@
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
+ export default function unshiftUnique<T = any>(array: T[], ...items: T[]): T[];
6
+ //# sourceMappingURL=unshiftUnique.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 items
2
+ * Shuffle value either it is a string or an array
3
3
  */
4
- export default function shuffle(array: any[] | string): any[] | string;
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 items
2
+ * Shuffle value either it is a string or an array
3
3
  */
4
- function shuffle(array) {
5
- if (typeof array === "string") {
6
- return shuffle(array.split("")).join("");
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(array)) return array;
9
- return array.sort(() => Math.random() - 0.5);
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 };
@@ -6,6 +6,7 @@ import ucfirst from "./ucfirst.js";
6
6
  * @return string
7
7
  */
8
8
  function capitalize(string) {
9
+ if (!string) return "";
9
10
  return string
10
11
  .split(" ")
11
12
  .map(word => ucfirst(word))
@@ -2,6 +2,7 @@
2
2
  * Get the extension of the file name
3
3
  */
4
4
  function extension(string) {
5
+ if (!string) return "";
5
6
  const regex = /(?:\.([^.]+))?$/,
6
7
  extension = regex.exec(string);
7
8
  return extension ? extension[1] : "";
@@ -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, "");
@@ -3,6 +3,7 @@
3
3
  *
4
4
  */
5
5
  function readMoreChars(string, length, readMoreDots = "...") {
6
+ if (!string) return "";
6
7
  if (string.length <= length) return string;
7
8
  return string.substring(0, length) + readMoreDots;
8
9
  }
@@ -3,6 +3,7 @@
3
3
  *
4
4
  */
5
5
  function readMoreWords(string, length, readMoreDots = "...") {
6
+ if (!string) return "";
6
7
  const wordsList = string.split(" ");
7
8
  const words = wordsList.slice(0, length);
8
9
  return (
@@ -7,6 +7,7 @@ import replaceFirst from "./replaceFirst.js";
7
7
  * @return string
8
8
  */
9
9
  function removeFirst(string, needle) {
10
+ if (!string) return "";
10
11
  return replaceFirst(string, needle, "");
11
12
  }
12
13
 
@@ -7,6 +7,7 @@ import replaceLast from "./replaceLast.js";
7
7
  * @return string
8
8
  */
9
9
  function removeLast(string, needle) {
10
+ if (!string) return "";
10
11
  return replaceLast(string, needle, "");
11
12
  }
12
13
 
@@ -5,6 +5,7 @@
5
5
  * @return int
6
6
  */
7
7
  function repeatsOf(string, needle, caseSensitive = true) {
8
+ if (!string) return 0;
8
9
  let flags = "g";
9
10
  if (caseSensitive === false) {
10
11
  flags += "i";
@@ -8,6 +8,7 @@ import escapeRegex from "../utils/escapeRegex.js";
8
8
  * @returns string
9
9
  */
10
10
  function replaceAll(string, searchText, replacement) {
11
+ if (!string) return "";
11
12
  return string.replace(new RegExp(escapeRegex(searchText), "g"), replacement);
12
13
  }
13
14
 
@@ -8,6 +8,7 @@ import escapeRegex from "../utils/escapeRegex.js";
8
8
  * @return string
9
9
  */
10
10
  function replaceFirst(string, needle, replacement) {
11
+ if (!string) return "";
11
12
  return string.replace(escapeRegex(needle), replacement);
12
13
  }
13
14
 
@@ -6,6 +6,7 @@
6
6
  * @return string
7
7
  */
8
8
  function replaceLast(string, needle, replacement) {
9
+ if (!string) return "";
9
10
  const lastIndex = string.lastIndexOf(needle);
10
11
  if (lastIndex < 0) {
11
12
  return string;
@@ -7,6 +7,7 @@ import escapeRegex from "../utils/escapeRegex.js";
7
7
  * @return string
8
8
  */
9
9
  function rtrim(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, "");
@@ -1,3 +1,3 @@
1
1
  export declare const ARABIC_PATTERN: RegExp;
2
- export default function startsWithArabic(text: string, trimmed?: boolean): boolean;
2
+ export default function startsWithArabic(string: string, trimmed?: boolean): boolean;
3
3
  //# sourceMappingURL=startsWithArabic.d.ts.map