@dxos/util 0.8.4-main.3f58842 → 0.8.4-main.548089c
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 +265 -100
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +265 -100
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/di-key.d.ts +3 -3
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/safe-stringify.d.ts +13 -0
- package/dist/types/src/safe-stringify.d.ts.map +1 -0
- package/dist/types/src/string.d.ts +5 -1
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/to-fallback.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts +14 -0
- package/dist/types/src/unit.d.ts.map +1 -0
- package/dist/types/src/unit.test.d.ts +2 -0
- package/dist/types/src/unit.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/array.test.ts +1 -1
- package/src/binder.ts +2 -2
- package/src/circular-buffer.test.ts +1 -1
- package/src/complex.test.ts +1 -1
- package/src/human-hash.test.ts +1 -1
- package/src/index.ts +2 -1
- package/src/position.test.ts +2 -2
- package/src/safe-parse.ts +4 -3
- package/src/safe-stringify.ts +104 -0
- package/src/sort.test.ts +1 -1
- package/src/string.test.ts +1 -1
- package/src/string.ts +32 -6
- package/src/to-fallback.ts +5 -4
- package/src/tree.test.ts +1 -1
- package/src/types.ts +1 -1
- package/src/uint8array.test.ts +1 -1
- package/src/unit.test.ts +25 -0
- package/src/unit.ts +82 -0
- package/src/weak.test.ts +1 -1
- package/dist/types/src/first-two-chars.d.ts +0 -9
- package/dist/types/src/first-two-chars.d.ts.map +0 -1
- package/src/first-two-chars.ts +0 -44
|
@@ -103,10 +103,10 @@ function assumeType(value) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// src/binder.ts
|
|
106
|
-
import
|
|
106
|
+
import { promisify } from "@dxos/node-std/util";
|
|
107
107
|
var createBinder = (obj) => ({
|
|
108
108
|
fn: (fn) => fn.bind(obj),
|
|
109
|
-
async: (fn) =>
|
|
109
|
+
async: (fn) => promisify(fn.bind(obj))
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
// src/bitfield.ts
|
|
@@ -207,6 +207,7 @@ var CallbackCollection = class {
|
|
|
207
207
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
208
208
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
|
|
209
209
|
var Callback = class {
|
|
210
|
+
_callback;
|
|
210
211
|
call(...args) {
|
|
211
212
|
invariant2(this._callback, "Callback not set", {
|
|
212
213
|
F: __dxlog_file2,
|
|
@@ -301,9 +302,10 @@ var chunkArray = (array, size) => {
|
|
|
301
302
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
302
303
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
|
|
303
304
|
var CircularBuffer = class {
|
|
305
|
+
_buffer;
|
|
306
|
+
_nextIndex = 0;
|
|
307
|
+
_elementCount = 0;
|
|
304
308
|
constructor(size) {
|
|
305
|
-
this._nextIndex = 0;
|
|
306
|
-
this._elementCount = 0;
|
|
307
309
|
invariant3(size >= 1, void 0, {
|
|
308
310
|
F: __dxlog_file3,
|
|
309
311
|
L: 13,
|
|
@@ -374,10 +376,11 @@ import { inspect } from "@dxos/node-std/util";
|
|
|
374
376
|
import { inspectObject, raise } from "@dxos/debug";
|
|
375
377
|
var MAX_SERIALIZATION_LENGTH = 10;
|
|
376
378
|
var ComplexSet = class {
|
|
379
|
+
_projection;
|
|
380
|
+
_values = /* @__PURE__ */ new Map();
|
|
377
381
|
// prettier-ignore
|
|
378
382
|
constructor(_projection, values) {
|
|
379
383
|
this._projection = _projection;
|
|
380
|
-
this._values = /* @__PURE__ */ new Map();
|
|
381
384
|
if (values) {
|
|
382
385
|
for (const value of values) {
|
|
383
386
|
this.add(value);
|
|
@@ -467,11 +470,12 @@ var makeSet = (projection) => {
|
|
|
467
470
|
};
|
|
468
471
|
};
|
|
469
472
|
var ComplexMap = class _ComplexMap {
|
|
473
|
+
_keyProjection;
|
|
474
|
+
_keys = /* @__PURE__ */ new Map();
|
|
475
|
+
_values = /* @__PURE__ */ new Map();
|
|
470
476
|
// prettier-ignore
|
|
471
477
|
constructor(_keyProjection, entries2) {
|
|
472
478
|
this._keyProjection = _keyProjection;
|
|
473
|
-
this._keys = /* @__PURE__ */ new Map();
|
|
474
|
-
this._values = /* @__PURE__ */ new Map();
|
|
475
479
|
if (entries2) {
|
|
476
480
|
for (const [key, value] of entries2) {
|
|
477
481
|
this.set(key, value);
|
|
@@ -599,6 +603,7 @@ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
|
599
603
|
// src/defer.ts
|
|
600
604
|
var defer = (fn) => new DeferGuard(fn);
|
|
601
605
|
var DeferGuard = class {
|
|
606
|
+
_fn;
|
|
602
607
|
/**
|
|
603
608
|
* @internal
|
|
604
609
|
*/
|
|
@@ -614,6 +619,7 @@ var DeferGuard = class {
|
|
|
614
619
|
};
|
|
615
620
|
var deferAsync = (fn) => new DeferAsyncGuard(fn);
|
|
616
621
|
var DeferAsyncGuard = class {
|
|
622
|
+
_fn;
|
|
617
623
|
/**
|
|
618
624
|
* @internal
|
|
619
625
|
*/
|
|
@@ -628,6 +634,8 @@ var DeferAsyncGuard = class {
|
|
|
628
634
|
// src/entry.ts
|
|
629
635
|
var entry = (map, key) => new MapEntry(map, key);
|
|
630
636
|
var MapEntry = class {
|
|
637
|
+
_map;
|
|
638
|
+
_key;
|
|
631
639
|
/**
|
|
632
640
|
* @internal
|
|
633
641
|
*/
|
|
@@ -653,33 +661,6 @@ var MapEntry = class {
|
|
|
653
661
|
}
|
|
654
662
|
};
|
|
655
663
|
|
|
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
|
-
};
|
|
682
|
-
|
|
683
664
|
// src/for-each-async.ts
|
|
684
665
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
685
666
|
|
|
@@ -944,6 +925,7 @@ var DEFAULT_WORDLIST = [
|
|
|
944
925
|
"zulu"
|
|
945
926
|
];
|
|
946
927
|
var HumanHasher = class {
|
|
928
|
+
wordlist;
|
|
947
929
|
/**
|
|
948
930
|
* Transforms hex digests to human-readable strings.
|
|
949
931
|
*
|
|
@@ -1209,31 +1191,10 @@ var deepMapValues = (value, fn) => {
|
|
|
1209
1191
|
return new DeepMapper(fn).map(value);
|
|
1210
1192
|
};
|
|
1211
1193
|
var DeepMapper = class {
|
|
1194
|
+
_fn;
|
|
1195
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1212
1196
|
constructor(_fn) {
|
|
1213
1197
|
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
1198
|
}
|
|
1238
1199
|
map(value) {
|
|
1239
1200
|
return this._map(value, void 0);
|
|
@@ -1244,36 +1205,37 @@ var DeepMapper = class {
|
|
|
1244
1205
|
}
|
|
1245
1206
|
return this._fn(value, this._recurse, key);
|
|
1246
1207
|
}
|
|
1208
|
+
_recurse = (value) => {
|
|
1209
|
+
if (this._cyclic.has(value)) {
|
|
1210
|
+
return this._cyclic.get(value);
|
|
1211
|
+
}
|
|
1212
|
+
if (Array.isArray(value)) {
|
|
1213
|
+
const res = new Array(value.length);
|
|
1214
|
+
this._cyclic.set(value, res);
|
|
1215
|
+
for (let i = 0; i < value.length; i++) {
|
|
1216
|
+
res[i] = this._map(value[i], i);
|
|
1217
|
+
}
|
|
1218
|
+
return res;
|
|
1219
|
+
} else if (value !== null && typeof value === "object") {
|
|
1220
|
+
const res = {};
|
|
1221
|
+
this._cyclic.set(value, res);
|
|
1222
|
+
for (const key in value) {
|
|
1223
|
+
res[key] = this._map(value[key], key);
|
|
1224
|
+
}
|
|
1225
|
+
return res;
|
|
1226
|
+
} else {
|
|
1227
|
+
return value;
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1247
1230
|
};
|
|
1248
1231
|
var deepMapValuesAsync = (value, fn) => {
|
|
1249
1232
|
return new DeepMapperAsync(fn).map(value);
|
|
1250
1233
|
};
|
|
1251
1234
|
var DeepMapperAsync = class {
|
|
1235
|
+
_fn;
|
|
1236
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1252
1237
|
constructor(_fn) {
|
|
1253
1238
|
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
1239
|
}
|
|
1278
1240
|
map(value) {
|
|
1279
1241
|
return this._map(value, void 0);
|
|
@@ -1284,6 +1246,28 @@ var DeepMapperAsync = class {
|
|
|
1284
1246
|
}
|
|
1285
1247
|
return this._fn(value, this._recurse, key);
|
|
1286
1248
|
}
|
|
1249
|
+
_recurse = async (value) => {
|
|
1250
|
+
if (this._cyclic.has(value)) {
|
|
1251
|
+
return this._cyclic.get(value);
|
|
1252
|
+
}
|
|
1253
|
+
if (Array.isArray(value)) {
|
|
1254
|
+
const res = new Array(value.length);
|
|
1255
|
+
this._cyclic.set(value, res);
|
|
1256
|
+
for (let i = 0; i < value.length; i++) {
|
|
1257
|
+
res[i] = await this._map(value[i], i);
|
|
1258
|
+
}
|
|
1259
|
+
return res;
|
|
1260
|
+
} else if (value !== null && typeof value === "object") {
|
|
1261
|
+
const res = {};
|
|
1262
|
+
this._cyclic.set(value, res);
|
|
1263
|
+
for (const key in value) {
|
|
1264
|
+
res[key] = await this._map(value[key], key);
|
|
1265
|
+
}
|
|
1266
|
+
return res;
|
|
1267
|
+
} else {
|
|
1268
|
+
return value;
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1287
1271
|
};
|
|
1288
1272
|
var visitValues = (object, visitor) => {
|
|
1289
1273
|
if (Array.isArray(object)) {
|
|
@@ -1605,7 +1589,7 @@ var safeParseInt = (value, defaultValue) => {
|
|
|
1605
1589
|
try {
|
|
1606
1590
|
const n = parseInt(value ?? "");
|
|
1607
1591
|
return isNaN(n) ? defaultValue : n;
|
|
1608
|
-
} catch
|
|
1592
|
+
} catch {
|
|
1609
1593
|
return defaultValue;
|
|
1610
1594
|
}
|
|
1611
1595
|
};
|
|
@@ -1620,18 +1604,87 @@ var safeParseJson = (data, defaultValue) => {
|
|
|
1620
1604
|
if (data && data.length > 0) {
|
|
1621
1605
|
try {
|
|
1622
1606
|
return JSON.parse(data);
|
|
1623
|
-
} catch
|
|
1607
|
+
} catch {
|
|
1624
1608
|
}
|
|
1625
1609
|
}
|
|
1626
1610
|
return defaultValue;
|
|
1627
1611
|
};
|
|
1628
1612
|
|
|
1613
|
+
// src/safe-stringify.ts
|
|
1614
|
+
var SKIP = Object.freeze({});
|
|
1615
|
+
function safeStringify(obj, filter = defaultFilter, indent = 2) {
|
|
1616
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1617
|
+
function replacer(key, value) {
|
|
1618
|
+
if (typeof value === "object" && value !== null) {
|
|
1619
|
+
if (seen.has(value)) {
|
|
1620
|
+
return "[Circular]";
|
|
1621
|
+
}
|
|
1622
|
+
seen.add(value);
|
|
1623
|
+
}
|
|
1624
|
+
if (filter) {
|
|
1625
|
+
const v2 = filter?.(key, value);
|
|
1626
|
+
if (v2 !== void 0) {
|
|
1627
|
+
return v2 === SKIP ? void 0 : v2;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return value;
|
|
1631
|
+
}
|
|
1632
|
+
let result = "";
|
|
1633
|
+
try {
|
|
1634
|
+
result = JSON.stringify(obj, replacer, indent);
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
result = `Error: ${error.message}`;
|
|
1637
|
+
}
|
|
1638
|
+
return result;
|
|
1639
|
+
}
|
|
1640
|
+
var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
|
|
1641
|
+
let currentDepth = 0;
|
|
1642
|
+
const depthMap = /* @__PURE__ */ new WeakMap();
|
|
1643
|
+
return function(key, value) {
|
|
1644
|
+
if (key === "") {
|
|
1645
|
+
currentDepth = 0;
|
|
1646
|
+
} else if (this && typeof this === "object") {
|
|
1647
|
+
const parentDepth = depthMap.get(this) ?? 0;
|
|
1648
|
+
currentDepth = parentDepth + 1;
|
|
1649
|
+
}
|
|
1650
|
+
if (typeof value === "function") {
|
|
1651
|
+
return void 0;
|
|
1652
|
+
}
|
|
1653
|
+
if (value && typeof value === "object") {
|
|
1654
|
+
depthMap.set(value, currentDepth);
|
|
1655
|
+
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
1656
|
+
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
if (omit2?.includes(key)) {
|
|
1660
|
+
return void 0;
|
|
1661
|
+
}
|
|
1662
|
+
if (parse?.includes(key) && typeof value === "string") {
|
|
1663
|
+
try {
|
|
1664
|
+
return JSON.parse(value);
|
|
1665
|
+
} catch {
|
|
1666
|
+
return value;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
|
|
1670
|
+
return `[length: ${value.length}]`;
|
|
1671
|
+
}
|
|
1672
|
+
if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
|
|
1673
|
+
return value.slice(0, maxStringLen) + "...";
|
|
1674
|
+
}
|
|
1675
|
+
return value;
|
|
1676
|
+
};
|
|
1677
|
+
};
|
|
1678
|
+
var defaultFilter = createReplacer();
|
|
1679
|
+
|
|
1629
1680
|
// src/sliding-window-summary.ts
|
|
1630
1681
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1631
1682
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
1632
1683
|
var SlidingWindowSummary = class {
|
|
1684
|
+
_buffer;
|
|
1685
|
+
_sum = 0;
|
|
1686
|
+
_precision;
|
|
1633
1687
|
constructor(options) {
|
|
1634
|
-
this._sum = 0;
|
|
1635
1688
|
this._buffer = new CircularBuffer(options.dataPoints);
|
|
1636
1689
|
if (options.precision != null) {
|
|
1637
1690
|
invariant5(options.precision >= 0, void 0, {
|
|
@@ -1711,12 +1764,24 @@ var capitalize = (str) => {
|
|
|
1711
1764
|
}
|
|
1712
1765
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1713
1766
|
};
|
|
1714
|
-
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1767
|
+
function trim(strings, ...values) {
|
|
1768
|
+
const raw = strings.reduce((out, str, i) => {
|
|
1769
|
+
out += str;
|
|
1770
|
+
if (i < values.length) {
|
|
1771
|
+
const match = str.match(/(^|\n)([ \t]*)$/);
|
|
1772
|
+
const baseIndent = match ? match[2] : "";
|
|
1773
|
+
const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
|
|
1774
|
+
out += val;
|
|
1775
|
+
}
|
|
1776
|
+
return out;
|
|
1777
|
+
}, "");
|
|
1778
|
+
const lines = raw.split("\n");
|
|
1779
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
1780
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
1781
|
+
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1782
|
+
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1783
|
+
}
|
|
1784
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1720
1785
|
|
|
1721
1786
|
// src/sum.ts
|
|
1722
1787
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -1915,10 +1980,8 @@ var toFallback = (hash) => {
|
|
|
1915
1980
|
|
|
1916
1981
|
// src/tracer.ts
|
|
1917
1982
|
var Tracer = class {
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
this._recording = false;
|
|
1921
|
-
}
|
|
1983
|
+
_events = /* @__PURE__ */ new Map();
|
|
1984
|
+
_recording = false;
|
|
1922
1985
|
// TODO(burdon): Start/stop methods for recording data? By id?
|
|
1923
1986
|
// Alternatively, enable subscriptions to track/compute series.
|
|
1924
1987
|
// TODO(burdon): Hierarchical traces?
|
|
@@ -2019,7 +2082,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2019
2082
|
};
|
|
2020
2083
|
|
|
2021
2084
|
// src/types.ts
|
|
2022
|
-
var
|
|
2085
|
+
var isTruthy = (value) => !!value;
|
|
2023
2086
|
var isNonNullable = (value) => value != null;
|
|
2024
2087
|
var doAsync = async (fn) => fn();
|
|
2025
2088
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2050,6 +2113,103 @@ var arrayMove = (array, from, to) => {
|
|
|
2050
2113
|
return array;
|
|
2051
2114
|
};
|
|
2052
2115
|
|
|
2116
|
+
// src/unit.ts
|
|
2117
|
+
var createFormat = (unit) => {
|
|
2118
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2119
|
+
const value = n / unit.quotient;
|
|
2120
|
+
return {
|
|
2121
|
+
unit,
|
|
2122
|
+
value,
|
|
2123
|
+
formattedValue: value.toFixed(precision),
|
|
2124
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2125
|
+
};
|
|
2126
|
+
};
|
|
2127
|
+
};
|
|
2128
|
+
var MS_SECONDS = 1e3;
|
|
2129
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2130
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2131
|
+
var Unit = {
|
|
2132
|
+
// General.
|
|
2133
|
+
Percent: createFormat({
|
|
2134
|
+
symbol: "%",
|
|
2135
|
+
quotient: 1 / 100,
|
|
2136
|
+
precision: 2
|
|
2137
|
+
}),
|
|
2138
|
+
Thousand: createFormat({
|
|
2139
|
+
symbol: "k",
|
|
2140
|
+
quotient: 1e3,
|
|
2141
|
+
precision: 2
|
|
2142
|
+
}),
|
|
2143
|
+
// Bytes (note KB vs KiB).
|
|
2144
|
+
Gigabyte: createFormat({
|
|
2145
|
+
symbol: "GB",
|
|
2146
|
+
quotient: 1e3 * 1e3 * 1e3,
|
|
2147
|
+
precision: 2
|
|
2148
|
+
}),
|
|
2149
|
+
Megabyte: createFormat({
|
|
2150
|
+
symbol: "MB",
|
|
2151
|
+
quotient: 1e3 * 1e3,
|
|
2152
|
+
precision: 2
|
|
2153
|
+
}),
|
|
2154
|
+
Kilobyte: createFormat({
|
|
2155
|
+
symbol: "KB",
|
|
2156
|
+
quotient: 1e3,
|
|
2157
|
+
precision: 2
|
|
2158
|
+
}),
|
|
2159
|
+
// Time.
|
|
2160
|
+
Hour: createFormat({
|
|
2161
|
+
symbol: "h",
|
|
2162
|
+
quotient: MS_HOURS
|
|
2163
|
+
}),
|
|
2164
|
+
Minute: createFormat({
|
|
2165
|
+
symbol: "m",
|
|
2166
|
+
quotient: MS_MINUTES
|
|
2167
|
+
}),
|
|
2168
|
+
Second: createFormat({
|
|
2169
|
+
symbol: "s",
|
|
2170
|
+
quotient: MS_SECONDS,
|
|
2171
|
+
precision: 1
|
|
2172
|
+
}),
|
|
2173
|
+
Millisecond: createFormat({
|
|
2174
|
+
symbol: "ms",
|
|
2175
|
+
quotient: 1
|
|
2176
|
+
}),
|
|
2177
|
+
Duration: (n) => {
|
|
2178
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2179
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2180
|
+
if (hours) {
|
|
2181
|
+
const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2182
|
+
return {
|
|
2183
|
+
unit: {
|
|
2184
|
+
symbol: "h",
|
|
2185
|
+
quotient: MS_HOURS
|
|
2186
|
+
},
|
|
2187
|
+
value: hours,
|
|
2188
|
+
formattedValue,
|
|
2189
|
+
toString: () => formattedValue
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
if (minutes) {
|
|
2193
|
+
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2194
|
+
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2195
|
+
return {
|
|
2196
|
+
unit: {
|
|
2197
|
+
symbol: "m",
|
|
2198
|
+
quotient: MS_MINUTES
|
|
2199
|
+
},
|
|
2200
|
+
value: minutes,
|
|
2201
|
+
formattedValue,
|
|
2202
|
+
toString: () => formattedValue
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
const seconds = n >= MS_SECONDS;
|
|
2206
|
+
if (seconds) {
|
|
2207
|
+
return Unit.Second(n);
|
|
2208
|
+
}
|
|
2209
|
+
return Unit.Millisecond(n);
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
2212
|
+
|
|
2053
2213
|
// src/url.ts
|
|
2054
2214
|
var createUrl = (url, search) => {
|
|
2055
2215
|
const base = typeof url === "string" ? new URL(url) : url;
|
|
@@ -2061,11 +2221,11 @@ var createUrl = (url, search) => {
|
|
|
2061
2221
|
|
|
2062
2222
|
// src/weak.ts
|
|
2063
2223
|
var WeakDictionary = class {
|
|
2224
|
+
_internal = /* @__PURE__ */ new Map();
|
|
2225
|
+
_finalization = new FinalizationRegistry((cleanUpCallback) => {
|
|
2226
|
+
cleanUpCallback();
|
|
2227
|
+
});
|
|
2064
2228
|
constructor(entries2) {
|
|
2065
|
-
this._internal = /* @__PURE__ */ new Map();
|
|
2066
|
-
this._finalization = new FinalizationRegistry((cleanUpCallback) => {
|
|
2067
|
-
cleanUpCallback();
|
|
2068
|
-
});
|
|
2069
2229
|
this._internal = new Map(entries2?.map(([key, value]) => [
|
|
2070
2230
|
key,
|
|
2071
2231
|
new WeakRef(value)
|
|
@@ -2162,8 +2322,10 @@ export {
|
|
|
2162
2322
|
ComplexSet,
|
|
2163
2323
|
HumanHasher,
|
|
2164
2324
|
MapEntry,
|
|
2325
|
+
SKIP,
|
|
2165
2326
|
SlidingWindowSummary,
|
|
2166
2327
|
Tracer,
|
|
2328
|
+
Unit,
|
|
2167
2329
|
WeakDictionary,
|
|
2168
2330
|
accessBy,
|
|
2169
2331
|
arrayMove,
|
|
@@ -2185,11 +2347,13 @@ export {
|
|
|
2185
2347
|
createBinder,
|
|
2186
2348
|
createBucketReducer,
|
|
2187
2349
|
createGroupReducer,
|
|
2350
|
+
createReplacer,
|
|
2188
2351
|
createSetDispatch,
|
|
2189
2352
|
createUrl,
|
|
2190
2353
|
decamelize,
|
|
2191
2354
|
deepMapValues,
|
|
2192
2355
|
deepMapValuesAsync,
|
|
2356
|
+
defaultFilter,
|
|
2193
2357
|
defaultMap,
|
|
2194
2358
|
defer,
|
|
2195
2359
|
deferAsync,
|
|
@@ -2206,7 +2370,6 @@ export {
|
|
|
2206
2370
|
getDate,
|
|
2207
2371
|
getDebugName,
|
|
2208
2372
|
getDeep,
|
|
2209
|
-
getFirstTwoRenderableChars,
|
|
2210
2373
|
getHostPlatform,
|
|
2211
2374
|
getPrototypeSpecificInstanceId,
|
|
2212
2375
|
getProviderValue,
|
|
@@ -2224,12 +2387,13 @@ export {
|
|
|
2224
2387
|
iosCheck,
|
|
2225
2388
|
isNode,
|
|
2226
2389
|
isNonNullable,
|
|
2227
|
-
|
|
2390
|
+
isTruthy,
|
|
2228
2391
|
joinTables,
|
|
2229
2392
|
jsonKeyReplacer,
|
|
2230
2393
|
jsonReplacer,
|
|
2231
2394
|
jsonify,
|
|
2232
2395
|
jsonlogify,
|
|
2396
|
+
kebabize,
|
|
2233
2397
|
keyToEmoji,
|
|
2234
2398
|
keyToFallback,
|
|
2235
2399
|
keyToHue,
|
|
@@ -2260,6 +2424,7 @@ export {
|
|
|
2260
2424
|
safeParseFloat,
|
|
2261
2425
|
safeParseInt,
|
|
2262
2426
|
safeParseJson,
|
|
2427
|
+
safeStringify,
|
|
2263
2428
|
set,
|
|
2264
2429
|
setDeep,
|
|
2265
2430
|
sortKeys,
|