@coderich/util 1.0.3 → 1.0.5

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +11 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/util",
3
3
  "main": "src/index.js",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -15,7 +15,7 @@
15
15
  "dev": "coderich-dev"
16
16
  },
17
17
  "dependencies": {
18
- "bson-objectid": "2.0.4",
18
+ "bson": "6.8.0",
19
19
  "dot-prop": "6.0.1",
20
20
  "lodash.isequal": "4.5.0"
21
21
  },
package/src/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const FS = require('fs');
2
2
  const Path = require('path');
3
3
  const ChildProcess = require('child_process');
4
- const ObjectId = require('bson-objectid');
5
4
  const isEqual = require('lodash.isequal');
5
+ const { ObjectId } = require('bson');
6
6
  const { set } = require('dot-prop');
7
7
 
8
8
  exports.set = set;
@@ -10,8 +10,8 @@ exports.isEqual = isEqual;
10
10
  exports.ObjectId = ObjectId;
11
11
 
12
12
  exports.push = (arr, el) => arr[arr.push(el) - 1];
13
- exports.uvl = (...values) => values.reduce((prev, value) => (prev === undefined ? value : prev), undefined);
14
- exports.nvl = (...values) => values.reduce((prev, value) => (prev === null ? value : prev), null);
13
+ exports.uvl = (...values) => values.reduce((prev, value) => (prev === undefined ? value : prev));
14
+ exports.nvl = (...values) => values.reduce((prev, value) => (prev === null ? value : prev));
15
15
  exports.pairs = (...values) => values.flat().reduce((prev, curr, i, arr) => (i % 2 === 0 ? prev.concat([arr.slice(i, i + 2)]) : prev), []);
16
16
  exports.filterBy = (arr, fn) => arr.filter((b, index) => index === arr.findIndex(a => fn(a, b)));
17
17
  exports.ensureArray = a => (Array.isArray(a) ? a : [a].filter(el => el !== undefined));
@@ -201,3 +201,11 @@ exports.requireDir = (dir) => {
201
201
 
202
202
  return data;
203
203
  };
204
+
205
+ exports.parseRegExp = (mixed) => {
206
+ if (mixed instanceof RegExp) return mixed;
207
+ const matches = mixed.match(/^\/?(.*?)\/?([gimy]*)$/);
208
+ if (!matches) throw new Error(`Invalid regular expression format: ${mixed}`);
209
+ const [, pattern, flags] = matches;
210
+ return new RegExp(pattern, flags);
211
+ };