@e280/stz 0.0.0-32 → 0.0.0-33
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 +55 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@ zero dependencies.
|
|
|
10
10
|
<br/>
|
|
11
11
|
|
|
12
12
|
## 🧰 STZ PRIMITIVES
|
|
13
|
-
> cool concepts we use all over the place
|
|
14
13
|
|
|
15
14
|
### 🍏 MapG
|
|
16
15
|
> extended js map
|
|
@@ -123,7 +122,6 @@ import {pub, sub} from "@e280/stz"
|
|
|
123
122
|
<br/>
|
|
124
123
|
|
|
125
124
|
## 🧰 FN TOOLS
|
|
126
|
-
> function-oriented tools
|
|
127
125
|
|
|
128
126
|
### 🍏 `queue(fn)`
|
|
129
127
|
> execute calls in sequence (not concurrent)
|
|
@@ -171,6 +169,26 @@ await fn()
|
|
|
171
169
|
// DeadlineError: deadline exceeded (0.1 seconds)
|
|
172
170
|
```
|
|
173
171
|
|
|
172
|
+
### 🍏 `debounce(100, fn)`
|
|
173
|
+
> wait some time before actually executing the fn (absorbing redundant calls)
|
|
174
|
+
|
|
175
|
+
we use `debounce` a lot in ui code, like on a user's keyboard input in a form field, but rendering the form input can actually be slow enough that it causes problems when they type fast — to eliminate the jank, we `debounce` with like 400 ms, so we wait for the user to finish typing for a moment before actually running the validation.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import {debounce} from "@e280/stz"
|
|
179
|
+
|
|
180
|
+
const fn = debounce(100, async() => {
|
|
181
|
+
await coolSlowActionOrWhatever()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// each fn() call resets the timer
|
|
185
|
+
fn()
|
|
186
|
+
fn()
|
|
187
|
+
fn()
|
|
188
|
+
|
|
189
|
+
// coolSlowActionOrWhatever, the others are redundant
|
|
190
|
+
```
|
|
191
|
+
|
|
174
192
|
### 🍏 `repeat(fn)`
|
|
175
193
|
> execute a function over and over again, back to back
|
|
176
194
|
|
|
@@ -194,10 +212,43 @@ stop()
|
|
|
194
212
|
<br/>
|
|
195
213
|
|
|
196
214
|
## 🧰 DATA UTILITIES
|
|
197
|
-
|
|
215
|
+
|
|
216
|
+
### 🍏 Hex
|
|
217
|
+
> convert to/from hexadecimal string format
|
|
218
|
+
- `Hex.fromBytes(bytes)` — bytes to hex string
|
|
219
|
+
- `Hex.toBytes(string)` — hex string to bytes
|
|
220
|
+
- `Hex.random(32)` — generate random hex string (32 bytes)
|
|
221
|
+
|
|
222
|
+
### 🍏 Base64
|
|
223
|
+
> convert to/from base64 string format
|
|
224
|
+
- `Base64.fromBytes(bytes)` — bytes to string
|
|
225
|
+
- `Base64.toBytes(string)` — string to bytes
|
|
226
|
+
- `Base64.random(32)` — generate random string (32 bytes)
|
|
227
|
+
|
|
228
|
+
### 🍏 Base64url
|
|
229
|
+
> convert to/from base64 string format
|
|
230
|
+
- `Base64url.fromBytes(bytes)` — bytes to string
|
|
231
|
+
- `Base64url.toBytes(string)` — string to bytes
|
|
232
|
+
- `Base64url.random(32)` — generate random string (32 bytes)
|
|
233
|
+
|
|
234
|
+
### 🍏 Base58
|
|
235
|
+
> convert to/from base64 string format
|
|
236
|
+
- `Base58.fromBytes(bytes)` — bytes to string
|
|
237
|
+
- `Base58.toBytes(string)` — string to bytes
|
|
238
|
+
- `Base58.random(32)` — generate random string (32 bytes)
|
|
239
|
+
|
|
240
|
+
### 🍏 Txt
|
|
241
|
+
> convert to/from utf8 string format
|
|
242
|
+
- `Txt.fromBytes(bytes)` — bytes to string
|
|
243
|
+
- `Txt.toBytes(string)` — string to bytes
|
|
244
|
+
|
|
245
|
+
### 🍏 Bytes
|
|
246
|
+
> utilities for dealing with Uint8Array
|
|
247
|
+
- `Bytes.eq(bytesA, bytesB)` — check if two byte arrays are equal
|
|
248
|
+
- `Bytes.random(32)` — generate crypto-random bytes
|
|
198
249
|
|
|
199
250
|
### 🍏 BaseX
|
|
200
|
-
>
|
|
251
|
+
> convert data into arbitrary data encodings
|
|
201
252
|
- make a BaseX instance
|
|
202
253
|
```ts
|
|
203
254
|
import {BaseX} from "@e280/stz"
|