Input and output file sizes available in the SVGO API (`optimize` function)
Hi! 👋
Is your feature request related to a problem? Please describe.
Metrics for SVG files optimized by SVGO (e.g., file sizes) are only printed/console.logged when using the SVGO CLI: https://github.com/svg/svgo/blob/9078e8ca089156996eadbdfc2b1b4f9201742114/lib/svgo/coa.js#L417-L426
It is not possible to obtain this data in an easier to manipulate format (e.g., JSON) nor when using the SVGO API directly (optimize function) in a script: https://github.com/svg/svgo/blob/9078e8ca089156996eadbdfc2b1b4f9201742114/lib/svgo.js#L70-L121
This data is interesting for evaluating and sharing improvements achieved by SVGO (via aggregations, five-number summaries, histograms, etc.). However, getting the raw data is currently cumbersome or require extra, custom logic (to mimic SVGO under the hood).
Describe the solution you'd like
In order to have access to the file sizes calculated when using the SVGO API, the input (the final value is already available) and output file sizes could be computed in the optimize function (instead of in the processSVGData function) and made available next to the optimized SVG string: https://github.com/svg/svgo/blob/9078e8ca089156996eadbdfc2b1b4f9201742114/lib/svgo.js#L118-L120
return {
data: output,
+ metadata: { inputFileSize, outputFileSize }
+ // or
+ inputFileSize,
+ outputFileSize,
};
This way, this data would be easily available for manipulation in scripts, in order to report it in different ways according to each user's needs.
Describe alternatives you've considered
- Add an output format flag (e.g., CSV and JSON) to the CLI for this data;
- Implement a function to simulate the SVG optimization (without writing the optimized SVG files) and calculate different metrics like file sizes (and their differences).
Additional context
- SVGO version: 3.3.2
Let me know what you think and if I can open a PR. Thanks!