qznt 1.0.1 → 1.0.21

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/index.d.mts CHANGED
@@ -178,6 +178,20 @@ declare const date: {
178
178
  parse: typeof parse;
179
179
  };
180
180
 
181
+ interface ReadDirOptions {
182
+ /** Whether to scan subdirectories. [default: true] */
183
+ recursive?: boolean;
184
+ }
185
+ /**
186
+ * Recursively (or shallowly) scans a directory and returns an array of relative file paths.
187
+ * @param path The path to the directory.
188
+ * @param options Options for the readDir function.
189
+ */
190
+ declare function readDir(path: string, options?: ReadDirOptions): string[];
191
+ declare const fs: {
192
+ readDir: typeof readDir;
193
+ };
194
+
181
195
  type AlphaCasing = "lower" | "upper" | "mixed";
182
196
  interface RndStrOptions {
183
197
  casing?: AlphaCasing;
@@ -607,7 +621,7 @@ declare function secs(num: number): number;
607
621
  * @param selector Function that selects the item's weight.
608
622
  * @param ignoreNaN If true, NaN values will not throw an error.
609
623
  */
610
- declare function sum<T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean): number;
624
+ declare function sum<T>(array: T[], selector?: (item: T) => number): number;
611
625
  declare const math: {
612
626
  clamp: typeof clamp;
613
627
  invLerp: typeof invLerp;
@@ -759,7 +773,7 @@ declare const qznt: {
759
773
  percent: (a: number, b: number, round?: boolean) => number;
760
774
  remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
761
775
  secs: (num: number) => number;
762
- sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
776
+ sum: <T>(array: T[], selector?: (item: T) => number) => number;
763
777
  };
764
778
  is: {
765
779
  defined: <T>(val: T | undefined | null) => val is T;
@@ -773,6 +787,9 @@ declare const qznt: {
773
787
  string: (val: unknown) => val is string;
774
788
  today: (date: number | Date) => boolean;
775
789
  };
790
+ fs: {
791
+ readDir: (path: string, options?: ReadDirOptions) => string[];
792
+ };
776
793
  format: {
777
794
  currency: (num: number, options?: {
778
795
  currency?: string;
@@ -880,7 +897,7 @@ declare const $: {
880
897
  percent: (a: number, b: number, round?: boolean) => number;
881
898
  remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
882
899
  secs: (num: number) => number;
883
- sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
900
+ sum: <T>(array: T[], selector?: (item: T) => number) => number;
884
901
  };
885
902
  is: {
886
903
  defined: <T>(val: T | undefined | null) => val is T;
@@ -894,6 +911,9 @@ declare const $: {
894
911
  string: (val: unknown) => val is string;
895
912
  today: (date: number | Date) => boolean;
896
913
  };
914
+ fs: {
915
+ readDir: (path: string, options?: ReadDirOptions) => string[];
916
+ };
897
917
  format: {
898
918
  currency: (num: number, options?: {
899
919
  currency?: string;
@@ -942,4 +962,4 @@ declare const $: {
942
962
  };
943
963
  };
944
964
 
945
- export { $, type AlphaCasing, type AnyFunc, Cache, type DateOptions, type DebouncedFunction, type DeepPartial, Loop, type MemoizedFunction, type ParseOptions, Pipe, type RndStrOptions, type SequentialMapContext, Storage, type ToRecordContext, type TypedEmitter, arr, async, date, qznt as default, fn, format, is, math, obj, rnd, str, timing, to };
965
+ export { $, type AlphaCasing, type AnyFunc, Cache, type DateOptions, type DebouncedFunction, type DeepPartial, Loop, type MemoizedFunction, type ParseOptions, Pipe, type ReadDirOptions, type RndStrOptions, type SequentialMapContext, Storage, type ToRecordContext, type TypedEmitter, arr, async, date, qznt as default, fn, format, fs, is, math, obj, rnd, str, timing, to };
package/dist/index.d.ts CHANGED
@@ -178,6 +178,20 @@ declare const date: {
178
178
  parse: typeof parse;
179
179
  };
180
180
 
181
+ interface ReadDirOptions {
182
+ /** Whether to scan subdirectories. [default: true] */
183
+ recursive?: boolean;
184
+ }
185
+ /**
186
+ * Recursively (or shallowly) scans a directory and returns an array of relative file paths.
187
+ * @param path The path to the directory.
188
+ * @param options Options for the readDir function.
189
+ */
190
+ declare function readDir(path: string, options?: ReadDirOptions): string[];
191
+ declare const fs: {
192
+ readDir: typeof readDir;
193
+ };
194
+
181
195
  type AlphaCasing = "lower" | "upper" | "mixed";
182
196
  interface RndStrOptions {
183
197
  casing?: AlphaCasing;
@@ -607,7 +621,7 @@ declare function secs(num: number): number;
607
621
  * @param selector Function that selects the item's weight.
608
622
  * @param ignoreNaN If true, NaN values will not throw an error.
609
623
  */
610
- declare function sum<T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean): number;
624
+ declare function sum<T>(array: T[], selector?: (item: T) => number): number;
611
625
  declare const math: {
612
626
  clamp: typeof clamp;
613
627
  invLerp: typeof invLerp;
@@ -759,7 +773,7 @@ declare const qznt: {
759
773
  percent: (a: number, b: number, round?: boolean) => number;
760
774
  remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
761
775
  secs: (num: number) => number;
762
- sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
776
+ sum: <T>(array: T[], selector?: (item: T) => number) => number;
763
777
  };
764
778
  is: {
765
779
  defined: <T>(val: T | undefined | null) => val is T;
@@ -773,6 +787,9 @@ declare const qznt: {
773
787
  string: (val: unknown) => val is string;
774
788
  today: (date: number | Date) => boolean;
775
789
  };
790
+ fs: {
791
+ readDir: (path: string, options?: ReadDirOptions) => string[];
792
+ };
776
793
  format: {
777
794
  currency: (num: number, options?: {
778
795
  currency?: string;
@@ -880,7 +897,7 @@ declare const $: {
880
897
  percent: (a: number, b: number, round?: boolean) => number;
881
898
  remap: (value: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
882
899
  secs: (num: number) => number;
883
- sum: <T>(array: T[], selector: (item: T) => number, ignoreNaN?: boolean) => number;
900
+ sum: <T>(array: T[], selector?: (item: T) => number) => number;
884
901
  };
885
902
  is: {
886
903
  defined: <T>(val: T | undefined | null) => val is T;
@@ -894,6 +911,9 @@ declare const $: {
894
911
  string: (val: unknown) => val is string;
895
912
  today: (date: number | Date) => boolean;
896
913
  };
914
+ fs: {
915
+ readDir: (path: string, options?: ReadDirOptions) => string[];
916
+ };
897
917
  format: {
898
918
  currency: (num: number, options?: {
899
919
  currency?: string;
@@ -942,4 +962,4 @@ declare const $: {
942
962
  };
943
963
  };
944
964
 
945
- export { $, type AlphaCasing, type AnyFunc, Cache, type DateOptions, type DebouncedFunction, type DeepPartial, Loop, type MemoizedFunction, type ParseOptions, Pipe, type RndStrOptions, type SequentialMapContext, Storage, type ToRecordContext, type TypedEmitter, arr, async, date, qznt as default, fn, format, is, math, obj, rnd, str, timing, to };
965
+ export { $, type AlphaCasing, type AnyFunc, Cache, type DateOptions, type DebouncedFunction, type DeepPartial, Loop, type MemoizedFunction, type ParseOptions, Pipe, type ReadDirOptions, type RndStrOptions, type SequentialMapContext, Storage, type ToRecordContext, type TypedEmitter, arr, async, date, qznt as default, fn, format, fs, is, math, obj, rnd, str, timing, to };
package/dist/index.js CHANGED
@@ -463,6 +463,41 @@ var format = {
463
463
  compactNumber
464
464
  };
465
465
 
466
+ // src/fs.ts
467
+ var fs_exports = {};
468
+ __export(fs_exports, {
469
+ fs: () => fs
470
+ });
471
+ import _fs from "fs";
472
+ import { join } from "path";
473
+ function readDir(path2, options = {}) {
474
+ const { recursive = true } = options;
475
+ if (!_fs.existsSync(path2)) return [];
476
+ if (!recursive) {
477
+ return _fs.readdirSync(path2).filter((fn2) => {
478
+ return _fs.statSync(join(path2, fn2)).isFile();
479
+ });
480
+ }
481
+ const walk = (dir, base = "") => {
482
+ const results = [];
483
+ const entries = _fs.readdirSync(dir, { withFileTypes: true });
484
+ for (const entry of entries) {
485
+ const relativePath = base ? join(base, entry.name) : entry.name;
486
+ const fullPath = join(dir, entry.name);
487
+ if (entry.isDirectory()) {
488
+ results.push(...walk(fullPath, relativePath));
489
+ } else if (entry.isFile()) {
490
+ results.push(relativePath);
491
+ }
492
+ }
493
+ return results;
494
+ };
495
+ return walk(path2);
496
+ }
497
+ var fs = {
498
+ readDir
499
+ };
500
+
466
501
  // src/is.ts
467
502
  var is_exports = {};
468
503
  __export(is_exports, {
@@ -543,10 +578,12 @@ function remap(value, inMin, inMax, outMin, outMax) {
543
578
  function secs(num) {
544
579
  return Math.floor(num / 1e3);
545
580
  }
546
- function sum(array, selector, ignoreNaN) {
547
- return array.map(selector).reduce((a, b) => {
548
- const invalid = isNaN(b) && !ignoreNaN;
549
- if (invalid) throw new TypeError(`sum: '${b}' is not a valid number.`);
581
+ function sum(array, selector) {
582
+ const _array = selector ? array.map(selector) : array;
583
+ if (!_array.every((v) => typeof v === "number")) {
584
+ throw new TypeError(`sum: Array must only contain numbers.`);
585
+ }
586
+ return _array.reduce((a, b) => {
550
587
  return (isNaN(b) ? 0 : b) < 0 ? a - -b : a + (b || 0);
551
588
  }, 0);
552
589
  }
@@ -774,16 +811,16 @@ function Pipe(value, ...fns) {
774
811
  }
775
812
 
776
813
  // src/Storage.ts
777
- import fs from "fs";
814
+ import fs2 from "fs";
778
815
  import path from "path";
779
816
  var Storage = class {
780
817
  isNode = typeof window === "undefined";
781
818
  filePath = null;
782
819
  memoryCache = /* @__PURE__ */ new Map();
783
820
  loadFromFile() {
784
- if (this.filePath && fs.existsSync(this.filePath)) {
821
+ if (this.filePath && fs2.existsSync(this.filePath)) {
785
822
  try {
786
- const data = JSON.parse(fs.readFileSync(this.filePath, "utf-8"));
823
+ const data = JSON.parse(fs2.readFileSync(this.filePath, "utf-8"));
787
824
  Object.entries(data).forEach(([k, v]) => this.memoryCache.set(k, JSON.stringify(v)));
788
825
  } catch (err) {
789
826
  console.error(`Store: Failed to load file '${this.filePath}'`, err);
@@ -794,7 +831,7 @@ var Storage = class {
794
831
  if (this.isNode && this.filePath) {
795
832
  const out = {};
796
833
  this.memoryCache.forEach((v, k) => out[k] = JSON.parse(v));
797
- fs.writeFileSync(this.filePath, JSON.stringify(out, null, 2));
834
+ fs2.writeFileSync(this.filePath, JSON.stringify(out, null, 2));
798
835
  }
799
836
  }
800
837
  /**
@@ -1012,6 +1049,7 @@ var qznt = {
1012
1049
  ...fn_exports,
1013
1050
  ...date_exports,
1014
1051
  ...format_exports,
1052
+ ...fs_exports,
1015
1053
  ...is_exports,
1016
1054
  ...math_exports,
1017
1055
  ...obj_exports,
@@ -1038,6 +1076,7 @@ export {
1038
1076
  index_default as default,
1039
1077
  fn,
1040
1078
  format,
1079
+ fs,
1041
1080
  is,
1042
1081
  math,
1043
1082
  obj,