@mongez/reinforcements 2.2.7 → 2.3.0

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 CHANGED
@@ -629,7 +629,8 @@ Now let's move to arrays utilities.
629
629
  - [Median](#median): Get the median of all values in an array or by given key.
630
630
  - [Unique](#unique): Get unique values from an array.
631
631
  - [Push Unique](#push-unique): Push a value or more to an array if it doesn't exist.
632
- - [Unshift Unique](#unshift-unique): Add a value or more to the beginning of an array if it doesn't exist.
632
+ - [Unshift Unique](#unshift-unique): Add a value or more to the beginning of an array if it
633
+ doesn't exist.
633
634
 
634
635
  ### Pluck
635
636
 
@@ -674,7 +675,7 @@ Group by a single key:
674
675
  ```ts
675
676
  import { groupBy } from "@mongez/reinforcements";
676
677
 
677
- const studentsClasses = [
678
+ const studentsClasses = [
678
679
  {
679
680
  id: 1,
680
681
  class: "A",
@@ -902,7 +903,7 @@ const studentsClasses = [
902
903
  },
903
904
  ];
904
905
 
905
- console.log(groupBy(studentsClasses, ["class", "grade"], 'students'));
906
+ console.log(groupBy(studentsClasses, ["class", "grade"], "students"));
906
907
  ```
907
908
 
908
909
  Output:
@@ -1013,7 +1014,7 @@ const array = [
1013
1014
  { id: 5, value: 5 },
1014
1015
  ];
1015
1016
 
1016
- console.log(count(array, (item) => item.value > 2)); // 3
1017
+ console.log(count(array, item => item.value > 2)); // 3
1017
1018
  ```
1018
1019
 
1019
1020
  ### Count By
@@ -1026,14 +1027,14 @@ Count total occurrence of values for the given key.
1026
1027
  import { countBy } from "@mongez/reinforcements";
1027
1028
 
1028
1029
  const array = [
1029
- { id: 1, animal: 'dog' },
1030
- { id: 2, animal: 'cat' },
1031
- { id: 3, animal: 'dog' },
1032
- { id: 4, animal: 'cat' },
1033
- { id: 5, animal: 'dog' },
1030
+ { id: 1, animal: "dog" },
1031
+ { id: 2, animal: "cat" },
1032
+ { id: 3, animal: "dog" },
1033
+ { id: 4, animal: "cat" },
1034
+ { id: 5, animal: "dog" },
1034
1035
  ];
1035
1036
 
1036
- console.log(countBy(array, 'animal')); // { dog: 3, cat: 2 }
1037
+ console.log(countBy(array, "animal")); // { dog: 3, cat: 2 }
1037
1038
  ```
1038
1039
 
1039
1040
  ### Even
@@ -1337,6 +1338,26 @@ const array = [1, 2, 3, 4, 5];
1337
1338
  console.log(unshiftUnique(array, 6, 7, 5, 6, 1, 2, 4, 3)); // [7, 6, 1, 2, 3, 4, 5]
1338
1339
  ```
1339
1340
 
1341
+ ### Range
1342
+
1343
+ > Added in v2.3.0
1344
+
1345
+ Generates an array of numbers starting from the given min value to the given max value.
1346
+
1347
+ `range(min: number, max: number): number[]`
1348
+
1349
+ ```ts
1350
+ import { range } from "@mongez/reinforcements";
1351
+
1352
+ console.log(range(1, 6)); // [1, 2, 3, 4, 5, 6]
1353
+
1354
+ console.log(range(3, 5)); // [3, 4, 5]
1355
+ ```
1356
+
1357
+ If the given `min` or `max` parameter is not a number, an error **will be thrown**.
1358
+
1359
+ > Min value must be higher than max value.
1360
+
1340
1361
  ## Working With Strings
1341
1362
 
1342
1363
  The following list defines all available string utilities
@@ -1410,7 +1431,7 @@ import { toSnakeCase } from "@mongez/reinforcements";
1410
1431
 
1411
1432
  const words = "hello world";
1412
1433
 
1413
- console.log(toSnakeCase(words, '-')); // hello-world
1434
+ console.log(toSnakeCase(words, "-")); // hello-world
1414
1435
  ```
1415
1436
 
1416
1437
  Also setting the third argument to false will not convert letters to lower case, will keep each letter as its own.
@@ -1420,7 +1441,7 @@ import { toSnakeCase } from "@mongez/reinforcements";
1420
1441
 
1421
1442
  const words = "Hello World";
1422
1443
 
1423
- console.log(toSnakeCase(words, '-', false)); // Hello_World
1444
+ console.log(toSnakeCase(words, "-", false)); // Hello_World
1424
1445
  ```
1425
1446
 
1426
1447
  ### Kebab Case
@@ -1758,7 +1779,7 @@ import { initials } from "@mongez/reinforcements";
1758
1779
 
1759
1780
  const name = "John Doe";
1760
1781
 
1761
- console.log(initials(name, '.')); // J.D
1782
+ console.log(initials(name, ".")); // J.D
1762
1783
  ```
1763
1784
 
1764
1785
  If the given parameter is not a string it will throw an error.
@@ -1918,7 +1939,8 @@ Escape regex special characters in the given string.
1918
1939
  ```ts
1919
1940
  import { escapeRegex } from "@mongez/reinforcements";
1920
1941
 
1921
- const string = "This is a string with special characters like: . * + ? ^ $ { } ( ) | [ ] / \\";
1942
+ const string =
1943
+ "This is a string with special characters like: . * + ? ^ $ { } ( ) | [ ] / \\";
1922
1944
 
1923
1945
  console.log(escapeRegex(string)); // This is a string with special characters like: \\. \\* \\+ \\? \\^ \\$ \\{ \\} \\( \\) \\| \\[ \\] / \\\\
1924
1946
  ```
@@ -2038,6 +2060,10 @@ To run tests run `npm run test` or `yarn test`
2038
2060
 
2039
2061
  ## Change Log
2040
2062
 
2063
+ - 2.3.0 (25 Mar 2023)
2064
+ - Added [Range](#range) function.
2065
+ - Exposed typings.
2066
+ - Enhanced tests for `areEqual` function,
2041
2067
  - 2.2.7 (22 Feb 2023)
2042
2068
  - Added [Name Initials](#name-initials) function.
2043
2069
  - 2.2.0 (08 Nov 2022)
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generate array of numbers starting from the" given min value to the given max value
3
+ */
4
+ export default function range(min: number, max: number): number[];
5
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Generate array of numbers starting from the" given min value to the given max value
5
+ */
6
+ function range(min, max) {
7
+ if (typeof min !== "number") {
8
+ throw new Error(`min parameter should be number, "${typeof min}" given.`);
9
+ }
10
+ if (typeof max !== "number") {
11
+ throw new Error(`max parameter should be number, "${typeof max}" given.`);
12
+ }
13
+ if (min >= max) {
14
+ throw new Error("max parameter should be higher than min parameter");
15
+ }
16
+ const array = [];
17
+ for (let i = min; i <= max; i++) {
18
+ array.push(i);
19
+ }
20
+ return array;
21
+ }
22
+
23
+ module.exports = range;
package/cjs/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { default as odd } from "./array/odd";
12
12
  export { default as oddIndexes } from "./array/oddIndexes";
13
13
  export { default as pluck } from "./array/pluck";
14
14
  export { default as pushUnique } from "./array/pushUnique";
15
+ export { default as range } from "./array/range";
15
16
  export { default as sum } from "./array/sum";
16
17
  export { default as unique } from "./array/unique";
17
18
  export { default as unshiftUnique } from "./array/unshiftUnique";
@@ -50,6 +51,7 @@ export { default as toSnakeCase } from "./string/toSnakeCase";
50
51
  export { default as toStudlyCase } from "./string/toStudlyCase";
51
52
  export { default as trim } from "./string/trim";
52
53
  export { default as ucfirst } from "./string/ucfirst";
54
+ export * from "./types";
53
55
  export { default as debounce } from "./utils/debounce";
54
56
  export { default as escapeRegex } from "./utils/escapeRegex";
55
57
  //# sourceMappingURL=index.d.ts.map
package/cjs/index.js CHANGED
@@ -16,6 +16,7 @@ var odd = require("./array/odd.js");
16
16
  var oddIndexes = require("./array/oddIndexes.js");
17
17
  var pluck = require("./array/pluck.js");
18
18
  var pushUnique = require("./array/pushUnique.js");
19
+ var range = require("./array/range.js");
19
20
  var sum = require("./array/sum.js");
20
21
  var unique = require("./array/unique.js");
21
22
  var unshiftUnique = require("./array/unshiftUnique.js");
@@ -72,6 +73,7 @@ exports.odd = odd;
72
73
  exports.oddIndexes = oddIndexes;
73
74
  exports.pluck = pluck;
74
75
  exports.pushUnique = pushUnique;
76
+ exports.range = range;
75
77
  exports.sum = sum;
76
78
  exports.unique = unique;
77
79
  exports.unshiftUnique = unshiftUnique;
@@ -1,9 +1,6 @@
1
1
  /**
2
2
  * Convert the current a dot notation string to compound input name
3
3
  * my.input.name >> my[input][name]
4
- *
5
- * @param {string} string
6
- * @returns {string}
7
4
  */
8
5
  export default function toInputName(string: string): string;
9
6
  //# sourceMappingURL=toInputName.d.ts.map
@@ -5,13 +5,9 @@ var rtrim = require("./rtrim.js");
5
5
  /**
6
6
  * Convert the current a dot notation string to compound input name
7
7
  * my.input.name >> my[input][name]
8
- *
9
- * @param {string} string
10
- * @returns {string}
11
8
  */
12
9
  function toInputName(string) {
13
10
  if (!string) return "";
14
- if (!string.includes(".")) return string;
15
11
  const namesList = string.split(".");
16
12
  let mainName = namesList.shift() || "";
17
13
  for (let name of namesList) {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generate array of numbers starting from the" given min value to the given max value
3
+ */
4
+ export default function range(min: number, max: number): number[];
5
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Generate array of numbers starting from the" given min value to the given max value
3
+ */
4
+ function range(min, max) {
5
+ if (typeof min !== "number") {
6
+ throw new Error(`min parameter should be number, "${typeof min}" given.`);
7
+ }
8
+ if (typeof max !== "number") {
9
+ throw new Error(`max parameter should be number, "${typeof max}" given.`);
10
+ }
11
+ if (min >= max) {
12
+ throw new Error("max parameter should be higher than min parameter");
13
+ }
14
+ const array = [];
15
+ for (let i = min; i <= max; i++) {
16
+ array.push(i);
17
+ }
18
+ return array;
19
+ }
20
+
21
+ export { range as default };
package/esm/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { default as odd } from "./array/odd";
12
12
  export { default as oddIndexes } from "./array/oddIndexes";
13
13
  export { default as pluck } from "./array/pluck";
14
14
  export { default as pushUnique } from "./array/pushUnique";
15
+ export { default as range } from "./array/range";
15
16
  export { default as sum } from "./array/sum";
16
17
  export { default as unique } from "./array/unique";
17
18
  export { default as unshiftUnique } from "./array/unshiftUnique";
@@ -50,6 +51,7 @@ export { default as toSnakeCase } from "./string/toSnakeCase";
50
51
  export { default as toStudlyCase } from "./string/toStudlyCase";
51
52
  export { default as trim } from "./string/trim";
52
53
  export { default as ucfirst } from "./string/ucfirst";
54
+ export * from "./types";
53
55
  export { default as debounce } from "./utils/debounce";
54
56
  export { default as escapeRegex } from "./utils/escapeRegex";
55
57
  //# sourceMappingURL=index.d.ts.map
package/esm/index.js CHANGED
@@ -12,6 +12,7 @@ export { default as odd } from "./array/odd.js";
12
12
  export { default as oddIndexes } from "./array/oddIndexes.js";
13
13
  export { default as pluck } from "./array/pluck.js";
14
14
  export { default as pushUnique } from "./array/pushUnique.js";
15
+ export { default as range } from "./array/range.js";
15
16
  export { default as sum } from "./array/sum.js";
16
17
  export { default as unique } from "./array/unique.js";
17
18
  export { default as unshiftUnique } from "./array/unshiftUnique.js";
@@ -1,9 +1,6 @@
1
1
  /**
2
2
  * Convert the current a dot notation string to compound input name
3
3
  * my.input.name >> my[input][name]
4
- *
5
- * @param {string} string
6
- * @returns {string}
7
4
  */
8
5
  export default function toInputName(string: string): string;
9
6
  //# sourceMappingURL=toInputName.d.ts.map
@@ -3,13 +3,9 @@ import rtrim from "./rtrim.js";
3
3
  /**
4
4
  * Convert the current a dot notation string to compound input name
5
5
  * my.input.name >> my[input][name]
6
- *
7
- * @param {string} string
8
- * @returns {string}
9
6
  */
10
7
  function toInputName(string) {
11
8
  if (!string) return "";
12
- if (!string.includes(".")) return string;
13
9
  const namesList = string.split(".");
14
10
  let mainName = namesList.shift() || "";
15
11
  for (let name of namesList) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mongez/reinforcements",
3
- "version": "2.2.7",
3
+ "version": "2.3.0",
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": {
7
- "@mongez/supportive-is": "^1.0.6"
7
+ "@mongez/supportive-is": "^1.0.11"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "jest ./src",