@e280/stz 0.0.0-31 → 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.
Files changed (2) hide show
  1. package/README.md +60 -9
  2. 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
@@ -35,7 +34,7 @@ const map = new MapG<number, string>([
35
34
  // "rofl"
36
35
  ```
37
36
 
38
- ### nap
37
+ ### 🍏 nap
39
38
  > sleep for some milliseconds
40
39
 
41
40
  ```ts
@@ -45,7 +44,7 @@ await nap(900)
45
44
  // wait for 900 milliseconds
46
45
  ```
47
46
 
48
- ### defer
47
+ ### 🍏 defer
49
48
  > defer the resolve/reject of a promise to the outside
50
49
 
51
50
  ```ts
@@ -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)
@@ -155,20 +153,40 @@ fn()
155
153
  console.log(count) // 1
156
154
  ```
157
155
 
158
- ### 🍏 `deadline(100, message, fn)`
156
+ ### 🍏 `deadline(100, fn)`
159
157
  > throws an error if the async function takes too long
160
158
 
161
159
  ```ts
162
160
  import {deadline} from "@e280/stz"
163
161
 
164
- const fn = deadline(100, "deadline exceeded", async() => {
162
+ const fn = deadline(100, async() => {
165
163
 
166
164
  // example deliberately takes too long
167
165
  await nap(200)
168
166
  })
169
167
 
170
168
  await fn()
171
- // DeadlineError: deadline exceeded, timed out in 0.1 seconds
169
+ // DeadlineError: deadline exceeded (0.1 seconds)
170
+ ```
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
172
190
  ```
173
191
 
174
192
  ### 🍏 `repeat(fn)`
@@ -194,10 +212,43 @@ stop()
194
212
  <br/>
195
213
 
196
214
  ## 🧰 DATA UTILITIES
197
- > transforming and representing binary data
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
- > represent data in arbitrary encodings
251
+ > convert data into arbitrary data encodings
201
252
  - make a BaseX instance
202
253
  ```ts
203
254
  import {BaseX} from "@e280/stz"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/stz",
3
- "version": "0.0.0-31",
3
+ "version": "0.0.0-33",
4
4
  "description": "everyday ts fns for everything",
5
5
  "license": "MIT",
6
6
  "author": "Chase Moskal <chasemoskal@gmail.com>",