Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@drovp/optimize

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drovp/optimize - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

38

dist/processor.js

@@ -34,3 +34,3 @@ "use strict";

let outputBuffer;
let plugin;
let optimizer;
switch (encoder) {

@@ -43,3 +43,3 @@ case 'mozjpeg': {

delete pluginOptions.smooth;
plugin = require('imagemin-mozjpeg')(pluginOptions);
optimizer = (await nativeImport('imagemin-mozjpeg')).default(pluginOptions);
break;

@@ -65,13 +65,13 @@ }

delete pluginOptions.size;
plugin = require('imagemin-webp')({ ...pluginOptions, size });
optimizer = (await nativeImport('imagemin-webp')).default({ ...pluginOptions, size });
break;
}
case 'pngquant':
plugin = require('imagemin-pngquant')(options.pngquant);
optimizer = (await nativeImport('imagemin-pngquant')).default(options.pngquant);
break;
case 'optipng':
plugin = require('imagemin-optipng')(options.optipng);
optimizer = (await nativeImport('imagemin-optipng')).default(options.optipng);
break;
case 'gifsicle':
plugin = require('imagemin-gifsicle')(options.gifsicle);
optimizer = (await nativeImport('imagemin-gifsicle')).default(options.gifsicle);
break;

@@ -88,3 +88,3 @@ case 'gif2webp':

delete pluginOptions.mode;
plugin = require('imagemin-gif2webp')(pluginOptions);
optimizer = (await nativeImport('imagemin-gif2webp')).default(pluginOptions);
break;

@@ -97,8 +97,7 @@ case 'svgo': {

}
plugin = (await nativeImport('imagemin-svgo')).default({ plugins });
optimizer = (await nativeImport('imagemin-svgo')).default({ plugins });
break;
}
}
const { default: imagemin } = await nativeImport('imagemin');
outputBuffer = await imagemin.buffer(inputBuffer, { plugins: [plugin] });
outputBuffer = await optimizer(inputBuffer);
if (!outputBuffer) {

@@ -118,3 +117,20 @@ console.error(`imagemin didn't produce any output.`);

});
output.file(outputPath);
const savings = ((inputBuffer.byteLength - outputBuffer.byteLength) / inputBuffer.byteLength) * -1;
const savingsPercent = numberToPercent(savings);
output.file(outputPath, {
flair: savings < 0
? {
variant: 'success',
title: savingsPercent,
description: `Result is ${savingsPercent} smaller than the original.`,
}
: {
variant: 'danger',
title: `+${savingsPercent}`,
description: `Result is ${savingsPercent} larger than the original.`,
},
});
};
function numberToPercent(value) {
return `${(value * 100).toFixed(Math.abs(value) > 0.01 ? 0 : 1)}%`;
}
{
"name": "@drovp/optimize",
"version": "5.0.1",
"version": "5.1.0",
"description": "Perceptually lossless png, jpg, svg, webp, and gif size optimization.",

@@ -52,16 +52,15 @@ "homepage": "https://github.com/drovp/optimize",

"tslib": "^2.3.1",
"typescript": "^4.5.2"
"typescript": "^4.6.3"
},
"dependencies": {
"@drovp/save-as-path": "^2.0.0",
"@drovp/types": "^3.0.2",
"imagemin": "^8.0.1",
"@drovp/types": "^4.2.1",
"imagemin-gif2webp": "^3.0.0",
"imagemin-gifsicle": "^7.0.0",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-mozjpeg": "^10.0.0",
"imagemin-optipng": "^8.0.0",
"imagemin-pngquant": "^9.0.2",
"imagemin-svgo": "^10.0.0",
"imagemin-webp": "^6.0.0"
"imagemin-webp": "^7.0.0"
}
}

@@ -9,6 +9,13 @@ # @drovp/optimize

- JPG: mozjpeg, libwebp
- PNG: pngquant, optipng, libwebp
- WEBP: libwebp
- GIF: gifsicle, gif2webp
- SVG: svgo
- JPG: mozjpeg, libwebp
- PNG: pngquant, optipng, libwebp
- WEBP: libwebp
- GIF: gifsicle, gif2webp
- SVG: svgo
## Changelog
### 5.1.0
- Added output flairs with file size savings percentage.
- Updated dependencies.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc