@mongez/reinforcements 2.0.2 → 2.0.4

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
@@ -812,7 +812,7 @@ Any of following will be used as a separator for the text, `.` | `-` | `whitespa
812
812
 
813
813
  ### Convert string to snake case
814
814
 
815
- Convert string to snake case, each word in string Separated by **whitespace** or **dashes** `toSnakeCase(string: string): string`.
815
+ Convert string to snake case, each word in string Separated by **whitespace** or **dashes** `toSnakeCase(string: string, separator: string = '_', lowerAll: boolean = true): string`.
816
816
 
817
817
  The final output of the text will be all letters in lower case string separated by \_ **underscores**.
818
818
 
@@ -824,6 +824,26 @@ const words = "hello world";
824
824
  console.log(toSnakeCase(words)); // hello_world
825
825
  ```
826
826
 
827
+ You can also set custom separator as second argument.
828
+
829
+ ```ts
830
+ import { toSnakeCase } from "@mongez/reinforcements";
831
+
832
+ const words = "hello world";
833
+
834
+ console.log(toSnakeCase(words, '-')); // hello-world
835
+ ```
836
+
837
+ Also setting the third argument to false will not convert letters to lower case, will keep each letter as its own.
838
+
839
+ ```ts
840
+ import { toSnakeCase } from "@mongez/reinforcements";
841
+
842
+ const words = "Hello World";
843
+
844
+ console.log(toSnakeCase(words, '-', false)); // Hello_World
845
+ ```
846
+
827
847
  ### Convert string to studly case
828
848
 
829
849
  Convert string to studly case, each word in string Separated by **whitespace**, **underscores** or **dashes** `toStudlyCase(string: string, separator: string = "-|\\.|_|\\s"): string`.
@@ -28,6 +28,10 @@ export default class ImmutableCollection {
28
28
  * Get items in the given indexes
29
29
  */
30
30
  onlyIndexes(...indexes: number[]): ImmutableCollection;
31
+ /**
32
+ * Get items that are not in the given indexes
33
+ */
34
+ exceptIndexes(...indexes: number[]): ImmutableCollection;
31
35
  /**
32
36
  * Get items keys (indexes) as collection of string
33
37
  */
@@ -96,6 +100,10 @@ export default class ImmutableCollection {
96
100
  */
97
101
  divide(amount: number): any;
98
102
  divide(key: string, amount: number): any;
103
+ /**
104
+ * Divide the given key in each element or the element by 2
105
+ */
106
+ half(key?: string): any;
99
107
  /**
100
108
  * Get the modulus of the given amount to each element or given key in each element
101
109
  */
@@ -205,10 +213,6 @@ export default class ImmutableCollection {
205
213
  * @alias push
206
214
  */
207
215
  append(...items: any[]): ImmutableCollection;
208
- /**
209
- * Get items that are not in the given indexes
210
- */
211
- exceptIndexes(...indexes: number[]): ImmutableCollection;
212
216
  /**
213
217
  * Add the given items to the end of the array only if they don't exist
214
218
  */
@@ -113,6 +113,20 @@ var ImmutableCollection = /** @class */ (function () {
113
113
  }),
114
114
  );
115
115
  };
116
+ /**
117
+ * Get items that are not in the given indexes
118
+ */
119
+ ImmutableCollection.prototype.exceptIndexes = function () {
120
+ var indexes = [];
121
+ for (var _i = 0; _i < arguments.length; _i++) {
122
+ indexes[_i] = arguments[_i];
123
+ }
124
+ return new ImmutableCollection(
125
+ this.items.filter(function (_, index) {
126
+ return !indexes.includes(index);
127
+ }),
128
+ );
129
+ };
116
130
  /**
117
131
  * Get items keys (indexes) as collection of string
118
132
  */
@@ -264,6 +278,12 @@ var ImmutableCollection = /** @class */ (function () {
264
278
  return item / amount;
265
279
  });
266
280
  };
