zeed 0.7.114 → 0.7.118

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.
@@ -5,7 +5,7 @@ import {
5
5
  __spreadValues,
6
6
  getGlobalContext,
7
7
  getTimestamp
8
- } from "./chunk-DUGVRMRT.js";
8
+ } from "./chunk-G3LBBVZT.js";
9
9
 
10
10
  // src/common/data/bin.ts
11
11
  var log = Logger("bin");
@@ -272,6 +272,14 @@ function between(min, value, max) {
272
272
  return Math.max(min, Math.min(max, value));
273
273
  }
274
274
  __name(between, "between");
275
+ function sum(array) {
276
+ return array.reduce((acc, value) => acc + value, 0);
277
+ }
278
+ __name(sum, "sum");
279
+ function avg(array) {
280
+ return sum(array) / array.length;
281
+ }
282
+ __name(avg, "avg");
275
283
 
276
284
  // src/common/data/orderby.ts
277
285
  function parseOrderby(value = "") {
@@ -417,6 +425,25 @@ function arrayMin(...array) {
417
425
  return arrayFlatten(array).reduce((acc, value) => acc != null ? value < acc ? value : acc : value, void 0);
418
426
  }
419
427
  __name(arrayMin, "arrayMin");
428
+ function arraySum(...array) {
429
+ return arrayFlatten(array).reduce((acc, value) => acc + value, 0);
430
+ }
431
+ __name(arraySum, "arraySum");
432
+ function arrayAvg(...array) {
433
+ let flatArray = arrayFlatten(array);
434
+ return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
435
+ }
436
+ __name(arrayAvg, "arrayAvg");
437
+ function arrayBatches(array, chunckLength) {
438
+ let chunks = [];
439
+ let i = 0;
440
+ const n = array.length;
441
+ while (i < n) {
442
+ chunks.push(array.slice(i, i += chunckLength));
443
+ }
444
+ return chunks;
445
+ }
446
+ __name(arrayBatches, "arrayBatches");
420
447
  function createArray(size2 = 0, item) {
421
448
  if (size2 <= 0)
422
449
  return [];
@@ -808,6 +835,7 @@ var Currency = _Currency;
808
835
  __name(Currency, "Currency");
809
836
  Currency.zero = new _Currency(0);
810
837
  Currency.one = new _Currency(1);
838
+ Currency.hundred = new _Currency(100);
811
839
  function parse(value, opts, useRounding = true) {
812
840
  let v = 0, { decimal, errorOnInvalid, precision: decimals, fromCents } = opts, precision = pow(decimals), isNumber = typeof value === "number";
813
841
  if (value instanceof Currency && fromCents) {
@@ -1046,7 +1074,6 @@ var Day = class {
1046
1074
  if (mm === 0)
1047
1075
  mm = 12;
1048
1076
  let yy = Math.floor((m - 1) / 12);
1049
- console.log("calc", m, mm, yy, [this.year + yy, mm, this.day]);
1050
1077
  return Day.from([this.year + yy, mm, this.day]);
1051
1078
  }
1052
1079
  daysUntil(otherDay) {
@@ -1282,6 +1309,134 @@ function cloneJsonObject(obj) {
1282
1309
  return JSON.parse(JSON.stringify(obj));
1283
1310
  }
1284
1311
  __name(cloneJsonObject, "cloneJsonObject");
1312
+ function memoize(fn) {
1313
+ let cache = /* @__PURE__ */ new Map();
1314
+ return (n) => {
1315
+ if (cache.has(n)) {
1316
+ return cache.get(n);
1317
+ }
1318
+ let result = fn(n);
1319
+ cache.set(n, result);
1320
+ return result;
1321
+ };
1322
+ }
1323
+ __name(memoize, "memoize");
1324
+ function forTimes(count, fn) {
1325
+ for (let i = 0; i < count; i++) {
1326
+ fn(i, count);
1327
+ }
1328
+ }
1329
+ __name(forTimes, "forTimes");
1330
+
1331
+ // src/common/data/xrx.ts
1332
+ var RX_WHITESPACE = /\\\s|\s+|#[^\n]*\n?/gm;
1333
+ var RX_REAL_GROUPS = /\(\?P?<(\w[\w\d_]+)>|\((?!\?(:|\!|=|<=|<\!))/gm;
1334
+ var RX_LOOK_BEHIND = /^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*?)\)/gm;
1335
+ function regExpString(rx) {
1336
+ return typeof rx === "string" ? rx : rx.source || "";
1337
+ }
1338
+ __name(regExpString, "regExpString");
1339
+ function regExpEscape(str) {
1340
+ return str.replace(/[-\[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
1341
+ }
1342
+ __name(regExpEscape, "regExpEscape");
1343
+ var XRX = class {
1344
+ constructor(pattern2, flags) {
1345
+ this.namedGroups = {};
1346
+ this.names = [];
1347
+ let _flags = flags != null ? flags : "";
1348
+ let _rx;
1349
+ if (pattern2 instanceof RegExp) {
1350
+ if (flags == null) {
1351
+ _flags = pattern2.flags;
1352
+ }
1353
+ _rx = pattern2.source;
1354
+ } else {
1355
+ _rx = pattern2;
1356
+ }
1357
+ const extended = _flags && _flags.indexOf("x") !== -1;
1358
+ if (extended) {
1359
+ _flags = _flags.replace("x", "");
1360
+ _rx = _rx.replace(RX_WHITESPACE, (r) => {
1361
+ return r[0] === "\\" ? r : "";
1362
+ });
1363
+ }
1364
+ if (!(pattern2 instanceof RegExp)) {
1365
+ let index = 0;
1366
+ _rx = _rx.replace(RX_REAL_GROUPS, (str, name) => {
1367
+ index += 1;
1368
+ if (name) {
1369
+ if (name !== "index" && name !== "length" && !this.namedGroups[name]) {
1370
+ this.namedGroups[name] = index;
1371
+ } else {
1372
+ console.error(`Unallowed or duplicate group name: ${name}`);
1373
+ }
1374
+ return "(";
1375
+ }
1376
+ return str;
1377
+ });
1378
+ this.names = Object.keys(this.namedGroups);
1379
+ }
1380
+ _rx = regExpString(_rx);
1381
+ RX_LOOK_BEHIND.lastIndex = 0;
1382
+ let parts = RX_LOOK_BEHIND.exec(_rx);
1383
+ if (parts) {
1384
+ this.lookBehind = {
1385
+ rx: new RegExp(`${parts[3]}$(?!\\s)`),
1386
+ expect: parts ? parts[2] === "=" : !parts
1387
+ };
1388
+ _rx = _rx.substr(parts[0].length);
1389
+ }
1390
+ this.rx = new RegExp(_rx, _flags);
1391
+ }
1392
+ get lastIndex() {
1393
+ return this.rx.lastIndex;
1394
+ }
1395
+ set lastIndex(index) {
1396
+ this.rx.lastIndex = index;
1397
+ }
1398
+ _handleMatch(m) {
1399
+ if (this.lookBehind) {
1400
+ let leftContext = m.input.slice(0, m.index);
1401
+ if (this.lookBehind.expect !== this.lookBehind.rx.test(leftContext)) {
1402
+ return null;
1403
+ }
1404
+ }
1405
+ for (let name of this.names) {
1406
+ m[name] = m[this.namedGroups[name]];
1407
+ }
1408
+ return m;
1409
+ }
1410
+ exec(str) {
1411
+ let m;
1412
+ while (m = this.rx.exec(str)) {
1413
+ if (this.rx.lastIndex === m.index) {
1414
+ this.rx.lastIndex++;
1415
+ }
1416
+ m = this._handleMatch(m);
1417
+ if (m != null) {
1418
+ return m;
1419
+ }
1420
+ }
1421
+ }
1422
+ execAll(str) {
1423
+ let matches = [];
1424
+ let m;
1425
+ this.rx.lastIndex = 0;
1426
+ while (m = this.exec(str)) {
1427
+ matches.push(m);
1428
+ }
1429
+ this.rx.lastIndex = 0;
1430
+ return matches;
1431
+ }
1432
+ replace(str, replacement) {
1433
+ let fn = typeof replacement === "function" ? replacement : () => replacement;
1434
+ return str.replace(this.rx, (m) => {
1435
+ return fn(m);
1436
+ });
1437
+ }
1438
+ };
1439
+ __name(XRX, "XRX");
1285
1440
 
1286
1441
  // src/common/dispose-defer.ts
1287
1442
  var log3 = Logger("dispose");
@@ -2216,11 +2371,14 @@ __name(usePool, "usePool");
2216
2371
 
2217
2372
  // src/common/queue.ts
2218
2373
  var log6 = Logger("zeed:queue");
2219
- var SerialQueue = class {
2374
+ var SerialQueue = class extends Emitter {
2220
2375
  constructor(opt = {}) {
2376
+ super();
2221
2377
  this.queue = [];
2222
- this.isPaused = false;
2223
2378
  this.waitToFinish = [];
2379
+ this.max = 0;
2380
+ this.resolved = 0;
2381
+ this.paused = false;
2224
2382
  const { name = uname("queue"), logLevel } = opt;
2225
2383
  this.name = name;
2226
2384
  this.log = Logger(`zeed:queue:${name}`);
@@ -2232,16 +2390,19 @@ var SerialQueue = class {
2232
2390
  this.log(`performNext => skip while another task is running`);
2233
2391
  return;
2234
2392
  }
2235
- if (this.isPaused) {
2393
+ if (this.paused) {
2236
2394
  this.log(`performNext => skip while is paused`);
2237
2395
  return;
2238
2396
  }
2239
- while (this.currentTask == null && !this.isPaused) {
2397
+ while (this.currentTask == null && !this.paused) {
2240
2398
  let info = this.queue.shift();
2241
2399
  this.log(`performNext => ${info == null ? void 0 : info.name}`);
2242
2400
  if (info == null) {
2243
2401
  break;
2244
2402
  }
2403
+ if (this.resolved === 0) {
2404
+ this.emit("didStart", this.max);
2405
+ }
2245
2406
  const { name, task, resolve } = info;
2246
2407
  this.currentTask = task();
2247
2408
  let result = void 0;
@@ -2254,6 +2415,13 @@ var SerialQueue = class {
2254
2415
  }
2255
2416
  resolve(result);
2256
2417
  this.currentTask = void 0;
2418
+ this.resolved += 1;
2419
+ this.emit("didUpdate", this.max, this.resolved);
2420
+ }
2421
+ if (this.queue.length === 0) {
2422
+ this.emit("didFinish", this.max);
2423
+ this.max = 0;
2424
+ this.resolved = 0;
2257
2425
  }
2258
2426
  while (this.waitToFinish.length > 0) {
2259
2427
  this.waitToFinish.shift()();
@@ -2272,6 +2440,8 @@ var SerialQueue = class {
2272
2440
  task,
2273
2441
  resolve
2274
2442
  });
2443
+ this.max += 1;
2444
+ this.emit("didUpdate", this.max, this.resolved);
2275
2445
  this.performNext();
2276
2446
  });
2277
2447
  }
@@ -2283,6 +2453,7 @@ var SerialQueue = class {
2283
2453
  }
2284
2454
  async cancelAll(unblock = true) {
2285
2455
  this.log(`cancelAll`);
2456
+ this.emit("didCancel", this.queue.length);
2286
2457
  let resolver = this.queue.map((task) => task.resolve);
2287
2458
  this.queue = [];
2288
2459
  resolver.forEach((r) => r(void 0));
@@ -2290,23 +2461,29 @@ var SerialQueue = class {
2290
2461
  }
2291
2462
  async pause() {
2292
2463
  this.log(`pause`);
2293
- this.isPaused = true;
2464
+ this.paused = true;
2294
2465
  await this.wait();
2295
2466
  }
2296
2467
  resume() {
2297
2468
  this.log(`resume`);
2298
- this.isPaused = false;
2469
+ this.paused = false;
2299
2470
  this.performNext();
2300
2471
  }
2301
2472
  async wait() {
2302
2473
  this.log(`wait`);
2303
- if (this.currentTask == null && (this.queue.length === 0 || this.isPaused)) {
2474
+ if (this.currentTask == null && (this.queue.length === 0 || this.paused)) {
2304
2475
  return;
2305
2476
  }
2306
2477
  return new Promise((resolve) => {
2307
2478
  this.waitToFinish.push(resolve);
2308
2479
  });
2309
2480
  }
2481
+ get isPaused() {
2482
+ return this.paused;
2483
+ }
2484
+ get hasTasks() {
2485
+ return this.queue.length !== 0;
2486
+ }
2310
2487
  };
2311
2488
  __name(SerialQueue, "SerialQueue");
2312
2489
 
@@ -2345,6 +2522,7 @@ function throttle(callback, opt = {}) {
2345
2522
  let timeoutID = 0;
2346
2523
  let checkpoint = 0;
2347
2524
  let visited = 0;
2525
+ let trailingExec;
2348
2526
  let debugCheckpoint = Date.now();
2349
2527
  function clearExistingTimeout() {
2350
2528
  if (timeoutID) {
@@ -2353,7 +2531,7 @@ function throttle(callback, opt = {}) {
2353
2531
  }
2354
2532
  }
2355
2533
  __name(clearExistingTimeout, "clearExistingTimeout");
2356
- function wrapper(...arguments_) {
2534
+ function wrapper(...args) {
2357
2535
  const now = Date.now();
2358
2536
  let self2 = this;
2359
2537
  let elapsed = now - checkpoint;
@@ -2365,9 +2543,10 @@ function throttle(callback, opt = {}) {
2365
2543
  function exec() {
2366
2544
  visited = 0;
2367
2545
  checkpoint = Date.now();
2368
- callback.apply(self2, arguments_);
2546
+ callback.apply(self2, args);
2369
2547
  }
2370
2548
  __name(exec, "exec");
2549
+ trailingExec = exec;
2371
2550
  if (elapsed > delay || !timeoutID) {
2372
2551
  DEBUG && log8("elapsed", debugElapsed());
2373
2552
  if (leading) {
@@ -2379,7 +2558,7 @@ function throttle(callback, opt = {}) {
2379
2558
  }
2380
2559
  }
2381
2560
  const timeout2 = elapsed > delay ? delay : delay - elapsed;
2382
- log8(`\u23F1 start timeout with ${timeout2.toFixed(1)}ms}`, debugElapsed());
2561
+ log8(`\u23F1 start timeout with ${timeout2.toFixed(1)}ms`, debugElapsed());
2383
2562
  clearExistingTimeout();
2384
2563
  checkpoint = now;
2385
2564
  timeoutID = setTimeout(() => {
@@ -2387,7 +2566,7 @@ function throttle(callback, opt = {}) {
2387
2566
  timeoutID = 0;
2388
2567
  if (trailing && (!leading || visited > 0)) {
2389
2568
  DEBUG && log8("\u{1F680} trailing", debugElapsed());
2390
- exec();
2569
+ trailingExec == null ? void 0 : trailingExec();
2391
2570
  }
2392
2571
  }, timeout2);
2393
2572
  } else {
@@ -2451,6 +2630,8 @@ export {
2451
2630
  randomInt,
2452
2631
  randomFloat,
2453
2632
  between,
2633
+ sum,
2634
+ avg,
2454
2635
  parseOrderby,
2455
2636
  composeOrderby,
2456
2637
  cmp,
@@ -2475,6 +2656,9 @@ export {
2475
2656
  arrayRandomElement,
2476
2657
  arrayMax,
2477
2658
  arrayMin,
2659
+ arraySum,
2660
+ arrayAvg,
2661
+ arrayBatches,
2478
2662
  createArray,
2479
2663
  useBase,
2480
2664
  encodeBase16,
@@ -2552,6 +2736,11 @@ export {
2552
2736
  empty,
2553
2737
  cloneObject,
2554
2738
  cloneJsonObject,
2739
+ memoize,
2740
+ forTimes,
2741
+ regExpString,
2742
+ regExpEscape,
2743
+ XRX,
2555
2744
  useDispose,
2556
2745
  useDisposer,
2557
2746
  useDefer,
@@ -2607,4 +2796,4 @@ export {
2607
2796
  throttle,
2608
2797
  debounce
2609
2798
  };
2610
- //# sourceMappingURL=chunk-MN2DIK4K.js.map
2799
+ //# sourceMappingURL=chunk-43EXW76G.js.map