@jscad/io-utils 2.0.24 → 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,371 +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.24](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io-utils@2.0.23...@jscad/io-utils@2.0.24) (2023-04-30)
7
-
8
- **Note:** Version bump only for package @jscad/io-utils
9
-
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)
10
7
 
8
+ ### Bug Fixes
11
9
 
10
+ * **io:** fix io after V3 refactoring ([7a12bbd](https://github.com/jscad/OpenJSCAD.org/commit/7a12bbdb7b4b3df792a4c5b3c8b30a6a985a48f0))
12
11
 
13
-
14
- ## [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)
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)
15
13
 
16
14
  **Note:** Version bump only for package @jscad/io-utils
17
15
 
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)
18
17
 
18
+ **Note:** Version bump only for package @jscad/io-utils
19
19
 
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)
20
21
 
22
+ **Note:** Version bump only for package @jscad/io-utils
21
23
 
22
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)
23
25
 
24
26
  **Note:** Version bump only for package @jscad/io-utils
25
27
 
26
-
27
-
28
-
29
-
30
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)
31
29
 
32
30
  **Note:** Version bump only for package @jscad/io-utils
33
31
 
34
-
35
-
36
-
37
-
38
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)
39
33
 
40
34
  **Note:** Version bump only for package @jscad/io-utils
41
35
 
42
-
43
-
44
-
45
-
46
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)
47
37
 
48
38
  **Note:** Version bump only for package @jscad/io-utils
49
39
 
50
-
51
-
52
-
53
-
54
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)
55
41
 
56
42
  **Note:** Version bump only for package @jscad/io-utils
57
43
 
58
-
59
-
60
-
61
-
62
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)
63
45
 
64
46
  **Note:** Version bump only for package @jscad/io-utils
65
47
 
66
-
67
-
68
-
69
-
70
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)
71
49
 
72
50
  **Note:** Version bump only for package @jscad/io-utils
73
51
 
74
-
75
-
76
-
77
-
78
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)
79
53
 
80
54
  **Note:** Version bump only for package @jscad/io-utils
81
55
 
82
-
83
-
84
-
85
-
86
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)
87
57
 
88
-
89
58
  ### Bug Fixes
90
59
 
91
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))
92
61
 
93
-
94
-
95
-
96
-
97
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)
98
63
 
99
64
  **Note:** Version bump only for package @jscad/io-utils
100
65
 
101
-
102
-
103
-
104
-
105
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)
106
67
 
107
68
  **Note:** Version bump only for package @jscad/io-utils
108
69
 
109
-
110
-
111
-
112
-
113
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)
114
71
 
115
72
  **Note:** Version bump only for package @jscad/io-utils
116
73
 
117
-
118
-
119
-
120
-
121
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)
122
75
 
123
76
  **Note:** Version bump only for package @jscad/io-utils
124
77
 
125
-
126
-
127
-
128
-
129
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)
130
79
 
131
80
  **Note:** Version bump only for package @jscad/io-utils
132
81
 
133
-
134
-
135
-
136
-
137
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)
138
83
 
139
84
  **Note:** Version bump only for package @jscad/io-utils
140
85
 
141
-
142
-
143
-
144
-
145
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)
146
87
 
147
88
  **Note:** Version bump only for package @jscad/io-utils
148
89
 
149
-
150
-
151
-
152
-
153
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)
154
91
 
155
92
  **Note:** Version bump only for package @jscad/io-utils
156
93
 
157
-
158
-
159
-
160
-
161
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)
162
95
 
163
96
  **Note:** Version bump only for package @jscad/io-utils
164
97
 
165
-
166
-
167
-
168
-
169
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)
170
99
 
171
100
  **Note:** Version bump only for package @jscad/io-utils
172
101
 
173
-
174
-
175
-
176
-
177
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)
178
103
 
179
104
  **Note:** Version bump only for package @jscad/io-utils
180
105
 