281
+ /**
282
+ * Divide the given key in each element or the element by 2
283
+ */
284
+ ImmutableCollection.prototype.half = function (key) {
285
+ return key ? this.divide(key, 2) : this.divide(2);
286
+ };
267
287
  ImmutableCollection.prototype.modulus = function () {
268
288
  var args = [];
269
289
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -602,20 +622,6 @@ var ImmutableCollection = /** @class */ (function () {
602
622
  tslib_es6.__spreadArray([], tslib_es6.__read(items), false),
603
623
  );
604
624
  };
605
- /**
606
- * Get items that are not in the given indexes
607
- */
608
- ImmutableCollection.prototype.exceptIndexes = function () {
609
- var indexes = [];
610
- for (var _i = 0; _i < arguments.length; _i++) {
611
- indexes[_i] = arguments[_i];
612
- }
613
- return new ImmutableCollection(
614
- this.items.filter(function (_, index) {
615
- return !indexes.includes(index);
616
- }),
617
- );
618
- };
619
625
  /**
620
626
  * Add the given items to the end of the array only if they don't exist
621
627
  */
@@ -4,5 +4,5 @@
4
4
  *
5
5
  * @return string
6
6
  */
7
- export default function toSnakeCase(string: string, lowerAll?: boolean): string;
7
+ export default function toSnakeCase(string: string, separator?: string, lowerAll?: boolean): string;
8
8
  //# sourceMappingURL=toSnakeCase.d.ts.map
@@ -6,19 +6,22 @@
6
6
  *
7
7
  * @return string
8
8
  */
9
- function toSnakeCase(string, lowerAll) {
9
+ function toSnakeCase(string, separator, lowerAll) {
10
+ if (separator === void 0) {
11
+ separator = "_";
12
+ }
10
13
  if (lowerAll === void 0) {
11
14
  lowerAll = true;
12
15
  }
13
- return string.replace(
14
- /(-|\/|\s|([A-Z]))+/g,
15
- function (_match, _v2, matchedUpperLetter) {
16
- if (!matchedUpperLetter) return "_";
16
+ return string
17
+ .replace(/(-|\/|\s|([A-Z]))+/g, function (_match, _v2, matchedUpperLetter) {
18
+ if (!matchedUpperLetter) return separator;
17
19
  return (
18
- "_" + (lowerAll ? matchedUpperLetter.toLowerCase() : matchedUpperLetter)
20
+ separator +
21
+ (lowerAll ? matchedUpperLetter.toLowerCase() : matchedUpperLetter)
19
22
  );
20
- },
21
- );
23
+ })
24
+ .replace(new RegExp("^".concat(separator)), "");
22
25
  }
23
26
 
24
27
  module.exports = toSnakeCase;
@@ -1524,7 +1524,7 @@ const numbers = collect([1, 2, 3, 4, 5]);
1524
1524
  numbers.random(2); // [3, 5]
1525
1525
  ```
1526
1526
 
1527
- ## Working With Numbers
1527
+ ## Working With Math
1528
1528
 
1529
1529
  Collection provides you with a set of methods to work with numbers which will make it easier to manipulate.
1530
1530
 
@@ -1728,7 +1728,7 @@ const users = collect([
1728
1728
  users.decrement('age'); // [{ name: 'John', age: 19 }, { name: 'Jane', age: 24 }, { name: 'Jack', age: 29 }]
1729
1729
  ```
1730
1730
 
1731
- ## Multiply
1731
+ ### Multiply
1732
1732
 
1733
1733
  The `multiply` method multiply the given value to each element of the array.
1734
1734
 
@@ -1770,7 +1770,7 @@ const users = collect([
1770
1770
  users.double('age'); // [{ name: 'John', age: 40 }, { name: 'Jane', age: 50 }, { name: 'Jack', age: 60 }]
1771
1771
  ```
1772
1772
 
1773
- ## Divide
1773
+ ### Divide
1774
1774
 
1775
1775
  The `divide` method divide the given value to each element of the array.
1776
1776
 
@@ -1802,7 +1802,7 @@ try {
1802
1802
  }
1803
1803
  ```
1804
1804
 
1805
- ## Modulus
1805
+ ### Modulus
1806
1806
 
1807
1807
  The `modulus` method returns the remainder of the division of each element of the array by the given value.
1808
1808
 
@@ -1878,7 +1878,7 @@ const users = collect([
1878
1878
  users.odd('age'); // [{ name: 'Jane', age: 25 }]
1879
1879
  ```
1880
1880
 
1881
- ## Working With Strings
1881
+ ### Working With Strings
1882
1882
 
1883
1883
  The Collection provides some utilities to work with strings.
1884
1884
 
@@ -28,6 +28,10 @@ export default class ImmutableCollection {
28
28
  * Get items in the given indexes
29
29
  */
30
30
  onlyIndexes(...indexes: number[]): ImmutableCollection;
31
+ /**
32
+ * Get items that are not in the given indexes
33
+ */
34
+ exceptIndexes(...indexes: number[]): ImmutableCollection;
31
35
  /**
32
36
  * Get items keys (indexes) as collection of string
33
37
  */
@@ -96,6 +100,10 @@ export default class ImmutableCollection {
96
100
  */
97
101
  divide(amount: number): any;
98
102
  divide(key: string, amount: number): any;
103
+ /**
104
+ * Divide the given key in each element or the element by 2
105
+ */
106
+ half(key?: string): any;
99
107
  /**
100
108
  * Get the modulus of the given amount to each element or given key in each element
101
109
  */
@@ -205,10 +213,6 @@ export default class ImmutableCollection {
205
213
  * @alias push
206
214
  */
207
215
  append(...items: any[]): ImmutableCollection;
208
- /**
209
- * Get items that are not in the given indexes
210
- */
211
- exceptIndexes(...indexes: number[]): ImmutableCollection;
212
216
  /**
213
217
  * Add the given items to the end of the array only if they don't exist
214
218
  */
@@ -101,6 +101,20 @@ var ImmutableCollection = /** @class */ (function () {
101
101
  }),
102
102
  );
103
103
  };
104
+ /**
105
+ * Get items that are not in the given indexes
106
+ */
107
+ ImmutableCollection.prototype.exceptIndexes = function () {
108
+ var indexes = [];
109
+ for (var _i = 0; _i < arguments.length; _i++) {
110
+ indexes[_i] = arguments[_i];
111
+ }
112
+ return new ImmutableCollection(
113
+ this.items.filter(function (_, index) {
114
+ return !indexes.includes(index);
115
+ }),
116
+ );
117
+ };
104
118
  /**
105
119
  * Get items keys (indexes) as collection of string
106
120
  */
@@ -252,6 +266,12 @@ var ImmutableCollection = /** @class */ (function () {
252
266
  return item / amount;
253
267
  });
254
268
  };
269
+ /**
270
+ * Divide the given key in each element or the element by 2
271
+ */
272
+ ImmutableCollection.prototype.half = function (key) {
273
+ return key ? this.divide(key, 2) : this.divide(2);
274
+ };
255
275
  ImmutableCollection.prototype.modulus = function () {
256
276
  var args = [];
257
277
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -569,20 +589,6 @@ var ImmutableCollection = /** @class */ (function () {
569
589
  }
570
590
  return this.push.apply(this, __spreadArray([], __read(items), false));
571
591
  };
572
- /**
573
- * Get items that are not in the given indexes
574
- */
575
- ImmutableCollection.prototype.exceptIndexes = function () {
576
- var indexes = [];
577
- for (var _i = 0; _i < arguments.length; _i++) {
578
- indexes[_i] = arguments[_i];
579
- }
580
- return new ImmutableCollection(
581
- this.items.filter(function (_, index) {
582
- return !indexes.includes(index);
583
- }),
584
- );
585
- };
586
592
  /**
587
593
  * Add the given items to the end of the array only if they don't exist
588
594
  */
@@ -4,5 +4,5 @@
4
4
  *
5
5
  * @return string
6
6
  */
7
- export default function toSnakeCase(string: string, lowerAll?: boolean): string;
7
+ export default function toSnakeCase(string: string, separator?: string, lowerAll?: boolean): string;
8
8
  //# sourceMappingURL=toSnakeCase.d.ts.map
@@ -4,19 +4,22 @@
4
4
  *
5
5
  * @return string
6
6
  */
7
- function toSnakeCase(string, lowerAll) {
7
+ function toSnakeCase(string, separator, lowerAll) {
8
+ if (separator === void 0) {
9
+ separator = "_";
10
+ }
8
11
  if (lowerAll === void 0) {
9
12
  lowerAll = true;
10
13
  }
11
- return string.replace(
12
- /(-|\/|\s|([A-Z]))+/g,
13
- function (_match, _v2, matchedUpperLetter) {
14
- if (!matchedUpperLetter) return "_";
14
+ return string
15
+ .replace(/(-|\/|\s|([A-Z]))+/g, function (_match, _v2, matchedUpperLetter) {
16
+ if (!matchedUpperLetter) return separator;
15
17
  return (
16
- "_" + (lowerAll ? matchedUpperLetter.toLowerCase() : matchedUpperLetter)
18
+ separator +
19
+ (lowerAll ? matchedUpperLetter.toLowerCase() : matchedUpperLetter)
17
20
  );
18
- },
19
- );
21
+ })
22
+ .replace(new RegExp("^".concat(separator)), "");
20
23
  }
21
24
 
22
25
  export { toSnakeCase as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongez/reinforcements",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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": {