@injex/stdlib
Advanced tools
Comparing version 3.5.1 to 4.0.0-alpha.0
177
lib/hooks.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Hook = void 0; | ||
var tslib_1 = require("tslib"); | ||
var Hook = /** @class */ (function () { | ||
function Hook() { | ||
class Hook { | ||
constructor() { | ||
this._callbacks = []; | ||
this._callCount = 0; | ||
} | ||
Object.defineProperty(Hook.prototype, "callCount", { | ||
get: function () { | ||
return this._callCount; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Hook.prototype, "calledOnce", { | ||
get: function () { | ||
return this._callCount > 0; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Hook.prototype.pipe = function (hook) { | ||
get callCount() { | ||
return this._callCount; | ||
} | ||
get calledOnce() { | ||
return this._callCount > 0; | ||
} | ||
pipe(hook) { | ||
this.tap(hook.call, null, hook); | ||
}; | ||
Hook.prototype.unpipe = function (hook) { | ||
} | ||
unpipe(hook) { | ||
this.untap(hook.call, hook); | ||
}; | ||
Hook.prototype.tap = function (callback, catchFn, scope) { | ||
} | ||
tap(callback, catchFn, scope) { | ||
this._callbacks.push({ | ||
async: false, | ||
callback: callback, | ||
catchFn: catchFn, | ||
scope: scope, | ||
callback, | ||
catchFn, | ||
scope, | ||
}); | ||
}; | ||
Hook.prototype.tapOnce = function (callback, catchFn, scope) { | ||
} | ||
tapOnce(callback, catchFn, scope) { | ||
this._callbacks.push({ | ||
async: false, | ||
once: true, | ||
callback: callback, | ||
catchFn: catchFn, | ||
scope: scope, | ||
callback, | ||
catchFn, | ||
scope, | ||
}); | ||
}; | ||
Hook.prototype.tapAsync = function (callback, catchFn, scope) { | ||
} | ||
tapAsync(callback, catchFn, scope) { | ||
this._callbacks.unshift({ | ||
async: true, | ||
callback: callback, | ||
catchFn: catchFn, | ||
scope: scope, | ||
callback, | ||
catchFn, | ||
scope, | ||
}); | ||
}; | ||
Hook.prototype.tapAsyncOnce = function (callback, catchFn, scope) { | ||
} | ||
tapAsyncOnce(callback, catchFn, scope) { | ||
this._callbacks.unshift({ | ||
async: true, | ||
once: true, | ||
callback: callback, | ||
catchFn: catchFn, | ||
scope: scope, | ||
callback, | ||
catchFn, | ||
scope, | ||
}); | ||
}; | ||
Hook.prototype.untap = function (callbackToRemove, callbackScope) { | ||
this._callbacks = this._callbacks.filter(function (_a) { | ||
var callback = _a.callback, scope = _a.scope; | ||
} | ||
untap(callbackToRemove, callbackScope) { | ||
this._callbacks = this._callbacks.filter(({ callback, scope }) => { | ||
return !(callbackToRemove === callback && (scope && callbackScope ? scope === callbackScope : true)); | ||
}); | ||
}; | ||
Hook.prototype.untapAll = function () { | ||
} | ||
untapAll() { | ||
this._callbacks = []; | ||
}; | ||
Hook.prototype.call = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
async call(...args) { | ||
const onceCallbacks = []; | ||
let callbackArgs; | ||
const callbacks = [...this._callbacks]; | ||
for (let i = 0, len = callbacks.length; i < len; i++) { | ||
callbackArgs = callbacks[i]; | ||
if (!callbackArgs) | ||
continue; | ||
try { | ||
if (callbackArgs.once) { | ||
onceCallbacks.push(callbackArgs.callback); | ||
} | ||
if (callbackArgs.async) { | ||
await callbackArgs.callback.apply(callbackArgs.scope, args); | ||
} | ||
else { | ||
callbackArgs.callback.apply(callbackArgs.scope, args); | ||
} | ||
} | ||
catch (e) { | ||
if (callbackArgs.catchFn) { | ||
callbackArgs.catchFn(e); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
} | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var onceCallbacks, callbackArgs, callbacks, i, len, e_1; | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
onceCallbacks = []; | ||
callbacks = tslib_1.__spreadArrays(this._callbacks); | ||
i = 0, len = callbacks.length; | ||
_a.label = 1; | ||
case 1: | ||
if (!(i < len)) return [3 /*break*/, 8]; | ||
callbackArgs = callbacks[i]; | ||
if (!callbackArgs) | ||
return [3 /*break*/, 7]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 6, , 7]); | ||
if (callbackArgs.once) { | ||
onceCallbacks.push(callbackArgs.callback); | ||
} | ||
if (!callbackArgs.async) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, callbackArgs.callback.apply(callbackArgs.scope, args)]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
callbackArgs.callback.apply(callbackArgs.scope, args); | ||
_a.label = 5; | ||
case 5: return [3 /*break*/, 7]; | ||
case 6: | ||
e_1 = _a.sent(); | ||
if (callbackArgs.catchFn) { | ||
callbackArgs.catchFn(e_1); | ||
} | ||
else { | ||
throw e_1; | ||
} | ||
return [3 /*break*/, 7]; | ||
case 7: | ||
i++; | ||
return [3 /*break*/, 1]; | ||
case 8: | ||
if (onceCallbacks.length) { | ||
onceCallbacks.map(function (callback) { return _this.untap(callback); }); | ||
onceCallbacks.length = 0; | ||
} | ||
this._callCount++; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Hook; | ||
}()); | ||
if (onceCallbacks.length) { | ||
onceCallbacks.map((callback) => this.untap(callback)); | ||
onceCallbacks.length = 0; | ||
} | ||
this._callCount++; | ||
} | ||
} | ||
exports.Hook = Hook; | ||
//# sourceMappingURL=hooks.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./interfaces"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./utils"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logger = exports.LogLevel = void 0; | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
var LogLevel; | ||
@@ -20,3 +20,3 @@ (function (LogLevel) { | ||
return function (target, name, propertyDescriptor) { | ||
var originalFn = propertyDescriptor.value; | ||
const originalFn = propertyDescriptor.value; | ||
propertyDescriptor.value = function () { | ||
@@ -29,76 +29,60 @@ if (this.logLevel >= level) { | ||
} | ||
var Logger = /** @class */ (function () { | ||
function Logger(logLevel, namespace) { | ||
class Logger { | ||
constructor(logLevel, namespace) { | ||
this.logLevel = logLevel; | ||
this.namespace = namespace; | ||
} | ||
Logger.prototype.setLogLevel = function (logLevel) { | ||
setLogLevel(logLevel) { | ||
this.logLevel = logLevel; | ||
return this; | ||
}; | ||
Logger.prototype.setNamespace = function (namespace) { | ||
} | ||
setNamespace(namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
}; | ||
Logger.prototype.info = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
} | ||
info(...args) { | ||
this.invokeLogMethod("info", args); | ||
}; | ||
Logger.prototype.debug = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
} | ||
debug(...args) { | ||
this.invokeLogMethod("debug", args); | ||
}; | ||
Logger.prototype.warn = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
} | ||
warn(...args) { | ||
this.invokeLogMethod("warn", args); | ||
}; | ||
Logger.prototype.error = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
} | ||
error(...args) { | ||
this.invokeLogMethod("error", args); | ||
}; | ||
Logger.prototype.invokeLogMethod = function (method, args) { | ||
args = tslib_1.__spreadArrays([ | ||
(new Date()).toLocaleTimeString() + " [" + method.toUpperCase() + "] " + this.namespace + ":" | ||
], Array.from(args)); | ||
console[method].apply(console, args); | ||
}; | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Info), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "info", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Debug), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "debug", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Warn), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "warn", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Error), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "error", null); | ||
return Logger; | ||
}()); | ||
} | ||
invokeLogMethod(method, args) { | ||
args = [ | ||
`${(new Date()).toLocaleTimeString()} [${method.toUpperCase()}] ${this.namespace}:`, | ||
...Array.from(args) | ||
]; | ||
console[method](...args); | ||
} | ||
} | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Info), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "info", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Debug), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "debug", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Warn), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "warn", null); | ||
tslib_1.__decorate([ | ||
filterLogLevel(LogLevel.Error), | ||
tslib_1.__metadata("design:type", Function), | ||
tslib_1.__metadata("design:paramtypes", [Object]), | ||
tslib_1.__metadata("design:returntype", void 0) | ||
], Logger.prototype, "error", null); | ||
exports.Logger = Logger; | ||
//# sourceMappingURL=logger.js.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
function setMetadata(target, key, value) { | ||
var metadata = ensureMetadata(target); | ||
const metadata = ensureMetadata(target); | ||
metadata[key] = value; | ||
@@ -24,3 +24,3 @@ } | ||
function pushMetadata(target, key, value) { | ||
var metadata = ensureMetadata(target); | ||
const metadata = ensureMetadata(target); | ||
if (!metadata[key]) { | ||
@@ -32,5 +32,5 @@ setMetadata(target, key, []); | ||
function forEachProtoMetadata(target, callback) { | ||
var __proto__ = target === null || target === void 0 ? void 0 : target.__proto__; | ||
let __proto__ = target?.__proto__; | ||
while (__proto__) { | ||
var meta = getMetadata(__proto__); | ||
const meta = getMetadata(__proto__); | ||
if (meta) { | ||
@@ -43,8 +43,8 @@ callback(__proto__, meta); | ||
return { | ||
ensureMetadata: ensureMetadata, | ||
setMetadata: setMetadata, | ||
getMetadata: getMetadata, | ||
hasMetadata: hasMetadata, | ||
pushMetadata: pushMetadata, | ||
forEachProtoMetadata: forEachProtoMetadata, | ||
ensureMetadata, | ||
setMetadata, | ||
getMetadata, | ||
hasMetadata, | ||
pushMetadata, | ||
forEachProtoMetadata, | ||
}; | ||
@@ -51,0 +51,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.yieldToMain = exports.getConstructorName = exports.isPromise = exports.isFunction = exports.toCamelCase = void 0; | ||
var _document = (function () { | ||
const _document = (function () { | ||
try { | ||
@@ -30,8 +30,8 @@ return window.document; | ||
function yieldToMain() { | ||
if (_document === null || _document === void 0 ? void 0 : _document.hidden) { | ||
if (_document?.hidden) { | ||
return Promise.resolve(); | ||
} | ||
return new Promise(function (resolve) { return setTimeout(resolve, 0); }); | ||
return new Promise((resolve) => setTimeout(resolve, 0)); | ||
} | ||
exports.yieldToMain = yieldToMain; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@injex/stdlib", | ||
"version": "3.5.1", | ||
"version": "4.0.0-alpha.0", | ||
"description": "", | ||
@@ -50,3 +50,3 @@ "keywords": [], | ||
}, | ||
"gitHead": "32ef46a3a5f5447e1320598e4bc71e03903d0a00" | ||
"gitHead": "c573d14be7e2530d19be7ebd7a6d4a8faf45b507" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
27977
588
1