@thi.ng/transducers-binary 2.1.103 → 2.1.104

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-03-01T15:22:50Z
3
+ - **Last updated**: 2024-03-02T14:05:52Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -101,26 +101,24 @@ directory are using this package:
101
101
 
102
102
  [Generated API docs](https://docs.thi.ng/umbrella/transducers-binary/)
103
103
 
104
- ```ts
105
- import * as tx from "@thi.ng/transducers";
106
- import * as txb from "@thi.ng/transducers-binary";
107
- ```
108
-
109
104
  ### Random bits
110
105
 
111
106
  ```ts
107
+ import { take } from "@thi.ng/transducers";
108
+ import { randomBits } from "@thi.ng/transducers-binary";
109
+
112
110
  // 10 samples with 50% probability of drawing a 1
113
- [...txb.randomBits(0.5, 10)]
111
+ [...randomBits(0.5, 10)]
114
112
  // [ 1, 0, 1, 1, 0, 1, 0, 1, 1, 0 ]
115
113
 
116
114
  // infinite iterator without 2nd arg, so limit with `take()`
117
- [...tx.take(10, txb.randomBits(0.1))]
115
+ [...take(10, randomBits(0.1))]
118
116
  // [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
119
117
 
120
118
  import { Smush32 } from "@thi.ng/random";
121
119
 
122
120
  // with seeded PRNG
123
- [...txb.randomBits(0.5, 10, new Smush32(12345678))]
121
+ [...randomBits(0.5, 10, new Smush32(12345678))]
124
122
  // [ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0 ]
125
123
  ```
126
124
 
@@ -131,9 +129,11 @@ transducers. [See code
131
129
  here](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-binary/src/hex-dump.ts).
132
130
 
133
131
  ```ts
132
+ import { hexDump } from "@thi.ng/transducers-binary";
133
+
134
134
  src = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 33, 48, 49, 50, 51, 126, 122, 121, 120]
135
135
 
136
- [...txb.hexDump({ cols: 8, address: 0x100 }, src)]
136
+ [...hexDump({ cols: 8, address: 0x100 }, src)]
137
137
  // [ '00000100 | 41 42 43 44 45 46 47 48 | ABCDEFGH',
138
138
  // '00000108 | 49 4a 21 30 31 32 33 7e | IJ!0123~',
139
139
  // '00000110 | 7a 79 78 00 00 00 00 00 | zyx.....' ]
@@ -147,6 +147,9 @@ reducer transforms a stream of declarative data definitions (optionally
147
147
  with Little-Endian encoding) into an `Uint8Array`.
148
148
 
149
149
  ```ts
150
+ import * as tx from "@thi.ng/transducers";
151
+ import * as txb from "@thi.ng/transducers-binary";
152
+
150
153
  const bytes = txb.bytes(
151
154
  // initial buffer capacity (grows on demand)
152
155
  32,
@@ -175,18 +178,21 @@ console.log(tx.str("\n", txb.hexDump({}, bytes)));
175
178
  Decompose / transform a stream of fixed size words into their bits:
176
179
 
177
180
  ```ts
178
- [...txb.bits(8, [0xf0, 0xaa])];
181
+ import { comp, map, partition, str, transduce } from "@thi.ng/transducers";
182
+ import { bits } from "@thi.ng/transducers-binary";
183
+
184
+ [...bits(8, [0xf0, 0xaa])];
179
185
  // [ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 ]
180
186
 
181
187
  console.log(
182
- tx.transduce(
183
- tx.comp(
184
- txb.bits(8),
185
- tx.map((x) => (x ? "#" : ".")),
186
- tx.partition(8),
187
- tx.map((x) => x.join(""))
188
+ transduce(
189
+ comp(
190
+ bits(8),
191
+ map((x) => (x ? "#" : ".")),
192
+ partition(8),
193
+ map((x) => x.join(""))
188
194
  ),
189
- tx.str("\n"),
195
+ str("\n"),
190
196
  [0x00, 0x18, 0x3c, 0x66, 0x66, 0x7e, 0x66, 0x00]
191
197
  )
192
198
  );
@@ -204,7 +210,10 @@ Extended to transform longer strings (taken from the [bitmap-font
204
210
  example](https://github.com/thi-ng/umbrella/tree/develop/examples/bitmap-font),
205
211
  [live demo](https://demo.thi.ng/umbrella/bitmap-font/)):
206
212
 
207
- ```ts
213
+ ```js
214
+ import * as tx from "@thi.ng/transducers";
215
+ import { bits } from "@thi.ng/transducers-binary";
216
+
208
217
  // font lookup table
209
218
  const chars = {
210
219
  a: [0x00, 0x18, 0x3c, 0x66, 0x66, 0x7e, 0x66, 0x00],
@@ -218,7 +227,7 @@ const xfJoin = tx.map((x) => x.join(""));
218
227
  const xfChar = (i) =>
219
228
  tx.comp(
220
229
  tx.pluck(i),
221
- txb.bits(8),
230
+ bits(8),
222
231
  tx.map((x) => (x ? "#" : ".")),
223
232
  tx.partition(8),
224
233
  xfJoin
@@ -258,10 +267,16 @@ strings, these transducers stepwise convert byte values to base64 and
258
267
  back.
259
268
 
260
269
  ```ts
270
+ import * as tx from "@thi.ng/transducers";
271
+ import {
272
+ base64Decode, base64Encode,
273
+ utf8Decode, utf8Encode
274
+ } from "@thi.ng/transducers-binary";
275
+
261
276
  // here we first add an offset (0x80) to allow negative values to be encoded
262
277
  // (URL safe results can be produced via opt arg to `base64Encode`)
263
278
  enc = tx.transduce(
264
- tx.comp(tx.map((x) => x + 0x80), txb.base64Encode()),
279
+ tx.comp(tx.map((x) => x + 0x80), base64Encode()),
265
280
  tx.str(),
266
281
  tx.range(-8, 8)
267
282
  );
@@ -281,13 +296,13 @@ enc = tx.transduce(
281
296
  // [ -8, -7, -6, -5, -4, -3, -2, -1 ]
282
297
 
283
298
  buf = tx.transduce(
284
- tx.comp(txb.utf8Encode(), txb.base64Encode()),
299
+ tx.comp(utf8Encode(), base64Encode()),
285
300
  tx.str(),
286
301
  "beer (🍺) or hot beverage (☕️)"
287
302
  );
288
303
  // "YmVlciAo8J+Nuikgb3IgaG90IGJldmVyYWdlICjimJXvuI4p"
289
304
 
290
- tx.transduce(tx.comp(txb.base64Decode(), txb.utf8Decode()), tx.str(), buf);
305
+ tx.transduce(tx.comp(base64Decode(), utf8Decode()), tx.str(), buf);
291
306
  // "beer (🍺) or hot beverage (☕️)"
292
307
  ```
293
308
 
package/bits.d.ts CHANGED
@@ -4,7 +4,10 @@ import type { Transducer } from "@thi.ng/transducers";
4
4
  * word size (default 8) and order (MSB first or LSB first). Only the
5
5
  * lowest `wordSize` bits of each value are used (max 32).
6
6
  *
7
- * ```
7
+ * ```ts
8
+ * import { bits } from "@thi.ng/transducers-binary";
9
+ * import { comp, iterator, partition } from "@thi.ng/transducers";
10
+ *
8
11
  * [...bits(8, [0xf0, 0xaa])]
9
12
  * // [ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 ]
10
13
  * [...iterator(comp(bits(8), partition(4)), [0xf0, 0xaa])]
package/hex-dump.d.ts CHANGED
@@ -22,6 +22,7 @@ import type { HexDumpOpts } from "./api.js";
22
22
  * // '00000408 | 49 4a 21 30 31 32 33 7e | IJ!0123~',
23
23
  * // '00000410 | 7a 79 78 00 00 00 00 00 | zyx.....' ]
24
24
  * ```
25
+ *
25
26
  * @param opts -
26
27
  * @param src -
27
28
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers-binary",
3
- "version": "2.1.103",
3
+ "version": "2.1.104",
4
4
  "description": "Binary data related transducers & reducers",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -40,8 +40,8 @@
40
40
  "@thi.ng/errors": "^2.4.19",
41
41
  "@thi.ng/hex": "^2.3.38",
42
42
  "@thi.ng/random": "^3.6.34",
43
- "@thi.ng/strings": "^3.7.19",
44
- "@thi.ng/transducers": "^8.9.8"
43
+ "@thi.ng/strings": "^3.7.20",
44
+ "@thi.ng/transducers": "^8.9.9"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@microsoft/api-extractor": "^7.40.1",
@@ -113,5 +113,5 @@
113
113
  ],
114
114
  "year": 2018
115
115
  },
116
- "gitHead": "d660ae8fd1bf64d919b4334f19509f1f539d70f6\n"
116
+ "gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
117
117
  }