pubo-utils 1.0.129 → 1.0.142

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.
@@ -1,171 +1,197 @@
1
- var __extends = this && this.__extends || function () {
2
- var _extendStatics = function extendStatics(d, b) {
3
- _extendStatics = Object.setPrototypeOf || {
4
- __proto__: []
5
- } instanceof Array && function (d, b) {
6
- d.__proto__ = b;
7
- } || function (d, b) {
8
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
9
- };
10
- return _extendStatics(d, b);
11
- };
12
- return function (d, b) {
13
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
- _extendStatics(d, b);
15
- function __() {
16
- this.constructor = d;
1
+ function _empty() {}
2
+ function _awaitIgnored(value, direct) {
3
+ if (!direct) {
4
+ return value && value.then ? value.then(_empty) : Promise.resolve();
5
+ }
6
+ }
7
+ function _invokeIgnored(body) {
8
+ var result = body();
9
+ if (result && result.then) {
10
+ return result.then(_empty);
11
+ }
12
+ }
13
+ var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
14
+ function _settle(pact, state, value) {
15
+ if (!pact.s) {
16
+ if (value instanceof _Pact) {
17
+ if (value.s) {
18
+ if (state & 1) {
19
+ state = value.s;
20
+ }
21
+ value = value.v;
22
+ } else {
23
+ value.o = _settle.bind(null, pact, state);
24
+ return;
25
+ }
17
26
  }
18
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
- };
20
- }();
21
- var __assign = this && this.__assign || function () {
22
- __assign = Object.assign || function (t) {
23
- for (var s, i = 1, n = arguments.length; i < n; i++) {
24
- s = arguments[i];
25
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
+ if (value && value.then) {
28
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
29
+ return;
30
+ }
31
+ pact.s = state;
32
+ pact.v = value;
33
+ var observer = pact.o;
34
+ if (observer) {
35
+ observer(pact);
26
36
  }
27
- return t;
28
- };
29
- return __assign.apply(this, arguments);
30
- };
31
- var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
32
- function adopt(value) {
33
- return value instanceof P ? value : new P(function (resolve) {
34
- resolve(value);
35
- });
36
37
  }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) {
39
- try {
40
- step(generator.next(value));
41
- } catch (e) {
42
- reject(e);
38
+ }
39
+ var _Pact = /*#__PURE__*/function () {
40
+ function _Pact() {}
41
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
42
+ var result = new _Pact();
43
+ var state = this.s;
44
+ if (state) {
45
+ var callback = state & 1 ? onFulfilled : onRejected;
46
+ if (callback) {
47
+ try {
48
+ _settle(result, 1, callback(this.v));
49
+ } catch (e) {
50
+ _settle(result, 2, e);
51
+ }
52
+ return result;
53
+ } else {
54
+ return this;
43
55
  }
44
56
  }
45
- function rejected(value) {
57
+ this.o = function (_this) {
46
58
  try {
47
- step(generator["throw"](value));
59
+ var value = _this.v;
60
+ if (_this.s & 1) {
61
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
62
+ } else if (onRejected) {
63
+ _settle(result, 1, onRejected(value));
64
+ } else {
65
+ _settle(result, 2, value);
66
+ }
48
67
  } catch (e) {
49
- reject(e);
68
+ _settle(result, 2, e);
50
69
  }
51
- }
52
- function step(result) {
53
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
54
- }
55
- step((generator = generator.apply(thisArg, _arguments || [])).next());
56
- });
57
- };
58
- var __generator = this && this.__generator || function (thisArg, body) {
59
- var _ = {
60
- label: 0,
61
- sent: function sent() {
62
- if (t[0] & 1) throw t[1];
63
- return t[1];
64
- },
65
- trys: [],
66
- ops: []
67
- },
68
- f,
69
- y,
70
- t,
71
- g;
72
- return g = {
73
- next: verb(0),
74
- "throw": verb(1),
75
- "return": verb(2)
76
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
77
- return this;
78
- }), g;
79
- function verb(n) {
80
- return function (v) {
81
- return step([n, v]);
82
70
  };
83
- }
84
- function step(op) {
85
- if (f) throw new TypeError("Generator is already executing.");
86
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
87
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
88
- if (y = 0, t) op = [op[0] & 2, t.value];
89
- switch (op[0]) {
90
- case 0:
91
- case 1:
92
- t = op;
93
- break;
94
- case 4:
95
- _.label++;
96
- return {
97
- value: op[1],
98
- done: false
99
- };
100
- case 5:
101
- _.label++;
102
- y = op[1];
103
- op = [0];
104
- continue;
105
- case 7:
106
- op = _.ops.pop();
107
- _.trys.pop();
108
- continue;
109
- default:
110
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
111
- _ = 0;
112
- continue;
113
- }
114
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
115
- _.label = op[1];
116
- break;
117
- }
118
- if (op[0] === 6 && _.label < t[1]) {
119
- _.label = t[1];
120
- t = op;
121
- break;
122
- }
123
- if (t && _.label < t[2]) {
124
- _.label = t[2];
125
- _.ops.push(op);
126
- break;
71
+ return result;
72
+ };
73
+ return _Pact;
74
+ }();
75
+ function _isSettledPact(thenable) {
76
+ return thenable instanceof _Pact && thenable.s & 1;
77
+ }
78
+ function _forTo(array, body, check) {
79
+ var i = -1,
80
+ pact,
81
+ reject;
82
+ function _cycle(result) {
83
+ try {
84
+ while (++i < array.length && (!check || !check())) {
85
+ result = body(i);
86
+ if (result && result.then) {
87
+ if (_isSettledPact(result)) {
88
+ result = result.v;
89
+ } else {
90
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
91
+ return;
127
92
  }
128
- if (t[2]) _.ops.pop();
129
- _.trys.pop();
130
- continue;
93
+ }
94
+ }
95
+ if (pact) {
96
+ _settle(pact, 1, result);
97
+ } else {
98
+ pact = result;
131
99
  }
132
- op = body.call(thisArg, _);
133
100
  } catch (e) {
134
- op = [6, e];
135
- y = 0;
136
- } finally {
137
- f = t = 0;
101
+ _settle(pact || (pact = new _Pact()), 2, e);
138
102
  }
139
- if (op[0] & 5) throw op[1];
140
- return {
141
- value: op[0] ? op[1] : void 0,
142
- done: true
143
- };
144
103
  }
145
- };
146
- var __values = this && this.__values || function (o) {
147
- var s = typeof Symbol === "function" && Symbol.iterator,
148
- m = s && o[s],
149
- i = 0;
150
- if (m) return m.call(o);
151
- if (o && typeof o.length === "number") return {
152
- next: function next() {
153
- if (o && i >= o.length) o = void 0;
154
- return {
155
- value: o && o[i++],
156
- done: !o
104
+ _cycle();
105
+ return pact;
106
+ }
107
+ function _forOf(target, body, check) {
108
+ if (typeof target[_iteratorSymbol] === "function") {
109
+ var _cycle = function _cycle(result) {
110
+ try {
111
+ while (!(step = iterator.next()).done && (!check || !check())) {
112
+ result = body(step.value);
113
+ if (result && result.then) {
114
+ if (_isSettledPact(result)) {
115
+ result = result.v;
116
+ } else {
117
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
118
+ return;
119
+ }
120
+ }
121
+ }
122
+ if (pact) {
123
+ _settle(pact, 1, result);
124
+ } else {
125
+ pact = result;
126
+ }
127
+ } catch (e) {
128
+ _settle(pact || (pact = new _Pact()), 2, e);
129
+ }
130
+ };
131
+ var iterator = target[_iteratorSymbol](),
132
+ step,
133
+ pact,
134
+ reject;
135
+ _cycle();
136
+ if (iterator["return"]) {
137
+ var _fixup = function _fixup(value) {
138
+ try {
139
+ if (!step.done) {
140
+ iterator["return"]();
141
+ }
142
+ } catch (e) {}
143
+ return value;
157
144
  };
145
+ if (pact && pact.then) {
146
+ return pact.then(_fixup, function (e) {
147
+ throw _fixup(e);
148
+ });
149
+ }
150
+ _fixup();
158
151
  }
159
- };
160
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
161
- };
152
+ return pact;
153
+ }
154
+ // No support for Symbol.iterator
155
+ if (!("length" in target)) {
156
+ throw new TypeError("Object is not iterable");
157
+ }
158
+ // Handle live collections properly
159
+ var values = [];
160
+ for (var i = 0; i < target.length; i++) {
161
+ values.push(target[i]);
162
+ }
163
+ return _forTo(values, function (i) {
164
+ return body(values[i]);
165
+ }, check);
166
+ }
167
+ function _continueIgnored(value) {
168
+ if (value && value.then) {
169
+ return value.then(_empty);
170
+ }
171
+ }
172
+ function _await(value, then, direct) {
173
+ if (direct) {
174
+ return then ? then(value) : value;
175
+ }
176
+ if (!value || !value.then) {
177
+ value = Promise.resolve(value);
178
+ }
179
+ return then ? value.then(then) : value;
180
+ }
181
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
182
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
183
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
184
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
185
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
186
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
162
187
  import { random } from '../random';
163
- var Emitter = /** @class */function () {
188
+ export var Emitter = /*#__PURE__*/function () {
164
189
  function Emitter() {
165
190
  this.state = {};
166
191
  this.ids = {};
167
192
  }
168
- Emitter.prototype.on = function (event, func) {
193
+ var _proto = Emitter.prototype;
194
+ _proto.on = function on(event, func) {
169
195
  if (!this.state[event]) {
170
196
  this.state[event] = [];
171
197
  }
@@ -180,15 +206,15 @@ var Emitter = /** @class */function () {
180
206
  };
181
207
  return key;
182
208
  };
183
- Emitter.prototype.cancel = function (id) {
209
+ _proto.cancel = function cancel(id) {
184
210
  var _this = this;
185
211
  if (!id) {
186
212
  this.clear();
187
213
  return;
188
214
  }
189
- var _a = this.ids[id] || {},
190
- event = _a.event,
191
- index = _a.index;
215
+ var _ref = this.ids[id] || {},
216
+ event = _ref.event,
217
+ index = _ref.index;
192
218
  if (!event) {
193
219
  return;
194
220
  }
@@ -203,105 +229,67 @@ var Emitter = /** @class */function () {
203
229
  }
204
230
  });
205
231
  };
206
- Emitter.prototype.clear = function () {
232
+ _proto.clear = function clear() {
207
233
  this.state.length = 0;
208
234
  };
209
- Emitter.prototype.emit = function (event, payload) {
210
- var e_1, _a;
235
+ _proto.emit = function emit(event, payload) {
211
236
  if (Array.isArray(this.state[event])) {
212
- try {
213
- for (var _b = __values(this.state[event]), _c = _b.next(); !_c.done; _c = _b.next()) {
214
- var func = _c.value;
215
- if (typeof func === 'function') {
216
- func(payload);
217
- }
218
- }
219
- } catch (e_1_1) {
220
- e_1 = {
221
- error: e_1_1
222
- };
223
- } finally {
224
- try {
225
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
226
- } finally {
227
- if (e_1) throw e_1.error;
237
+ for (var _iterator = _createForOfIteratorHelperLoose(this.state[event]), _step; !(_step = _iterator()).done;) {
238
+ var func = _step.value;
239
+ if (typeof func === 'function') {
240
+ func(payload);
228
241
  }
229
242
  }
230
243
  }
231
244
  };
232
- Emitter.prototype.emitSync = function (event, payload) {
233
- return __awaiter(this, void 0, void 0, function () {
234
- var _a, _b, func, e_2_1;
235
- var e_2, _c;
236
- return __generator(this, function (_d) {
237
- switch (_d.label) {
238
- case 0:
239
- if (!Array.isArray(this.state[event])) return [3 /*break*/, 8];
240
- _d.label = 1;
241
- case 1:
242
- _d.trys.push([1, 6, 7, 8]);
243
- _a = __values(this.state[event]), _b = _a.next();
244
- _d.label = 2;
245
- case 2:
246
- if (!!_b.done) return [3 /*break*/, 5];
247
- func = _b.value;
248
- if (!(typeof func === 'function')) return [3 /*break*/, 4];
249
- return [4 /*yield*/, func(payload)];
250
- case 3:
251
- _d.sent();
252
- _d.label = 4;
253
- case 4:
254
- _b = _a.next();
255
- return [3 /*break*/, 2];
256
- case 5:
257
- return [3 /*break*/, 8];
258
- case 6:
259
- e_2_1 = _d.sent();
260
- e_2 = {
261
- error: e_2_1
262
- };
263
- return [3 /*break*/, 8];
264
- case 7:
265
- try {
266
- if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
267
- } finally {
268
- if (e_2) throw e_2.error;
269
- }
270
- return [7 /*endfinally*/];
271
- case 8:
272
- return [2 /*return*/];
245
+ _proto.emitSync = function emitSync(event, payload) {
246
+ try {
247
+ var _this2 = this;
248
+ return _await(_invokeIgnored(function () {
249
+ if (Array.isArray(_this2.state[event])) {
250
+ return _continueIgnored(_forOf(_this2.state[event], function (func) {
251
+ return _invokeIgnored(function () {
252
+ if (typeof func === 'function') {
253
+ return _awaitIgnored(func(payload));
254
+ }
255
+ });
256
+ }));
273
257
  }
274
- });
275
- });
258
+ }));
259
+ } catch (e) {
260
+ return Promise.reject(e);
261
+ }
276
262
  };
277
-
278
- Emitter.prototype.clone = function () {
263
+ _proto.clone = function clone() {
279
264
  return {
280
- state: __assign({}, this.state),
281
- ids: __assign({}, this.ids)
265
+ state: _extends({}, this.state),
266
+ ids: _extends({}, this.ids)
282
267
  };
283
268
  };
284
- Emitter.prototype.restore = function (snapshot) {
269
+ _proto.restore = function restore(snapshot) {
285
270
  this.state = snapshot.state;
286
271
  this.ids = snapshot.ids;
287
272
  };
288
273
  return Emitter;
289
274
  }();
290
- export { Emitter };
291
- var CacheEmitter = /** @class */function (_super) {
292
- __extends(CacheEmitter, _super);
275
+ export var CacheEmitter = /*#__PURE__*/function (_Emitter) {
276
+ _inheritsLoose(CacheEmitter, _Emitter);
293
277
  function CacheEmitter() {
294
- var _this = _super !== null && _super.apply(this, arguments) || this;
295
- _this._cache = {};
296
- return _this;
278
+ var _this3;
279
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
280
+ args[_key] = arguments[_key];
281
+ }
282
+ _this3 = _Emitter.call.apply(_Emitter, [this].concat(args)) || this;
283
+ _this3._cache = {};
284
+ return _this3;
297
285
  }
298
- CacheEmitter.prototype.emit = function (event, payload) {
286
+ var _proto2 = CacheEmitter.prototype;
287
+ _proto2.emit = function emit(event, payload) {
299
288
  this._cache[event] = payload;
300
- _super.prototype.emit.call(this, event, payload);
289
+ _Emitter.prototype.emit.call(this, event, payload);
301
290
  };
302
- CacheEmitter.prototype.getState = function (event) {
291
+ _proto2.getState = function getState(event) {
303
292
  return this._cache[event];
304
293
  };
305
294
  return CacheEmitter;
306
- }(Emitter);
307
- export { CacheEmitter };
295
+ }(Emitter);
@@ -1,19 +1,3 @@
1
- var __values = this && this.__values || function (o) {
2
- var s = typeof Symbol === "function" && Symbol.iterator,
3
- m = s && o[s],
4
- i = 0;
5
- if (m) return m.call(o);
6
- if (o && typeof o.length === "number") return {
7
- next: function next() {
8
- if (o && i >= o.length) o = void 0;
9
- return {
10
- value: o && o[i++],
11
- done: !o
12
- };
13
- }
14
- };
15
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
16
- };
17
1
  /**
18
2
  * Creates a factory function that takes another factory function and returns a new function that creates a product object based on the options passed in.
19
3
  *
@@ -22,23 +6,10 @@ var __values = this && this.__values || function (o) {
22
6
  */
23
7
  export var superFactory = function superFactory(factory) {
24
8
  return function (options) {
25
- var e_1, _a;
26
9
  var product = {};
27
- try {
28
- for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
29
- var key = _c.value;
30
- product[key] = factory(options[key], key);
31
- }
32
- } catch (e_1_1) {
33
- e_1 = {
34
- error: e_1_1
35
- };
36
- } finally {
37
- try {
38
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
39
- } finally {
40
- if (e_1) throw e_1.error;
41
- }
10
+ for (var _i = 0, _Object$keys = Object.keys(options); _i < _Object$keys.length; _i++) {
11
+ var key = _Object$keys[_i];
12
+ product[key] = factory(options[key], key);
42
13
  }
43
14
  return product;
44
15
  };