qznt 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -37,6 +37,7 @@ const timeRemaining = $.date.duration(Date.now() + 5000); // "5 seconds"
37
37
  - **`qznt.date` (Time)**: Shorthand parsing (`"1h 30m"`), `duration` (digital/hms), and `eta`
38
38
  - **`qznt.fn` (Functions)**: `memoize` with TTL and custom resolvers
39
39
  - **`qznt.format` (Strings)**: `currency`, `memory` (bytes), `ordinal`, and `compactNumber`
40
+ - **`$.fs` (File System)**: Efficient recursive directory scanning with `readDir`
40
41
  - **`qznt.is` (Predicates)**: Type guards: `is.today`, `is.empty`, `is.object`, and `is.sorted`
41
42
  - **`qznt.math` (Calculations)**: `lerp`, `invLerp`, `remap`, `percent`, and `sum`
42
43
  - **`qznt.num` (Numbers)**: Essential logic like `clamp` and range handling
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ $: () => $,
33
34
  Cache: () => Cache,
34
35
  Loop: () => Loop,
35
36
  Pipe: () => Pipe,
@@ -40,11 +41,10 @@ __export(index_exports, {
40
41
  default: () => index_default,
41
42
  fn: () => fn,
42
43
  format: () => format,
44
+ fs: () => fs,
43
45
  is: () => is,
44
46
  math: () => math,
45
- num: () => num,
46
47
  obj: () => obj,
47
- qznt: () => qznt,
48
48
  rnd: () => rnd,
49
49
  str: () => str2,
50
50
  timing: () => timing,
@@ -334,8 +334,16 @@ async function retry(fn2, retries = 3, delay = 500) {
334
334
  return await new Promise((resolve) => setTimeout(resolve, delay + jitter));
335
335
  }
336
336
  }
337
+ function wait(ms2) {
338
+ return new Promise(
339
+ (resolve) => setTimeout(() => {
340
+ resolve(true);
341
+ }, ms2)
342
+ );
343
+ }
337
344
  var async = {
338
- retry
345
+ retry,
346
+ wait
339
347
  };
340
348
 
341
349
  // src/fn.ts
@@ -456,17 +464,17 @@ var format_exports = {};
456
464
  __export(format_exports, {
457
465
  format: () => format
458
466
  });
459
- function currency(num2, options = {}) {
467
+ function currency(num, options = {}) {
460
468
  return new Intl.NumberFormat(options.locale, {
461
469
  style: "currency",
462
470
  currency: options.currency
463
- }).format(num2);
471
+ }).format(num);
464
472
  }
465
- function number(num2, options = {}) {
473
+ function number(num, options = {}) {
466
474
  return new Intl.NumberFormat(options.locale, {
467
475
  minimumFractionDigits: options.precision,
468
476
  maximumFractionDigits: options.precision
469
- }).format(num2);
477
+ }).format(num);
470
478
  }
