@mongez/reinforcements 2.0.3 → 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
  */
@@ -209,10 +213,6 @@ export default class ImmutableCollection {
209
213
  * @alias push
210
214
  */
211
215
  append(...items: any[]): ImmutableCollection;
212
- /**
213
- * Get items that are not in the given indexes
214
- */
215
- exceptIndexes(...indexes: number[]): ImmutableCollection;
216
216
  /**
217
217
  * Add the given items to the end of the array only if they don't exist
218
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
  */
@@ -608,20 +622,6 @@ var ImmutableCollection = /** @class */ (function () {
608
622
  tslib_es6.__spreadArray([], tslib_es6.__read(items), false),
609
623
  );
610
624
  };
611
- /**
612
- * Get items that are not in the given indexes
613
- */
614
- ImmutableCollection.prototype.exceptIndexes = function () {
615
- var indexes = [];
616
- for (var _i = 0; _i < arguments.length; _i++) {
617
- indexes[_i] = arguments[_i];
618
- }
619
- return new ImmutableCollection(
620
- this.items.filter(function (_, index) {
621
- return !indexes.includes(index);
622
- }),
623
- );
624
- };
625
625
  /**
626
626
  * Add the given items to the end of the array only if they don't exist
627
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
  */
@@ -209,10 +213,6 @@ export default class ImmutableCollection {
209
213
  * @alias push
210
214
  */
211
215
  append(...items: any[]): ImmutableCollection;
212
- /**
213
- * Get items that are not in the given indexes
214
- */
215
- exceptIndexes(...indexes: number[]): ImmutableCollection;
216
216
  /**
217
217
  * Add the given items to the end of the array only if they don't exist
218
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
  */
@@ -575,20 +589,6 @@ var ImmutableCollection = /** @class */ (function () {
575
589
  }
576
590
  return this.push.apply(this, __spreadArray([], __read(items), false));
577
591
  };
578
- /**
579
- * Get items that are not in the given indexes
580
- */
581
- ImmutableCollection.prototype.exceptIndexes = function () {
582
- var indexes = [];
583
- for (var _i = 0; _i < arguments.length; _i++) {
584
- indexes[_i] = arguments[_i];
585
- }
586
- return new ImmutableCollection(
587
- this.items.filter(function (_, index) {
588
- return !indexes.includes(index);
589
- }),
590
- );
591
- };
592
592
  /**
593
593
  * Add the given items to the end of the array only if they don't exist
594
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.3",
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": {