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

imagemin

Package Overview
Dependencies
Maintainers
6
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagemin - npm Package Compare versions

Comparing version 8.0.1 to 9.0.0

52

index.js

@@ -1,30 +0,25 @@

import {Buffer} from 'node:buffer';
import {promises as fsPromises} from 'node:fs';
import {promisify} from 'node:util';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import fs from 'graceful-fs';
import FileType from 'file-type';
import {fileTypeFromBuffer} from 'file-type';
import {globby} from 'globby';
import pPipe from 'p-pipe';
import replaceExt from 'replace-ext';
import junk from 'junk';
import changeFileExtension from 'change-file-extension';
import {isNotJunk} from 'junk';
import convertToUnixPath from 'slash';
import {assertUint8Array} from 'uint8array-extras';
import {isBrowser} from 'environment';
import ow from 'ow';
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const handleFile = async (sourcePath, {destination, plugins = []}) => {
if (plugins && !Array.isArray(plugins)) {
throw new TypeError('The `plugins` option should be an `Array`');
}
ow(plugins, ow.optional.array.message('The `plugins` option should be an `Array`'));
let data = await readFile(sourcePath);
let data = await fsPromises.readFile(sourcePath);
data = await (plugins.length > 0 ? pPipe(...plugins)(data) : data);
const {ext} = await FileType.fromBuffer(data) || {ext: path.extname(sourcePath)};
const {ext} = await fileTypeFromBuffer(data) ?? {ext: path.extname(sourcePath)};
let destinationPath = destination ? path.join(destination, path.basename(sourcePath)) : undefined;
destinationPath = ext === 'webp' ? replaceExt(destinationPath, '.webp') : destinationPath;
destinationPath = ext === 'webp' ? changeFileExtension(destinationPath, 'webp') : destinationPath;
const returnValue = {
data,
data: new Uint8Array(data),
sourcePath,

@@ -39,3 +34,3 @@ destinationPath,

await fsPromises.mkdir(path.dirname(returnValue.destinationPath), {recursive: true});
await writeFile(returnValue.destinationPath, returnValue.data);
await fsPromises.writeFile(returnValue.destinationPath, returnValue.data);

@@ -46,6 +41,8 @@ return returnValue;

export default async function imagemin(input, {glob = true, ...options} = {}) {
if (!Array.isArray(input)) {
throw new TypeError(`Expected an \`Array\`, got \`${typeof input}\``);
if (isBrowser) {
throw new Error('This package does not work in the browser.');
}
ow(input, ow.array);
const unixFilePaths = input.map(path => convertToUnixPath(path));

@@ -56,3 +53,3 @@ const filePaths = glob ? await globby(unixFilePaths, {onlyFiles: true}) : input;

filePaths
.filter(filePath => junk.not(path.basename(filePath)))
.filter(filePath => isNotJunk(path.basename(filePath)))
.map(async filePath => {

@@ -69,12 +66,15 @@ try {

imagemin.buffer = async (input, {plugins = []} = {}) => {
if (!Buffer.isBuffer(input)) {
throw new TypeError(`Expected a \`Buffer\`, got \`${typeof input}\``);
imagemin.buffer = async (data, {plugins = []} = {}) => {
if (isBrowser) {
throw new Error('This package does not work in the browser.');
}
assertUint8Array(data);
if (plugins.length === 0) {
return input;
return new Uint8Array(data);
}
return pPipe(...plugins)(input);
// The `new Uint8Array` can be removed if all plugins are changed to return `Uint8Array` instead of `Buffer`.
return new Uint8Array(await pPipe(...plugins)(data));
};
{
"name": "imagemin",
"version": "8.0.1",
"version": "9.0.0",
"description": "Minify images seamlessly",
"license": "MIT",
"repository": "imagemin/imagemin",
"funding": "https://github.com/sponsors/sindresorhus",
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
"node": ">=18"
},

@@ -30,20 +31,21 @@ "scripts": {

"dependencies": {
"file-type": "^16.5.3",
"globby": "^12.0.0",
"graceful-fs": "^4.2.8",
"junk": "^3.1.0",
"change-file-extension": "^0.1.1",
"environment": "^1.0.0",
"file-type": "^19.0.0",
"globby": "^14.0.1",
"junk": "^4.0.1",
"ow": "^2.0.0",
"p-pipe": "^4.0.0",
"replace-ext": "^2.0.0",
"slash": "^3.0.0"
"slash": "^5.1.0",
"uint8array-extras": "^1.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
"del": "^6.0.0",
"ava": "^6.1.2",
"del": "^7.1.0",
"imagemin-jpegtran": "^7.0.0",
"imagemin-svgo": "^9.0.0",
"imagemin-webp": "^6.0.0",
"is-jpg": "^2.0.0",
"tempy": "^1.0.1",
"xo": "^0.43.0"
"imagemin-svgo": "^10.0.1",
"imagemin-webp": "^8.0.0",
"tempy": "^3.1.0",
"xo": "^0.58.0"
}
}

@@ -24,15 +24,2 @@ # imagemin

<br>
<br>
<a href="https://doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=imagemin&utm_source=github">
<div>
<img src="https://dashboard.doppler.com/imgs/logo-long.svg" width="240" alt="Doppler">
</div>
<b>All your environment variables, in one place</b>
<div>
<span>Stop struggling with scattered API keys, hacking together home-brewed tools,</span>
<br>
<span>and avoiding access controls. Keep your team and servers in sync with Doppler.</span>
</div>
</a>
<br>
<a href="https://strapi.io/?ref=sindresorhus">

@@ -56,5 +43,5 @@ <div>

```sh
npm install imagemin
```
$ npm install imagemin
```

@@ -79,3 +66,3 @@ ## Usage

console.log(files);
//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]
```

@@ -87,3 +74,3 @@

Returns `Promise<object[]>` in the format `{data: Buffer, sourcePath: string, destinationPath: string}`.
Returns `Promise<object[]>` in the format `{data: Uint8Array, sourcePath: string, destinationPath: string}`.

@@ -110,3 +97,3 @@ #### input

[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use.
The [plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use.

@@ -120,11 +107,11 @@ ##### glob

### imagemin.buffer(buffer, options?)
### imagemin.buffer(data, options?)
Returns `Promise<Buffer>`.
Returns `Promise<Uint8Array>`.
#### buffer
#### data
Type: `Buffer`
Type: `Uint8Array`
Buffer to optimize.
The image data to optimize.

@@ -144,4 +131,2 @@ #### options

- [imagemin-cli](https://github.com/imagemin/imagemin-cli) - CLI for this module
- [imagemin-app](https://github.com/imagemin/imagemin-app) - GUI app for this module
- [gulp-imagemin](https://github.com/sindresorhus/gulp-imagemin) - Gulp plugin
- [grunt-contrib-imagemin](https://github.com/gruntjs/grunt-contrib-imagemin) - Grunt plugin
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