qznt 1.0.36 → 2.0.0

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
@@ -14,57 +14,31 @@ yarn add qznt
14
14
 
15
15
  ## 🛠 Quick Start
16
16
 
17
- You can import this library as `qznt`, `$`, or by namespace.
18
-
19
17
  ```ts
20
- import qznt from "qznt";
21
- // or
22
- import { $ } from "qznt";
23
- // or
24
- import { obj, Loop, date } from "qznt";
18
+ import { getProp, formatETA } from "qznt";
25
19
 
26
- // Nested object access (defaults to "dark" if mode is undefined)
27
- const theme = qznt.obj.get(settings, "ui.theme.mode", "dark");
20
+ // Nested object access (defaults to "dark" if mode ends up being undefined)
21
+ const theme = getProp(settings, "ui.theme.mode", "dark");
28
22
 
29
23
  // Readable durations
30
- const time = $.date.duration(Date.now() + 5000); // "in 5 seconds"
24
+ const time = formatETA(Date.now() + 5000); // "in 5 seconds"
31
25
  ```
32
26
 
33
- ## 📦 Namespaces
34
-
35
- - **`qznt.arr` (Arrays)**: Advanced `chunk`, `cluster`, `shuffle`, `unique`, and `seqMap`
36
- - **`qznt.async` (Promises)**: `retry` logic with exponential backoff and delay
37
- - **`qznt.date` (Time)**: Shorthand parsing (`"1h 30m"`), `duration` (digital/hms), and `eta`
38
- - **`qznt.fn` (Functions)**: `memoize` with TTL and custom resolvers
39
- - **`qznt.format` (Strings)**: `currency`, `memory` (bytes), `ordinal`, and `compactNumber`
40
- - **`qznt.fs` (File System)**: Efficient recursive directory scanning with `readDir`
41
- - **`qznt.is` (Predicates)**: Type guards: `is.today`, `is.empty`, `is.object`, and `is.sorted`
42
- - **`qznt.math` (Calculations)**: `lerp`, `invLerp`, `remap`, `percent`, and `sum`
43
- - **`qznt.num` (Numbers)**: Essential logic like `clamp` and range handling
44
- - **`qznt.obj` (Data)**: Type-safe deep paths (`get`, `set`, `merge`, `pick`, `omit`)
45
- - **`qznt.rnd` (Random)**: Seedable PRNG, `weighted` choice, `sampler`, and `chance`
46
- - **`qznt.timing` (Execution)**: `debounce`, `throttle`, and promise-based `wait`
47
- - **`qznt.to` (Transformations)**: Powerful data mappers like `to.record`
48
-
49
- _These are just the highlights, there's more inside._
50
-
51
27
  ## ✨ Featured Utilities
52
28
 
53
29
  ### The Smart `Loop`
54
30
 
55
- `qznt.Loop` ensures async tasks never overlap. It waits for execution to finish before scheduling the next interval, and supports precise pausing/resuming. _This is usually more efficient than `node-cron` for tasks that don't need scheduling._
31
+ `Loop` ensures async tasks never overlap. It waits for execution to finish before scheduling the next interval, and supports precise pausing/resuming. _This is more lightweight than using `node-cron` for tasks that don't need scheduling._
56
32
 
57
33
  ```ts
58
- import qznt from "qznt";
34
+ import { Loop, parseTime } from "qznt";
59
35
 
60
- const heartbeat = new qznt.Loop<string>(async () => {
61
- return await syncData();
62
- }, qznt.date.parse("10s"));
36
+ const heartbeat = new Loop<string>(syncData, parseTime("10s"));
63
37
 
64
- // Result is automatically inferred as 'string'
65
- heartbeat.on("tick", res => console.log(`Synced: ${res}`));
38
+ // Result is inferred as 'string'
39
+ heartbeat.on("tick", result => console.log(`Synced: ${result}`));
66
40
 
67
- heartbeat.pause(); // Calculates remaining time in the current cycle
41
+ heartbeat.pause(); // Notes how much time's remaining until the next cycle
68
42
  heartbeat.resume(); // Resumes with the exact remaining delay
69
43
  ```
