@dxos/util 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b

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.
Files changed (62) hide show
  1. package/dist/lib/browser/index.mjs +313 -114
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +313 -114
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/array.d.ts +1 -0
  8. package/dist/types/src/array.d.ts.map +1 -1
  9. package/dist/types/src/defer.d.ts +1 -1
  10. package/dist/types/src/defer.d.ts.map +1 -1
  11. package/dist/types/src/di-key.d.ts +3 -3
  12. package/dist/types/src/di-key.d.ts.map +1 -1
  13. package/dist/types/src/error-format.d.ts +5 -0
  14. package/dist/types/src/error-format.d.ts.map +1 -0
  15. package/dist/types/src/filename.d.ts +9 -0
  16. package/dist/types/src/filename.d.ts.map +1 -0
  17. package/dist/types/src/index.d.ts +4 -1
  18. package/dist/types/src/index.d.ts.map +1 -1
  19. package/dist/types/src/safe-parse.d.ts +6 -4
  20. package/dist/types/src/safe-parse.d.ts.map +1 -1
  21. package/dist/types/src/safe-stringify.d.ts +13 -0
  22. package/dist/types/src/safe-stringify.d.ts.map +1 -0
  23. package/dist/types/src/string.d.ts +5 -1
  24. package/dist/types/src/string.d.ts.map +1 -1
  25. package/dist/types/src/to-fallback.d.ts.map +1 -1
  26. package/dist/types/src/types.d.ts +5 -1
  27. package/dist/types/src/types.d.ts.map +1 -1
  28. package/dist/types/src/unit.d.ts +14 -0
  29. package/dist/types/src/unit.d.ts.map +1 -0
  30. package/dist/types/src/unit.test.d.ts +2 -0
  31. package/dist/types/src/unit.test.d.ts.map +1 -0
  32. package/dist/types/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +10 -9
  34. package/src/array.test.ts +1 -1
  35. package/src/array.ts +7 -0
  36. package/src/binder.ts +2 -2
  37. package/src/circular-buffer.test.ts +1 -1
  38. package/src/complex.test.ts +1 -1
  39. package/src/defer.ts +1 -1
  40. package/src/error-format.ts +22 -0
  41. package/src/filename.ts +16 -0
  42. package/src/human-hash.test.ts +1 -1
  43. package/src/index.ts +4 -1
  44. package/src/position.test.ts +2 -2
  45. package/src/safe-parse.ts +21 -17
  46. package/src/safe-stringify.ts +104 -0
  47. package/src/sort.test.ts +1 -1
  48. package/src/string.test.ts +1 -1
  49. package/src/string.ts +32 -6
  50. package/src/to-fallback.ts +5 -4
  51. package/src/tree.test.ts +1 -1
  52. package/src/types.ts +9 -1
  53. package/src/uint8array.test.ts +1 -1
  54. package/src/unit.test.ts +25 -0
  55. package/src/unit.ts +83 -0
  56. package/src/weak.test.ts +1 -1
  57. package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
  58. package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
  59. package/dist/types/src/first-two-chars.d.ts +0 -9
  60. package/dist/types/src/first-two-chars.d.ts.map +0 -1
  61. package/src/explicit-resource-management-polyfill.ts +0 -13
  62. package/src/first-two-chars.ts +0 -44
@@ -97,16 +97,24 @@ var intersectBy = (arrays, selector) => {
97
97
  return lookups.every((lookup) => lookup.has(key));
98
98
  });
99
99
  };
100
+ var coerceArray = (arr) => {
101
+ if (arr === void 0) {
102
+ return [];
103
+ }
104
+ return Array.isArray(arr) ? arr : [
105
+ arr
106
+ ];
107
+ };
100
108
 
101
109
  // src/assume.ts
102
110
  function assumeType(value) {
103
111
  }
104
112
 
105
113
  // src/binder.ts
106
- import util from "@dxos/node-std/util";
114
+ import { promisify } from "@dxos/node-std/util";
107
115
  var createBinder = (obj) => ({
108
116
  fn: (fn) => fn.bind(obj),
109
- async: (fn) => util.promisify(fn.bind(obj))
117
+ async: (fn) => promisify(fn.bind(obj))
110
118
  });
