UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MQTTJS_VERSION = exports.nextTick = exports.applyMixin = exports.ErrorWithReasonCode = void 0;
4class ErrorWithReasonCode extends Error {
5 constructor(message, code) {
6 super(message);
7 this.code = code;
8 Object.setPrototypeOf(this, ErrorWithReasonCode.prototype);
9 Object.getPrototypeOf(this).name = 'ErrorWithReasonCode';
10 }
11}
12exports.ErrorWithReasonCode = ErrorWithReasonCode;
13function applyMixin(target, mixin, includeConstructor = false) {
14 var _a;
15 const inheritanceChain = [mixin];
16 while (true) {
17 const current = inheritanceChain[0];
18 const base = Object.getPrototypeOf(current);
19 if (base === null || base === void 0 ? void 0 : base.prototype) {
20 inheritanceChain.unshift(base);
21 }
22 else {
23 break;
24 }
25 }
26 for (const ctor of inheritanceChain) {
27 for (const prop of Object.getOwnPropertyNames(ctor.prototype)) {
28 if (includeConstructor || prop !== 'constructor') {
29 Object.defineProperty(target.prototype, prop, (_a = Object.getOwnPropertyDescriptor(ctor.prototype, prop)) !== null && _a !== void 0 ? _a : Object.create(null));
30 }
31 }
32 }
33}
34exports.applyMixin = applyMixin;
35exports.nextTick = typeof (process === null || process === void 0 ? void 0 : process.nextTick) === 'function'
36 ? process.nextTick
37 : (callback) => {
38 setTimeout(callback, 0);
39 };
40exports.MQTTJS_VERSION = require('../../package.json').version;
41//# sourceMappingURL=shared.js.map
\No newline at end of file