70
44
 
@@ -72,26 +46,30 @@ heartbeat.resume(); // Resumes with the exact remaining delay
72
46
 
73
47
  `qznt` provides high-performant data persistence and memory management.
74
48
 
75
- - `qznt.Cache`: An in-memory TTL cache with Sampled Passive/Active Eviction. It automatically purges expired entries to prevent memory leaks without blocking the event loop.
76
- - `qznt.Storage`: A persistent cache. It automatically uses `localStorage` in browsers and falls back to local JSON files in Node.js environments. Think a mini, smart-Redis cache.
49
+ - `Cache`: An in-memory TTL cache with Sampled Passive/Active Eviction. It automatically purges expired entries to prevent memory leaks without blocking the event loop.
50
+ - `Storage`: A persistent cache. It automatically uses `localStorage` in browsers and falls back to local JSON files in Node.js environments. Think a mini, smart-Redis cache.
77
51
 
78
52
  ```ts
53
+ import { Cache, Storage } from "qznt";
54
+
79
55
  // Cache with a 1-minute global TTL
80
- const userCache = new qznt.Cache<UserData>(60000);
56
+ const userCache = new Cache<UserData>(60000);
81
57
  userCache.set("user_1", data);
82
58
 
83
- // Persistent storage (Browser or Node)
84
- const settings = new qznt.Storage("app_settings");
59
+ // Persistent storage (Browser or NodeJS based)
60
+ const settings = new Storage("app_settings");
85
61
  settings.set("theme", "dark");
86
62
  ```
87
63
 
88
64
  ### Seedable Randomness
89
65
 
90
- Every random utility in `qznt.rnd` accepts an optional seed. This allows you to generate predictable random data for testing, games, or procedural generation.
66
+ Every random utility in `qznt` accepts an optional seed. This allows you to generate predictable random data for testing, games, or procedural generation.
91
67
 
92
68
  ```ts
69
+ import { rndChoice } from "qznt";
70
+
93
71
  // Always returns the same item for seed 12345
94
- const item = qznt.rnd.choice(["Sword", "Shield", "Potion"], 12345);
72
+ const item = rndChoice(["Sword", "Shield", "Potion"], 12345);
95
73
  ```
96
74
 
97
75
  ### Object Merging
@@ -99,34 +77,27 @@ const item = qznt.rnd.choice(["Sword", "Shield", "Potion"], 12345);
99
77
  A deep, recursive merge that maintains type safety across multiple sources.
100
78
 
101
79
  ```ts
102
- const config = qznt.obj.merge(defaultConfig, userConfig, envOverrides);
80
+ import { merge } from "qznt";
81
+
82
+ const config = merge(defaultConfig, userConfig, envOverrides);
103
83
  ```
104
84
 
105
85
  ### Type Guards
106
86
 
107
- The `qznt.is` namespace provides predicates that act as type guards, ensuring type safety across your app.
87
+ `qznt` provides predicates that act as type guards, ensuring type safety across your app.
108
88
 
109
89
  ```ts
110
- if (qznt.is.today(user.lastLogin)) {
90
+ // Checks if the user's lastLogin date is from today
91
+ if (isToday(user.lastLogin)) {
111
92
  console.log("Welcome back!");
112
93
  }
113
94
 
114
- if (qznt.is.empty(results)) {
95
+ // Checks if the `results` array is empty
96
+ if (isEmpty(results)) {
115
97
  return "No data found";
116
98
  }
117
99
  ```
118
100
 
119
- ### Type-Safe Transformations
120
-
121
- The `qznt.to` and `qznt.arr` namespaces also provide _✨ exquisite ✨_ ways to transform data structures while maintaining type safety.
122
-
123
- ```ts
124
- const userRecord = qznt.to.record(usersArray, u => ({
125
- key: u.id,
126
- value: { name: u.username, active: qznt.is.today(u.lastLogin) }
127
- }));
128
- ```
129
-
130
101
  ## 👀 Mentionables
131
102
 
132
103
  - Zero Dependencies: Lightweight and fast.