@thi.ng/transducers-binary 2.1.102 → 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-02-25T14:07:53Z
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
@@ -1,16 +1,5 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
  <!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
3
- > [!IMPORTANT]
4
- > ‼️ Announcing the thi.ng user survey 2024 📋
5
- >
6
- > [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
7
- > (open until end of February)
8
- >
9
- > **To achieve a better sample size, I'd highly appreciate if you could
10
- > circulate the link to this survey in your own networks.**
11
- >
12
- > [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
13
-
14
3
  # ![@thi.ng/transducers-binary](https://media.thi.ng/umbrella/banners-20230807/thing-transducers-binary.svg?56c93de8)
15
4
 
16
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/transducers-binary.svg)](https://www.npmjs.com/package/@thi.ng/transducers-binary)
@@ -22,7 +11,7 @@
22
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
23
12
  > and anti-framework.
24
13
  >
25
- > 🚀 Help me to work full-time on these projects by [sponsoring me on
14
+ > 🚀 Please help me to work full-time on these projects by [sponsoring me on
26
15
  > GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
27
16
 
28
17
  - [About](#about)
@@ -112,26 +101,24 @@ directory are using this package:
112
101
 
113
102
  [Generated API docs](https://docs.thi.ng/umbrella/transducers-binary/)
114
103
 
115
- ```ts
116
- import * as tx from "@thi.ng/transducers";
117
- import * as txb from "@thi.ng/transducers-binary";
118
- ```
119
-
120
104
  ### Random bits
121
105
 
122
106
  ```ts
107
+ import { take } from "@thi.ng/transducers";
108
+ import { randomBits } from "@thi.ng/transducers-binary";
109
+
123
110
  // 10 samples with 50% probability of drawing a 1
124
- [...txb.randomBits(0.5, 10)]
111
+ [...randomBits(0.5, 10)]
125
112
  // [ 1, 0, 1, 1, 0, 1, 0, 1, 1, 0 ]
126
113
 
127
114
  // infinite iterator without 2nd arg, so limit with `take()`
128
- [...tx.take(10, txb.randomBits(0.1))]
115
+ [...take(10, randomBits(0.1))]
129
116
  // [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
130
117
 
131
118
  import { Smush32 } from "@thi.ng/random";
132
119
 
133
120
  // with seeded PRNG
134
- [...txb.randomBits(0.5, 10, new Smush32(12345678))]
121
+ [...randomBits(0.5, 10, new Smush32(12345678))]
135
122
  // [ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0 ]
136
123
  ```
137
124
 
@@ -142,9 +129,11 @@ transducers. [See code
142
129
  here](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-binary/src/hex-dump.ts).
143
130
 
144
131
  ```ts
132
+ import { hexDump } from "@thi.ng/transducers-binary";
133
+
145
134
  src = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 33, 48, 49, 50, 51, 126, 122, 121, 120]
146
135
 
147
- [...txb.hexDump({ cols: 8, address: 0x100 }, src)]
136
+ [...hexDump({ cols: 8, address: 0x100 }, src)]
148
137
  // [ '00000100 | 41 42 43 44 45 46 47 48 | ABCDEFGH',
149
138
  // '00000108 | 49 4a 21 30 31 32 33 7e | IJ!0123~',
150
139
  // '00000110 | 7a 79 78 00 00 00 00 00 | zyx.....' ]
@@ -158,6 +147,9 @@ reducer transforms a stream of declarative data definitions (optionally
158
147
  with Little-Endian encoding) into an `Uint8Array`.
159
148
 
160
149
  ```ts
150
+ import * as tx from "@thi.ng/transducers";
151
+ import * as txb from "@thi.ng/transducers-binary";
152
+
161
153
  const bytes = txb.bytes(
162
154
  // initial buffer capacity (grows on demand)
163
155
  32,
@@ -186,18 +178,21 @@ console.log(tx.str("\n", txb.hexDump({}, bytes)));
186
178
  Decompose / transform a stream of fixed size words into their bits:
187
179
 
188
180
  ```ts
189
- [...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])];
190
185
  // [ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 ]
191
186
 
192
187
  console.log(
193
- tx.transduce(
194
- tx.comp(
195
- txb.bits(8),
196
- tx.map((x) => (x ? "#" : ".")),
197
- tx.partition(8),
198
- tx.map((x) => x.join(""))
188
+ transduce(
189
+ comp(
190
+ bits(8),
191
+ map((x) => (x ? "#" : ".")),
192
+ partition(8),
193
+ map((x) => x.join(""))
199
194
  ),
200
- tx.str("\n"),
195
+ str("\n"),
201
196
  [0x00, 0x18, 0x3c, 0x66, 0x66, 0x7e, 0x66, 0x00]
202
197
  )
203
198
  );
@@ -215,7 +210,10 @@ Extended to transform longer strings (taken from the [bitmap-font
215
210
  example](https://github.com/thi-ng/umbrella/tree/develop/examples/bitmap-font),
216
211
  [live demo](https://demo.thi.ng/umbrella/bitmap-font/)):
217
212
 
218
- ```ts
213
+ ```js
214
+ import * as tx from "@thi.ng/transducers";
215
+ import { bits } from "@thi.ng/transducers-binary";
216
+
219
217
  // font lookup table
220
218
  const chars = {
221
219
  a: [0x00, 0x18, 0x3c, 0x66, 0x66, 0x7e, 0x66, 0x00],
@@ -229,7 +227,7 @@ const xfJoin = tx.map((x) => x.join(""));
229
227
  const xfChar = (i) =>
230
228
  tx.comp(
231
229
  tx.pluck(i),
232
- txb.bits(8),
230
+ bits(8),
233
231
  tx.map((x) => (x ? "#" : ".")),
234
232
  tx.partition(8),
235
233
  xfJoin
@@ -269,10 +267,16 @@ strings, these transducers stepwise convert byte values to base64 and
269
267
  back.
270
268
 
271
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
+
272
276
  // here we first add an offset (0x80) to allow negative values to be encoded
273
277
  // (URL safe results can be produced via opt arg to `base64Encode`)
274
278
  enc = tx.transduce(
275
- tx.comp(tx.map((x) => x + 0x80), txb.base64Encode()),
279
+ tx.comp(tx.map((x) => x + 0x80), base64Encode()),
276
280
  tx.str(),
277
281
  tx.range(-8, 8)
278
282
  );
@@ -292,13 +296,13 @@ enc = tx.transduce(
292
296
  // [ -8, -7, -6, -5, -4, -3, -2, -1 ]
293
297
 
294
298
  buf = tx.transduce(
295
- tx.comp(txb.utf8Encode(), txb.base64Encode()),
299
+ tx.comp(utf8Encode(), base64Encode()),
296
300
  tx.str(),
297
301
  "beer (🍺) or hot beverage (☕️)"
298
302
  );
299
303
  // "YmVlciAo8J+Nuikgb3IgaG90IGJldmVyYWdlICjimJXvuI4p"
300
304
 
301
- tx.transduce(tx.comp(txb.base64Decode(), txb.utf8Decode()), tx.str(), buf);
305
+ tx.transduce(tx.comp(base64Decode(), utf8Decode()), tx.str(), buf);
302
306
  // "beer (🍺) or hot beverage (☕️)"
303
307
  ```
304
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.102",
3
+ "version": "2.1.104",
4
4
  "description": "Binary data related transducers & reducers",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,13 +35,13 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/binary": "^3.4.15",
39
- "@thi.ng/compose": "^2.1.65",
40
- "@thi.ng/errors": "^2.4.18",
41
- "@thi.ng/hex": "^2.3.37",
42
- "@thi.ng/random": "^3.6.33",
43
- "@thi.ng/strings": "^3.7.18",
44
- "@thi.ng/transducers": "^8.9.7"
38
+ "@thi.ng/binary": "^3.4.16",
39
+ "@thi.ng/compose": "^2.1.66",
40
+ "@thi.ng/errors": "^2.4.19",
41
+ "@thi.ng/hex": "^2.3.38",
42
+ "@thi.ng/random": "^3.6.34",
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": "190d68e7f7524631b333cfdbf32c6a23be27c166\n"
116
+ "gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
117
117
  }