not-node 6.2.24 → 6.2.25
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/package.json +1 -1
- package/src/common.js +36 -23
- package/test/module/routes.js +1 -1
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -25,12 +25,12 @@ module.exports.firstLetterToUpper = function (string) {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Validates if string is a ObjectId
|
|
28
|
-
* @param {string} id ObjectId string to validate
|
|
29
|
-
* @return {
|
|
28
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} id ObjectId string to validate
|
|
29
|
+
* @return {boolean} true if check is not failed
|
|
30
30
|
*/
|
|
31
31
|
module.exports.validateObjectId = (id) => {
|
|
32
32
|
try {
|
|
33
|
-
return id.match(/^[0-9a-fA-F]{24}$/) ? true : false;
|
|
33
|
+
return id.toString().match(/^[0-9a-fA-F]{24}$/) ? true : false;
|
|
34
34
|
} catch (e) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -38,9 +38,9 @@ module.exports.validateObjectId = (id) => {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Validates and compares ObjectIds in string or Object form
|
|
41
|
-
* @param {string|ObjectId} firstId first id
|
|
42
|
-
* @param {string|ObjectId} secondId second id
|
|
43
|
-
* @return {
|
|
41
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} firstId first id
|
|
42
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} secondId second id
|
|
43
|
+
* @return {boolean} true if equal
|
|
44
44
|
*/
|
|
45
45
|
module.exports.compareObjectIds = (firstId, secondId) => {
|
|
46
46
|
try {
|
|
@@ -160,7 +160,9 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
|
160
160
|
}
|
|
161
161
|
if (name.indexOf(".") > -1) {
|
|
162
162
|
const proc =
|
|
163
|
-
typeof obj == "object"
|
|
163
|
+
typeof obj == "object"
|
|
164
|
+
? notPath.get(":" + name, obj, {})
|
|
165
|
+
: obj[name];
|
|
164
166
|
if (!proc) {
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
@@ -179,9 +181,8 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
|
179
181
|
/**
|
|
180
182
|
* Executes method of object in apropriate way inside Promise
|
|
181
183
|
* @param {Object} from original object
|
|
182
|
-
* @param {Object}
|
|
183
|
-
* @param {Array}
|
|
184
|
-
* @return {Promise} results of method execution
|
|
184
|
+
* @param {Object} to method name to execute
|
|
185
|
+
* @param {Array} list array of params
|
|
185
186
|
**/
|
|
186
187
|
module.exports.mapBind = (from, to, list) => {
|
|
187
188
|
list.forEach((item) => {
|
|
@@ -262,7 +263,7 @@ module.exports.tryParseAsync = (
|
|
|
262
263
|
* path
|
|
263
264
|
* @param {Array<string>} content list of module components ['models', 'logics', 'routes',...]
|
|
264
265
|
* @param {string} relative path to parent folder of components
|
|
265
|
-
* @
|
|
266
|
+
* @returns {Object} paths object for module/index.js
|
|
266
267
|
**/
|
|
267
268
|
module.exports.generatePaths = (content = [], relative = "src") => {
|
|
268
269
|
const toPath = (name) => path.join(relative, name);
|
|
@@ -291,31 +292,40 @@ module.exports.getIP = (req) => {
|
|
|
291
292
|
}
|
|
292
293
|
};
|
|
293
294
|
|
|
295
|
+
/**
|
|
296
|
+
*
|
|
297
|
+
*
|
|
298
|
+
* @param {string} prefix
|
|
299
|
+
* @return {function}
|
|
300
|
+
*/
|
|
294
301
|
const createIsStringPrefixedTester = (prefix) => {
|
|
295
302
|
if (!prefix || prefix.length === 0) throw Error("No prefix provided");
|
|
296
303
|
return (str) => {
|
|
297
|
-
return str && str.length > prefix.length && str.indexOf(prefix) === 0
|
|
304
|
+
return str && str.length > prefix.length && str.indexOf(prefix) === 0
|
|
305
|
+
? prefix.length
|
|
306
|
+
: 0;
|
|
298
307
|
};
|
|
299
308
|
};
|
|
300
309
|
module.exports.createIsStringPrefixedTester = createIsStringPrefixedTester;
|
|
301
310
|
|
|
311
|
+
/**
|
|
312
|
+
*
|
|
313
|
+
*
|
|
314
|
+
* @param {string} val
|
|
315
|
+
* @param {Object} options
|
|
316
|
+
* @return {number} prefix length
|
|
317
|
+
*/
|
|
302
318
|
const stringIsPrefixed = (val, options) => {
|
|
303
319
|
if (typeof val === "string" && options) {
|
|
304
320
|
if (options.tester && typeof options.tester === "function") {
|
|
305
|
-
|
|
306
|
-
if (Object.hasOwn(process.env, val)) {
|
|
307
|
-
return res;
|
|
308
|
-
}
|
|
321
|
+
return options.tester(val);
|
|
309
322
|
}
|
|
310
323
|
if (
|
|
311
324
|
options.prefix &&
|
|
312
325
|
typeof options.prefix === "string" &&
|
|
313
326
|
options.prefix.length > 0
|
|
314
327
|
) {
|
|
315
|
-
|
|
316
|
-
if (Object.hasOwn(process.env, val)) {
|
|
317
|
-
return res;
|
|
318
|
-
}
|
|
328
|
+
return createIsStringPrefixedTester(options.prefix)(val);
|
|
319
329
|
}
|
|
320
330
|
}
|
|
321
331
|
return 0;
|
|
@@ -339,11 +349,14 @@ const getValueFromEnv = (
|
|
|
339
349
|
name,
|
|
340
350
|
options = { prefix: "ENV$", drop: true }
|
|
341
351
|
) => {
|
|
342
|
-
if (source &&
|
|
352
|
+
if (source && objHas(source, name)) {
|
|
343
353
|
const val = source[name];
|
|
344
354
|
const len = stringIsPrefixed(val, options);
|
|
345
|
-
if (len) {
|
|
346
|
-
|
|
355
|
+
if (len > 0) {
|
|
356
|
+
const envName = options.drop ? val.slice(len) : val;
|
|
357
|
+
if (typeof process.env[envName] !== "undefined") {
|
|
358
|
+
return process.env[envName];
|
|
359
|
+
}
|
|
347
360
|
}
|
|
348
361
|
return val;
|
|
349
362
|
}
|
package/test/module/routes.js
CHANGED
|
@@ -54,7 +54,7 @@ module.exports = ({ expect }) => {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
describe("tryRouteFile", function () {
|
|
57
|
-
it("route file doesnt exists", function () {
|
|
57
|
+
it("route file doesnt exists,", function () {
|
|
58
58
|
const res = notModuleRegistratorRoutes.tryRouteFile({
|
|
59
59
|
srcDir: routesPath,
|
|
60
60
|
routeBasename: "jingle",
|