blob: 6447b91834431aca56d6ebb2d2d28a87b528e911 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2const isSvg = require('is-svg');
3const SVGO = require('svgo');
4
5module.exports = options => buffer => {
6 options = Object.assign({multipass: true}, options);
7
8 if (!isSvg(buffer)) {
9 return Promise.resolve(buffer);
10 }
11
12 if (Buffer.isBuffer(buffer)) {
13 buffer = buffer.toString();
14 }
15
16 const svgo = new SVGO(options);
17 return svgo.optimize(buffer).then(result => Buffer.from(result.data));
18};