@squared-functions/module
Advanced tools
Comparing version 0.13.3 to 0.14.0
59
index.js
@@ -1,2 +0,2 @@ | ||
/* @squared-functions/module 0.13.3 | ||
/* @squared-functions/module 0.14.0 | ||
https://github.com/anpham6/squared-functions */ | ||
@@ -19,7 +19,8 @@ | ||
LOG_TYPE[LOG_TYPE["WATCH"] = 16] = "WATCH"; | ||
LOG_TYPE[LOG_TYPE["CLOUD_STORAGE"] = 32] = "CLOUD_STORAGE"; | ||
LOG_TYPE[LOG_TYPE["CLOUD_DATABASE"] = 64] = "CLOUD_DATABASE"; | ||
LOG_TYPE[LOG_TYPE["FILE"] = 32] = "FILE"; | ||
LOG_TYPE[LOG_TYPE["CLOUD"] = 64] = "CLOUD"; | ||
LOG_TYPE[LOG_TYPE["TIME_ELAPSED"] = 128] = "TIME_ELAPSED"; | ||
})(LOG_TYPE = exports.LOG_TYPE || (exports.LOG_TYPE = {})); | ||
let SETTINGS = {}; | ||
const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor; | ||
const SETTINGS = {}; | ||
function allSettled(values) { | ||
@@ -42,2 +43,8 @@ return Promise.all(values.map((promise) => promise.then(value => ({ status: 'fulfilled', value })).catch(reason => ({ status: 'rejected', reason })))); | ||
} | ||
static isObject(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
static escapePattern(value) { | ||
return value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture); | ||
} | ||
static formatMessage(type, title, value, message, options = {}) { | ||
@@ -74,9 +81,9 @@ switch (type) { | ||
break; | ||
case LOG_TYPE.CLOUD_STORAGE: | ||
if (SETTINGS.cloud_storage === false) { | ||
case LOG_TYPE.FILE: | ||
if (SETTINGS.file === false) { | ||
return; | ||
} | ||
break; | ||
case LOG_TYPE.CLOUD_DATABASE: | ||
if (SETTINGS.cloud_database === false) { | ||
case LOG_TYPE.CLOUD: | ||
if (SETTINGS.cloud === false) { | ||
return; | ||
@@ -137,6 +144,6 @@ } | ||
} | ||
static writeFail(value, message) { | ||
this.formatMessage(LOG_TYPE.SYSTEM, 'FAIL', value, message, applyFailStyle()); | ||
static writeFail(value, message, type) { | ||
this.formatMessage(type || LOG_TYPE.SYSTEM, ' FAIL! ', value, message, applyFailStyle()); | ||
} | ||
static parseFunction(value, name) { | ||
static parseFunction(value, name, sync = true) { | ||
const uri = Module.fromLocalPath(value = value.trim()); | ||
@@ -148,6 +155,15 @@ if (uri) { | ||
catch (err) { | ||
this.writeFail(['Could not load function', value], err); | ||
this.writeFail(['Unable to read file', path.basename(uri)], err, LOG_TYPE.FILE); | ||
return; | ||
} | ||
} | ||
const match = /^(async\s+)?(function\s+([^(]*)\(([^)]*)\)\s*\{([\S\s]+)\})$/.exec(value); | ||
if (match) { | ||
if (!sync || match[1]) { | ||
const args = match[4].trim().split(',').map(arg => arg.trim()); | ||
args.push(match[5]); | ||
return new ASYNC_FUNCTION(...args); | ||
} | ||
value = match[2]; | ||
} | ||
if (value.startsWith('function')) { | ||
@@ -245,3 +261,3 @@ return (0, eval)(`(${value})`); | ||
} | ||
return Module.joinPosix(origin, pathname.join('/'), value); | ||
return Module.joinPath(origin, pathname.join('/'), value); | ||
} | ||
@@ -253,3 +269,3 @@ catch (_a) { | ||
} | ||
static joinPosix(...values) { | ||
static joinPath(...values) { | ||
values = values.filter(value => value && value.trim().replace(/\\+/g, '/')); | ||
@@ -277,11 +293,2 @@ let result = ''; | ||
} | ||
static responseError(err, hint) { | ||
return { | ||
success: false, | ||
error: { | ||
hint, | ||
message: err instanceof Error ? err.message : err.toString() | ||
} | ||
}; | ||
} | ||
static allSettled(values, rejected, errors) { | ||
@@ -305,3 +312,3 @@ const promise = Promise.allSettled ? Promise.allSettled(values) : allSettled(values); | ||
if (value.logger) { | ||
SETTINGS = value.logger; | ||
Object.assign(SETTINGS, value.logger); | ||
} | ||
@@ -327,4 +334,4 @@ } | ||
} | ||
writeFail(value, message) { | ||
this.formatFail(LOG_TYPE.SYSTEM, ' FAIL! ', value, message); | ||
writeFail(value, message, type) { | ||
this.formatFail(type || LOG_TYPE.SYSTEM, ' FAIL! ', value, message); | ||
} | ||
@@ -331,0 +338,0 @@ writeTimeElapsed(title, value, time, options) { |
{ | ||
"name": "@squared-functions/module", | ||
"version": "0.13.3", | ||
"version": "0.14.0", | ||
"description": "Module extension class for squared-functions", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@squared-functions/types": "^0.13.3", | ||
"@squared-functions/types": "^0.14.0", | ||
"uuid": "^8.3.2", | ||
@@ -21,0 +21,0 @@ "chalk": "^4.1.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15028
352
+ Added@squared-functions/types@0.14.4(transitive)
- Removed@squared-functions/types@0.13.3(transitive)