live-connect-common
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -9,3 +9,3 @@ interface ErrorBus { | ||
emit(name: string, event: unknown): this; | ||
off(name: string, callback: (event: unknown) => void): this; | ||
off(name: string, callback?: (event: unknown) => void): this; | ||
} | ||
@@ -57,3 +57,3 @@ interface ReadOnlyStorageHandler { | ||
emit(name: string, event: unknown): this; | ||
off(name: string, callback: (event: unknown) => void): this; | ||
off(name: string, callback?: (event: unknown) => void): this; | ||
emitErrorWithMessage(name: string, message: string, exception?: unknown): this; | ||
@@ -60,0 +60,0 @@ emitError(name: string, exception: unknown): this; |
@@ -1,2 +0,167 @@ | ||
"use strict";var t="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",r=new RegExp("^".concat(t,"$"),"i"),e=!!String.prototype.trim;function n(t){return null!=t}function o(t){return"[object Array]"===Object.prototype.toString.call(t)}function i(t){return e?(""+t).trim():(""+t).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}function a(t){return"string"==typeof t}function s(t){return!!t&&"object"==typeof t&&!o(t)}function u(t,r){return new Date((new Date).getTime()+t*r)}function c(t,r,e){if(s(r)){var n=void 0;return(n="message"in r&&"string"==typeof r.message?new Error(e||r.message):new Error(e)).name=t,"stack"in r&&"string"==typeof r.stack&&(n.stack=r.stack),"lineNumber"in r&&"number"==typeof r.lineNumber&&(n.lineNumber=r.lineNumber),"columnNumber"in r&&"number"==typeof r.columnNumber&&(n.columnNumber=r.columnNumber),n}return(n=Error(e)).name=t,n}var p=function(){return p=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t},p.apply(this,arguments)};function f(t,r,e){if(e||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return t.concat(n||Array.prototype.slice.call(r))}"function"==typeof SuppressedError&&SuppressedError;var l="li_errors",h=function(){function t(t){var r=parseInt(t.toString())||5;this.data={h:{},q:{},size:r}}return t.prototype.on=function(t,r,e){var n,o={callback:r.bind(e),unbound:r};return this.data=p(p({},this.data),{h:p(p({},this.data.h),(n={},n[t]=f(f([],this.data.h[t]||[],!0),[o],!1),n))}),(this.data.q[t]||[]).forEach((function(t){return r.call(e,t)})),this},t.prototype.once=function(t,r,e){var n=this,o=this.data.q[t]||[];if(o.length>0)return r.call(e,o[0]),this;var i=function(o){n.off(t,i),r.call(e,o)};return i._=r,this.on(t,i,e)},t.prototype.emit=function(t,r){var e;(this.data.h[t]||[]).forEach((function(t){return t.callback(r)}));var n=this.data.q[t]||[];return this.data=p(p({},this.data),{q:p(p({},this.data.q),(e={},e[t]=f(f([],n.length<this.data.size?n:n.slice(1),!0),[r],!1),e))}),this},t.prototype.off=function(t,r){var e,n=this.data.h[t],o=n&&r&&n.filter((function(t){return t.unbound!==r}))||[];if(o.length)this.data=p(p({},this.data),{h:p(p({},this.data.h),(e={},e[t]=o,e))});else{var i=this.data.h,a=t;i[a];var s=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(i,["symbol"==typeof a?a:a+""]);this.data=p(p({},this.data),{h:s})}return this},t.prototype.emitErrorWithMessage=function(t,r,e){var n=c(t,e,r);return this.emit(l,n)},t.prototype.emitError=function(t,r){var e=c(t,r);return this.emit(l,e)},t}();exports.ERRORS_CHANNEL=l,exports.ReplayEmitter=h,exports.UUID=t,exports.expiresInDays=function(t){return u(t,864e5)},exports.expiresInHours=function(t){return u(t,36e5)},exports.isArray=o,exports.isFunction=function(t){return!!t&&"function"==typeof t},exports.isNonEmpty=function(t){return n(t)&&i(t).length>0},exports.isObject=s,exports.isRecord=function(t){return s(t)},exports.isString=a,exports.isUUID=function(t){return!!t&&r.test(i(t))},exports.nonNull=n,exports.onNonNull=function(t,r){return null!=t?r(t):t},exports.safeToString=function(t){return"object"==typeof t?JSON.stringify(t):""+t},exports.strEqualsIgnoreCase=function(t,r){return a(t)&&a(r)&&i(t.toLowerCase())===i(r.toLowerCase())},exports.trim=i,exports.wrapError=c; | ||
//# sourceMappingURL=index.js.map | ||
'use strict'; | ||
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'; | ||
const uuidRegex = new RegExp(`^${UUID}$`, 'i'); | ||
const hasTrim = !!String.prototype.trim; | ||
function onNonNull(value, fn) { | ||
return value != null ? fn(value) : value; | ||
} | ||
function safeToString(value) { | ||
return typeof value === 'object' ? JSON.stringify(value) : ('' + value); | ||
} | ||
function nonNull(value) { | ||
return value != null; | ||
} | ||
function isNonEmpty(value) { | ||
return nonNull(value) && trim(value).length > 0; | ||
} | ||
function isUUID(value) { | ||
return !!value && uuidRegex.test(trim(value)); | ||
} | ||
function isArray(arr) { | ||
return Object.prototype.toString.call(arr) === '[object Array]'; | ||
} | ||
function trim(value) { | ||
return hasTrim ? ('' + value).trim() : ('' + value).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | ||
} | ||
function isString(str) { | ||
return typeof str === 'string'; | ||
} | ||
function strEqualsIgnoreCase(fistStr, secondStr) { | ||
return isString(fistStr) && isString(secondStr) && trim(fistStr.toLowerCase()) === trim(secondStr.toLowerCase()); | ||
} | ||
function isObject(obj) { | ||
return !!obj && typeof obj === 'object' && !isArray(obj); | ||
} | ||
function isRecord(obj) { | ||
return isObject(obj); | ||
} | ||
function isFunction(fun) { | ||
return !!fun && typeof fun === 'function'; | ||
} | ||
function _expiresIn(expires, number) { | ||
return new Date((new Date().getTime() + (expires * number))); | ||
} | ||
function expiresInDays(expires) { | ||
return _expiresIn(expires, 864e5); | ||
} | ||
function expiresInHours(expires) { | ||
return _expiresIn(expires, 36e5); | ||
} | ||
function wrapError(name, e, message) { | ||
if (isObject(e)) { | ||
let error; | ||
if ('message' in e && typeof e.message === 'string') { | ||
error = new Error(message || e.message); | ||
} | ||
else { | ||
error = new Error(message); | ||
} | ||
error.name = name; | ||
if ('stack' in e && typeof e.stack === 'string') { | ||
error.stack = e.stack; | ||
} | ||
if ('lineNumber' in e && typeof e.lineNumber === 'number') { | ||
error.lineNumber = e.lineNumber; | ||
} | ||
if ('columnNumber' in e && typeof e.columnNumber === 'number') { | ||
error.columnNumber = e.columnNumber; | ||
} | ||
return error; | ||
} | ||
else { | ||
const error = Error(message); | ||
error.name = name; | ||
return error; | ||
} | ||
} | ||
const ERRORS_CHANNEL = 'li_errors'; | ||
class ReplayEmitter { | ||
data; | ||
constructor(replaySize) { | ||
const size = parseInt(replaySize.toString()) || 5; | ||
this.data = { | ||
h: {}, | ||
q: {}, | ||
size | ||
}; | ||
} | ||
on(name, callback, ctx) { | ||
const handler = { | ||
callback: callback.bind(ctx), | ||
unbound: callback | ||
}; | ||
this.data = { ...this.data, h: { ...this.data.h, [name]: [...(this.data.h[name] || []), handler] } }; | ||
(this.data.q[name] || []).forEach(i => callback.call(ctx, i)); | ||
return this; | ||
} | ||
once(name, callback, ctx) { | ||
const eventQueue = this.data.q[name] || []; | ||
if (eventQueue.length > 0) { | ||
callback.call(ctx, eventQueue[0]); | ||
return this; | ||
} | ||
else { | ||
const listener = (args) => { | ||
this.off(name, listener); | ||
callback.call(ctx, args); | ||
}; | ||
listener._ = callback; | ||
return this.on(name, listener, ctx); | ||
} | ||
} | ||
emit(name, event) { | ||
(this.data.h[name] || []).forEach(i => i.callback(event)); | ||
const queue = this.data.q[name] || []; | ||
this.data = { | ||
...this.data, | ||
q: { | ||
...this.data.q, | ||
[name]: [...(queue.length < this.data.size ? queue : queue.slice(1)), event] | ||
} | ||
}; | ||
return this; | ||
} | ||
off(name, callback) { | ||
const handlers = this.data.h[name]; | ||
const liveHandlers = (handlers && callback && handlers.filter(h => h.unbound !== callback)) || []; | ||
if (liveHandlers.length) { | ||
this.data = { ...this.data, h: { ...this.data.h, [name]: liveHandlers } }; | ||
} | ||
else { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { [name]: _, ...rest } = this.data.h; | ||
this.data = { ...this.data, h: rest }; | ||
} | ||
return this; | ||
} | ||
emitErrorWithMessage(name, message, exception) { | ||
const wrappedError = wrapError(name, exception, message); | ||
return this.emit(ERRORS_CHANNEL, wrappedError); | ||
} | ||
emitError(name, exception) { | ||
const wrappedError = wrapError(name, exception); | ||
return this.emit(ERRORS_CHANNEL, wrappedError); | ||
} | ||
} | ||
exports.ERRORS_CHANNEL = ERRORS_CHANNEL; | ||
exports.ReplayEmitter = ReplayEmitter; | ||
exports.UUID = UUID; | ||
exports.expiresInDays = expiresInDays; | ||
exports.expiresInHours = expiresInHours; | ||
exports.isArray = isArray; | ||
exports.isFunction = isFunction; | ||
exports.isNonEmpty = isNonEmpty; | ||
exports.isObject = isObject; | ||
exports.isRecord = isRecord; | ||
exports.isString = isString; | ||
exports.isUUID = isUUID; | ||
exports.nonNull = nonNull; | ||
exports.onNonNull = onNonNull; | ||
exports.safeToString = safeToString; | ||
exports.strEqualsIgnoreCase = strEqualsIgnoreCase; | ||
exports.trim = trim; | ||
exports.wrapError = wrapError; |
@@ -8,12 +8,12 @@ { | ||
"description": "Interfaces and basic functionality for LiveConnect projects", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"license": "Apache-2.0", | ||
"private": false, | ||
"name": "live-connect-common", | ||
"type": "commonjs", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.cjs.mjs", | ||
"types": "./dist/index.d.ts", | ||
@@ -23,4 +23,4 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.cjs.mjs" | ||
}, | ||
@@ -33,4 +33,5 @@ "./package.json": "./package.json" | ||
"scripts": { | ||
"build": "rollup -c rollup.config.mjs", | ||
"test": "ts-mocha -p ./tsconfig-test.json 'test/**/*.ts'", | ||
"build": "rollup -c rollup.config.js", | ||
"test": "mocha --config mocha.json", | ||
"test:ci": "mocha --config mocha.json -R mocha-junit-reporter -O mochaFile=test-results/results.xml", | ||
"lint": "eslint 'src/**/*.ts' 'test/**/*.ts'", | ||
@@ -50,26 +51,16 @@ "fix": "eslint --fix 'src/**/*.ts' 'test/**/*.ts'", | ||
"@rollup/plugin-strip": "^3.0.2", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@rollup/plugin-typescript": "^11.1.1", | ||
"@types/chai": "^4.3.5", | ||
"@types/compression": "^1.7.2", | ||
"@types/cors": "^2.8.13", | ||
"@types/chai": "^4.3.12", | ||
"@types/chai-spies": "^1.0.6", | ||
"@types/dirty-chai": "^2.0.2", | ||
"@types/express": "^4.17.17", | ||
"@types/js-cookie": "^3.0.3", | ||
"@types/mocha": "^10.0.1", | ||
"@types/sinon": "^17.0.0", | ||
"@typescript-eslint/eslint-plugin": "^6.5.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"@typescript-eslint/eslint-plugin": "^7.0.0", | ||
"chai": "^4.3.7", | ||
"chai-spies": "^1.0.0", | ||
"core-js": "^3.31.0", | ||
"dirty-chai": "^2.0.1", | ||
"eslint": "^8.43.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-typescript-formatter": "0.0.2", | ||
"mocha": "^10.2.0", | ||
"mocha-junit-reporter": "^2.2.0", | ||
"mocha-junit-reporter": "^2.2.1", | ||
"release-it": "^17.0.0", | ||
@@ -81,10 +72,5 @@ "rollup": "^4.0.2", | ||
"rollup-plugin-mjs-entry": "^0.1.1", | ||
"serialize-javascript": ">=6.0.1", | ||
"sinon": "^17.0.0", | ||
"sinon-chai": "^3.7.0", | ||
"ts-mocha": "^10.0.0", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.6.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.1.3" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
23
243
Yes
23433
6
1