oslllo-svg-fixer 5.0.0 → 6.0.1

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/README.md CHANGED
@@ -22,7 +22,7 @@ Attempts to fix your svg by turning it into a fill / single path (and making it
22
22
 
23
23
  ## Documentation, Installation, and Usage Instructions
24
24
 
25
- See the full installation and usage documentation [HERE](https://docs.oslllo.com/svg-fixer/master/).
25
+ See the full installation and usage documentation [HERE](https://docs-oslllo-com.onrender.com/svg-fixer/master/).
26
26
 
27
27
  ### The Objective
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-svg-fixer",
3
- "version": "5.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "Converts SVG Strokes To Fill.",
5
5
  "bin": "src/cli.js",
6
6
  "main": "src/index.js",
@@ -13,7 +13,8 @@
13
13
  "lint": "eslint -- src test ./",
14
14
  "lint:fix": "eslint --fix src test ./",
15
15
  "test:only": "nyc mocha test/main.test.js && mocha test/output.test.js",
16
- "test": "nyc mocha test/main.test.js && mocha test/output.test.js && npm run lint",
16
+ "test": "nyc npm run test:all && npm run lint",
17
+ "test:all": "mocha test/main.test.js && mocha test/output.test.js",
17
18
  "test:cli": "mocha test/src/test.cli.js",
18
19
  "coverage": "nyc report --reporter=lcovonly"
19
20
  },
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ DEFAULT_TRACE_RESOLUTION: 600,
5
+ };
package/src/fixer.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ const Svg = require("./svg");
4
+
5
+ module.exports = ({ source, resolution }) => {
6
+ const svg = new Svg(source, resolution);
7
+
8
+ return svg.process();
9
+ };
package/src/index.js CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  const SVGFixer = require("./constructor");
4
4
 
5
+ SVGFixer.fixString = require("./string-fixer");
6
+
5
7
  module.exports = SVGFixer;
package/src/option.js CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  const error = require("./error");
4
4
  const is = require("oslllo-validator");
5
+ const { DEFAULT_TRACE_RESOLUTION } = require("./constants");
5
6
 
6
7
  const Option = function (options) {
7
8
  this.data = {
8
9
  showProgressBar: false,
9
10
  throwIfDestinationDoesNotExist: true,
10
- traceResolution: 600,
11
+ traceResolution: DEFAULT_TRACE_RESOLUTION,
11
12
  };
12
13
  if (!is.object(options)) {
13
14
  throw error.invalidParameterError("options", "object", options);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const is = require("oslllo-validator");
4
+
5
+ const { DEFAULT_TRACE_RESOLUTION } = require("./constants");
6
+ const fix = require("./fixer");
7
+ const error = require("./error");
8
+
9
+ module.exports = (svg, resolution = DEFAULT_TRACE_RESOLUTION) => {
10
+ if (is.buffer(svg)) {
11
+ return fix({ source: svg, resolution });
12
+ }
13
+
14
+ if (!is.string(svg)) {
15
+ throw error.invalidParameterError("svg", "string or buffer", svg);
16
+ }
17
+
18
+ return fix({ source: Buffer.from(svg), resolution });
19
+ };
package/src/svg.js CHANGED
@@ -3,13 +3,12 @@
3
3
  const Svg2 = require("oslllo-svg2");
4
4
  const Potrace = require("oslllo-potrace");
5
5
 
6
- const Svg = function (path, traceResolution) {
6
+ const Svg = function (pathOrBuffer, traceResolution) {
7
7
  this.filled = false;
8
- this.path = path;
9
8
  this.traceResolution = traceResolution;
10
9
  this.png = new Object();
11
10
  this.resized = new Object();
12
- this.svg2 = Svg2(this.path);
11
+ this.svg2 = Svg2(pathOrBuffer);
13
12
  this.element = this.svg2.toElement();
14
13
  this.outerHTML = this.element.outerHTML;
15
14
  this.original = this.getOriginal();
package/src/tracer.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require("fs/promises");
4
- const Svg = require("./svg");
4
+
5
+ const fix = require("./fixer");
5
6
 
6
7
  module.exports = async ({ source, destination, resolution }) => {
7
- const svg = new Svg(source, resolution);
8
- const fixed = await svg.process();
8
+ const fixed = await fix({ source, resolution });
9
9
  await fs.writeFile(destination, fixed);
10
10
  };
package/CHANGELOG.md DELETED
@@ -1,392 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [5.0.0](https://github.com/oslllo/svg-fixer/compare/v4.0.1...v5.0.0) (2024-07-21)
9
-
10
-
11
- ### Breaking Changes
12
-
13
- * Breaking changes will only affect users on node 21.x, as the security fixes will throw a deprication warning that might
14
- cause the fixer to exit if you are using it in a cli. See https://github.com/yarnpkg/yarn/issues/9005 for more details.
15
-
16
- ### Bug Fixes
17
-
18
- * security vulnerabilities ([0ade74b](https://github.com/oslllo/svg-fixer/commit/0ade74b4813387c5af448da815ed5f9e667f1c16))
19
-
20
- ## [4.0.1](https://github.com/oslllo/svg-fixer/compare/v4.0.0...v4.0.1) (2024-03-27)
21
-
22
-
23
- ### Bug Fixes
24
-
25
- * security vulnerabilities ([81cc6ac](https://github.com/oslllo/svg-fixer/commit/81cc6ac7e1ba5a446aad6c4206872ee6c3ca8e8b))
26
-
27
- ## [4.0.0](https://github.com/oslllo/svg-fixer/compare/v3.0.0...v4.0.0) (2024-03-26)
28
-
29
- ### Breaking
30
- * drop support for node 16
31
-
32
- ### Bug Fixes
33
-
34
- * node version ([8a45ad0](https://github.com/oslllo/svg-fixer/commit/8a45ad02df73759d99ef58a467edaf6697415292))
35
- * Process never ends on error when use promise [#98](https://github.com/oslllo/svg-fixer/issues/98) ([9cacc5c](https://github.com/oslllo/svg-fixer/commit/9cacc5c08016a4882a745009221ae51f55769d0c))
36
-
37
- ## [3.0.0](https://github.com/oslllo/svg-fixer/compare/v2.2.0...v3.0.0) (2023-09-16)
38
-
39
- ⚠️ Contains breaking changes.
40
-
41
- ### Breaking Changes
42
-
43
- * Dropped support for node `<16.0.0`
44
- * This version will not work with `<16.0.0`
45
-
46
- ### Features
47
-
48
- * Made the tool 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89)
49
-
50
- ### Bug Fixes
51
-
52
- * update release actions ([a1a66fe](https://github.com/oslllo/svg-fixer/commit/a1a66fe13539eb5e76c9cb6ac574e35da421636d))
53
-
54
- ## [2.2.0](https://www.github.com/oslllo/svg-fixer/compare/v2.1.2...v2.2.0) (2022-10-19)
55
-
56
-
57
- ### Features
58
-
59
- * closes [#82](https://www.github.com/oslllo/svg-fixer/issues/82) - fix negative viewBox min-x min-y bug ([b64aa75](https://www.github.com/oslllo/svg-fixer/commit/b64aa75b4ea8d3b7a0378cc1f9ce27c92b4f606f))
60
-
61
- ### [2.1.2](https://www.github.com/oslllo/svg-fixer/compare/v2.1.0...v2.1.2) (2022-07-16)
62
-
63
-
64
- ### Miscellaneous Chores
65
-
66
- * release 2.1.2 ([fd8cdaf](https://www.github.com/oslllo/svg-fixer/commit/fd8cdaf08b4645fe3fad229fefa9a97ec9124c9e))
67
-
68
- ## 2.1.1 (2022-05-1)
69
-
70
- ### Chore
71
-
72
- - update dependencies
73
- - npm audit fix
74
-
75
-
76
- ## [2.1.0](https://www.github.com/oslllo/svg-fixer/compare/v2.0.1...v2.1.1) (2022-03-8)
77
-
78
- ### Added
79
-
80
- - add configurable trace resolution ([#72](https://github.com/oslllo/svg-fixer/pull/72))
81
-
82
- ### Updated
83
-
84
- - Updated dependencies
85
-
86
- ## [2.0.1](https://www.github.com/oslllo/svg-fixer/compare/v2.0.0...v2.0.1) (2022-01-21)
87
-
88
-
89
- ### Refactor
90
-
91
- - improve perfomance ([3b310aa](https://github.com/oslllo/svg-fixer/commit/3b310aaf3bf39f47b0bb56a722f03d40ad6a1b31))
92
-
93
- ## [2.0.0](https://www.github.com/oslllo/svg-fixer/compare/v1.4.1...v2.0.0) (2022-01-12)
94
-
95
- This version did not break the api so upgrading from `v1.0.0` without any changes should be fine. The reason for the major version change is just in case something did break.
96
-
97
- ### Changed
98
-
99
- - Removed `Canvas & JSDOM` to fix very slow `npm install` cycles.
100
- - Switched from `Canvas` to `svg2png-wasm`.
101
-
102
- ### Updated
103
-
104
- - Updated dependencies
105
-
106
-
107
- ## [1.4.1](https://www.github.com/oslllo/svg-fixer/compare/v1.4.0...v1.4.1) (2021-09-05)
108
-
109
-
110
- ### Bug Fixes
111
-
112
- * vulnerabilities ([99621c6](https://www.github.com/oslllo/svg-fixer/commit/99621c6258e52836f0aaaf9876fe4b4859c81ab6))
113
-
114
- ## [1.4.0](https://www.github.com/oslllo/svg-fixer/compare/v1.3.2...v1.4.0) (2021-07-14)
115
-
116
-
117
- ### Features
118
-
119
- * add support for svgs with "ex", "ch", "cm", "mm", "q", "in", "pc", "pt" ([4d2c18e](https://www.github.com/oslllo/svg-fixer/commit/4d2c18ef496b9ce08cbc917e3fbb91d9f352c6ff))
120
- * add support for svgs with fill color in path style attribute ([1aeb079](https://www.github.com/oslllo/svg-fixer/commit/1aeb0794e9693079c79981616ea00e99379c863f))
121
- * support svgs without a set viewBox attribute ([17b876c](https://www.github.com/oslllo/svg-fixer/commit/17b876ce49ed0a047dedb098d47adcccb22ff0cf))
122
-
123
- ### [1.3.2](https://www.github.com/oslllo/svg-fixer/compare/v1.3.1...v1.3.2) (2021-06-26)
124
-
125
-
126
- ### Bug Fixes
127
-
128
- * security vulnerabilities ([372730b](https://www.github.com/oslllo/svg-fixer/commit/372730bef6cf761877961796635fc406a2ecc776))
129
-
130
- ### [1.3.1](https://www.github.com/oslllo/svg-fixer/compare/v1.3.0...v1.3.1) (2021-05-27)
131
-
132
-
133
- ### Bug Fixes
134
-
135
- * output svg being smaller than viewBox ([#48](https://www.github.com/oslllo/svg-fixer/issues/48)) ([f658614](https://www.github.com/oslllo/svg-fixer/commit/f65861448802b9b7c6cd6c889207b5f1a7c66592))
136
-
137
- ## [1.3.0](https://www.github.com/oslllo/svg-fixer/compare/v1.2.1...v1.3.0) (2021-05-15)
138
-
139
-
140
- ### Features
141
-
142
- * add support for svgs with light colored fill ([#45](https://www.github.com/oslllo/svg-fixer/issues/45)) ([47aa95d](https://www.github.com/oslllo/svg-fixer/commit/47aa95da9e7054b84f3b2d36528784c5dbe6663d))
143
-
144
-
145
- ### Bug Fixes
146
-
147
- * **eslint:** script error ([d34780e](https://www.github.com/oslllo/svg-fixer/commit/d34780e1db64d350695f5be7c4713136f9c66331))
148
-
149
- ### [1.2.1](https://www.github.com/oslllo/svg-fixer/compare/v1.2.0...v1.2.1) (2021-05-06)
150
-
151
-
152
- ### Bug Fixes
153
-
154
- * drop yargs version to 16 ([7b4d9cc](https://www.github.com/oslllo/svg-fixer/commit/7b4d9ccb563027b24aefe59d394848b8937067b9))
155
- * package breaking when process.env.NODE_ENV env variable is set ([51c6318](https://www.github.com/oslllo/svg-fixer/commit/51c6318340b97d6840ab7d2c499c77aff27b6f10))
156
-
157
- ## [1.2.0] - 2021/4/1
158
-
159
- ### Fixed
160
-
161
- - Fixed bug in test.
162
-
163
- ### Updated
164
-
165
- - Updated dependencies.
166
-
167
- ## [1.1.2] - 2020/12/12
168
-
169
- ### Fixed
170
-
171
- - Fixed vulnerability.
172
-
173
- ### Updated
174
-
175
- - Updated dependencies.
176
-
177
- ## [1.1.1] - 2020/10/22
178
-
179
- ### Fixed
180
-
181
- - Fixed large npm package.
182
-
183
- ## [1.1.0] - 2020/10/22
184
-
185
- ### Fixed
186
-
187
- - Fixed bug that allowed you to update `options` that do not exist.
188
-
189
- ### Added
190
-
191
- - Added `CLI` functionality.
192
- - Added `callback` functionality to `SVGFixer.fix()`.
193
-
194
- ### Changed
195
-
196
- - Refactored `tests`.
197
- - Refactored `progress bar`.
198
-
199
- ## [1.0.2] - 2020/10/2
200
-
201
- ### Fixed
202
-
203
- - Fixed not being able to process SVGs with `%` dimensions.
204
-
205
- ### Added
206
-
207
- - SVG attribute tests.
208
-
209
- ## [1.0.1] - 2020/9/16
210
-
211
- ### Changed
212
-
213
- - Remove tests from npm `package` to help reduce unpacked `package` size.
214
-
215
- ## [1.0.0] - 2020/9/16
216
-
217
- ⚠️ Contains breaking changes.
218
-
219
- ### Breaking Changes
220
-
221
- - `svgfixer.fix(source, destination, options)` ***=>*** `SVGFixer(source, destination, options).fix()`.
222
- - It was changed from a wrapper function to a method function for `SVGFixer`.
223
- - It still returns a `Promise`.
224
- - `fix()` no more takes in `parameters`, those should be passed into `SVGFixer()`.
225
- - `svgfixer.SVGFixer()` class ***=>*** `SVGFixer()`.
226
- - The `.setOptions(options)` method has been removed, `options` should now be passed in class constructor as the 3rd `parameter`.
227
- - The `.setSourceAndDest()` method has been removed, `source` and `destination` should now be passed in class constructor as the 1st and 2nd `parameters`.
228
- - The `.process()` method has been removed, use `.fix()` instead.
229
- - `SVGFixer()` does not require the [`new`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) operator anymore.
230
- - `fixConcurrency` has been removed, might be reimplemented on later versions.
231
-
232
- ### Changed
233
-
234
- - Updated dependencies.
235
- - Refactored codebase.
236
- - Refactored progressbar.
237
-
238
- ## [0.6.0] - 2020/8/13
239
-
240
- ### Security
241
-
242
- - Updated dependencies. Fixes [Vulnerability](https://npmjs.com/advisories/1548)
243
-
244
- ### Changed
245
-
246
- - Updated image processor.
247
- - Updated `CHANGELOG.md` wording and formatting.
248
-
249
- ## [0.5.1] - 2020/7/7
250
-
251
- ### Changed
252
-
253
- - Updated `README.md`.
254
-
255
- ### Added
256
-
257
- - Documentation.
258
-
259
- ## [0.5.0] - 2020/6/13
260
-
261
- ### Changed
262
-
263
- - Changed image processing engine from Sharp to Jimp. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
264
- - Refactored async pools (fixConcurrency).
265
-
266
- ### Fixed
267
-
268
- - Fixed pathing issues on windows. Fixes [#8](https://github.com/oslllo/svg-fixer/issues/8)
269
-
270
- ## [0.4.4] - 2020/6/8
271
-
272
- ### Changed
273
-
274
- - Updated dependencies. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
275
-
276
- ## [0.4.3] - 2020/6/2
277
-
278
- ### Changed
279
-
280
- - Updated `package.json` description.
281
-
282
- ## [0.4.2] - 2020/5/24
283
-
284
- ### Fixed
285
-
286
- - Fixed incorrect svg data when source svg has 'px', 'rem' or 'em' on height and width attributes as a unit of measurement. See ([#5](https://github.com/oslllo/svg-fixer/issues/5))
287
-
288
- ## [0.4.1] - 2020/5/16
289
-
290
- ### Security
291
-
292
- - Fixed [Vulnerability](https://www.npmjs.com/advisories/1500)
293
-
294
- ## [0.4.0] - 2020/5/14
295
-
296
- ### Added
297
-
298
- - Added new parameter `fixConcurrency` to control how many svgs to fix at a given time.
299
- - Added new tests
300
- - Added an perfomance increase by ~67%
301
-
302
- |Version|completion (%)|Time (seconds)|Number of SVGs fixed|
303
- |------|------|-----|-----|
304
- |v0.4.0|100.00|~ 127|1315|
305
- |v0.3.3|100.00|~ 190|1315|
306
- |-|-|-|-|
307
- |**VPS**|**CPU**|**RAM**|||
308
- ||Intel(R) Xeon(R) E5-1650 v3 3.50GHz (2x) | 1548MiB|||
309
-
310
- ### Fixed
311
-
312
- - Fixed tests
313
-
314
- ### Changed
315
-
316
- - Reduceed npm package size.
317
- - Updated `README.md`.
318
-
319
- ## [0.3.3] - 2020/5/12
320
-
321
- ### Added
322
-
323
- - Added badge links to `README.md`.
324
- - Added new tags to `package.json`.
325
-
326
- ### Changed
327
-
328
- - Updated `README.md` content.
329
-
330
- ## [0.3.2] - 2020/5/10
331
-
332
- ### Changed
333
-
334
- - Updated README.md
335
-
336
- ## [0.3.1] - 2020/5/9
337
-
338
- ### Changed
339
-
340
- - Updated `README.md`
341
-
342
- ## [0.3.0] - 2020/5/8
343
-
344
- ### Changed
345
-
346
- - Refactored the whole codebase.
347
- - Updated README.md
348
-
349
- ### Added
350
-
351
- - Added tests
352
- - Added slight performance increase.
353
-
354
- ## [0.2.0] - 2020/4/18
355
-
356
- ### Added
357
-
358
- - Added progress bar
359
-
360
- ## [0.1.0] - 2020/4/17
361
-
362
- ### Added
363
-
364
- - Added [CHANGELOG.md](https://github.com/oslllo/svg-fixer/blob/master/CHANGELOG.md)
365
- - Create destination folder if it does not exist.
366
-
367
- ### Changed
368
-
369
- - Switched from `fs` to `fs-extra`
370
- - Changed `SvgFixer()` function name from `SvgFixer` to `svgFixer` because its a function not a class.
371
-
372
- ### Removed
373
-
374
- - Removed debug functions
375
-
376
- ## [0.0.3] - 2020/4/16
377
-
378
- ### Added
379
-
380
- - Added package.json description
381
-
382
- ## [0.0.2] - 2020/4/16
383
-
384
- ### Added
385
-
386
- - Added [README.md](https://github.com/oslllo/svg-fixer/blob/master/README.md)
387
-
388
- ## [0.0.1] - 2020/4/16
389
-
390
- ### Added
391
-
392
- - Added everything, initial release.