181
-
182
-
183
-
184
-
185
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)
186
107
 
187
-
188
108
  ### Bug Fixes
189
109
 
190
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))
191
111
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
192
112
 
193
-
194
-
195
-
196
-
197
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)
198
114
 
199
-
200
115
  ### Bug Fixes
201
116
 
202
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))
203
118
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
204
119
 
205
-
206
-
207
-
208
-
209
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)
210
121
 
211
122
  **Note:** Version bump only for package @jscad/io-utils
212
123
 
213
-
214
-
215
-
216
-
217
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)
218
125
 
219
126
  **Note:** Version bump only for package @jscad/io-utils
220
127
 
221
-
222
-
223
-
224
-
225
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)
226
129
 
227
130
  **Note:** Version bump only for package @jscad/io-utils
228
131
 
229
-
230
-
231
-
232
-
233
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)
234
133
 
235
134
  **Note:** Version bump only for package @jscad/io-utils
236
135
 
237
-
238
-
239
-
240
-
241
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)
242
137
 
243
138
  **Note:** Version bump only for package @jscad/io-utils
244
139
 
245
-
246
-
247
-
248
-
249
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)
250
141
 
251
-
252
142
  ### Bug Fixes
253
143
 
254
144
  * **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
255
145
 
256
-
257
-
258
-
259
-
260
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)
261
147
 
262
-
263
148
  ### Bug Fixes
264
149
 
265
150
  * **all:** V2 : several fixes for modeling ([#705](https://github.com/jscad/io/issues/705)) ([62017a4](https://github.com/jscad/io/commit/62017a41214169d6e000f1e0c11aaefdd68e1097))
266
151
 
267
-
268
-
269
-
270
-
271
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)
272
153
 
273
154
  **Note:** Version bump only for package @jscad/io-utils
274
155
 
275
-
276
-
277
-
278
-
279
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)
280
157
 
281
158
  **Note:** Version bump only for package @jscad/io-utils
282
159
 
283
-
284
-
285
-
286
-
287
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)
288
161
 
289
162
  **Note:** Version bump only for package @jscad/io-utils
290
163
 
291
-
292
-
293
-
294
-
295
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)
296
165
 
297
166
  **Note:** Version bump only for package @jscad/io-utils
298
167
 
299
-
300
-
301
-
302
-
303
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)
304
169
 
305
170
  **Note:** Version bump only for package @jscad/io-utils
306
171
 
307
-
308
-
309
-
310
-
311
172
  # 2.0.0-alpha.0 (2020-08-13)
312
173
 
313
174
  ### Features
314
175
 
315
176
  * **io:** move most of io code from core/io to io/io-utils
316
177
 
317
-
318
-
319
-
320
-
321
178
  <a name="0.1.3"></a>
322
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)
323
180
 
324
-
325
181
  ### Bug Fixes
326
182
 
327
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))
328
184
 
329
-
330
-
331
-
332
185
  <a name="0.1.2"></a>
333
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)
334
187
 
335
-
336
-
337
-
338
188
  **Note:** Version bump only for package @jscad/io-utils
339
189
 
340
190
  <a name="0.1.1"></a>
341
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)
342
192
 
343
-
344
-
345
-
346
193
  **Note:** Version bump only for package @jscad/io-utils
347
194
 
348
195
  <a name="0.1.0"></a>
349
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)
350
197
 
351
-
352
198
  ### Features
353
199
 
354
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))
355
201
 
356
-
357
-
358
-
359
202
  <a name="0.0.4"></a>
360
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)
361
204
 
362
-
363
-
364
-
365
205
  **Note:** Version bump only for package @jscad/io-utils
366
206
 
367
207
  <a name="0.0.3"></a>
368
208
  ## 0.0.3 (2017-10-10)
369
209
 
370
-
371
-
372
-
373
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.24",
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.11.1",
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": "4313974b50957018d2edd010e3a251f59bea46a4"
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
- }