471
479
  function memory(bytes, decimals = 1, units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]) {
472
480
  if (bytes <= 0) return `0 ${units[0]}`;
@@ -474,8 +482,8 @@ function memory(bytes, decimals = 1, units = ["B", "KB", "MB", "GB", "TB", "PB",
474
482
  const val = bytes / Math.pow(1024, i);
475
483
  return `${val.toFixed(i === 0 ? 0 : decimals)} ${units[i]}`;
476
484
  }
477
- function ordinal(num2, locale) {
478
- const _num = Number(num2);
485
+ function ordinal(num, locale) {
486
+ const _num = Number(num);
479
487
  if (isNaN(_num)) throw new TypeError("Invalid input");
480
488
  const pr = new Intl.PluralRules(locale, { type: "ordinal" });
481
489
  const rule = pr.select(_num);
@@ -488,12 +496,12 @@ function ordinal(num2, locale) {
488
496
  const suffix = suffixes[rule] || "th";
489
497
  return _num.toLocaleString(locale) + suffix;
490
498
  }
491
- function compactNumber(num2, locale) {
499
+ function compactNumber(num, locale) {
492
500
  return new Intl.NumberFormat(locale, {
493
501
  notation: "compact",
494
502
  compactDisplay: "short",
495
503
  maximumFractionDigits: 1
496
- }).format(num2);
504
+ }).format(num);
497
505
  }
498
506
  var format = {
499
507
  currency,
@@ -503,6 +511,41 @@ var format = {
503
511
  compactNumber
504
512
  };
505
513
 
514
+ // src/fs.ts
515
+ var fs_exports = {};
516
+ __export(fs_exports, {
517
+ fs: () => fs
518
+ });
519
+ var import_node_fs = __toESM(require("fs"));
520
+ var import_node_path = require("path");
521
+ function readDir(path2, options = {}) {
522
+ const { recursive = true } = options;
523
+ if (!import_node_fs.default.existsSync(path2)) return [];
524
+ if (!recursive) {
525
+ return import_node_fs.default.readdirSync(path2).filter((fn2) => {
526
+ return import_node_fs.default.statSync((0, import_node_path.join)(path2, fn2)).isFile();
527
+ });
528
+ }
529
+ const walk = (dir, base = "") => {
530
+ const results = [];
531
+ const entries = import_node_fs.default.readdirSync(dir, { withFileTypes: true });
532
+ for (const entry of entries) {
533
+ const relativePath = base ? (0, import_node_path.join)(base, entry.name) : entry.name;
534
+ const fullPath = (0, import_node_path.join)(dir, entry.name);
535
+ if (entry.isDirectory()) {
536
+ results.push(...walk(fullPath, relativePath));
537
+ } else if (entry.isFile()) {
538
+ results.push(relativePath);
539
+ }
540
+ }
541
+ return results;
542
+ };
543
+ return walk(path2);
544
+ }
545
+ var fs = {
546
+ readDir
547
+ };
548
+
506
549
  // src/is.ts
507
550
  var is_exports = {};
508
551
  __export(is_exports, {
@@ -517,11 +560,11 @@ function empty(val) {
517
560
  if (object(val)) return Object.keys(val).length === 0;
518
561
  return false;
519
562
  }
520
- function inRange(num2, a, b) {
563
+ function inRange(num, a, b) {
521
564
  let min = b !== void 0 ? a : 0;
522
565
  let max = b !== void 0 ? b : a;
523
566
  if (min > max) [min, max] = [max, min];
524
- return num2 >= min && num2 <= max;
567
+ return num >= min && num <= max;
525
568
  }
526
569
  function object(val) {
527
570
  return val !== null && typeof val === "object" && !Array.isArray(val);
@@ -556,6 +599,12 @@ var math_exports = {};
556
599
  __export(math_exports, {
557
600
  math: () => math
558
601
  });
602
+ function clamp(num, a, b) {
603
+ let min = b !== void 0 ? a : 0;
604
+ let max = b !== void 0 ? b : a;
605
+ if (min > max) [min, max] = [max, min];
606
+ return Math.max(min, Math.min(num, max));
607
+ }
559
608
  function invLerp(start, end, value) {
560
609
  if (start === end) return 0;
561
610
  return (value - start) / (end - start);
@@ -563,8 +612,8 @@ function invLerp(start, end, value) {
563
612
  function lerp(start, end, t) {
564
613
  return start + (end - start) * t;
565
614
  }
566
- function ms(num2) {
567
- return Math.floor(num2 * 1e3);
615
+ function ms(num) {
616
+ return Math.floor(num * 1e3);
568
617
  }
569
618
  function percent(a, b, round = true) {
570
619
  const result = a / b * 100;
@@ -574,17 +623,20 @@ function remap(value, inMin, inMax, outMin, outMax) {
574
623
  const t = invLerp(inMin, inMax, value);
575
624
  return lerp(outMin, outMax, t);
576
625
  }
577
- function secs(num2) {
578
- return Math.floor(num2 / 1e3);
626
+ function secs(num) {
627
+ return Math.floor(num / 1e3);
579
628
  }
580
- function sum(array, selector, ignoreNaN) {
581
- return array.map(selector).reduce((a, b) => {
582
- const invalid = isNaN(b) && !ignoreNaN;
583
- if (invalid) throw new TypeError(`sum: '${b}' is not a valid number.`);
629
+ function sum(array, selector) {
630
+ const _array = selector ? array.map(selector) : array;
631
+ if (!_array.every((v) => typeof v === "number")) {
632
+ throw new TypeError(`sum: Array must only contain numbers.`);
633
+ }
634
+ return _array.reduce((a, b) => {
584
635
  return (isNaN(b) ? 0 : b) < 0 ? a - -b : a + (b || 0);
585
636
  }, 0);
586
637
  }
587
638
  var math = {
639
+ clamp,
588
640
  invLerp,
589
641
  lerp,
590
642
  ms,
@@ -594,21 +646,6 @@ var math = {
594
646
  sum
595
647
  };
596
648
 
597
- // src/num.ts
598
- var num_exports = {};
599
- __export(num_exports, {
600
- num: () => num
601
- });
602
- function clamp(num2, a, b) {
603
- let min = b !== void 0 ? a : 0;
604
- let max = b !== void 0 ? b : a;
605
- if (min > max) [min, max] = [max, min];
606
- return Math.max(min, Math.min(num2, max));
607
- }
608
- var num = {
609
- clamp
610
- };
611
-
612
649
  // src/obj.ts
613
650
  var obj_exports = {};
614
651
  __export(obj_exports, {
@@ -786,17 +823,9 @@ function throttle(fn2, limit) {
786
823
  }
787
824
  };
788
825
  }
789
- function wait(ms2) {
790
- return new Promise(
791
- (resolve) => setTimeout(() => {
792
- resolve(true);
793
- }, ms2)
794
- );
795
- }
796
826
  var timing = {
797
827
  debounce,
798
- throttle,
799
- wait
828
+ throttle
800
829
  };
801
830
 
802
831
  // src/to.ts
@@ -830,16 +859,16 @@ function Pipe(value, ...fns) {
830
859
  }
831
860
 
832
861
  // src/Storage.ts
833
- var import_node_fs = __toESM(require("fs"));
834
- var import_node_path = __toESM(require("path"));
862
+ var import_node_fs2 = __toESM(require("fs"));
863
+ var import_node_path2 = __toESM(require("path"));
835
864
  var Storage = class {
836
865
  isNode = typeof window === "undefined";
837
866
  filePath = null;
838
867
  memoryCache = /* @__PURE__ */ new Map();
839
868
  loadFromFile() {
840
- if (this.filePath && import_node_fs.default.existsSync(this.filePath)) {
869
+ if (this.filePath && import_node_fs2.default.existsSync(this.filePath)) {
841
870
  try {
842
- const data = JSON.parse(import_node_fs.default.readFileSync(this.filePath, "utf-8"));
871
+ const data = JSON.parse(import_node_fs2.default.readFileSync(this.filePath, "utf-8"));
843
872
  Object.entries(data).forEach(([k, v]) => this.memoryCache.set(k, JSON.stringify(v)));
844
873
  } catch (err) {
845
874
  console.error(`Store: Failed to load file '${this.filePath}'`, err);
@@ -850,7 +879,7 @@ var Storage = class {
850
879
  if (this.isNode && this.filePath) {
851
880
  const out = {};
852
881
  this.memoryCache.forEach((v, k) => out[k] = JSON.parse(v));
853
- import_node_fs.default.writeFileSync(this.filePath, JSON.stringify(out, null, 2));
882
+ import_node_fs2.default.writeFileSync(this.filePath, JSON.stringify(out, null, 2));
854
883
  }
855
884
  }
856
885
  /**
@@ -861,7 +890,7 @@ var Storage = class {
861
890
  */
862
891
  constructor(fileName, directory = process.cwd()) {
863
892
  if (this.isNode && fileName) {
864
- this.filePath = import_node_path.default.join(directory, fileName.endsWith(".json") ? fileName : `${fileName}.json`);
893
+ this.filePath = import_node_path2.default.join(directory, fileName.endsWith(".json") ? fileName : `${fileName}.json`);
865
894
  this.loadFromFile();
866
895
  }
867
896
  }
@@ -1062,15 +1091,15 @@ var Loop = class extends TypedEmitterBase {
1062
1091
  };
1063
1092
 
1064
1093
  // src/index.ts
1065
- var $ = {
1094
+ var qznt = {
1066
1095
  ...arr_exports,
1067
1096
  ...async_exports,
1068
1097
  ...fn_exports,
1069
1098
  ...date_exports,
1070
1099
  ...format_exports,
1100
+ ...fs_exports,
1071
1101
  ...is_exports,
1072
1102
  ...math_exports,
1073
- ...num_exports,
1074
1103
  ...obj_exports,
1075
1104
  ...timing_exports,
1076
1105
  ...rnd_exports,
@@ -1081,10 +1110,11 @@ var $ = {
1081
1110
  Cache,
1082
1111
  Loop
1083
1112
  };
1084
- var qznt = $;
1085
- var index_default = $;
1113
+ var $ = qznt;
1114
+ var index_default = qznt;
1086
1115
  // Annotate the CommonJS export names for ESM import in node:
1087
1116
  0 && (module.exports = {
1117
+ $,
1088
1118
  Cache,
1089
1119
  Loop,
1090
1120
  Pipe,
@@ -1094,11 +1124,10 @@ var index_default = $;
1094
1124
  date,
1095
1125
  fn,
1096
1126
  format,
1127
+ fs,
1097
1128
  is,
1098
1129
  math,
1099
- num,
1100
1130
  obj,
1101
- qznt,
1102
1131
  rnd,
1103
1132
  str,
1104
1133
  timing,