111
119
 
112
120
  // src/bitfield.ts
@@ -207,6 +215,7 @@ var CallbackCollection = class {
207
215
  import { invariant as invariant2 } from "@dxos/invariant";
208
216
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
209
217
  var Callback = class {
218
+ _callback;
210
219
  call(...args) {
211
220
  invariant2(this._callback, "Callback not set", {
212
221
  F: __dxlog_file2,
@@ -301,9 +310,10 @@ var chunkArray = (array, size) => {
301
310
  import { invariant as invariant3 } from "@dxos/invariant";
302
311
  var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
303
312
  var CircularBuffer = class {
313
+ _buffer;
314
+ _nextIndex = 0;
315
+ _elementCount = 0;
304
316
  constructor(size) {
305
- this._nextIndex = 0;
306
- this._elementCount = 0;
307
317
  invariant3(size >= 1, void 0, {
308
318
  F: __dxlog_file3,
309
319
  L: 13,
@@ -374,10 +384,11 @@ import { inspect } from "@dxos/node-std/util";
374
384
  import { inspectObject, raise } from "@dxos/debug";
375
385
  var MAX_SERIALIZATION_LENGTH = 10;
376
386
  var ComplexSet = class {
387
+ _projection;
388
+ _values = /* @__PURE__ */ new Map();
377
389
  // prettier-ignore
378
390
  constructor(_projection, values) {
379
391
  this._projection = _projection;
380
- this._values = /* @__PURE__ */ new Map();
381
392
  if (values) {
382
393
  for (const value of values) {
383
394
  this.add(value);
@@ -467,11 +478,12 @@ var makeSet = (projection) => {
467
478
  };
468
479
  };
469
480
  var ComplexMap = class _ComplexMap {
481
+ _keyProjection;
482
+ _keys = /* @__PURE__ */ new Map();
483
+ _values = /* @__PURE__ */ new Map();
470
484
  // prettier-ignore
471
485
  constructor(_keyProjection, entries2) {
472
486
  this._keyProjection = _keyProjection;
473
- this._keys = /* @__PURE__ */ new Map();
474
- this._values = /* @__PURE__ */ new Map();
475
487
  if (entries2) {
476
488
  for (const [key, value] of entries2) {
477
489
  this.set(key, value);
@@ -592,13 +604,11 @@ var getDeep = (obj, path) => {
592
604
  // src/defer-function.ts
593
605
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
594
606
 
595
- // src/explicit-resource-management-polyfill.ts
596
- Symbol.dispose ??= Symbol("Symbol.dispose");
597
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
598
-
599
607
  // src/defer.ts
608
+ import "@hazae41/symbol-dispose-polyfill";
600
609
  var defer = (fn) => new DeferGuard(fn);
601
610
  var DeferGuard = class {
611
+ _fn;
602
612
  /**
603
613
  * @internal
604
614
  */
@@ -614,6 +624,7 @@ var DeferGuard = class {
614
624
  };
615
625
  var deferAsync = (fn) => new DeferAsyncGuard(fn);
616
626
  var DeferAsyncGuard = class {
627
+ _fn;
617
628
  /**
618
629
  * @internal
619
630
  */
@@ -628,6 +639,8 @@ var DeferAsyncGuard = class {
628
639
  // src/entry.ts
629
640
  var entry = (map, key) => new MapEntry(map, key);
630
641
  var MapEntry = class {
642
+ _map;
643
+ _key;
631
644
  /**
632
645
  * @internal
633
646
  */
@@ -653,32 +666,11 @@ var MapEntry = class {
653
666
  }
654
667
  };
655
668
 
656
- // src/first-two-chars.ts
657
- var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
658
- var getFirstTwoRenderableChars = (label) => {
659
- const characters = Array.from(label);
660
- const result = [
661
- "",
662
- ""
663
- ];
664
- let foundFirst = false;
665
- for (let i = 0; i < characters.length; i++) {
666
- const char = characters[i];
667
- if (renderableCharRegex.test(char)) {
668
- if (!foundFirst) {
669
- result[0] = char;
670
- foundFirst = true;
671
- } else {
672
- const textBetween = characters.slice(result[0].length, i).join("");
673
- if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
674
- result[1] = char;
675
- break;
676
- }
677
- }
678
- }
679
- }
680
- return result;
681
- };
669
+ // src/filename.ts
670
+ var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
671
+ date.toISOString().replace(/[:.]/g, "-"),
672
+ ...parts
673
+ ].join("_") + (ext ? `.${ext}` : "");
682
674
 
683
675
  // src/for-each-async.ts
684
676
  var forEachAsync = (items, fn) => Promise.all(items.map(fn));
@@ -944,6 +936,7 @@ var DEFAULT_WORDLIST = [
944
936
  "zulu"
945
937
  ];
946
938
  var HumanHasher = class {
939
+ wordlist;
947
940
  /**
948
941
  * Transforms hex digests to human-readable strings.
949
942
  *
@@ -1209,31 +1202,10 @@ var deepMapValues = (value, fn) => {
1209
1202
  return new DeepMapper(fn).map(value);
1210
1203
  };
1211
1204
  var DeepMapper = class {
1205
+ _fn;
1206
+ _cyclic = /* @__PURE__ */ new Map();
1212
1207
  constructor(_fn) {
1213
1208
  this._fn = _fn;
1214
- this._cyclic = /* @__PURE__ */ new Map();
1215
- this._recurse = (value) => {
1216
- if (this._cyclic.has(value)) {
1217
- return this._cyclic.get(value);
1218
- }
1219
- if (Array.isArray(value)) {
1220
- const res = new Array(value.length);
1221
- this._cyclic.set(value, res);
1222
- for (let i = 0; i < value.length; i++) {
1223
- res[i] = this._map(value[i], i);
1224
- }
1225
- return res;
1226
- } else if (value !== null && typeof value === "object") {
1227
- const res = {};
1228
- this._cyclic.set(value, res);
1229
- for (const key in value) {
1230
- res[key] = this._map(value[key], key);
1231
- }
1232
- return res;
1233
- } else {
1234
- return value;
1235
- }
1236
- };
1237
1209
  }
1238
1210
  map(value) {
1239
1211
  return this._map(value, void 0);
@@ -1244,36 +1216,37 @@ var DeepMapper = class {
1244
1216
  }
1245
1217
  return this._fn(value, this._recurse, key);
1246
1218
  }
1219
+ _recurse = (value) => {
1220
+ if (this._cyclic.has(value)) {
1221
+ return this._cyclic.get(value);
1222
+ }
1223
+ if (Array.isArray(value)) {
1224
+ const res = new Array(value.length);
1225
+ this._cyclic.set(value, res);
1226
+ for (let i = 0; i < value.length; i++) {
1227
+ res[i] = this._map(value[i], i);
1228
+ }
1229
+ return res;
1230
+ } else if (value !== null && typeof value === "object") {
1231
+ const res = {};
1232
+ this._cyclic.set(value, res);
1233
+ for (const key in value) {
1234
+ res[key] = this._map(value[key], key);
1235
+ }
1236
+ return res;
1237
+ } else {
1238
+ return value;
1239
+ }
1240
+ };
1247
1241
  };
1248
1242
  var deepMapValuesAsync = (value, fn) => {
1249
1243
  return new DeepMapperAsync(fn).map(value);
1250
1244
  };
1251
1245
  var DeepMapperAsync = class {
1246
+ _fn;
1247
+ _cyclic = /* @__PURE__ */ new Map();
1252
1248
  constructor(_fn) {
1253
1249
  this._fn = _fn;
1254
- this._cyclic = /* @__PURE__ */ new Map();
1255
- this._recurse = async (value) => {
1256
- if (this._cyclic.has(value)) {
1257
- return this._cyclic.get(value);
1258
- }
1259
- if (Array.isArray(value)) {
1260
- const res = new Array(value.length);
1261
- this._cyclic.set(value, res);
1262
- for (let i = 0; i < value.length; i++) {
1263
- res[i] = await this._map(value[i], i);
1264
- }
1265
- return res;
1266
- } else if (value !== null && typeof value === "object") {
1267
- const res = {};
1268
- this._cyclic.set(value, res);
1269
- for (const key in value) {
1270
- res[key] = await this._map(value[key], key);
1271
- }
1272
- return res;
1273
- } else {
1274
- return value;
1275
- }
1276
- };
1277
1250
  }
1278
1251
  map(value) {
1279
1252
  return this._map(value, void 0);
@@ -1284,6 +1257,28 @@ var DeepMapperAsync = class {
1284
1257
  }
1285
1258
  return this._fn(value, this._recurse, key);
1286
1259
  }
1260
+ _recurse = async (value) => {
1261
+ if (this._cyclic.has(value)) {
1262
+ return this._cyclic.get(value);
1263
+ }
1264
+ if (Array.isArray(value)) {
1265
+ const res = new Array(value.length);
1266
+ this._cyclic.set(value, res);
1267
+ for (let i = 0; i < value.length; i++) {
1268
+ res[i] = await this._map(value[i], i);
1269
+ }
1270
+ return res;
1271
+ } else if (value !== null && typeof value === "object") {
1272
+ const res = {};
1273
+ this._cyclic.set(value, res);
1274
+ for (const key in value) {
1275
+ res[key] = await this._map(value[key], key);
1276
+ }
1277
+ return res;
1278
+ } else {
1279
+ return value;
1280
+ }
1281
+ };
1287
1282
  };
1288
1283
  var visitValues = (object, visitor) => {
1289
1284
  if (Array.isArray(object)) {
@@ -1601,37 +1596,107 @@ var safeInstanceof = (tag) => (target) => {
1601
1596
  };
1602
1597
 
1603
1598
  // src/safe-parse.ts
1604
- var safeParseInt = (value, defaultValue) => {
1599
+ function safeParseInt(str, defaultValue) {
1605
1600
  try {
1606
- const n = parseInt(value ?? "");
1607
- return isNaN(n) ? defaultValue : n;
1608
- } catch (err) {
1601
+ const value = parseInt(str ?? "");
1602
+ return isNaN(value) ? defaultValue : value;
1603
+ } catch {
1609
1604
  return defaultValue;
1610
1605
  }
1611
- };
1612
- var safeParseFloat = (str, defaultValue) => {
1606
+ }
1607
+ function safeParseFloat(str, defaultValue) {
1613
1608
  try {
1614
- return parseFloat(str);
1609
+ const value = parseFloat(str ?? "");
1610
+ return isNaN(value) ? defaultValue : value;
1615
1611
  } catch {
1616
- return defaultValue ?? 0;
1612
+ return defaultValue;
1617
1613
  }
1618
- };
1619
- var safeParseJson = (data, defaultValue) => {
1620
- if (data && data.length > 0) {
1614
+ }
1615
+ var safeParseJson = (str, defaultValue) => {
1616
+ if (str && str.length > 0) {
1621
1617
  try {
1622
- return JSON.parse(data);
1623
- } catch (err) {
1618
+ return JSON.parse(str);
1619
+ } catch {
1624
1620
  }
1625
1621
  }
1626
1622
  return defaultValue;
1627
1623
  };
1628
1624
 
1625
+ // src/safe-stringify.ts
1626
+ var SKIP = Object.freeze({});
1627
+ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1628
+ const seen = /* @__PURE__ */ new WeakSet();
1629
+ function replacer(key, value) {
1630
+ if (typeof value === "object" && value !== null) {
1631
+ if (seen.has(value)) {
1632
+ return "[Circular]";
1633
+ }
1634
+ seen.add(value);
1635
+ }
1636
+ if (filter) {
1637
+ const v2 = filter?.(key, value);
1638
+ if (v2 !== void 0) {
1639
+ return v2 === SKIP ? void 0 : v2;
1640
+ }
1641
+ }
1642
+ return value;
1643
+ }
1644
+ let result = "";
1645
+ try {
1646
+ result = JSON.stringify(obj, replacer, indent);
1647
+ } catch (error) {
1648
+ result = `Error: ${error.message}`;
1649
+ }
1650
+ return result;
1651
+ }
1652
+ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1653
+ let currentDepth = 0;
1654
+ const depthMap = /* @__PURE__ */ new WeakMap();
1655
+ return function(key, value) {
1656
+ if (key === "") {
1657
+ currentDepth = 0;
1658
+ } else if (this && typeof this === "object") {
1659
+ const parentDepth = depthMap.get(this) ?? 0;
1660
+ currentDepth = parentDepth + 1;
1661
+ }
1662
+ if (typeof value === "function") {
1663
+ return void 0;
1664
+ }
1665
+ if (value && typeof value === "object") {
1666
+ depthMap.set(value, currentDepth);
1667
+ if (maxDepth != null && currentDepth >= maxDepth) {
1668
+ return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
1669
+ }
1670
+ }
1671
+ if (omit2?.includes(key)) {
1672
+ return void 0;
1673
+ }
1674
+ if (parse?.includes(key) && typeof value === "string") {
1675
+ try {
1676
+ return JSON.parse(value);
1677
+ } catch {
1678
+ return value;
1679
+ }
1680
+ }
1681
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1682
+ return `[length: ${value.length}]`;
1683
+ }
1684
+ if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1685
+ return value.slice(0, maxStringLen) + "...";
1686
+ }
1687
+ return value;
1688
+ };
1689
+ };
1690
+ var defaultFilter = createReplacer();
1691
+
1629
1692
  // src/sliding-window-summary.ts
1630
1693
  import { invariant as invariant5 } from "@dxos/invariant";
1631
1694
  var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1632
1695
  var SlidingWindowSummary = class {
1696
+ _buffer;
1697
+ _sum = 0;
1698
+ _precision;
1633
1699
  constructor(options) {
1634
- this._sum = 0;
1635
1700
  this._buffer = new CircularBuffer(options.dataPoints);
1636
1701
  if (options.precision != null) {
1637
1702
  invariant5(options.precision >= 0, void 0, {
@@ -1711,12 +1776,24 @@ var capitalize = (str) => {
1711
1776
  }
1712
1777
  return str.charAt(0).toUpperCase() + str.slice(1);
1713
1778
  };
1714
- var trim = (strings, ...values) => {
1715
- const full = String.raw(strings, ...values);
1716
- const lines = full.replace(/^\n/, "").split("\n");
1717
- const indent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^ */)[0].length));
1718
- return lines.map((l) => l.slice(indent)).join("\n");
1719
- };
1779
+ function trim(strings, ...values) {
1780
+ const raw = strings.reduce((out, str, i) => {
1781
+ out += str;
1782
+ if (i < values.length) {
1783
+ const match = str.match(/(^|\n)([ \t]*)$/);
1784
+ const baseIndent = match ? match[2] : "";
1785
+ const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
1786
+ out += val;
1787
+ }
1788
+ return out;
1789
+ }, "");
1790
+ const lines = raw.split("\n");
1791
+ while (lines.length && !lines[0].trim()) lines.shift();
1792
+ while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
1793
+ const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
1794
+ return lines.map((l) => l.slice(minIndent)).join("\n");
1795
+ }
1796
+ var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
1720
1797
 
1721
1798
  // src/sum.ts
1722
1799
  var sum = (values) => values.reduce((a, b) => a + b, 0);
@@ -1915,10 +1992,8 @@ var toFallback = (hash) => {
1915
1992
 
1916
1993
  // src/tracer.ts
1917
1994
  var Tracer = class {
1918
- constructor() {
1919
- this._events = /* @__PURE__ */ new Map();
1920
- this._recording = false;
1921
- }
1995
+ _events = /* @__PURE__ */ new Map();
1996
+ _recording = false;
1922
1997
  // TODO(burdon): Start/stop methods for recording data? By id?
1923
1998
  // Alternatively, enable subscriptions to track/compute series.
1924
1999
  // TODO(burdon): Hierarchical traces?
@@ -2019,7 +2094,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
2019
2094
  };
2020
2095
 
2021
2096
  // src/types.ts
2022
- var isNotFalsy = (value) => !!value;
2097
+ var isTruthy = (value) => !!value;
2023
2098
  var isNonNullable = (value) => value != null;
2024
2099
  var doAsync = async (fn) => fn();
2025
2100
  var getProviderValue = (provider, arg) => {
@@ -2050,6 +2125,107 @@ var arrayMove = (array, from, to) => {
2050
2125
  return array;
2051
2126
  };
2052
2127
 
2128
+ // src/unit.ts
2129
+ var createFormat = (unit) => {
2130
+ return (n, precision = unit.precision ?? 0) => {
2131
+ const value = n / unit.quotient;
2132
+ return {
2133
+ unit,
2134
+ value,
2135
+ formattedValue: value.toFixed(precision),
2136
+ toString: () => `${value.toFixed(precision)}${unit.symbol}`
2137
+ };
2138
+ };
2139
+ };
2140
+ var MS_SECONDS = 1e3;
2141
+ var MS_MINUTES = 60 * MS_SECONDS;
2142
+ var MS_HOURS = 60 * MS_MINUTES;
2143
+ var Unit = {
2144
+ // General.
2145
+ Percent: createFormat({
2146
+ symbol: "%",
2147
+ quotient: 1 / 100,
2148
+ precision: 2
2149
+ }),
2150
+ Thousand: createFormat({
2151
+ symbol: "k",
2152
+ quotient: 1e3,
2153
+ precision: 2
2154
+ }),
2155
+ // Bytes (note KB vs KiB).
2156
+ Gigabyte: createFormat({
2157
+ symbol: "GB",
2158
+ quotient: 1e3 * 1e3 * 1e3,
2159
+ precision: 2
2160
+ }),
2161
+ Megabyte: createFormat({
2162
+ symbol: "MB",
2163
+ quotient: 1e3 * 1e3,
2164
+ precision: 2
2165
+ }),
2166
+ Kilobyte: createFormat({
2167
+ symbol: "KB",
2168
+ quotient: 1e3,
2169
+ precision: 2
2170
+ }),
2171
+ Byte: createFormat({
2172
+ symbol: "B",
2173
+ quotient: 1
2174
+ }),
2175
+ // Time.
2176
+ Hour: createFormat({
2177
+ symbol: "h",
2178
+ quotient: MS_HOURS
2179
+ }),
2180
+ Minute: createFormat({
2181
+ symbol: "m",
2182
+ quotient: MS_MINUTES
2183
+ }),
2184
+ Second: createFormat({
2185
+ symbol: "s",
2186
+ quotient: MS_SECONDS,
2187
+ precision: 1
2188
+ }),
2189
+ Millisecond: createFormat({
2190
+ symbol: "ms",
2191
+ quotient: 1
2192
+ }),
2193
+ Duration: (n) => {
2194
+ const hours = Math.floor(n / MS_HOURS);
2195
+ const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
2196
+ if (hours) {
2197
+ const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2198
+ return {
2199
+ unit: {
2200
+ symbol: "h",
2201
+ quotient: MS_HOURS
2202
+ },
2203
+ value: hours,
2204
+ formattedValue,
2205
+ toString: () => formattedValue
2206
+ };
2207
+ }
2208
+ if (minutes) {
2209
+ const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
2210
+ const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
2211
+ return {
2212
+ unit: {
2213
+ symbol: "m",
2214
+ quotient: MS_MINUTES
2215
+ },
2216
+ value: minutes,
2217
+ formattedValue,
2218
+ toString: () => formattedValue
2219
+ };
2220
+ }
2221
+ const seconds = n >= MS_SECONDS;
2222
+ if (seconds) {
2223
+ return Unit.Second(n);
2224
+ }
2225
+ return Unit.Millisecond(n);
2226
+ }
2227
+ };
2228
+
2053
2229
  // src/url.ts
2054
2230
  var createUrl = (url, search) => {
2055
2231
  const base = typeof url === "string" ? new URL(url) : url;
@@ -2061,11 +2237,11 @@ var createUrl = (url, search) => {
2061
2237
 
2062
2238
  // src/weak.ts
2063
2239
  var WeakDictionary = class {
2240
+ _internal = /* @__PURE__ */ new Map();
2241
+ _finalization = new FinalizationRegistry((cleanUpCallback) => {
2242
+ cleanUpCallback();
2243
+ });
2064
2244
  constructor(entries2) {
2065
- this._internal = /* @__PURE__ */ new Map();
2066
- this._finalization = new FinalizationRegistry((cleanUpCallback) => {
2067
- cleanUpCallback();
2068
- });
2069
2245
  this._internal = new Map(entries2?.map(([key, value]) => [
2070
2246
  key,
2071
2247
  new WeakRef(value)
@@ -2153,6 +2329,21 @@ var WeakDictionary = class {
2153
2329
  this._finalization.unregister(value);
2154
2330
  }
2155
2331
  };
2332
+
2333
+ // src/error-format.ts
2334
+ var formatErrorWithCauses = (error) => {
2335
+ const lines = [];
2336
+ let current = error;
2337
+ let level = 0;
2338
+ while (current) {
2339
+ const prefix = level === 0 ? "" : `Caused by: `;
2340
+ lines.push(prefix + (current.stack ?? String(current)));
2341
+ if (!(current.cause instanceof Error)) break;
2342
+ current = current.cause;
2343
+ level += 1;
2344
+ }
2345
+ return lines.join("\n\n");
2346
+ };
2156
2347
  export {
2157
2348
  BitField,
2158
2349
  Callback,
@@ -2162,8 +2353,10 @@ export {
2162
2353
  ComplexSet,
2163
2354
  HumanHasher,
2164
2355
  MapEntry,
2356
+ SKIP,
2165
2357
  SlidingWindowSummary,
2166
2358
  Tracer,
2359
+ Unit,
2167
2360
  WeakDictionary,
2168
2361
  accessBy,
2169
2362
  arrayMove,
@@ -2178,18 +2371,22 @@ export {
2178
2371
  chunkArray,
2179
2372
  clamp,
2180
2373
  clearUndefined,
2374
+ coerceArray,
2181
2375
  compareMulti,
2182
2376
  compareObject,
2183
2377
  compareScalar,
2184
2378
  compareString,
2185
2379
  createBinder,
2186
2380
  createBucketReducer,
2381
+ createFilename,
2187
2382
  createGroupReducer,
2383
+ createReplacer,
2188
2384
  createSetDispatch,
2189
2385
  createUrl,
2190
2386
  decamelize,
2191
2387
  deepMapValues,
2192
2388
  deepMapValuesAsync,
2389
+ defaultFilter,
2193
2390
  defaultMap,
2194
2391
  defer,
2195
2392
  deferAsync,
@@ -2201,12 +2398,12 @@ export {
2201
2398
  entry,
2202
2399
  exponentialBackoffInterval,
2203
2400
  forEachAsync,
2401
+ formatErrorWithCauses,
2204
2402
  get,
2205
2403
  getAsyncProviderValue,
2206
2404
  getDate,
2207
2405
  getDebugName,
2208
2406
  getDeep,
2209
- getFirstTwoRenderableChars,
2210
2407
  getHostPlatform,
2211
2408
  getPrototypeSpecificInstanceId,
2212
2409
  getProviderValue,
@@ -2224,12 +2421,13 @@ export {
2224
2421
  iosCheck,
2225
2422
  isNode,
2226
2423
  isNonNullable,
2227
- isNotFalsy,
2424
+ isTruthy,
2228
2425
  joinTables,
2229
2426
  jsonKeyReplacer,
2230
2427
  jsonReplacer,
2231
2428
  jsonify,
2232
2429
  jsonlogify,
2430
+ kebabize,
2233
2431
  keyToEmoji,
2234
2432
  keyToFallback,
2235
2433
  keyToHue,
@@ -2260,6 +2458,7 @@ export {
2260
2458
  safeParseFloat,
2261
2459
  safeParseInt,
2262
2460
  safeParseJson,
2461
+ safeStringify,
2263
2462
  set,
2264
2463
  setDeep,
2265
2464
  sortKeys,