| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | const isSvg = require('is-svg'); | ||||
| 3 | const SVGO = require('svgo'); | ||||
| 4 | |||||
| 5 | module.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 | }; | ||||