@dxos/util 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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.
- package/dist/lib/browser/index.mjs +273 -60
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +273 -60
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/array.d.ts +3 -2
- package/dist/types/src/array.d.ts.map +1 -1
- package/dist/types/src/deep.d.ts.map +1 -1
- package/dist/types/src/defer.d.ts +1 -1
- package/dist/types/src/defer.d.ts.map +1 -1
- package/dist/types/src/error-format.d.ts +5 -0
- package/dist/types/src/error-format.d.ts.map +1 -0
- package/dist/types/src/filename.d.ts +9 -0
- package/dist/types/src/filename.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +4 -1
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/retry.d.ts +32 -0
- package/dist/types/src/retry.d.ts.map +1 -0
- package/dist/types/src/safe-parse.d.ts +6 -4
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/safe-stringify.d.ts +22 -0
- package/dist/types/src/safe-stringify.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +22 -4
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts +12 -13
- package/dist/types/src/unit.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -7
- package/src/array.ts +9 -2
- package/src/binder.ts +2 -2
- package/src/deep.ts +2 -0
- package/src/defer.ts +1 -1
- package/src/error-format.ts +22 -0
- package/src/filename.ts +16 -0
- package/src/index.ts +4 -0
- package/src/platform.ts +11 -1
- package/src/retry.ts +74 -0
- package/src/safe-parse.ts +19 -16
- package/src/safe-stringify.ts +146 -0
- package/src/types.test.ts +11 -1
- package/src/types.ts +37 -9
- package/src/unit.test.ts +1 -1
- package/src/unit.ts +59 -28
- package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
- package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
- package/src/explicit-resource-management-polyfill.ts +0 -13
|
@@ -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
|
|
114
|
+
import { promisify } from "@dxos/node-std/util";
|
|
107
115
|
var createBinder = (obj) => ({
|
|
108
116
|
fn: (fn) => fn.bind(obj),
|
|
109
|
-
async: (fn) =>
|
|
117
|
+
async: (fn) => promisify(fn.bind(obj))
|
|
110
118
|
});
|
|
111
119
|
|
|
112
120
|
// src/bitfield.ts
|
|
@@ -596,11 +604,8 @@ var getDeep = (obj, path) => {
|
|
|
596
604
|
// src/defer-function.ts
|
|
597
605
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
598
606
|
|
|
599
|
-
// src/explicit-resource-management-polyfill.ts
|
|
600
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
601
|
-
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
602
|
-
|
|
603
607
|
// src/defer.ts
|
|
608
|
+
import "@hazae41/symbol-dispose-polyfill";
|
|
604
609
|
var defer = (fn) => new DeferGuard(fn);
|
|
605
610
|
var DeferGuard = class {
|
|
606
611
|
_fn;
|
|
@@ -661,6 +666,12 @@ var MapEntry = class {
|
|
|
661
666
|
}
|
|
662
667
|
};
|
|
663
668
|
|
|
669
|
+
// src/filename.ts
|
|
670
|
+
var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
|
|
671
|
+
date.toISOString().replace(/[:.]/g, "-"),
|
|
672
|
+
...parts
|
|
673
|
+
].join("_") + (ext ? `.${ext}` : "");
|
|
674
|
+
|
|
664
675
|
// src/for-each-async.ts
|
|
665
676
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
666
677
|
|
|
@@ -1356,7 +1367,18 @@ var omit = (obj, keys2) => {
|
|
|
1356
1367
|
|
|
1357
1368
|
// src/platform.ts
|
|
1358
1369
|
var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
1359
|
-
var
|
|
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 = () => {
|
|
1360
1382
|
let check = false;
|
|
1361
1383
|
((a) => {
|
|
1362
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))) {
|
|
@@ -1585,31 +1607,115 @@ var safeInstanceof = (tag) => (target) => {
|
|
|
1585
1607
|
};
|
|
1586
1608
|
|
|
1587
1609
|
// src/safe-parse.ts
|
|
1588
|
-
|
|
1610
|
+
function safeParseInt(str, defaultValue) {
|
|
1589
1611
|
try {
|
|
1590
|
-
const
|
|
1591
|
-
return isNaN(
|
|
1612
|
+
const value = parseInt(str ?? "");
|
|
1613
|
+
return isNaN(value) ? defaultValue : value;
|
|
1592
1614
|
} catch {
|
|
1593
1615
|
return defaultValue;
|
|
1594
1616
|
}
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1617
|
+
}
|
|
1618
|
+
function safeParseFloat(str, defaultValue) {
|
|
1597
1619
|
try {
|
|
1598
|
-
|
|
1620
|
+
const value = parseFloat(str ?? "");
|
|
1621
|
+
return isNaN(value) ? defaultValue : value;
|
|
1599
1622
|
} catch {
|
|
1600
|
-
return defaultValue
|
|
1623
|
+
return defaultValue;
|
|
1601
1624
|
}
|
|
1602
|
-
}
|
|
1603
|
-
var safeParseJson = (
|
|
1604
|
-
if (
|
|
1625
|
+
}
|
|
1626
|
+
var safeParseJson = (str, defaultValue) => {
|
|
1627
|
+
if (str && str.length > 0) {
|
|
1605
1628
|
try {
|
|
1606
|
-
return JSON.parse(
|
|
1629
|
+
return JSON.parse(str);
|
|
1607
1630
|
} catch {
|
|
1608
1631
|
}
|
|
1609
1632
|
}
|
|
1610
1633
|
return defaultValue;
|
|
1611
1634
|
};
|
|
1612
1635
|
|
|
1636
|
+
// src/safe-stringify.ts
|
|
1637
|
+
var SKIP = Object.freeze({});
|
|
1638
|
+
function safeStringify(obj, filter = defaultFilter, indent = 2) {
|
|
1639
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
1640
|
+
function replacer(key, value) {
|
|
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;
|
|
1649
|
+
}
|
|
1650
|
+
if (value == null) {
|
|
1651
|
+
return value;
|
|
1652
|
+
}
|
|
1653
|
+
if (typeof value === "function") {
|
|
1654
|
+
return void 0;
|
|
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}`;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return JSON.stringify(obj, replacer, indent);
|
|
1678
|
+
}
|
|
1679
|
+
var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
|
|
1680
|
+
let currentDepth = 0;
|
|
1681
|
+
const depthMap = /* @__PURE__ */ new WeakMap();
|
|
1682
|
+
return function(key, value) {
|
|
1683
|
+
if (key === "") {
|
|
1684
|
+
currentDepth = 0;
|
|
1685
|
+
} else if (this && typeof this === "object") {
|
|
1686
|
+
const parentDepth = depthMap.get(this) ?? 0;
|
|
1687
|
+
currentDepth = parentDepth + 1;
|
|
1688
|
+
}
|
|
1689
|
+
if (typeof value === "function") {
|
|
1690
|
+
return SKIP;
|
|
1691
|
+
}
|
|
1692
|
+
if (value && typeof value === "object") {
|
|
1693
|
+
depthMap.set(value, currentDepth);
|
|
1694
|
+
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
1695
|
+
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (omit2?.includes(key)) {
|
|
1699
|
+
return SKIP;
|
|
1700
|
+
}
|
|
1701
|
+
if (parse?.includes(key) && typeof value === "string") {
|
|
1702
|
+
try {
|
|
1703
|
+
return JSON.parse(value);
|
|
1704
|
+
} catch {
|
|
1705
|
+
return value;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
|
|
1709
|
+
return `[length: ${value.length}]`;
|
|
1710
|
+
}
|
|
1711
|
+
if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
|
|
1712
|
+
return value.slice(0, maxStringLen) + "...";
|
|
1713
|
+
}
|
|
1714
|
+
return value;
|
|
1715
|
+
};
|
|
1716
|
+
};
|
|
1717
|
+
var defaultFilter = createReplacer();
|
|
1718
|
+
|
|
1613
1719
|
// src/sliding-window-summary.ts
|
|
1614
1720
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1615
1721
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
@@ -2045,69 +2151,112 @@ var arrayMove = (array, from, to) => {
|
|
|
2045
2151
|
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
|
|
2046
2152
|
return array;
|
|
2047
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
|
+
}
|
|
2048
2160
|
|
|
2049
2161
|
// src/unit.ts
|
|
2050
|
-
var
|
|
2051
|
-
return (n, precision =
|
|
2162
|
+
var createFormat = (unit) => {
|
|
2163
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2052
2164
|
const value = n / unit.quotient;
|
|
2053
|
-
return
|
|
2165
|
+
return {
|
|
2166
|
+
unit,
|
|
2167
|
+
value,
|
|
2168
|
+
formattedValue: value.toFixed(precision),
|
|
2169
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2170
|
+
};
|
|
2054
2171
|
};
|
|
2055
2172
|
};
|
|
2173
|
+
var MS_SECONDS = 1e3;
|
|
2174
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2175
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2056
2176
|
var Unit = {
|
|
2057
|
-
//
|
|
2058
|
-
|
|
2177
|
+
// General.
|
|
2178
|
+
Percent: createFormat({
|
|
2179
|
+
symbol: "%",
|
|
2180
|
+
quotient: 1 / 100,
|
|
2181
|
+
precision: 2
|
|
2182
|
+
}),
|
|
2183
|
+
Thousand: createFormat({
|
|
2184
|
+
symbol: "k",
|
|
2185
|
+
quotient: 1e3,
|
|
2186
|
+
precision: 2
|
|
2187
|
+
}),
|
|
2188
|
+
// Bytes (note KB vs KiB).
|
|
2189
|
+
Gigabyte: createFormat({
|
|
2190
|
+
symbol: "GB",
|
|
2191
|
+
quotient: 1e3 * 1e3 * 1e3,
|
|
2192
|
+
precision: 2
|
|
2193
|
+
}),
|
|
2194
|
+
Megabyte: createFormat({
|
|
2195
|
+
symbol: "MB",
|
|
2196
|
+
quotient: 1e3 * 1e3,
|
|
2197
|
+
precision: 2
|
|
2198
|
+
}),
|
|
2199
|
+
Kilobyte: createFormat({
|
|
2200
|
+
symbol: "KB",
|
|
2201
|
+
quotient: 1e3,
|
|
2202
|
+
precision: 2
|
|
2203
|
+
}),
|
|
2204
|
+
Byte: createFormat({
|
|
2205
|
+
symbol: "B",
|
|
2206
|
+
quotient: 1
|
|
2207
|
+
}),
|
|
2208
|
+
// Time.
|
|
2209
|
+
Hour: createFormat({
|
|
2059
2210
|
symbol: "h",
|
|
2060
|
-
quotient:
|
|
2211
|
+
quotient: MS_HOURS
|
|
2061
2212
|
}),
|
|
2062
|
-
Minute:
|
|
2213
|
+
Minute: createFormat({
|
|
2063
2214
|
symbol: "m",
|
|
2064
|
-
quotient:
|
|
2215
|
+
quotient: MS_MINUTES
|
|
2065
2216
|
}),
|
|
2066
|
-
Second:
|
|
2217
|
+
Second: createFormat({
|
|
2067
2218
|
symbol: "s",
|
|
2068
|
-
quotient:
|
|
2219
|
+
quotient: MS_SECONDS,
|
|
2220
|
+
precision: 1
|
|
2069
2221
|
}),
|
|
2070
|
-
Millisecond:
|
|
2222
|
+
Millisecond: createFormat({
|
|
2071
2223
|
symbol: "ms",
|
|
2072
2224
|
quotient: 1
|
|
2073
2225
|
}),
|
|
2074
2226
|
Duration: (n) => {
|
|
2075
|
-
const hours = Math.floor(n /
|
|
2076
|
-
const minutes = Math.floor(n %
|
|
2227
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2228
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2077
2229
|
if (hours) {
|
|
2078
|
-
|
|
2230
|
+
const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2231
|
+
return {
|
|
2232
|
+
unit: {
|
|
2233
|
+
symbol: "h",
|
|
2234
|
+
quotient: MS_HOURS
|
|
2235
|
+
},
|
|
2236
|
+
value: hours,
|
|
2237
|
+
formattedValue,
|
|
2238
|
+
toString: () => formattedValue
|
|
2239
|
+
};
|
|
2079
2240
|
}
|
|
2080
|
-
const seconds = Math.floor(n % (60 * 1e3) / 1e3);
|
|
2081
2241
|
if (minutes) {
|
|
2082
|
-
|
|
2242
|
+
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2243
|
+
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2244
|
+
return {
|
|
2245
|
+
unit: {
|
|
2246
|
+
symbol: "m",
|
|
2247
|
+
quotient: MS_MINUTES
|
|
2248
|
+
},
|
|
2249
|
+
value: minutes,
|
|
2250
|
+
formattedValue,
|
|
2251
|
+
toString: () => formattedValue
|
|
2252
|
+
};
|
|
2083
2253
|
}
|
|
2254
|
+
const seconds = n >= MS_SECONDS;
|
|
2084
2255
|
if (seconds) {
|
|
2085
|
-
return
|
|
2256
|
+
return Unit.Second(n);
|
|
2086
2257
|
}
|
|
2087
|
-
return
|
|
2088
|
-
}
|
|
2089
|
-
// bytes (note KB via KiB).
|
|
2090
|
-
Gigabyte: Formatter({
|
|
2091
|
-
symbol: "GB",
|
|
2092
|
-
quotient: 1e3 * 1e3 * 1e3
|
|
2093
|
-
}),
|
|
2094
|
-
Megabyte: Formatter({
|
|
2095
|
-
symbol: "MB",
|
|
2096
|
-
quotient: 1e3 * 1e3
|
|
2097
|
-
}),
|
|
2098
|
-
Kilobyte: Formatter({
|
|
2099
|
-
symbol: "KB",
|
|
2100
|
-
quotient: 1e3
|
|
2101
|
-
}),
|
|
2102
|
-
// general.
|
|
2103
|
-
Thousand: Formatter({
|
|
2104
|
-
symbol: "k",
|
|
2105
|
-
quotient: 1e3
|
|
2106
|
-
}),
|
|
2107
|
-
Percent: Formatter({
|
|
2108
|
-
symbol: "%",
|
|
2109
|
-
quotient: 1 / 100
|
|
2110
|
-
})
|
|
2258
|
+
return Unit.Millisecond(n);
|
|
2259
|
+
}
|
|
2111
2260
|
};
|
|
2112
2261
|
|
|
2113
2262
|
// src/url.ts
|
|
@@ -2213,6 +2362,58 @@ var WeakDictionary = class {
|
|
|
2213
2362
|
this._finalization.unregister(value);
|
|
2214
2363
|
}
|
|
2215
2364
|
};
|
|
2365
|
+
|
|
2366
|
+
// src/error-format.ts
|
|
2367
|
+
var formatErrorWithCauses = (error) => {
|
|
2368
|
+
const lines = [];
|
|
2369
|
+
let current = error;
|
|
2370
|
+
let level = 0;
|
|
2371
|
+
while (current) {
|
|
2372
|
+
const prefix = level === 0 ? "" : `Caused by: `;
|
|
2373
|
+
lines.push(prefix + (current.stack ?? String(current)));
|
|
2374
|
+
if (!(current.cause instanceof Error)) break;
|
|
2375
|
+
current = current.cause;
|
|
2376
|
+
level += 1;
|
|
2377
|
+
}
|
|
2378
|
+
return lines.join("\n\n");
|
|
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
|
+
};
|
|
2216
2417
|
export {
|
|
2217
2418
|
BitField,
|
|
2218
2419
|
Callback,
|
|
@@ -2222,12 +2423,14 @@ export {
|
|
|
2222
2423
|
ComplexSet,
|
|
2223
2424
|
HumanHasher,
|
|
2224
2425
|
MapEntry,
|
|
2426
|
+
SKIP,
|
|
2225
2427
|
SlidingWindowSummary,
|
|
2226
2428
|
Tracer,
|
|
2227
2429
|
Unit,
|
|
2228
2430
|
WeakDictionary,
|
|
2229
2431
|
accessBy,
|
|
2230
2432
|
arrayMove,
|
|
2433
|
+
arraySwap,
|
|
2231
2434
|
arrayToBuffer,
|
|
2232
2435
|
arrayToHex,
|
|
2233
2436
|
arrayToString,
|
|
@@ -2239,18 +2442,22 @@ export {
|
|
|
2239
2442
|
chunkArray,
|
|
2240
2443
|
clamp,
|
|
2241
2444
|
clearUndefined,
|
|
2445
|
+
coerceArray,
|
|
2242
2446
|
compareMulti,
|
|
2243
2447
|
compareObject,
|
|
2244
2448
|
compareScalar,
|
|
2245
2449
|
compareString,
|
|
2246
2450
|
createBinder,
|
|
2247
2451
|
createBucketReducer,
|
|
2452
|
+
createFilename,
|
|
2248
2453
|
createGroupReducer,
|
|
2454
|
+
createReplacer,
|
|
2249
2455
|
createSetDispatch,
|
|
2250
2456
|
createUrl,
|
|
2251
2457
|
decamelize,
|
|
2252
2458
|
deepMapValues,
|
|
2253
2459
|
deepMapValuesAsync,
|
|
2460
|
+
defaultFilter,
|
|
2254
2461
|
defaultMap,
|
|
2255
2462
|
defer,
|
|
2256
2463
|
deferAsync,
|
|
@@ -2262,6 +2469,7 @@ export {
|
|
|
2262
2469
|
entry,
|
|
2263
2470
|
exponentialBackoffInterval,
|
|
2264
2471
|
forEachAsync,
|
|
2472
|
+
formatErrorWithCauses,
|
|
2265
2473
|
get,
|
|
2266
2474
|
getAsyncProviderValue,
|
|
2267
2475
|
getDate,
|
|
@@ -2282,8 +2490,12 @@ export {
|
|
|
2282
2490
|
intersectBy,
|
|
2283
2491
|
intersection,
|
|
2284
2492
|
iosCheck,
|
|
2493
|
+
isBun,
|
|
2494
|
+
isMobile,
|
|
2495
|
+
isMobileOrTablet,
|
|
2285
2496
|
isNode,
|
|
2286
2497
|
isNonNullable,
|
|
2498
|
+
isTauri,
|
|
2287
2499
|
isTruthy,
|
|
2288
2500
|
joinTables,
|
|
2289
2501
|
jsonKeyReplacer,
|
|
@@ -2299,7 +2511,6 @@ export {
|
|
|
2299
2511
|
makeSet,
|
|
2300
2512
|
mapValues,
|
|
2301
2513
|
median,
|
|
2302
|
-
mobileAndTabletCheck,
|
|
2303
2514
|
numericalValues,
|
|
2304
2515
|
omit,
|
|
2305
2516
|
orderKeys,
|
|
@@ -2315,12 +2526,14 @@ export {
|
|
|
2315
2526
|
removeBy,
|
|
2316
2527
|
removeProperties,
|
|
2317
2528
|
removeUndefinedProperties,
|
|
2529
|
+
retry,
|
|
2318
2530
|
safariCheck,
|
|
2319
2531
|
safeAwaitAll,
|
|
2320
2532
|
safeInstanceof,
|
|
2321
2533
|
safeParseFloat,
|
|
2322
2534
|
safeParseInt,
|
|
2323
2535
|
safeParseJson,
|
|
2536
|
+
safeStringify,
|
|
2324
2537
|
set,
|
|
2325
2538
|
setDeep,
|
|
2326
2539
|
sortKeys,
|