@dxos/util 0.8.4-main.bc674ce → 0.8.4-main.c351d160a8

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.
@@ -335,6 +335,10 @@ var CircularBuffer = class {
335
335
  get elementCount() {
336
336
  return this._elementCount;
337
337
  }
338
+ clear() {
339
+ this._nextIndex = 0;
340
+ this._elementCount = 0;
341
+ }
338
342
  getLast() {
339
343
  if (this._elementCount === 0) {
340
344
  return void 0;
@@ -568,14 +572,12 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
568
572
  };
569
573
 
570
574
  // src/deep.ts
571
- import get from "lodash.get";
572
- import set from "lodash.set";
573
575
  import { invariant as invariant4 } from "@dxos/invariant";
574
576
  var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
575
577
  var setDeep = (obj, path, value) => {
576
578
  invariant4(path.length > 0, void 0, {
577
579
  F: __dxlog_file4,
578
- L: 18,
580
+ L: 12,
579
581
  S: void 0,
580
582
  A: [
581
583
  "path.length > 0",
@@ -1018,7 +1020,7 @@ var defaultMap = (map, key, def) => {
1018
1020
  };
1019
1021
 
1020
1022
  // src/instance-id.ts
1021
- var symbol = Symbol.for("dxos.instance-contexts");
1023
+ var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
1022
1024
  var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1023
1025
  var getPrototypeSpecificInstanceId = (instance) => {
1024
1026
  const prototype = Object.getPrototypeOf(instance);
@@ -1400,7 +1402,7 @@ var iosCheck = () => {
1400
1402
  };
1401
1403
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1402
1404
  var getHostPlatform = () => {
1403
- if (!("navigator" in window)) {
1405
+ if (!("navigator" in globalThis)) {
1404
1406
  return "unknown";
1405
1407
  }
1406
1408
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1595,7 +1597,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1595
1597
  };
1596
1598
 
1597
1599
  // src/safe-instanceof.ts
1598
- var instanceTag = Symbol("instanceTag");
1600
+ var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
1599
1601
  var safeInstanceof = (tag) => (target) => {
1600
1602
  target.prototype[instanceTag] = tag;
1601
1603
  Object.defineProperty(target.prototype, Symbol.hasInstance, {
@@ -1632,6 +1634,13 @@ var safeParseJson = (str, defaultValue) => {
1632
1634
  }
1633
1635
  return defaultValue;
1634
1636
  };
1637
+ var safeUrl = (str) => {
1638
+ try {
1639
+ return new URL(str ?? "");
1640
+ } catch {
1641
+ return void 0;
1642
+ }
1643
+ };
1635
1644
 
1636
1645
  // src/safe-stringify.ts
1637
1646
  var SKIP = Object.freeze({});
@@ -1642,6 +1651,9 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1642
1651
  let path = key;
1643
1652
  if (!key) {
1644
1653
  path = "$";
1654
+ if (value != null && typeof value === "object") {
1655
+ seen.set(value, path);
1656
+ }
1645
1657
  return value;
1646
1658
  } else if (this) {
1647
1659
  const parentPath = seen.get(this);
@@ -1653,7 +1665,7 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1653
1665
  if (typeof value === "function") {
1654
1666
  return void 0;
1655
1667
  }
1656
- if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype) {
1668
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
1657
1669
  return void 0;
1658
1670
  }
1659
1671
  if (typeof value === "object" && value !== null) {
@@ -1674,7 +1686,11 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1674
1686
  return `ERROR: ${error.message}`;
1675
1687
  }
1676
1688
  }
1677
- return JSON.stringify(obj, replacer, indent);
1689
+ try {
1690
+ return JSON.stringify(obj, replacer, indent);
1691
+ } catch (error) {
1692
+ return `ERROR: ${error.message}`;
1693
+ }
1678
1694
  }
1679
1695
  var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1680
1696
  let currentDepth = 0;
@@ -1689,6 +1705,9 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1689
1705
  if (typeof value === "function") {
1690
1706
  return SKIP;
1691
1707
  }
1708
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1709
+ return `[length: ${value.length}]`;
1710
+ }
1692
1711
  if (value && typeof value === "object") {
1693
1712
  depthMap.set(value, currentDepth);
1694
1713
  if (maxDepth != null && currentDepth >= maxDepth) {
@@ -1705,9 +1724,6 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1705
1724
  return value;
1706
1725
  }
1707
1726
  }
1708
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1709
- return `[length: ${value.length}]`;
1710
- }
1711
1727
  if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1712
1728
  return value.slice(0, maxStringLen) + "...";
1713
1729
  }
@@ -1834,18 +1850,6 @@ var throwUnhandledError = (error) => {
1834
1850
 
1835
1851
  // src/to-fallback.ts
1836
1852
  var idEmoji = [
1837
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1838
- // Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
1839
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1840
- // – not people or isolated anthropomorphic faces
1841
- // – not flags
1842
- // – more concrete than abstract
1843
- // – less culturally specific
1844
- // – less easily confused with another emoji in the set
1845
- // – requires less special knowledge to identify
1846
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1847
- // – less common as a signifier in UX
1848
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1849
1853
  "\u{1F47B}",
1850
1854
  "\u{1F479}",
1851
1855
  "\u{1F47D}",
@@ -1981,17 +1985,18 @@ var idEmoji = [
1981
1985
  ];
1982
1986
  var idHue = [
1983
1987
  "red",
1984
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
1988
+ "orange",
1985
1989
  "amber",
1986
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
1990
+ "yellow",
1987
1991
  "lime",
1988
1992
  "green",
1989
1993
  "emerald",
1990
1994
  "teal",
1991
1995
  "cyan",
1992
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
1993
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
1994
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
1996
+ // Omit colors similar to primary accent.
1997
+ // 'sky' as const,
1998
+ // 'blue' as const,
1999
+ // 'indigo' as const,
1995
2000
  "violet",
1996
2001
  "purple",
1997
2002
  "fuchsia",
@@ -2470,7 +2475,6 @@ export {
2470
2475
  exponentialBackoffInterval,
2471
2476
  forEachAsync,
2472
2477
  formatErrorWithCauses,
2473
- get,
2474
2478
  getAsyncProviderValue,
2475
2479
  getDate,
2476
2480
  getDebugName,
@@ -2534,7 +2538,7 @@ export {
2534
2538
  safeParseInt,
2535
2539
  safeParseJson,
2536
2540
  safeStringify,
2537
- set,
2541
+ safeUrl,
2538
2542
  setDeep,
2539
2543
  sortKeys,
2540
2544
  stringToArray,