@dxos/util 0.8.4-main.f9ba587 → 0.8.4-main.fffef41
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 +268 -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 +268 -100
- 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.map +1 -1
- package/dist/types/src/assume.d.ts.map +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 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/json.d.ts +1 -1
- package/dist/types/src/json.d.ts.map +1 -1
- package/dist/types/src/object.d.ts +3 -0
- package/dist/types/src/object.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 +8 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/string.test.d.ts +2 -0
- package/dist/types/src/string.test.d.ts.map +1 -0
- 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 +9 -9
- package/src/array.test.ts +1 -1
- package/src/array.ts +0 -2
- package/src/assume.ts +0 -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 -2
- package/src/json.ts +2 -7
- package/src/object.ts +3 -0
- package/src/position.test.ts +2 -2
- package/src/safe-parse.ts +6 -3
- package/src/safe-stringify.ts +104 -0
- package/src/sort.test.ts +1 -1
- package/src/string.test.ts +19 -0
- package/src/string.ts +36 -0
- 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);
|
|
@@ -592,13 +596,10 @@ var getDeep = (obj, path) => {
|
|
|
592
596
|
// src/defer-function.ts
|
|
593
597
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
594
598
|
|
|
595
|
-
// src/explicit-resource-management-polyfill.ts
|
|
596
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
597
|
-
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
598
|
-
|
|
599
599
|
// src/defer.ts
|
|
600
600
|
var defer = (fn) => new DeferGuard(fn);
|
|
601
601
|
var DeferGuard = class {
|
|
602
|
+
_fn;
|
|
602
603
|
/**
|
|
603
604
|
* @internal
|
|
604
605
|
*/
|
|
@@ -614,6 +615,7 @@ var DeferGuard = class {
|
|
|
614
615
|
};
|
|
615
616
|
var deferAsync = (fn) => new DeferAsyncGuard(fn);
|
|
616
617
|
var DeferAsyncGuard = class {
|
|
618
|
+
_fn;
|
|
617
619
|
/**
|
|
618
620
|
* @internal
|
|
619
621
|
*/
|
|
@@ -628,6 +630,8 @@ var DeferAsyncGuard = class {
|
|
|
628
630
|
// src/entry.ts
|
|
629
631
|
var entry = (map, key) => new MapEntry(map, key);
|
|
630
632
|
var MapEntry = class {
|
|
633
|
+
_map;
|
|
634
|
+
_key;
|
|
631
635
|
/**
|
|
632
636
|
* @internal
|
|
633
637
|
*/
|
|
@@ -653,33 +657,6 @@ var MapEntry = class {
|
|
|
653
657
|
}
|
|
654
658
|
};
|
|
655
659
|
|
|
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
660
|
// src/for-each-async.ts
|
|
684
661
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
685
662
|
|
|
@@ -944,6 +921,7 @@ var DEFAULT_WORDLIST = [
|
|
|
944
921
|
"zulu"
|
|
945
922
|
];
|
|
946
923
|
var HumanHasher = class {
|
|
924
|
+
wordlist;
|
|
947
925
|
/**
|
|
948
926
|
* Transforms hex digests to human-readable strings.
|
|
949
927
|
*
|
|
@@ -1109,7 +1087,7 @@ var arrayToString = (array) => arrayToBuffer(array).toString("hex");
|
|
|
1109
1087
|
// src/json.ts
|
|
1110
1088
|
var MAX_DEPTH = 5;
|
|
1111
1089
|
var LOG_MAX_DEPTH = 7;
|
|
1112
|
-
|
|
1090
|
+
var jsonReplacer = (key, value) => {
|
|
1113
1091
|
if (value !== null && typeof value === "object" && typeof value[inspect2.custom] === "function") {
|
|
1114
1092
|
return value[inspect2.custom]();
|
|
1115
1093
|
}
|
|
@@ -1122,7 +1100,7 @@ function jsonReplacer(key, value) {
|
|
|
1122
1100
|
}
|
|
1123
1101
|
}
|
|
1124
1102
|
return value;
|
|
1125
|
-
}
|
|
1103
|
+
};
|
|
1126
1104
|
var jsonify = (value, depth = 0, visitedObjects = /* @__PURE__ */ new WeakSet()) => {
|
|
1127
1105
|
if (depth > MAX_DEPTH) {
|
|
1128
1106
|
return null;
|
|
@@ -1209,31 +1187,10 @@ var deepMapValues = (value, fn) => {
|
|
|
1209
1187
|
return new DeepMapper(fn).map(value);
|
|
1210
1188
|
};
|
|
1211
1189
|
var DeepMapper = class {
|
|
1190
|
+
_fn;
|
|
1191
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1212
1192
|
constructor(_fn) {
|
|
1213
1193
|
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
1194
|
}
|
|
1238
1195
|
map(value) {
|
|
1239
1196
|
return this._map(value, void 0);
|
|
@@ -1244,36 +1201,37 @@ var DeepMapper = class {
|
|
|
1244
1201
|
}
|
|
1245
1202
|
return this._fn(value, this._recurse, key);
|
|
1246
1203
|
}
|
|
1204
|
+
_recurse = (value) => {
|
|
1205
|
+
if (this._cyclic.has(value)) {
|
|
1206
|
+
return this._cyclic.get(value);
|
|
1207
|
+
}
|
|
1208
|
+
if (Array.isArray(value)) {
|
|
1209
|
+
const res = new Array(value.length);
|
|
1210
|
+
this._cyclic.set(value, res);
|
|
1211
|
+
for (let i = 0; i < value.length; i++) {
|
|
1212
|
+
res[i] = this._map(value[i], i);
|
|
1213
|
+
}
|
|
1214
|
+
return res;
|
|
1215
|
+
} else if (value !== null && typeof value === "object") {
|
|
1216
|
+
const res = {};
|
|
1217
|
+
this._cyclic.set(value, res);
|
|
1218
|
+
for (const key in value) {
|
|
1219
|
+
res[key] = this._map(value[key], key);
|
|
1220
|
+
}
|
|
1221
|
+
return res;
|
|
1222
|
+
} else {
|
|
1223
|
+
return value;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1247
1226
|
};
|
|
1248
1227
|
var deepMapValuesAsync = (value, fn) => {
|
|
1249
1228
|
return new DeepMapperAsync(fn).map(value);
|
|
1250
1229
|
};
|
|
1251
1230
|
var DeepMapperAsync = class {
|
|
1231
|
+
_fn;
|
|
1232
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1252
1233
|
constructor(_fn) {
|
|
1253
1234
|
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
1235
|
}
|
|
1278
1236
|
map(value) {
|
|
1279
1237
|
return this._map(value, void 0);
|
|
@@ -1284,6 +1242,28 @@ var DeepMapperAsync = class {
|
|
|
1284
1242
|
}
|
|
1285
1243
|
return this._fn(value, this._recurse, key);
|
|
1286
1244
|
}
|
|
1245
|
+
_recurse = async (value) => {
|
|
1246
|
+
if (this._cyclic.has(value)) {
|
|
1247
|
+
return this._cyclic.get(value);
|
|
1248
|
+
}
|
|
1249
|
+
if (Array.isArray(value)) {
|
|
1250
|
+
const res = new Array(value.length);
|
|
1251
|
+
this._cyclic.set(value, res);
|
|
1252
|
+
for (let i = 0; i < value.length; i++) {
|
|
1253
|
+
res[i] = await this._map(value[i], i);
|
|
1254
|
+
}
|
|
1255
|
+
return res;
|
|
1256
|
+
} else if (value !== null && typeof value === "object") {
|
|
1257
|
+
const res = {};
|
|
1258
|
+
this._cyclic.set(value, res);
|
|
1259
|
+
for (const key in value) {
|
|
1260
|
+
res[key] = await this._map(value[key], key);
|
|
1261
|
+
}
|
|
1262
|
+
return res;
|
|
1263
|
+
} else {
|
|
1264
|
+
return value;
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1287
1267
|
};
|
|
1288
1268
|
var visitValues = (object, visitor) => {
|
|
1289
1269
|
if (Array.isArray(object)) {
|
|
@@ -1605,7 +1585,7 @@ var safeParseInt = (value, defaultValue) => {
|
|
|
1605
1585
|
try {
|
|
1606
1586
|
const n = parseInt(value ?? "");
|
|
1607
1587
|
return isNaN(n) ? defaultValue : n;
|
|
1608
|
-
} catch
|
|
1588
|
+
} catch {
|
|
1609
1589
|
return defaultValue;
|
|
1610
1590
|
}
|
|
1611
1591
|
};
|
|
@@ -1620,18 +1600,87 @@ var safeParseJson = (data, defaultValue) => {
|
|
|
1620
1600
|
if (data && data.length > 0) {
|
|
1621
1601
|
try {
|
|
1622
1602
|
return JSON.parse(data);
|
|
1623
|
-
} catch
|
|
1603
|
+
} catch {
|
|
1624
1604
|
}
|
|
1625
1605
|
}
|
|
1626
1606
|
return defaultValue;
|
|
1627
1607
|
};
|
|
1628
1608
|
|
|
1609
|
+
// src/safe-stringify.ts
|
|
1610
|
+
var SKIP = Object.freeze({});
|
|
1611
|
+
function safeStringify(obj, filter = defaultFilter, indent = 2) {
|
|
1612
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1613
|
+
function replacer(key, value) {
|
|
1614
|
+
if (typeof value === "object" && value !== null) {
|
|
1615
|
+
if (seen.has(value)) {
|
|
1616
|
+
return "[Circular]";
|
|
1617
|
+
}
|
|
1618
|
+
seen.add(value);
|
|
1619
|
+
}
|
|
1620
|
+
if (filter) {
|
|
1621
|
+
const v2 = filter?.(key, value);
|
|
1622
|
+
if (v2 !== void 0) {
|
|
1623
|
+
return v2 === SKIP ? void 0 : v2;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return value;
|
|
1627
|
+
}
|
|
1628
|
+
let result = "";
|
|
1629
|
+
try {
|
|
1630
|
+
result = JSON.stringify(obj, replacer, indent);
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
result = `Error: ${error.message}`;
|
|
1633
|
+
}
|
|
1634
|
+
return result;
|
|
1635
|
+
}
|
|
1636
|
+
var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
|
|
1637
|
+
let currentDepth = 0;
|
|
1638
|
+
const depthMap = /* @__PURE__ */ new WeakMap();
|
|
1639
|
+
return function(key, value) {
|
|
1640
|
+
if (key === "") {
|
|
1641
|
+
currentDepth = 0;
|
|
1642
|
+
} else if (this && typeof this === "object") {
|
|
1643
|
+
const parentDepth = depthMap.get(this) ?? 0;
|
|
1644
|
+
currentDepth = parentDepth + 1;
|
|
1645
|
+
}
|
|
1646
|
+
if (typeof value === "function") {
|
|
1647
|
+
return void 0;
|
|
1648
|
+
}
|
|
1649
|
+
if (value && typeof value === "object") {
|
|
1650
|
+
depthMap.set(value, currentDepth);
|
|
1651
|
+
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
1652
|
+
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
if (omit2?.includes(key)) {
|
|
1656
|
+
return void 0;
|
|
1657
|
+
}
|
|
1658
|
+
if (parse?.includes(key) && typeof value === "string") {
|
|
1659
|
+
try {
|
|
1660
|
+
return JSON.parse(value);
|
|
1661
|
+
} catch {
|
|
1662
|
+
return value;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
|
|
1666
|
+
return `[length: ${value.length}]`;
|
|
1667
|
+
}
|
|
1668
|
+
if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
|
|
1669
|
+
return value.slice(0, maxStringLen) + "...";
|
|
1670
|
+
}
|
|
1671
|
+
return value;
|
|
1672
|
+
};
|
|
1673
|
+
};
|
|
1674
|
+
var defaultFilter = createReplacer();
|
|
1675
|
+
|
|
1629
1676
|
// src/sliding-window-summary.ts
|
|
1630
1677
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1631
1678
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
1632
1679
|
var SlidingWindowSummary = class {
|
|
1680
|
+
_buffer;
|
|
1681
|
+
_sum = 0;
|
|
1682
|
+
_precision;
|
|
1633
1683
|
constructor(options) {
|
|
1634
|
-
this._sum = 0;
|
|
1635
1684
|
this._buffer = new CircularBuffer(options.dataPoints);
|
|
1636
1685
|
if (options.precision != null) {
|
|
1637
1686
|
invariant5(options.precision >= 0, void 0, {
|
|
@@ -1711,6 +1760,24 @@ var capitalize = (str) => {
|
|
|
1711
1760
|
}
|
|
1712
1761
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1713
1762
|
};
|
|
1763
|
+
function trim(strings, ...values) {
|
|
1764
|
+
const raw = strings.reduce((out, str, i) => {
|
|
1765
|
+
out += str;
|
|
1766
|
+
if (i < values.length) {
|
|
1767
|
+
const match = str.match(/(^|\n)([ \t]*)$/);
|
|
1768
|
+
const baseIndent = match ? match[2] : "";
|
|
1769
|
+
const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
|
|
1770
|
+
out += val;
|
|
1771
|
+
}
|
|
1772
|
+
return out;
|
|
1773
|
+
}, "");
|
|
1774
|
+
const lines = raw.split("\n");
|
|
1775
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
1776
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
1777
|
+
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1778
|
+
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1779
|
+
}
|
|
1780
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1714
1781
|
|
|
1715
1782
|
// src/sum.ts
|
|
1716
1783
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -1909,10 +1976,8 @@ var toFallback = (hash) => {
|
|
|
1909
1976
|
|
|
1910
1977
|
// src/tracer.ts
|
|
1911
1978
|
var Tracer = class {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
this._recording = false;
|
|
1915
|
-
}
|
|
1979
|
+
_events = /* @__PURE__ */ new Map();
|
|
1980
|
+
_recording = false;
|
|
1916
1981
|
// TODO(burdon): Start/stop methods for recording data? By id?
|
|
1917
1982
|
// Alternatively, enable subscriptions to track/compute series.
|
|
1918
1983
|
// TODO(burdon): Hierarchical traces?
|
|
@@ -2013,7 +2078,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2013
2078
|
};
|
|
2014
2079
|
|
|
2015
2080
|
// src/types.ts
|
|
2016
|
-
var
|
|
2081
|
+
var isTruthy = (value) => !!value;
|
|
2017
2082
|
var isNonNullable = (value) => value != null;
|
|
2018
2083
|
var doAsync = async (fn) => fn();
|
|
2019
2084
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2044,6 +2109,103 @@ var arrayMove = (array, from, to) => {
|
|
|
2044
2109
|
return array;
|
|
2045
2110
|
};
|
|
2046
2111
|
|
|
2112
|
+
// src/unit.ts
|
|
2113
|
+
var createFormat = (unit) => {
|
|
2114
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2115
|
+
const value = n / unit.quotient;
|
|
2116
|
+
return {
|
|
2117
|
+
unit,
|
|
2118
|
+
value,
|
|
2119
|
+
formattedValue: value.toFixed(precision),
|
|
2120
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2121
|
+
};
|
|
2122
|
+
};
|
|
2123
|
+
};
|
|
2124
|
+
var MS_SECONDS = 1e3;
|
|
2125
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2126
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2127
|
+
var Unit = {
|
|
2128
|
+
// General.
|
|
2129
|
+
Percent: createFormat({
|
|
2130
|
+
symbol: "%",
|
|
2131
|
+
quotient: 1 / 100,
|
|
2132
|
+
precision: 2
|
|
2133
|
+
}),
|
|
2134
|
+
Thousand: createFormat({
|
|
2135
|
+
symbol: "k",
|
|
2136
|
+
quotient: 1e3,
|
|
2137
|
+
precision: 2
|
|
2138
|
+
}),
|
|
2139
|
+
// Bytes (note KB vs KiB).
|
|
2140
|
+
Gigabyte: createFormat({
|
|
2141
|
+
symbol: "GB",
|
|
2142
|
+
quotient: 1e3 * 1e3 * 1e3,
|
|
2143
|
+
precision: 2
|
|
2144
|
+
}),
|
|
2145
|
+
Megabyte: createFormat({
|
|
2146
|
+
symbol: "MB",
|
|
2147
|
+
quotient: 1e3 * 1e3,
|
|
2148
|
+
precision: 2
|
|
2149
|
+
}),
|
|
2150
|
+
Kilobyte: createFormat({
|
|
2151
|
+
symbol: "KB",
|
|
2152
|
+
quotient: 1e3,
|
|
2153
|
+
precision: 2
|
|
2154
|
+
}),
|
|
2155
|
+
// Time.
|
|
2156
|
+
Hour: createFormat({
|
|
2157
|
+
symbol: "h",
|
|
2158
|
+
quotient: MS_HOURS
|
|
2159
|
+
}),
|
|
2160
|
+
Minute: createFormat({
|
|
2161
|
+
symbol: "m",
|
|
2162
|
+
quotient: MS_MINUTES
|
|
2163
|
+
}),
|
|
2164
|
+
Second: createFormat({
|
|
2165
|
+
symbol: "s",
|
|
2166
|
+
quotient: MS_SECONDS,
|
|
2167
|
+
precision: 1
|
|
2168
|
+
}),
|
|
2169
|
+
Millisecond: createFormat({
|
|
2170
|
+
symbol: "ms",
|
|
2171
|
+
quotient: 1
|
|
2172
|
+
}),
|
|
2173
|
+
Duration: (n) => {
|
|
2174
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2175
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2176
|
+
if (hours) {
|
|
2177
|
+
const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2178
|
+
return {
|
|
2179
|
+
unit: {
|
|
2180
|
+
symbol: "h",
|
|
2181
|
+
quotient: MS_HOURS
|
|
2182
|
+
},
|
|
2183
|
+
value: hours,
|
|
2184
|
+
formattedValue,
|
|
2185
|
+
toString: () => formattedValue
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
if (minutes) {
|
|
2189
|
+
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2190
|
+
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2191
|
+
return {
|
|
2192
|
+
unit: {
|
|
2193
|
+
symbol: "m",
|
|
2194
|
+
quotient: MS_MINUTES
|
|
2195
|
+
},
|
|
2196
|
+
value: minutes,
|
|
2197
|
+
formattedValue,
|
|
2198
|
+
toString: () => formattedValue
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
const seconds = n >= MS_SECONDS;
|
|
2202
|
+
if (seconds) {
|
|
2203
|
+
return Unit.Second(n);
|
|
2204
|
+
}
|
|
2205
|
+
return Unit.Millisecond(n);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2047
2209
|
// src/url.ts
|
|
2048
2210
|
var createUrl = (url, search) => {
|
|
2049
2211
|
const base = typeof url === "string" ? new URL(url) : url;
|
|
@@ -2055,11 +2217,11 @@ var createUrl = (url, search) => {
|
|
|
2055
2217
|
|
|
2056
2218
|
// src/weak.ts
|
|
2057
2219
|
var WeakDictionary = class {
|
|
2220
|
+
_internal = /* @__PURE__ */ new Map();
|
|
2221
|
+
_finalization = new FinalizationRegistry((cleanUpCallback) => {
|
|
2222
|
+
cleanUpCallback();
|
|
2223
|
+
});
|
|
2058
2224
|
constructor(entries2) {
|
|
2059
|
-
this._internal = /* @__PURE__ */ new Map();
|
|
2060
|
-
this._finalization = new FinalizationRegistry((cleanUpCallback) => {
|
|
2061
|
-
cleanUpCallback();
|
|
2062
|
-
});
|
|
2063
2225
|
this._internal = new Map(entries2?.map(([key, value]) => [
|
|
2064
2226
|
key,
|
|
2065
2227
|
new WeakRef(value)
|
|
@@ -2156,8 +2318,10 @@ export {
|
|
|
2156
2318
|
ComplexSet,
|
|
2157
2319
|
HumanHasher,
|
|
2158
2320
|
MapEntry,
|
|
2321
|
+
SKIP,
|
|
2159
2322
|
SlidingWindowSummary,
|
|
2160
2323
|
Tracer,
|
|
2324
|
+
Unit,
|
|
2161
2325
|
WeakDictionary,
|
|
2162
2326
|
accessBy,
|
|
2163
2327
|
arrayMove,
|
|
@@ -2179,11 +2343,13 @@ export {
|
|
|
2179
2343
|
createBinder,
|
|
2180
2344
|
createBucketReducer,
|
|
2181
2345
|
createGroupReducer,
|
|
2346
|
+
createReplacer,
|
|
2182
2347
|
createSetDispatch,
|
|
2183
2348
|
createUrl,
|
|
2184
2349
|
decamelize,
|
|
2185
2350
|
deepMapValues,
|
|
2186
2351
|
deepMapValuesAsync,
|
|
2352
|
+
defaultFilter,
|
|
2187
2353
|
defaultMap,
|
|
2188
2354
|
defer,
|
|
2189
2355
|
deferAsync,
|
|
@@ -2200,7 +2366,6 @@ export {
|
|
|
2200
2366
|
getDate,
|
|
2201
2367
|
getDebugName,
|
|
2202
2368
|
getDeep,
|
|
2203
|
-
getFirstTwoRenderableChars,
|
|
2204
2369
|
getHostPlatform,
|
|
2205
2370
|
getPrototypeSpecificInstanceId,
|
|
2206
2371
|
getProviderValue,
|
|
@@ -2218,12 +2383,13 @@ export {
|
|
|
2218
2383
|
iosCheck,
|
|
2219
2384
|
isNode,
|
|
2220
2385
|
isNonNullable,
|
|
2221
|
-
|
|
2386
|
+
isTruthy,
|
|
2222
2387
|
joinTables,
|
|
2223
2388
|
jsonKeyReplacer,
|
|
2224
2389
|
jsonReplacer,
|
|
2225
2390
|
jsonify,
|
|
2226
2391
|
jsonlogify,
|
|
2392
|
+
kebabize,
|
|
2227
2393
|
keyToEmoji,
|
|
2228
2394
|
keyToFallback,
|
|
2229
2395
|
keyToHue,
|
|
@@ -2254,6 +2420,7 @@ export {
|
|
|
2254
2420
|
safeParseFloat,
|
|
2255
2421
|
safeParseInt,
|
|
2256
2422
|
safeParseJson,
|
|
2423
|
+
safeStringify,
|
|
2257
2424
|
set,
|
|
2258
2425
|
setDeep,
|
|
2259
2426
|
sortKeys,
|
|
@@ -2266,6 +2433,7 @@ export {
|
|
|
2266
2433
|
toFallback,
|
|
2267
2434
|
toHue,
|
|
2268
2435
|
tracer,
|
|
2436
|
+
trim,
|
|
2269
2437
|
visitValues
|
|
2270
2438
|
};
|
|
2271
2439
|
//# sourceMappingURL=index.mjs.map
|