@jscad/io-utils 2.0.25 → 3.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -3,379 +3,208 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [2.0.25](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.24...@jscad/io-utils@2.0.25) (2023-06-27)
7
-
8
- **Note:** Version bump only for package @jscad/io-utils
6
+ # [3.0.0-alpha.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.22...@jscad/io-utils@3.0.0-alpha.0) (2023-10-09)
9
7
 
8
+ ### Bug Fixes
10
9
 
10
+ * **io:** fix io after V3 refactoring ([7a12bbd](https://github.com/jscad/OpenJSCAD.org/commit/7a12bbdb7b4b3df792a4c5b3c8b30a6a985a48f0))
11
11
 
12
+ ## [2.0.25](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.24...@jscad/io-utils@2.0.25) (2023-06-27)
12
13
 
14
+ **Note:** Version bump only for package @jscad/io-utils
13
15
 
14
16
  ## [2.0.24](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.23...@jscad/io-utils@2.0.24) (2023-04-30)
15
17
 
16
18
  **Note:** Version bump only for package @jscad/io-utils
17
19
 
18
-
19
-
20
-
21
-
22
20
  ## [2.0.23](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.22...@jscad/io-utils@2.0.23) (2022-11-26)
23
21
 
24
22
  **Note:** Version bump only for package @jscad/io-utils
25
23
 
26
-
27
-
28
-
29
-
30
24
  ## [2.0.22](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.21...@jscad/io-utils@2.0.22) (2022-08-21)
31
25
 
32
26
  **Note:** Version bump only for package @jscad/io-utils
33
27
 
34
-
35
-
36
-
37
-
38
28
  ## [2.0.21](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.20...@jscad/io-utils@2.0.21) (2022-07-17)
39
29
 
40
30
  **Note:** Version bump only for package @jscad/io-utils
41
31
 
42
-
43
-
44
-
45
-
46
32
  ## [2.0.20](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.19...@jscad/io-utils@2.0.20) (2022-06-12)
47
33
 
48
34
  **Note:** Version bump only for package @jscad/io-utils
49
35
 
50
-
51
-
52
-
53
-
54
36
  ## [2.0.19](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.18...@jscad/io-utils@2.0.19) (2022-05-15)
55
37
 
56
38
  **Note:** Version bump only for package @jscad/io-utils
57
39
 
58
-
59
-
60
-
61
-
62
40
  ## [2.0.18](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.17...@jscad/io-utils@2.0.18) (2022-04-24)
63
41
 
64
42
  **Note:** Version bump only for package @jscad/io-utils
65
43
 
66
-
67
-
68
-
69
-
70
44
  ## [2.0.17](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.16...@jscad/io-utils@2.0.17) (2022-04-03)
71
45
 
72
46
  **Note:** Version bump only for package @jscad/io-utils
73
47
 
74
-
75
-
76
-
77
-
78
48
  ## [2.0.16](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.15...@jscad/io-utils@2.0.16) (2022-04-03)
79
49
 
80
50
  **Note:** Version bump only for package @jscad/io-utils
81
51
 
82
-
83
-
84
-
85
-
86
52
  ## [2.0.15](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.14...@jscad/io-utils@2.0.15) (2022-03-13)
87
53
 
88
54
  **Note:** Version bump only for package @jscad/io-utils
89
55
 
90
-
91
-
92
-
93
-
94
56
  ## [2.0.14](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.13...@jscad/io-utils@2.0.14) (2022-03-06)
95
57
 
96
-
97
58
  ### Bug Fixes
98
59
 
99
60
  * **io:** corrected Blob to allocate internal buffer based contents ([#1006](https://github.com/jscad/OpenJSCAD.org/issues/1006)) ([df4552a](https://github.com/jscad/OpenJSCAD.org/commit/df4552a842fd884680d618f6f9b97ac7c7eb9d8b))
100
61
 
101
-
102
-
103
-
104
-
105
62
  ## [2.0.13](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.12...@jscad/io-utils@2.0.13) (2022-02-19)
106
63
 
107
64
  **Note:** Version bump only for package @jscad/io-utils
108
65
 
109
-
110
-
111
-
112
-
113
66
  ## [2.0.12](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.11...@jscad/io-utils@2.0.12) (2021-12-26)
114
67
 
115
68
  **Note:** Version bump only for package @jscad/io-utils
116
69
 
117
-
118
-
119
-
120
-
121
70
  ## [2.0.11](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.10...@jscad/io-utils@2.0.11) (2021-12-11)
122
71
 
123
72
  **Note:** Version bump only for package @jscad/io-utils
124
73
 
125
-
126
-
127
-
128
-
129
74
  ## [2.0.10](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.9...@jscad/io-utils@2.0.10) (2021-11-07)
130
75
 
131
76
  **Note:** Version bump only for package @jscad/io-utils
132
77
 
133
-
134
-
135
-
136
-
137
78
  ## [2.0.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.8...@jscad/io-utils@2.0.9) (2021-10-17)
138
79
 
139
80
  **Note:** Version bump only for package @jscad/io-utils
140
81
 
141
-
142
-
143
-
144
-
145
82
  ## [2.0.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.7...@jscad/io-utils@2.0.8) (2021-10-04)
146
83
 
147
84
  **Note:** Version bump only for package @jscad/io-utils
148
85
 
149
-
150
-
151
-
152
-
153
86
  ## [2.0.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.6...@jscad/io-utils@2.0.7) (2021-09-27)
154
87
 
155
88
  **Note:** Version bump only for package @jscad/io-utils
156
89
 
157
-
158
-
159
-
160
-
161
90
  ## [2.0.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.5...@jscad/io-utils@2.0.6) (2021-09-09)
162
91
 
163
92
  **Note:** Version bump only for package @jscad/io-utils
164
93
 
165
-
166
-
167
-
168
-
169
94
  ## [2.0.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.4...@jscad/io-utils@2.0.5) (2021-06-20)
170
95
 
171
96
  **Note:** Version bump only for package @jscad/io-utils
172
97
 
173
-
174
-
175
-
176
-
177
98
  ## [2.0.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.3...@jscad/io-utils@2.0.4) (2021-06-11)
178
99
 
179
100
  **Note:** Version bump only for package @jscad/io-utils
180
101
 
181
-
182
-
183
-
184
-
185
102
  ## [2.0.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.2...@jscad/io-utils@2.0.3) (2021-06-01)
186
103
 
187
104
  **Note:** Version bump only for package @jscad/io-utils
188
105
 
189
-
190
-
191
-
192
-
193
106
  ## [2.0.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.0...@jscad/io-utils@2.0.2) (2021-04-20)
194
107
 
195
-
196
108
  ### Bug Fixes
197
109
 
198
110
  * **all:** V2 : several fixes for modeling ([#705](https://github.com/jscad/OpenJSCAD.org/issues/705)) ([62017a4](https://github.com/jscad/OpenJSCAD.org/commit/62017a41214169d6e000f1e0c11aaefdd68e1097))
199
111
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
200
112
 
201
-
202
-
203
-
204
-
205
113
  ## [2.0.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.0...@jscad/io-utils@2.0.1) (2021-04-15)
206
114
 
207
-
208
115
  ### Bug Fixes
209
116
 
210
117
  * **all:** V2 : several fixes for modeling ([#705](https://github.com/jscad/OpenJSCAD.org/issues/705)) ([62017a4](https://github.com/jscad/OpenJSCAD.org/commit/62017a41214169d6e000f1e0c11aaefdd68e1097))
211
118
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
212
119
 
213
-
214
-
215
-
216
-
217
120
  # [2.0.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.11...@jscad/io-utils@2.0.0) (2021-04-12)
218
121
 
219
122
  **Note:** Version bump only for package @jscad/io-utils
220
123
 
221
-
222
-
223
-
224
-
225
124
  # [2.0.0-alpha.11](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.10...@jscad/io-utils@2.0.0-alpha.11) (2021-03-07)
226
125
 
227
126
  **Note:** Version bump only for package @jscad/io-utils
228
127
 
229
-
230
-
231
-
232
-
233
128
  # [2.0.0-alpha.10](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.9...@jscad/io-utils@2.0.0-alpha.10) (2021-02-07)
234
129
 
235
130
  **Note:** Version bump only for package @jscad/io-utils
236
131
 
237
-
238
-
239
-
240
-
241
132
  # [2.0.0-alpha.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.8...@jscad/io-utils@2.0.0-alpha.9) (2021-01-02)
242
133
 
243
134
  **Note:** Version bump only for package @jscad/io-utils
244
135
 
245
-
246
-
247
-
248
-
249
136
  # [2.0.0-alpha.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.7...@jscad/io-utils@2.0.0-alpha.8) (2020-12-04)
250
137
 
251
138
  **Note:** Version bump only for package @jscad/io-utils
252
139
 
253
-
254
-
255
-
256
-
257
140
  # [2.0.0-alpha.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.0-alpha.6...@jscad/io-utils@2.0.0-alpha.7) (2020-11-07)
258
141
 
259
-
260
142
  ### Bug Fixes
261
143
 
262
144
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
263
145
 
264
-
265
-
266
-
267
-
268
146
  # [2.0.0-alpha.6](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.5...@jscad/io-utils@2.0.0-alpha.6) (2020-10-11)
269
147
 
270
-
271
148
  ### Bug Fixes
272
149
 
273
150
  * **all:** V2 : several fixes for modeling ([#705](https://github.com/jscad/io/issues/705)) ([62017a4](https://github.com/jscad/io/commit/62017a41214169d6e000f1e0c11aaefdd68e1097))
274
151
 
275
-
276
-
277
-
278
-
279
152
  # [2.0.0-alpha.5](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.4...@jscad/io-utils@2.0.0-alpha.5) (2020-09-29)
280
153
 
281
154
  **Note:** Version bump only for package @jscad/io-utils
282
155
 
283
-
284
-
285
-
286
-
287
156
  # [2.0.0-alpha.4](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.3...@jscad/io-utils@2.0.0-alpha.4) (2020-09-28)
288
157
 
289
158
  **Note:** Version bump only for package @jscad/io-utils
290
159
 
291
-
292
-
293
-
294
-
295
160
  # [2.0.0-alpha.3](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.2...@jscad/io-utils@2.0.0-alpha.3) (2020-09-19)
296
161
 
297
162
  **Note:** Version bump only for package @jscad/io-utils
298
163
 
299
-
300
-
301
-
302
-
303
164
  # [2.0.0-alpha.2](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.1...@jscad/io-utils@2.0.0-alpha.2) (2020-09-08)
304
165
 
305
166
  **Note:** Version bump only for package @jscad/io-utils
306
167
 
307
-
308
-
309
-
310
-
311
168
  # [2.0.0-alpha.1](https://github.com/jscad/io/compare/@jscad/io-utils@2.0.0-alpha.0...@jscad/io-utils@2.0.0-alpha.1) (2020-08-19)
312
169
 
313
170
  **Note:** Version bump only for package @jscad/io-utils
314
171
 
315
-
316
-
317
-
318
-
319
172
  # 2.0.0-alpha.0 (2020-08-13)
320
173
 
321
174
  ### Features
322
175
 
323
176
  * **io:** move most of io code from core/io to io/io-utils
324
177
 
325
-
326
-
327
-
328
-
329
178
  <a name="0.1.3"></a>
330
179
  ## [0.1.3](https://github.com/jscad/io/compare/@jscad/io-utils@0.1.2...@jscad/io-utils@0.1.3) (2018-09-02)
331
180
 
332
-
333
181
  ### Bug Fixes
334
182
 
335
183
  * **svg deserializer:** fixed svg-deserializer to work with Inkscape files ([#72](https://github.com/jscad/io/issues/72)) ([f35ea5e](https://github.com/jscad/io/commit/f35ea5e))
336
184
 
337
-
338
-
339
-
340
185
  <a name="0.1.2"></a>
341
186
  ## [0.1.2](https://github.com/jscad/io/compare/@jscad/io-utils@0.1.1...@jscad/io-utils@0.1.2) (2017-11-04)
342
187
 
343
-
344
-
345
-
346
188
  **Note:** Version bump only for package @jscad/io-utils
347
189
 
348
190
  <a name="0.1.1"></a>
349
191
  ## [0.1.1](https://github.com/jscad/io/compare/@jscad/io-utils@0.1.0...@jscad/io-utils@0.1.1) (2017-10-30)
350
192
 
351
-
352
-
353
-
354
193
  **Note:** Version bump only for package @jscad/io-utils
355
194
 
356
195
  <a name="0.1.0"></a>
357
196
  # [0.1.0](https://github.com/jscad/io/compare/@jscad/io-utils@0.0.4...@jscad/io-utils@0.1.0) (2017-10-15)
358
197
 
359
-
360
198
  ### Features
361
199
 
362
200
  * **stl-deserializer:** add ability to deserialize stl to csg ([#32](https://github.com/jscad/io/issues/32)) ([a90dcf4](https://github.com/jscad/io/commit/a90dcf4))
363
201
 
364
-
365
-
366
-
367
202
  <a name="0.0.4"></a>
368
203
  ## [0.0.4](https://github.com/jscad/io/compare/@jscad/io-utils@0.0.3...@jscad/io-utils@0.0.4) (2017-10-10)
369
204
 
370
-
371
-
372
-
373
205
  **Note:** Version bump only for package @jscad/io-utils
374
206
 
375
207
  <a name="0.0.3"></a>
376
208
  ## 0.0.3 (2017-10-10)
377
209
 
378
-
379
-
380
-
381
210
  **Note:** Version bump only for package @jscad/io-utils
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![License](https://img.shields.io/github/license/jscad/OpenJSCAD.org)](https://github.com/jscad/OpenJSCAD.org/blob/master/LICENSE)
10
10
 
11
11
  [![User Group](https://img.shields.io/badge/maintained%20by-user%20group-blue)](https://openjscad.nodebb.com/)
12
- [![Lerna](https://img.shields.io/badge/maintained%20with-lerna-blue)](https://lerna.js.org/)
12
+ [![lerna--lite](https://img.shields.io/badge/maintained%20with-lerna--lite-e137ff)](https://github.com/ghiscoding/lerna-lite)
13
13
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-blue)](https://standardjs.com)
14
14
 
15
15
  [![Backers](https://img.shields.io/opencollective/backers/openjscad)](https://opencollective.com/openjscad)
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
1
  {
2
2
  "name": "@jscad/io-utils",
3
- "version": "2.0.25",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Utilities for JSCAD IO Packages",
5
5
  "homepage": "https://openjscad.xyz/",
6
6
  "repository": "https://github.com/jscad/OpenJSCAD.org",
7
- "main": "index.js",
7
+ "type": "module",
8
+ "main": "src/index.js",
8
9
  "scripts": {
9
- "coverage": "nyc --all --reporter=html --reporter=text npm test",
10
- "test": "ava '*.test.js' --verbose --timeout 2m"
10
+ "coverage": "c8 --all --reporter=html --reporter=text npm test",
11
+ "test": "ava './tests/*.test.js' --verbose --timeout 2m"
11
12
  },
12
13
  "contributors": [
13
14
  {
14
15
  "name": "Rene K. Mueller",
15
- "url": "http://renekmueller.com"
16
+ "url": "https://github.com/Spiritdude"
16
17
  },
17
18
  {
18
19
  "name": "z3dev",
19
- "url": "http://www.z3d.jp"
20
+ "url": "https://github.com/z3dev"
20
21
  },
21
22
  {
22
23
  "name": "Mark 'kaosat-dev' Moissette",
23
- "url": "http://kaosat.net"
24
+ "url": "https://github.com/kaosat-dev"
24
25
  }
25
26
  ],
26
27
  "keywords": [
@@ -33,9 +34,9 @@
33
34
  ],
34
35
  "license": "MIT",
35
36
  "devDependencies": {
36
- "@jscad/modeling": "2.12.0",
37
- "ava": "3.15.0",
38
- "nyc": "15.1.0"
37
+ "@jscad/modeling": "3.0.0-alpha.0",
38
+ "ava": "^4.3.3",
39
+ "c8": "^8.0.0"
39
40
  },
40
- "gitHead": "e269f212db5a00cda740d2f7ad3e5206d1eb839f"
41
+ "gitHead": "3656d36ed9cd738ab884e86aae5a2ce08d52adf7"
41
42
  }
@@ -7,7 +7,7 @@
7
7
  // + Jonas Raoni Soares Silva
8
8
  // @ http://jsfromhell.com/classes/binary-deserializer [rev. #1]
9
9
 
10
- class BinaryReader {
10
+ export class BinaryReader {
11
11
  /*
12
12
  * Construct a BinaryReader from the given data.
13
13
  * The data is a string created from the specified sequence of UTF-16 code units.
@@ -62,7 +62,7 @@ class BinaryReader {
62
62
  const exponent = this._readBits(precisionBits, exponentBits, size)
63
63
  let significand = 0
64
64
  let divisor = 2
65
- let curByte = 0 // length + (-precisionBits >> 3) - 1;
65
+ let curByte = 0 // length + (-precisionBits >> 3) - 1
66
66
  let startBit = 0
67
67
  do {
68
68
  const byteValue = this._readByte(++curByte, size)
@@ -78,9 +78,13 @@ class BinaryReader {
78
78
 
79
79
  this._pos += size
80
80
 
81
- return exponent === (bias << 1) + 1 ? significand ? NaN : signal ? -Infinity : +Infinity
82
- : (1 + signal * -2) * (exponent || significand ? !exponent ? Math.pow(2, -bias + 1) * significand
83
- : Math.pow(2, exponent - bias) * (1 + significand) : 0)
81
+ return exponent === (bias << 1) + 1
82
+ ? significand ? NaN : signal ? -Infinity : +Infinity
83
+ : (1 + signal * -2) * (exponent || significand
84
+ ? !exponent
85
+ ? Math.pow(2, -bias + 1) * significand
86
+ : Math.pow(2, exponent - bias) * (1 + significand)
87
+ : 0)
84
88
  }
85
89
 
86
90
  _decodeInt (bits, signed) {
@@ -124,9 +128,7 @@ class BinaryReader {
124
128
 
125
129
  _checkSize (neededBits) {
126
130
  if (!(this._pos + Math.ceil(neededBits / 8) < this._buffer.length)) {
127
- // throw new Error("Index out of bound");
131
+ // throw new Error("Index out of bound")
128
132
  }
129
133
  }
130
134
  }
131
-
132
- module.exports = BinaryReader
@@ -20,7 +20,7 @@
20
20
  * The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data.
21
21
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob
22
22
  */
23
- class Blob {
23
+ export class Blob {
24
24
  /**
25
25
  * Returns a newly created Blob object which contains a concatenation of all of the data in the given contents.
26
26
  * @param {Array} contents - an array of ArrayBuffer, or String objects that will be put inside the Blob.
@@ -136,5 +136,3 @@ class Blob {
136
136
  return ''
137
137
  }
138
138
  }
139
-
140
- module.exports = Blob
@@ -1,4 +1,4 @@
1
- const makeBlob = require('./makeBlob')
1
+ import { makeBlob } from './makeBlob.js'
2
2
 
3
3
  const Blob = makeBlob()
4
4
 
@@ -13,10 +13,8 @@ const Blob = makeBlob()
13
13
  * const blob1 = convertToBlob({ data: ['test'], mimeType: 'text/plain' })
14
14
  * const blob2 = convertToBlob({ data: [Int32Array.from('12345').buffer], mimeType: 'application/mine' })
15
15
  */
16
- const convertToBlob = (input) => {
16
+ export const convertToBlob = (input) => {
17
17
  const { data, mimeType } = input
18
18
  const blob = new Blob(data, { type: mimeType })
19
19
  return blob
20
20
  }
21
-
22
- module.exports = convertToBlob
package/src/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Utility functions of various sorts in support of IO packages.
3
+ * @module io/utils
4
+ * @example
5
+ * const { BinaryReader } = require('@jscad/io-utils')
6
+ */
7
+ export { convertToBlob } from './convertToBlob.js'
8
+ export { makeBlob } from './makeBlob.js'
9
+ export { BinaryReader } from './BinaryReader.js'
10
+ export { Blob } from './Blob.js'
11
+ export { stringify } from './stringify.js'
@@ -1,4 +1,4 @@
1
- const nodeBlob = require('./Blob.js')
1
+ import { Blob as nodeBlob } from './Blob.js'
2
2
 
3
3
  /**
4
4
  * Make a constructor for Blob objects.
@@ -8,9 +8,7 @@ const nodeBlob = require('./Blob.js')
8
8
  * const Blob = makeBlob()
9
9
  * const ablob = new Blob(data, { type: mimeType })
10
10
  */
11
- const makeBlob = () => {
11
+ export const makeBlob = () => {
12
12
  const blob = typeof window !== 'undefined' ? window.Blob : nodeBlob
13
13
  return blob
14
14
  }
15
-
16
- module.exports = makeBlob
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Originally from OMNL library by @drom
3
+ * License MIT
4
+ */
5
+ const isObject = (o) => o && Object.prototype.toString.call(o) === '[object Object]'
6
+
7
+ const indenter = (indentation) => {
8
+ if (!(indentation > 0)) {
9
+ return (txt) => txt
10
+ }
11
+ const space = ' '.repeat(indentation)
12
+ return (txt) => {
13
+ if (typeof txt !== 'string') {
14
+ return txt
15
+ }
16
+
17
+ const arr = txt.split('\n')
18
+
19
+ if (arr.length === 1) {
20
+ return space + txt
21
+ }
22
+
23
+ return arr
24
+ .map((e) => (e.trim() === '') ? e : space + e)
25
+ .join('\n')
26
+ }
27
+ }
28
+
29
+ const clean = (txt) => txt
30
+ .split('\n')
31
+ .filter((e) => e.trim() !== '')
32
+ .join('\n')
33
+
34
+ export const stringify = (a, indentation) => {
35
+ const cr = (indentation > 0) ? '\n' : ''
36
+ const indent = indenter(indentation)
37
+
38
+ const rec = (a) => {
39
+ let body = ''
40
+ let isFlat = true
41
+
42
+ let res
43
+ const isEmpty = a.some((e, i, arr) => {
44
+ if (i === 0) {
45
+ res = '<' + e
46
+ return (arr.length === 1)
47
+ }
48
+
49
+ if (i === 1) {
50
+ if (isObject(e)) {
51
+ Object.keys(e).forEach((key) => {
52
+ let val = e[key]
53
+ if (Array.isArray(val)) {
54
+ val = val.join(' ')
55
+ }
56
+ res += ' ' + key + '="' + val + '"'
57
+ })
58
+ if (arr.length === 2) {
59
+ return true
60
+ }
61
+ res += '>'
62
+ return false
63
+ }
64
+ res += '>'
65
+ }
66
+
67
+ switch (typeof e) {
68
+ case 'string':
69
+ case 'number':
70
+ case 'boolean':
71
+ case 'undefined':
72
+ body += e + cr
73
+ return false
74
+ }
75
+
76
+ isFlat = false
77
+ body += rec(e)
78
+ return false
79
+ })
80
+
81
+ if (isEmpty) {
82
+ return res + '/>' + cr // short form
83
+ }
84
+
85
+ return isFlat
86
+ ? res + clean(body) + '</' + a[0] + '>' + cr
87
+ : res + cr + indent(body) + '</' + a[0] + '>' + cr
88
+ }
89
+
90
+ return rec(a)
91
+ }
@@ -1,6 +1,6 @@
1
- const test = require('ava')
1
+ import test from 'ava'
2
2
 
3
- const { makeBlob } = require('./index')
3
+ import { makeBlob } from '../src/index.js'
4
4
 
5
5
  const Blob = makeBlob()
6
6
 
@@ -1,6 +1,6 @@
1
- const test = require('ava')
1
+ import test from 'ava'
2
2
 
3
- const { convertToBlob } = require('./index')
3
+ import { convertToBlob } from '../src/index.js'
4
4
 
5
5
  test('convert strings', (t) => {
6
6
  let ablob = convertToBlob({ data: ['test'], mimeType: 'test1' })
package/index.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * Utility functions of various sorts in support of IO packages.
3
- * @module io/utils
4
- * @example
5
- * const { BinaryReader } = require('@jscad/io-utils')
6
- */
7
- module.exports = {
8
- convertToBlob: require('./convertToBlob'),
9
- makeBlob: require('./makeBlob'),
10
- BinaryReader: require('./BinaryReader'),
11
- Blob: require('./Blob')
12
- }