@dxos/util 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203

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.
@@ -1367,7 +1367,18 @@ var omit = (obj, keys2) => {
1367
1367
 
1368
1368
  // src/platform.ts
1369
1369
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1370
- var mobileAndTabletCheck = () => {
1370
+ var isBun = () => globalThis.Bun !== void 0;
1371
+ var isTauri = () => !!globalThis.__TAURI__;
1372
+ var isMobile = () => {
1373
+ let check = false;
1374
+ (function(a) {
1375
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
1376
+ check = true;
1377
+ }
1378
+ })(navigator.userAgent || navigator.vendor || window.opera);
1379
+ return check;
1380
+ };
1381
+ var isMobileOrTablet = () => {
1371
1382
  let check = false;
1372
1383
  ((a) => {
1373
1384
  if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
@@ -1389,7 +1400,7 @@ var iosCheck = () => {
1389
1400
  };
1390
1401
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1391
1402
  var getHostPlatform = () => {
1392
- if (!("navigator" in window)) {
1403
+ if (!("navigator" in globalThis)) {
1393
1404
  return "unknown";
1394
1405
  }
1395
1406
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1625,29 +1636,45 @@ var safeParseJson = (str, defaultValue) => {
1625
1636
  // src/safe-stringify.ts
1626
1637
  var SKIP = Object.freeze({});
1627
1638
  function safeStringify(obj, filter = defaultFilter, indent = 2) {
1628
- const seen = /* @__PURE__ */ new WeakSet();
1639
+ const seen = /* @__PURE__ */ new WeakMap();
1629
1640
  function replacer(key, value) {
1630
- if (typeof value === "object" && value !== null) {
1631
- if (seen.has(value)) {
1632
- return "[Circular]";
1641
+ try {
1642
+ let path = key;
1643
+ if (!key) {
1644
+ path = "$";
1645
+ return value;
1646
+ } else if (this) {
1647
+ const parentPath = seen.get(this);
1648
+ path = parentPath ? `${parentPath}.${key}` : key;
1633
1649
  }
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;
1650
+ if (value == null) {
1651
+ return value;
1652
+ }
1653
+ if (typeof value === "function") {
1654
+ return void 0;
1640
1655
  }
1656
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype) {
1657
+ return void 0;
1658
+ }
1659
+ if (typeof value === "object" && value !== null) {
1660
+ const exists = seen.get(value);
1661
+ if (exists) {
1662
+ return `[${path} => ${exists}]`;
1663
+ }
1664
+ seen.set(value, path);
1665
+ }
1666
+ if (filter) {
1667
+ const filteredValue = filter?.(key, value);
1668
+ if (filteredValue !== void 0) {
1669
+ return filteredValue === SKIP ? void 0 : filteredValue;
1670
+ }
1671
+ }
1672
+ return value;
1673
+ } catch (error) {
1674
+ return `ERROR: ${error.message}`;
1641
1675
  }
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
1676
  }
1650
- return result;
1677
+ return JSON.stringify(obj, replacer, indent);
1651
1678
  }
1652
1679
  var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1653
1680
  let currentDepth = 0;
@@ -1660,7 +1687,7 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1660
1687
  currentDepth = parentDepth + 1;
1661
1688
  }
1662
1689
  if (typeof value === "function") {
1663
- return void 0;
1690
+ return SKIP;
1664
1691
  }
1665
1692
  if (value && typeof value === "object") {
1666
1693
  depthMap.set(value, currentDepth);
@@ -1669,7 +1696,7 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1669
1696
  }
1670
1697
  }
1671
1698
  if (omit2?.includes(key)) {
1672
- return void 0;
1699
+ return SKIP;
1673
1700
  }
1674
1701
  if (parse?.includes(key) && typeof value === "string") {
1675
1702
  try {
@@ -2124,6 +2151,12 @@ var arrayMove = (array, from, to) => {
2124
2151
  array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
2125
2152
  return array;
2126
2153
  };
2154
+ function arraySwap(array, from, to) {
2155
+ const current = array[from];
2156
+ array[from] = array[to];
2157
+ array[to] = current;
2158
+ return array;
2159
+ }
2127
2160
 
2128
2161
  // src/unit.ts
2129
2162
  var createFormat = (unit) => {
@@ -2344,6 +2377,43 @@ var formatErrorWithCauses = (error) => {
2344
2377
  }
2345
2378
  return lines.join("\n\n");
2346
2379
  };
2380
+
2381
+ // src/retry.ts
2382
+ var DEFAULT_RETRY_OPTIONS = {
2383
+ count: 3,
2384
+ delayMs: 100,
2385
+ exponent: 2,
2386
+ retryOnError: async () => true,
2387
+ retryOnValue: async () => false
2388
+ };
2389
+ var retry = async (options, cb) => {
2390
+ const fullOptions = {
2391
+ ...DEFAULT_RETRY_OPTIONS,
2392
+ ...options
2393
+ };
2394
+ let numRetries = 0, currentDelay = fullOptions.delayMs;
2395
+ while (true) {
2396
+ let result;
2397
+ try {
2398
+ result = await cb();
2399
+ } catch (err) {
2400
+ if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
2401
+ throw err;
2402
+ }
2403
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2404
+ currentDelay *= fullOptions.exponent;
2405
+ numRetries++;
2406
+ continue;
2407
+ }
2408
+ if (!await fullOptions.retryOnValue(result)) {
2409
+ return result;
2410
+ }
2411
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2412
+ currentDelay *= fullOptions.exponent;
2413
+ numRetries++;
2414
+ continue;
2415
+ }
2416
+ };
2347
2417
  export {
2348
2418
  BitField,
2349
2419
  Callback,
@@ -2360,6 +2430,7 @@ export {
2360
2430
  WeakDictionary,
2361
2431
  accessBy,
2362
2432
  arrayMove,
2433
+ arraySwap,
2363
2434
  arrayToBuffer,
2364
2435
  arrayToHex,
2365
2436
  arrayToString,
@@ -2419,8 +2490,12 @@ export {
2419
2490
  intersectBy,
2420
2491
  intersection,
2421
2492
  iosCheck,
2493
+ isBun,
2494
+ isMobile,
2495
+ isMobileOrTablet,
2422
2496
  isNode,
2423
2497
  isNonNullable,
2498
+ isTauri,
2424
2499
  isTruthy,
2425
2500
  joinTables,
2426
2501
  jsonKeyReplacer,
@@ -2436,7 +2511,6 @@ export {
2436
2511
  makeSet,
2437
2512
  mapValues,
2438
2513
  median,
2439
- mobileAndTabletCheck,
2440
2514
  numericalValues,
2441
2515
  omit,
2442
2516
  orderKeys,
@@ -2452,6 +2526,7 @@ export {
2452
2526
  removeBy,
2453
2527
  removeProperties,
2454
2528
  removeUndefinedProperties,
2529
+ retry,
2455
2530
  safariCheck,
2456
2531
  safeAwaitAll,
2457
2532
  safeInstanceof,