qznt 1.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 +138 -0
- package/dist/index.cjs +1107 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +952 -0
- package/dist/index.d.ts +952 -0
- package/dist/index.js +1059 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# qznt
|
|
2
|
+
|
|
3
|
+
**qznt** (pronounced as in _ex-quisite_) is a strictly-typed, high-performant utility toolkit for modern TypeScript/Javascript and Node.js environments.
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install qznt
|
|
9
|
+
# or
|
|
10
|
+
pnpm add qznt
|
|
11
|
+
# or
|
|
12
|
+
yarn add qznt
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🛠Quick Start
|
|
16
|
+
|
|
17
|
+
You can import this library as `qznt`, `$`, or by namespace.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import qznt from "qznt";
|
|
21
|
+
// or
|
|
22
|
+
import { $ } from "qznt";
|
|
23
|
+
// or
|
|
24
|
+
import { obj, Loop, date } from "qznt";
|
|
25
|
+
|
|
26
|
+
// Deep object access (defaults to "dark" if mode is undefined)
|
|
27
|
+
const theme = qznt.obj.get(settings, "ui.theme.mode", "dark");
|
|
28
|
+
|
|
29
|
+
// Human-readable durations
|
|
30
|
+
const timeRemaining = $.date.duration(Date.now() + 5000); // "5 seconds"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 📦 Namespaces
|
|
34
|
+
|
|
35
|
+
- **`qznt.arr` (Lists)**: 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.is` (Predicates)**: Type guards: `is.today`, `is.empty`, `is.object`, and `is.sorted`
|
|
41
|
+
- **`qznt.math` (Calculations)**: `lerp`, `invLerp`, `remap`, `percent`, and `sum`
|
|
42
|
+
- **`qznt.num` (Numbers)**: Essential logic like `clamp` and range handling
|
|
43
|
+
- **`qznt.obj` (Data)**: Type-safe deep paths (`get`, `set`, `merge`, `pick`, `omit`)
|
|
44
|
+
- **`qznt.rnd` (Random)**: Seedable PRNG, `weighted` choice, `sampler`, and `chance`
|
|
45
|
+
- **`qznt.timing` (Execution)**: `debounce`, `throttle`, and promise-based `wait`
|
|
46
|
+
- **`qznt.to` (Transformations)**: Powerful data mappers like `to.record`
|
|
47
|
+
|
|
48
|
+
## ✨ Featured Utilities
|
|
49
|
+
|
|
50
|
+
### The Smart `Loop`
|
|
51
|
+
|
|
52
|
+
The `qznt.Loop` ensures asynchronous tasks never overlap. It waits for execution to finish before scheduling the next interval and supports precise pausing/resuming based on remaining time.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import qznt from "qznt";
|
|
56
|
+
|
|
57
|
+
const heartbeat = new qznt.Loop<string>(async () => {
|
|
58
|
+
return await syncData();
|
|
59
|
+
}, qznt.date.parse("10s"));
|
|
60
|
+
|
|
61
|
+
// Result is automatically inferred as 'string'
|
|
62
|
+
heartbeat.on("tick", res => console.log(`Synced: ${res}`));
|
|
63
|
+
|
|
64
|
+
heartbeat.pause(); // Calculates remaining time in the current cycle
|
|
65
|
+
heartbeat.resume(); // Resumes with the exact remaining delay
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Advanced Caching & Storage
|
|
69
|
+
|
|
70
|
+
`qznt` provides high-performant data persistence and memory management.
|
|
71
|
+
|
|
72
|
+
- `qznt.Cache`: An in-memory TTL cache with Sampled Passive/Active Eviction. It automatically cleans up expired entries to prevent memory leaks without blocking the event loop.
|
|
73
|
+
- `qznt.Storage`: A universal persistence layer. It automatically uses `localStorage` in the browser and falls back to a local JSON file in Node.js environments.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// Cache with a 1-minute global TTL
|
|
77
|
+
const userCache = new qznt.Cache<UserData>(60000);
|
|
78
|
+
userCache.set("user_1", data);
|
|
79
|
+
|
|
80
|
+
// Persistent storage (Browser or Node)
|
|
81
|
+
const settings = new qznt.Storage("app_settings");
|
|
82
|
+
settings.set("theme", "dark");
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Seedable Randomness
|
|
86
|
+
|
|
87
|
+
Every random utility in `qznt` accepts an optional seed. This allows you to generate predictable random data for testing, games, or procedural generation.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// Always returns the same item for seed 12345
|
|
91
|
+
const item = qznt.rnd.choice(["Sword", "Shield", "Potion"], 12345);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Object Merging
|
|
95
|
+
|
|
96
|
+
A deep, recursive merge that maintains TypeScript's type safety across multiple sources.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const config = qznt.obj.merge(defaultConfig, userConfig, envOverrides);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Type Guards
|
|
103
|
+
|
|
104
|
+
The `is` namespace provides predicates that act as TypeScript type guards, ensuring safety across your application.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
if (qznt.is.today(user.lastLogin)) {
|
|
108
|
+
console.log("Welcome back!");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (qznt.is.empty(results)) {
|
|
112
|
+
return "No data found";
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Type-Safe Transformations
|
|
117
|
+
|
|
118
|
+
The `to` and `arr` namespaces provide _exquisite_ ways to transform data structures while maintaining total type safety.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const userRecord = qznt.to.record(usersArray, u => ({
|
|
122
|
+
key: u.id,
|
|
123
|
+
value: { name: u.username, active: qznt.is.today(u.lastLogin) }
|
|
124
|
+
}));
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 👀 Mentionables
|
|
128
|
+
|
|
129
|
+
- Zero Dependencies: Lightweight and fast.
|
|
130
|
+
- Tree-Shakable: Only bundle the functions you actually use.
|
|
131
|
+
- Strictly Typed: Deep inference for everything from EventEmitter results to object paths.
|
|
132
|
+
- Node & Browser: Optimized for Node.js but safe for modern browsers.
|
|
133
|
+
|
|
134
|
+
## 👋 About
|
|
135
|
+
|
|
136
|
+
_Built by **@xsqu1znt** as a core library for my projects._ Published for anyone to use.
|
|
137
|
+
|
|
138
|
+
License: MIT
|