@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,11 +1,12 @@
1
1
  import trim from "./trim.js";
2
2
 
3
3
  const ARABIC_PATTERN = /[\u0600-\u06FF]/;
4
- function startsWithArabic(text, trimmed = true) {
4
+ function startsWithArabic(string, trimmed = true) {
5
+ if (!string) return false;
5
6
  if (trimmed === true) {
6
- text = trim(String(text));
7
+ string = trim(String(string));
7
8
  }
8
- return text.charAt(0).match(ARABIC_PATTERN) !== null;
9
+ return string.charAt(0).match(ARABIC_PATTERN) !== null;
9
10
  }
10
11
 
11
12
  export { ARABIC_PATTERN, startsWithArabic as default };
@@ -1,6 +1,7 @@
1
1
  import capitalize from "./capitalize.js";
2
2
 
3
3
  function toCamelCase(string, separator = "\\s+|-|/|_|\\.") {
4
+ if (!string) return "";
4
5
  const regex = new RegExp(separator + "|(?=[A-Z])", "g");
5
6
  return string
6
7
  .split(regex)
@@ -4,6 +4,7 @@ import toSnakeCase from "./toSnakeCase.js";
4
4
  * Convert current string to kebab case
5
5
  */
6
6
  function toKebabCase(string, lowerAll = true) {
7
+ if (!string) return "";
7
8
  return toSnakeCase(string, "-", lowerAll);
8
9
  }
9
10
 
@@ -5,6 +5,7 @@
5
5
  * @return string
6
6
  */
7
7
  function toSnakeCase(string, separator = "_", lowerAll = true) {
8
+ if (!string) return "";
8
9
  return string
9
10
  .replace(/(-|\/|\s|([A-Z]))+/g, function (_match, _v2, matchedUpperLetter) {
10
11
  if (!matchedUpperLetter) return separator;
@@ -9,6 +9,7 @@ import capitalize from "./capitalize.js";
9
9
  * @see String.capitalize
10
10
  */
11
11
  function toStudlyCase(string, separator = "-|\\.|_|/|\\s") {
12
+ if (!string) return "";
12
13
  const regex = new RegExp(separator, "g");
13
14
  return string
14
15
  .split(regex)
@@ -7,6 +7,7 @@ import escapeRegex from "../utils/escapeRegex.js";
7
7
  * @return string
8
8
  */
9
9
  function trim(string, needle = " ") {
10
+ if (!string) return "";
10
11
  if (needle === " ") {
11
12
  return string.replace(/^\s+|\s+$/g, "");
12
13
  }
@@ -4,6 +4,7 @@
4
4
  * @return string
5
5
  */
6
6
  function ucfirst(string) {
7
+ if (!string) return "";
7
8
  return string.charAt(0).toUpperCase() + string.slice(1);
8
9
  }
9
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongez/reinforcements",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "A lightweight package to give a massive reinforcements to variant types of data in Nodejs/Javascript",
5
5
  "main": "./cjs/index.js",
6
6
  "dependencies": {
@@ -1,6 +0,0 @@
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 prependUnique<T>(array: T[], ...items: T[]): T[];
6
- //# sourceMappingURL=prependUnique.d.ts.map
@@ -1,27 +0,0 @@
1
- import areEqual from "src/mixed/areEqual/areEqual";
2
- import clone from "../mixed/clone/clone";
3
- import except from "./except";
4
- import flatten from "./flatten";
5
- import get from "./get";
6
- import map from "./map";
7
- import merge from "./merge";
8
- import only from "./only";
9
- import set from "./set";
10
- import sort from "./sort";
11
- /**
12
- * Object methods
13
- */
14
- declare const Obj: {
15
- set: typeof set;
16
- get: typeof get;
17
- merge: typeof merge;
18
- clone: typeof clone;
19
- sort: typeof sort;
20
- only: typeof only;
21
- except: typeof except;
22
- map: typeof map;
23
- flatten: typeof flatten;
24
- areEqual: typeof areEqual;
25
- };
26
- export default Obj;
27
- //# sourceMappingURL=obj.d.ts.map
package/cjs/object/obj.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var areEqual = require("../mixed/areEqual/areEqual.js");
4
- var clone = require("../mixed/clone/clone.js");
5
- var except = require("./except.js");
6
- var flatten = require("./flatten.js");
7
- var get = require("./get.js");
8
- var map = require("./map.js");
9
- var merge = require("./merge.js");
10
- var only = require("./only.js");
11
- var set = require("./set.js");
12
- var sort = require("./sort.js");
13
-
14
- /**
15
- * Object methods
16
- */
17
- const Obj = {
18
- set,
19
- get,
20
- merge,
21
- clone,
22
- sort,
23
- only,
24
- except,
25
- map,
26
- flatten,
27
- areEqual,
28
- };
29
-
30
- module.exports = Obj;