zeed 0.7.147 → 0.7.151

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.
@@ -229,6 +229,7 @@ __export(index_all_exports, {
229
229
  randomFloat: () => randomFloat,
230
230
  randomInt: () => randomInt,
231
231
  randomUint8Array: () => randomUint8Array,
232
+ readText: () => readText,
232
233
  regExpEscape: () => regExpEscape,
233
234
  regExpString: () => regExpString,
234
235
  removeFolder: () => removeFolder,
@@ -312,7 +313,8 @@ __export(index_all_exports, {
312
313
  valueToInteger: () => valueToInteger,
313
314
  valueToPath: () => valueToPath,
314
315
  valueToString: () => valueToString,
315
- waitOn: () => waitOn
316
+ waitOn: () => waitOn,
317
+ writeText: () => writeText
316
318
  });
317
319
  module.exports = __toCommonJS(index_all_exports);
318
320
 
@@ -434,8 +436,7 @@ function getNamespaceFilterString(defaultNamespaceFilter2) {
434
436
  return defaultNamespaceFilter2;
435
437
  }
436
438
  __name(getNamespaceFilterString, "getNamespaceFilterString");
437
- var _a, _b;
438
- var defaultNamespaceFilter = getNamespaceFilterString(typeof process !== "undefined" ? (_a = process.env.ZEED) != null ? _a : process.env.DEBUG : typeof localStorage !== "undefined" ? (_b = localStorage.zeed) != null ? _b : localStorage.debug : "*");
439
+ var defaultNamespaceFilter = getNamespaceFilterString(typeof process !== "undefined" ? process.env.ZEED ?? process.env.DEBUG : typeof localStorage !== "undefined" ? localStorage.zeed ?? localStorage.debug : "*");
439
440
  function useNamespaceFilter(filter = defaultNamespaceFilter) {
440
441
  let fn;
441
442
  let reject = [];
@@ -487,8 +488,7 @@ function useNamespaceFilter(filter = defaultNamespaceFilter) {
487
488
  return fn;
488
489
  }
489
490
  __name(useNamespaceFilter, "useNamespaceFilter");
490
- var _a2, _b2, _c, _d;
491
- var defaultLevelFilter = typeof process !== "undefined" ? (_b2 = (_a2 = process.env.ZEED_LEVEL) != null ? _a2 : process.env.LEVEL) != null ? _b2 : process.env.DEBUG_LEVEL : typeof localStorage !== "undefined" ? (_d = (_c = localStorage.zeed_level) != null ? _c : localStorage.level) != null ? _d : localStorage.debug_level : void 0;
491
+ var defaultLevelFilter = typeof process !== "undefined" ? process.env.ZEED_LEVEL ?? process.env.LEVEL ?? process.env.DEBUG_LEVEL : typeof localStorage !== "undefined" ? localStorage.zeed_level ?? localStorage.level ?? localStorage.debug_level : void 0;
492
492
  function useLevelFilter(filter = defaultLevelFilter) {
493
493
  let filterLevel = -1 /* all */;
494
494
  if (typeof filter === "string") {
@@ -904,13 +904,12 @@ async function digest(message, algorithm = DEFAULT_HASH_ALG) {
904
904
  }
905
905
  __name(digest, "digest");
906
906
  async function deriveKeyPbkdf2(secret, opt = {}) {
907
- var _a4;
908
907
  const secretBuffer = toUint8Array(secret);
909
908
  const keyMaterial = await crypto.subtle.importKey("raw", secretBuffer, DEFAULT_DERIVE_ALG, false, ["deriveKey"]);
910
909
  return await crypto.subtle.deriveKey({
911
910
  name: DEFAULT_DERIVE_ALG,
912
911
  salt: opt.salt ? toUint8Array(opt.salt) : new Uint8Array(0),
913
- iterations: (_a4 = opt.iterations) != null ? _a4 : 1e5,
912
+ iterations: opt.iterations ?? 1e5,
914
913
  hash: DEFAULT_HASH_ALG
915
914
  }, keyMaterial, {
916
915
  name: DEFAULT_CRYPTO_ALG,
@@ -1399,17 +1398,15 @@ function stringToBoolean(value, defaultValue = false) {
1399
1398
  }
1400
1399
  __name(stringToBoolean, "stringToBoolean");
1401
1400
  function stringToInteger(value, defaultValue = 0) {
1402
- var _a4;
1403
1401
  if (value == null || typeof value !== "string")
1404
1402
  return defaultValue;
1405
- return (_a4 = parseInt(value.trim(), 10)) != null ? _a4 : defaultValue;
1403
+ return parseInt(value.trim(), 10) ?? defaultValue;
1406
1404
  }
1407
1405
  __name(stringToInteger, "stringToInteger");
1408
1406
  function stringToFloat(value, defaultValue = 0) {
1409
- var _a4;
1410
1407
  if (value == null || typeof value !== "string")
1411
1408
  return defaultValue;
1412
- return (_a4 = parseFloat(value.trim())) != null ? _a4 : defaultValue;
1409
+ return parseFloat(value.trim()) ?? defaultValue;
1413
1410
  }
1414
1411
  __name(stringToFloat, "stringToFloat");
1415
1412
  function valueToBoolean(value, defaultValue = false) {
@@ -1423,32 +1420,29 @@ function valueToBoolean(value, defaultValue = false) {
1423
1420
  }
1424
1421
  __name(valueToBoolean, "valueToBoolean");
1425
1422
  function valueToInteger(value, defaultValue = 0) {
1426
- var _a4;
1427
1423
  if (value == null)
1428
1424
  return defaultValue;
1429
1425
  if (typeof value === "boolean")
1430
1426
  return value ? 1 : 0;
1431
1427
  if (typeof value === "number")
1432
1428
  return Math.floor(value);
1433
- return (_a4 = parseInt(String(value).trim(), 10)) != null ? _a4 : defaultValue;
1429
+ return parseInt(String(value).trim(), 10) ?? defaultValue;
1434
1430
  }
1435
1431
  __name(valueToInteger, "valueToInteger");
1436
1432
  function valueToFloat(value, defaultValue = 0) {
1437
- var _a4;
1438
1433
  if (value == null)
1439
1434
  return defaultValue;
1440
1435
  if (typeof value === "boolean")
1441
1436
  return value ? 1 : 0;
1442
1437
  if (typeof value === "number")
1443
1438
  return Math.floor(value);
1444
- return (_a4 = parseFloat(String(value).trim())) != null ? _a4 : defaultValue;
1439
+ return parseFloat(String(value).trim()) ?? defaultValue;
1445
1440
  }
1446
1441
  __name(valueToFloat, "valueToFloat");
1447
1442
  function valueToString(value, defaultValue = "") {
1448
- var _a4;
1449
1443
  if (value == null)
1450
1444
  return defaultValue;
1451
- return (_a4 = String(value)) != null ? _a4 : defaultValue;
1445
+ return String(value) ?? defaultValue;
1452
1446
  }
1453
1447
  __name(valueToString, "valueToString");
1454
1448
  var toFloat = valueToFloat;
@@ -1508,9 +1502,8 @@ function currency(value, opts = {}) {
1508
1502
  __name(currency, "currency");
1509
1503
  var _Currency = class {
1510
1504
  constructor(value, opts = {}) {
1511
- var _a4;
1512
1505
  let settings = Object.assign({}, defaults, opts);
1513
- let precision = pow((_a4 = settings.precision) != null ? _a4 : 2);
1506
+ let precision = pow(settings.precision ?? 2);
1514
1507
  let v = parse(value, settings);
1515
1508
  this.intValue = v;
1516
1509
  this.value = v / precision;
@@ -1833,13 +1826,13 @@ var Day = class {
1833
1826
  return this.days;
1834
1827
  }
1835
1828
  constructor(days) {
1836
- var _a4;
1829
+ var _a2;
1837
1830
  if (typeof days === "number") {
1838
1831
  this.days = days;
1839
1832
  return;
1840
1833
  }
1841
1834
  if (days != null) {
1842
- days = (_a4 = Day.from(days)) == null ? void 0 : _a4.days;
1835
+ days = (_a2 = Day.from(days)) == null ? void 0 : _a2.days;
1843
1836
  }
1844
1837
  if (days == null) {
1845
1838
  const date = new Date();
@@ -1921,8 +1914,8 @@ var Day = class {
1921
1914
  return Day.from([this.year + yy, mm, this.day]);
1922
1915
  }
1923
1916
  daysUntil(otherDay) {
1924
- var _a4;
1925
- return Math.round((((_a4 = new Day(otherDay)) == null ? void 0 : _a4.toDateGMT().getTime()) - this.toDateGMT().getTime()) / DAY_MS);
1917
+ var _a2;
1918
+ return Math.round((((_a2 = new Day(otherDay)) == null ? void 0 : _a2.toDateGMT().getTime()) - this.toDateGMT().getTime()) / DAY_MS);
1926
1919
  }
1927
1920
  yesterday() {
1928
1921
  return this.dayOffset(-1);
@@ -2239,7 +2232,7 @@ var XRX = class {
2239
2232
  constructor(pattern2, flags) {
2240
2233
  this.namedGroups = {};
2241
2234
  this.names = [];
2242
- let _flags = flags != null ? flags : "";
2235
+ let _flags = flags ?? "";
2243
2236
  let _rx;
2244
2237
  if (pattern2 instanceof RegExp) {
2245
2238
  if (flags == null) {
@@ -2352,7 +2345,7 @@ async function callDisposer(disposable) {
2352
2345
  }
2353
2346
  __name(callDisposer, "callDisposer");
2354
2347
  function useDispose(config) {
2355
- const { name } = typeof config === "string" ? { name: config } : config != null ? config : {};
2348
+ const { name } = typeof config === "string" ? { name: config } : config ?? {};
2356
2349
  let tracked = [];
2357
2350
  const untrack = /* @__PURE__ */ __name(async (disposable) => {
2358
2351
  if (disposable != null && tracked.includes(disposable)) {
@@ -2514,12 +2507,17 @@ var Emitter = class {
2514
2507
  constructor() {
2515
2508
  this.subscribers = {};
2516
2509
  this.subscribersOnAny = [];
2510
+ this.dispose = useDispose("emitter");
2517
2511
  this.call = new Proxy({}, {
2518
2512
  get: (target, name) => (...args) => this.emit(name, ...args)
2519
2513
  });
2520
2514
  }
2521
2515
  async emit(event, ...args) {
2522
2516
  let ok = false;
2517
+ this.dispose.add(() => {
2518
+ this.subscribers = {};
2519
+ this.subscribersOnAny = [];
2520
+ });
2523
2521
  try {
2524
2522
  let subscribers = this.subscribers[event] || [];
2525
2523
  this.subscribersOnAny.forEach((fn) => fn(event, ...args));
@@ -2573,10 +2571,6 @@ var Emitter = class {
2573
2571
  this.subscribers = {};
2574
2572
  return this;
2575
2573
  }
2576
- dispose() {
2577
- this.subscribers = {};
2578
- this.subscribersOnAny = [];
2579
- }
2580
2574
  };
2581
2575
  __name(Emitter, "Emitter");
2582
2576
  function getGlobalEmitter() {
@@ -2868,12 +2862,11 @@ function usePool(config = {}) {
2868
2862
  }
2869
2863
  __name(cancelAll, "cancelAll");
2870
2864
  function enqueue(task, config2 = {}) {
2871
- var _a4, _b4, _c2, _d2;
2872
2865
  let done;
2873
2866
  let promise = new Promise((resolve5) => done = resolve5);
2874
- let id = (_a4 = config2.id) != null ? _a4 : uuid();
2867
+ let id = config2.id ?? uuid();
2875
2868
  if (tasks[id] != null) {
2876
- const resolution = (_b4 = config2.idConflictResolution) != null ? _b4 : 1 /* memoize */;
2869
+ const resolution = config2.idConflictResolution ?? 1 /* memoize */;
2877
2870
  if (resolution === 0 /* replace */) {
2878
2871
  cancel(id);
2879
2872
  } else if (resolution === 1 /* memoize */) {
@@ -2897,8 +2890,8 @@ function usePool(config = {}) {
2897
2890
  task,
2898
2891
  priority: ++priority,
2899
2892
  state: 0 /* waiting */,
2900
- max: (_c2 = config2.max) != null ? _c2 : 1,
2901
- resolved: (_d2 = config2.resolved) != null ? _d2 : 0,
2893
+ max: config2.max ?? 1,
2894
+ resolved: config2.resolved ?? 0,
2902
2895
  done,
2903
2896
  payload: config2.payload,
2904
2897
  setMax(max) {
@@ -2948,7 +2941,7 @@ var SerialQueue = class extends Emitter {
2948
2941
  const { name = uname("queue"), logLevel } = opt;
2949
2942
  this.name = name;
2950
2943
  this.log = Logger(`zeed:queue:${name}`);
2951
- this.log.level = logLevel != null ? logLevel : Infinity /* off */;
2944
+ this.log.level = logLevel ?? Infinity /* off */;
2952
2945
  }
2953
2946
  async performNext() {
2954
2947
  this.log(`performNext, queue.length =`, this.queue.length);
@@ -3146,7 +3139,7 @@ function debounce(callback, opt = {}) {
3146
3139
  __name(debounce, "debounce");
3147
3140
 
3148
3141
  // src/common/localhost.ts
3149
- function isLocalHost(hostname = ((_b4) => (_b4 = ((_a4) => (_a4 = globalThis == null ? void 0 : globalThis.location) == null ? void 0 : _a4.hostname)()) != null ? _b4 : "")()) {
3142
+ function isLocalHost(hostname = ((_a2) => (_a2 = globalThis == null ? void 0 : globalThis.location) == null ? void 0 : _a2.hostname)() ?? "") {
3150
3143
  return ["localhost", "127.0.0.1", "", "::1", "::"].includes(hostname) || hostname.startsWith("192.168.") || hostname.startsWith("10.0.") || hostname.endsWith(".local");
3151
3144
  }
3152
3145
  __name(isLocalHost, "isLocalHost");
@@ -3182,8 +3175,8 @@ var LocalChannel = class extends Channel {
3182
3175
  this.isConnected = true;
3183
3176
  }
3184
3177
  postMessage(data) {
3185
- var _a4;
3186
- (_a4 = this.other) == null ? void 0 : _a4.emit("message", {
3178
+ var _a2;
3179
+ (_a2 = this.other) == null ? void 0 : _a2.emit("message", {
3187
3180
  data,
3188
3181
  origin: "local",
3189
3182
  lastEventId: uuid()
@@ -3377,7 +3370,6 @@ __name(useMessageHub, "useMessageHub");
3377
3370
  // src/common/msg/pubsub.ts
3378
3371
  var PubSub = class extends Emitter {
3379
3372
  constructor(opt) {
3380
- var _a4;
3381
3373
  super();
3382
3374
  this.publish = this.emit;
3383
3375
  this.subscribe = this.on;
@@ -3385,7 +3377,7 @@ var PubSub = class extends Emitter {
3385
3377
  this.channel = channel;
3386
3378
  this.encoder = encoder;
3387
3379
  this.debug = debug;
3388
- this.name = (_a4 = name != null ? name : this.channel.id) != null ? _a4 : uname("pubsub");
3380
+ this.name = name ?? this.channel.id ?? uname("pubsub");
3389
3381
  this.log = Logger(`${this.shortId}`);
3390
3382
  if (this.debug) {
3391
3383
  this.channel.on("connect", () => {
@@ -3416,9 +3408,9 @@ var PubSub = class extends Emitter {
3416
3408
  async emit(event, ...args) {
3417
3409
  try {
3418
3410
  if (this.debug)
3419
- this.log(`emit(${event})`, event);
3411
+ this.log(`emit(${String(event)})`, event);
3420
3412
  else
3421
- this.log(`emit(${event})`, args.length);
3413
+ this.log(`emit(${String(event)})`, args.length);
3422
3414
  if (!this.channel.isConnected) {
3423
3415
  this.log.warn("channel not connected");
3424
3416
  return false;
@@ -3427,7 +3419,7 @@ var PubSub = class extends Emitter {
3427
3419
  this.channel.postMessage(data);
3428
3420
  return true;
3429
3421
  } catch (err) {
3430
- this.log.warn(`emit(${event})`, err);
3422
+ this.log.warn(`emit(${String(event)})`, err);
3431
3423
  }
3432
3424
  return false;
3433
3425
  }
@@ -3440,13 +3432,15 @@ __name(usePubSub, "usePubSub");
3440
3432
 
3441
3433
  // src/common/msg/rpc.ts
3442
3434
  var rpcCounter = 1;
3435
+ var defaultSerialize = /* @__PURE__ */ __name((i) => i, "defaultSerialize");
3436
+ var defaultDeserialize = defaultSerialize;
3443
3437
  function useRPC(functions, options) {
3444
3438
  const {
3445
3439
  post,
3446
3440
  on,
3447
3441
  eventNames = [],
3448
- serialize = /* @__PURE__ */ __name((i) => i, "serialize"),
3449
- deserialize = /* @__PURE__ */ __name((i) => i, "deserialize")
3442
+ serialize = defaultSerialize,
3443
+ deserialize = defaultDeserialize
3450
3444
  } = options;
3451
3445
  const rpcPromiseMap = /* @__PURE__ */ new Map();
3452
3446
  on(async (data) => {
@@ -3454,10 +3448,14 @@ function useRPC(functions, options) {
3454
3448
  const [mode, args, id, method] = msg;
3455
3449
  if (mode === 1 /* request */ || mode === 2 /* event */) {
3456
3450
  let result, error2;
3457
- try {
3458
- result = await functions[method](...args);
3459
- } catch (e) {
3460
- error2 = String(e);
3451
+ if (method != null) {
3452
+ try {
3453
+ result = await functions[method](...args);
3454
+ } catch (e) {
3455
+ error2 = String(e);
3456
+ }
3457
+ } else {
3458
+ error2 = "Method implementation missing";
3461
3459
  }
3462
3460
  if (mode === 1 /* request */ && id) {
3463
3461
  if (error2) {
@@ -3468,10 +3466,12 @@ function useRPC(functions, options) {
3468
3466
  }
3469
3467
  } else if (id) {
3470
3468
  const promise = rpcPromiseMap.get(id);
3471
- if (mode === 4 /* reject */)
3472
- promise == null ? void 0 : promise.reject(args);
3473
- else
3474
- promise == null ? void 0 : promise.resolve(args);
3469
+ if (promise != null) {
3470
+ if (mode === 4 /* reject */)
3471
+ promise.reject(args);
3472
+ else
3473
+ promise.resolve(args);
3474
+ }
3475
3475
  rpcPromiseMap.delete(id);
3476
3476
  }
3477
3477
  });
@@ -3587,8 +3587,7 @@ function getNavigator() {
3587
3587
  }
3588
3588
  __name(getNavigator, "getNavigator");
3589
3589
  function getGlobal() {
3590
- var _a4;
3591
- return ((_a4 = getWindow()) != null ? _a4 : typeof WorkerGlobalScope !== "undefined") ? self : typeof global !== "undefined" ? global : Function("return this;")();
3590
+ return getWindow() ?? typeof WorkerGlobalScope !== "undefined" ? self : typeof global !== "undefined" ? global : Function("return this;")();
3592
3591
  }
3593
3592
  __name(getGlobal, "getGlobal");
3594
3593
  var _navigator = getNavigator();
@@ -3612,12 +3611,12 @@ function detect(info = {
3612
3611
  appleNative: false,
3613
3612
  touch: false
3614
3613
  }) {
3615
- var _a4, _b4, _c2, _d2, _e, _f, _g, _h, _i;
3616
- info.ios = ((_a4 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _a4.match(/(iPhone|iPod|iPad)/i)) != null;
3617
- info.macos = !!((_b4 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _b4.startsWith("Mac"));
3618
- info.windows = !!((_c2 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _c2.startsWith("Win"));
3614
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
3615
+ info.ios = ((_a2 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _a2.match(/(iPhone|iPod|iPad)/i)) != null;
3616
+ info.macos = !!((_b2 = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _b2.startsWith("Mac"));
3617
+ info.windows = !!((_c = _navigator == null ? void 0 : _navigator.platform) == null ? void 0 : _c.startsWith("Win"));
3619
3618
  info.beaker = (_window == null ? void 0 : _window["beaker"]) != null;
3620
- info.electron = (((_e = (_d2 = _navigator == null ? void 0 : _navigator.userAgent) == null ? void 0 : _d2.toLowerCase()) == null ? void 0 : _e.indexOf(" electron/")) || -1) > -1 && !info.beaker;
3619
+ info.electron = (((_e = (_d = _navigator == null ? void 0 : _navigator.userAgent) == null ? void 0 : _d.toLowerCase()) == null ? void 0 : _e.indexOf(" electron/")) || -1) > -1 && !info.beaker;
3621
3620
  info.wkwebview = ((_f = _window == null ? void 0 : _window.webkit) == null ? void 0 : _f["messageHandlers"]) != null;
3622
3621
  info.pwa = (_navigator == null ? void 0 : _navigator.serviceWorker) != null;
3623
3622
  info.pwaInstalled = (_navigator == null ? void 0 : _navigator.standalone) || ((_h = (_g = _window == null ? void 0 : _window.matchMedia) == null ? void 0 : _g.call(_window, "(display-mode: standalone)")) == null ? void 0 : _h.matches);
@@ -3728,7 +3727,7 @@ function parse2(src, options = {}) {
3728
3727
  }
3729
3728
  __name(parse2, "parse");
3730
3729
  function stringToPath(value, defaultValue = ".") {
3731
- return (0, import_path.resolve)(process.cwd(), value != null ? value : defaultValue);
3730
+ return (0, import_path.resolve)(process.cwd(), value ?? defaultValue);
3732
3731
  }
3733
3732
  __name(stringToPath, "stringToPath");
3734
3733
  function valueToPath(value, defaultValue = "") {
@@ -3739,9 +3738,8 @@ function valueToPath(value, defaultValue = "") {
3739
3738
  __name(valueToPath, "valueToPath");
3740
3739
  var toPath = valueToPath;
3741
3740
  function setupEnv(options = {}) {
3742
- var _a4, _b4, _c2, _d2;
3743
- const dotenvPath = (_b4 = options == null ? void 0 : options.path) != null ? _b4 : toPath((_a4 = options == null ? void 0 : options.filename) != null ? _a4 : ".env");
3744
- const encoding = (_c2 = options == null ? void 0 : options.encoding) != null ? _c2 : "utf8";
3741
+ const dotenvPath = (options == null ? void 0 : options.path) ?? toPath((options == null ? void 0 : options.filename) ?? ".env");
3742
+ const encoding = (options == null ? void 0 : options.encoding) ?? "utf8";
3745
3743
  const debug = (options == null ? void 0 : options.debug) || false;
3746
3744
  if (debug !== true)
3747
3745
  log10.level = Infinity /* off */;
@@ -3749,7 +3747,7 @@ function setupEnv(options = {}) {
3749
3747
  const parsedEnv = import_fs.default.existsSync(dotenvPath) ? parse2(import_fs.default.readFileSync(dotenvPath, { encoding }), { debug }) : {};
3750
3748
  const parsedEnvLocal = import_fs.default.existsSync(dotenvPath + ".local") ? parse2(import_fs.default.readFileSync(dotenvPath + ".local", { encoding }), { debug }) : {};
3751
3749
  const parsed = Object.assign({}, parsedEnv, parsedEnvLocal);
3752
- let env = (_d2 = options == null ? void 0 : options.env) != null ? _d2 : process.env;
3750
+ let env = (options == null ? void 0 : options.env) ?? process.env;
3753
3751
  Object.entries(parsed).forEach(([key, value]) => {
3754
3752
  if (typeof (options == null ? void 0 : options.prefix) === "string") {
3755
3753
  key = (options == null ? void 0 : options.prefix) + key;
@@ -3780,25 +3778,24 @@ var FileStorage = class {
3780
3778
  this.store = {};
3781
3779
  this.fileKeys = void 0;
3782
3780
  this.pretty = false;
3783
- var _a4, _b4, _c2, _d2;
3784
3781
  this.dirname = (0, import_path2.resolve)(process.cwd(), opt.path || ".fileStorage");
3785
3782
  this.pretty = !!opt.pretty;
3786
- this.extension = (_a4 = opt.extension) != null ? _a4 : ".json";
3783
+ this.extension = opt.extension ?? ".json";
3787
3784
  if (opt.extension && !this.extension.startsWith(".")) {
3788
3785
  this.extension = "." + this.extension;
3789
3786
  }
3790
3787
  this.extensionLength = this.extension.length;
3791
- this.objectToString = (_b4 = opt.objectToString) != null ? _b4 : (data) => {
3788
+ this.objectToString = opt.objectToString ?? ((data) => {
3792
3789
  return this.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
3793
- };
3794
- this.objectFromString = (_c2 = opt.objectFromString) != null ? _c2 : (data) => {
3790
+ });
3791
+ this.objectFromString = opt.objectFromString ?? ((data) => {
3795
3792
  try {
3796
3793
  return JSON.parse(data);
3797
3794
  } catch (err) {
3798
3795
  log11.warn(`fileStorage parse error '${err}' in`, data);
3799
3796
  }
3800
- };
3801
- this.keyToFilename = (_d2 = opt.keyToFilename) != null ? _d2 : toValidFilename;
3797
+ });
3798
+ this.keyToFilename = opt.keyToFilename ?? toValidFilename;
3802
3799
  }
3803
3800
  setItem(key, value) {
3804
3801
  this.store[key] = cloneObject(value);
@@ -3904,6 +3901,17 @@ async function removeFolder(...parts) {
3904
3901
  return path;
3905
3902
  }
3906
3903
  __name(removeFolder, "removeFolder");
3904
+ async function readText(...parts) {
3905
+ const path = (0, import_node_path.join)(...parts);
3906
+ if (await exists(path)) {
3907
+ return await (0, import_promises.readFile)(path, "utf-8");
3908
+ }
3909
+ }
3910
+ __name(readText, "readText");
3911
+ async function writeText(path, content) {
3912
+ await (0, import_promises.writeFile)(path, content, "utf-8");
3913
+ }
3914
+ __name(writeText, "writeText");
3907
3915
 
3908
3916
  // src/node/log-file.ts
3909
3917
  var import_fs3 = require("fs");
@@ -3959,10 +3967,10 @@ var import_tty = __toESM(require("tty"), 1);
3959
3967
  // src/node/log-util.ts
3960
3968
  var import_path5 = require("path");
3961
3969
  function getStackLlocationList(stack) {
3962
- var _a4, _b4;
3970
+ var _a2, _b2;
3963
3971
  if (typeof stack !== "string")
3964
3972
  return [];
3965
- return ((_b4 = (_a4 = stack == null ? void 0 : stack.split("\n")) == null ? void 0 : _a4.map((rawLine) => {
3973
+ return ((_b2 = (_a2 = stack == null ? void 0 : stack.split("\n")) == null ? void 0 : _a2.map((rawLine) => {
3966
3974
  let m = rawLine.match(/^\s+at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/);
3967
3975
  if (m) {
3968
3976
  let line = m[3] || m[2] || m[4];
@@ -3970,12 +3978,12 @@ function getStackLlocationList(stack) {
3970
3978
  line = line.slice(0, -1);
3971
3979
  return line;
3972
3980
  }
3973
- })) == null ? void 0 : _b4.filter((v) => v != null)) || [];
3981
+ })) == null ? void 0 : _b2.filter((v) => v != null)) || [];
3974
3982
  }
3975
3983
  __name(getStackLlocationList, "getStackLlocationList");
3976
3984
  var cwd = (0, import_path5.resolve)(process.cwd());
3977
- var _a3, _b3;
3978
- var home = ((_a3 = process.env) == null ? void 0 : _a3.HOME) ? (0, import_path5.resolve)((_b3 = process.env) == null ? void 0 : _b3.HOME) : "";
3985
+ var _a, _b;
3986
+ var home = ((_a = process.env) == null ? void 0 : _a.HOME) ? (0, import_path5.resolve)((_b = process.env) == null ? void 0 : _b.HOME) : "";
3979
3987
  function pathStripCwd(path) {
3980
3988
  if (path.includes("/node_modules/")) {
3981
3989
  return "";
@@ -4005,9 +4013,9 @@ function extractFileInfo(stackLine) {
4005
4013
  }
4006
4014
  __name(extractFileInfo, "extractFileInfo");
4007
4015
  function getSourceLocation(level = 2, stripCwd = true) {
4008
- var _a4;
4016
+ var _a2;
4009
4017
  let stack = new Error().stack || "";
4010
- let line = (_a4 = getStackLlocationList(stack)) == null ? void 0 : _a4[level];
4018
+ let line = (_a2 = getStackLlocationList(stack)) == null ? void 0 : _a2[level];
4011
4019
  if (line && stripCwd) {
4012
4020
  line = pathStripCwd(line);
4013
4021
  }
@@ -4108,7 +4116,7 @@ function LoggerNodeHandler(opt = {}) {
4108
4116
  const matchesNamespace = useNamespaceFilter(filter);
4109
4117
  const matchesLevel = useLevelFilter(level);
4110
4118
  return (msg) => {
4111
- var _a4;
4119
+ var _a2;
4112
4120
  if (!matchesLevel(msg.level))
4113
4121
  return;
4114
4122
  if (!matchesNamespace(msg.name))
@@ -4146,7 +4154,7 @@ function LoggerNodeHandler(opt = {}) {
4146
4154
  args = [displayName, ...msg.messages];
4147
4155
  args.push(`+${diff}`);
4148
4156
  }
4149
- if (((_a4 = msg.messages) == null ? void 0 : _a4[0]) === loggerStackTraceDebug) {
4157
+ if (((_a2 = msg.messages) == null ? void 0 : _a2[0]) === loggerStackTraceDebug) {
4150
4158
  console.log(getStack());
4151
4159
  }
4152
4160
  if (stack) {
@@ -4192,14 +4200,13 @@ __name(LoggerNodeHandler, "LoggerNodeHandler");
4192
4200
 
4193
4201
  // src/node/log-context-node.ts
4194
4202
  function setupLogContextNode() {
4195
- var _a4;
4196
4203
  let handlers = [
4197
4204
  LoggerNodeHandler({
4198
4205
  padding: 32,
4199
4206
  nameBrackets: false
4200
4207
  })
4201
4208
  ];
4202
- let logFilePath = (_a4 = process.env.ZEED_LOG) != null ? _a4 : process.env.LOG;
4209
+ let logFilePath = process.env.ZEED_LOG ?? process.env.LOG;
4203
4210
  if (logFilePath) {
4204
4211
  handlers.unshift(LoggerFileHandler(toPath(logFilePath)));
4205
4212
  }
@@ -4412,20 +4419,19 @@ var log14 = Logger("zeed:localstorage");
4412
4419
  var LocalStorage = class {
4413
4420
  constructor(opt) {
4414
4421
  this.pretty = false;
4415
- var _a4, _b4;
4416
4422
  log14.assert(opt.name, "name required");
4417
4423
  this.name = opt.name;
4418
4424
  this.prefix = `${opt.name}$`;
4419
- this.objectToString = (_a4 = opt.objectToString) != null ? _a4 : (data) => {
4425
+ this.objectToString = opt.objectToString ?? ((data) => {
4420
4426
  return this.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
4421
- };
4422
- this.objectFromString = (_b4 = opt.objectFromString) != null ? _b4 : (data) => {
4427
+ });
4428
+ this.objectFromString = opt.objectFromString ?? ((data) => {
4423
4429
  try {
4424
4430
  return JSON.parse(data);
4425
4431
  } catch (err) {
4426
4432
  log14.warn(`LocalStorage parse error '${err}' in`, data);
4427
4433
  }
4428
- };
4434
+ });
4429
4435
  }
4430
4436
  setItem(key, value) {
4431
4437
  const data = this.objectToString(value);
@@ -4570,7 +4576,7 @@ function LoggerBrowserHandler(opt = {}) {
4570
4576
  const matchesNamespace = useNamespaceFilter(filter);
4571
4577
  const matchesLevel = useLevelFilter(level);
4572
4578
  return (msg) => {
4573
- var _a4, _b4;
4579
+ var _a2;
4574
4580
  if (!matchesLevel(msg.level))
4575
4581
  return;
4576
4582
  if (!matchesNamespace(msg.name))
@@ -4593,7 +4599,7 @@ function LoggerBrowserHandler(opt = {}) {
4593
4599
  args = [`%c${name}%c %s %c+${diff}`];
4594
4600
  args.push(`color:${ninfo.color}; ${styleBold}`);
4595
4601
  args.push(styleDefault);
4596
- args.push((_b4 = (_a4 = msg.messages) == null ? void 0 : _a4[0]) != null ? _b4 : "");
4602
+ args.push(((_a2 = msg.messages) == null ? void 0 : _a2[0]) ?? "");
4597
4603
  args.push(`color:${ninfo.color};`);
4598
4604
  args.push(...msg.messages.slice(1));
4599
4605
  } else {
@@ -4625,8 +4631,7 @@ function LoggerBrowserHandler(opt = {}) {
4625
4631
  }
4626
4632
  __name(LoggerBrowserHandler, "LoggerBrowserHandler");
4627
4633
  function LoggerBrowserSetupDebugFactory(opt = {}) {
4628
- var _a4, _b4;
4629
- const filter = (_b4 = (_a4 = opt.filter) != null ? _a4 : localStorage.zeed) != null ? _b4 : localStorage.debug;
4634
+ const filter = opt.filter ?? localStorage.zeed ?? localStorage.debug;
4630
4635
  return /* @__PURE__ */ __name(function LoggerBrowserDebugFactory(name = "") {
4631
4636
  let log15;
4632
4637
  const matches = useNamespaceFilter(filter);
@@ -4937,6 +4942,7 @@ if (isBrowser()) {
4937
4942
  randomFloat,
4938
4943
  randomInt,
4939
4944
  randomUint8Array,
4945
+ readText,
4940
4946
  regExpEscape,
4941
4947
  regExpString,
4942
4948
  removeFolder,
@@ -5020,6 +5026,7 @@ if (isBrowser()) {
5020
5026
  valueToInteger,
5021
5027
  valueToPath,
5022
5028
  valueToString,
5023
- waitOn
5029
+ waitOn,
5030
+ writeText
5024
5031
  });
5025
5032
  //# sourceMappingURL=index.all.cjs.map