Socket
Socket
Sign inDemoInstall

@jimp/core

Package Overview
Dependencies
9
Maintainers
2
Versions
220
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.21.4--canary.1163.d07ed6254d130e2995d24101e93427ec091016e6.0 to 0.22.0

29

CHANGELOG.md

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

# v0.22.0 (Mon Feb 06 2023)
### Release Notes
#### Switch to fetch for url requests ([#1165](https://github.com/jimp-dev/jimp/pull/1165))
The underlying library for fetching images has been changed.
`loadFromURL` can take a set of options. When in the node environment all those options are passed to phin. Any options used to pass to `phin` that are not supported by the `fetch` API will stop working.
---
#### 💥 Breaking Change
- Switch to fetch for url requests [#1165](https://github.com/jimp-dev/jimp/pull/1165) ([@danielholmes](https://github.com/danielholmes))
#### 🏠 Internal
- switch from should to expect [#1163](https://github.com/jimp-dev/jimp/pull/1163) ([@hipstersmoothie](https://github.com/hipstersmoothie))
- delete CLI package [#1162](https://github.com/jimp-dev/jimp/pull/1162) ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Change test matching strategy to include all test files [#1161](https://github.com/jimp-dev/jimp/pull/1161) ([@danielholmes](https://github.com/danielholmes))
#### Authors: 2
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
- Daniel Holmes ([@danielholmes](https://github.com/danielholmes))
---
# v0.21.2 (Sun Feb 05 2023)

@@ -2,0 +31,0 @@

12

dist/index.js

@@ -68,15 +68,13 @@ "use strict";

function loadFromURL(options, cb) {
(0, _request.default)(options, (err, response, data) => {
(0, _request.default)(options, (err, data) => {
if (err) {
return cb(err);
}
if ("headers" in response && "location" in response.headers) {
options.url = response.headers.location;
return loadFromURL(options, cb);
}
if (typeof data === "object" && Buffer.isBuffer(data)) {
return cb(null, data);
}
const msg = "Could not load Buffer from <" + options.url + "> " + "(HTTP: " + response.statusCode + ")";
return new Error(msg);
if (typeof data === "object" && isArrayBuffer(data)) {
return cb(null, bufferFromArrayBuffer(data));
}
return new Error(`Could not load Buffer from <${options.url}>`);
});

@@ -83,0 +81,0 @@ }

"use strict";
/* global XMLHttpRequest */
if (process.browser || process.env.ENVIRONMENT === "BROWSER" || typeof process.versions.electron !== "undefined" && process.type === "renderer" && typeof XMLHttpRequest === "function") {
// If we run into a browser or the electron renderer process,
// use XHR method instead of Request node module.
module.exports = function (options, cb) {
const xhr = new XMLHttpRequest();
xhr.open("GET", options.url, true);
xhr.responseType = "arraybuffer";
xhr.addEventListener("load", function () {
if (xhr.status < 400) {
try {
const data = Buffer.from(this.response);
cb(null, xhr, data);
} catch (error) {
return cb(new Error("Response is not a buffer for url " + options.url + ". Error: " + error.message));
}
} else {
cb(new Error("HTTP Status " + xhr.status + " for url " + options.url));
}
});
xhr.addEventListener("error", e => {
cb(e);
});
xhr.send();
};
} else {
module.exports = function (_ref, cb) {
let {
...options
} = _ref;
const p = require("phin");
const allOptions = {
compression: true,
...options
};
try {
p(allOptions, (err, res) => {
if (err) {
cb(err);
} else {
cb(null, res, res.body);
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("isomorphic-fetch");
var _default = (_ref, cb) => {
let {
url,
...options
} = _ref;
fetch(url, options).then(response => {
if (response.ok) {
return response.arrayBuffer().catch(error => {
throw new Error(`Response is not a buffer for url ${url}. Error: ${error.message}`);
});
} catch (error) {
cb(error);
}
};
}
throw new Error(`HTTP Status ${response.status} for url ${url}`);
}).then(data => cb(null, data)).catch(error => cb(error));
};
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=request.js.map

@@ -49,15 +49,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function loadFromURL(options, cb) {
request(options, (err, response, data) => {
request(options, (err, data) => {
if (err) {
return cb(err);
}
if ("headers" in response && "location" in response.headers) {
options.url = response.headers.location;
return loadFromURL(options, cb);
}
if (typeof data === "object" && Buffer.isBuffer(data)) {
return cb(null, data);
}
const msg = "Could not load Buffer from <" + options.url + "> " + "(HTTP: " + response.statusCode + ")";
return new Error(msg);
if (typeof data === "object" && isArrayBuffer(data)) {
return cb(null, bufferFromArrayBuffer(data));
}
return new Error(`Could not load Buffer from <${options.url}>`);
});

@@ -64,0 +62,0 @@ }

@@ -1,51 +0,16 @@

/* global XMLHttpRequest */
if (process.browser || process.env.ENVIRONMENT === "BROWSER" || typeof process.versions.electron !== "undefined" && process.type === "renderer" && typeof XMLHttpRequest === "function") {
// If we run into a browser or the electron renderer process,
// use XHR method instead of Request node module.
module.exports = function (options, cb) {
const xhr = new XMLHttpRequest();
xhr.open("GET", options.url, true);
xhr.responseType = "arraybuffer";
xhr.addEventListener("load", function () {
if (xhr.status < 400) {
try {
const data = Buffer.from(this.response);
cb(null, xhr, data);
} catch (error) {
return cb(new Error("Response is not a buffer for url " + options.url + ". Error: " + error.message));
}
} else {
cb(new Error("HTTP Status " + xhr.status + " for url " + options.url));
}
});
xhr.addEventListener("error", e => {
cb(e);
});
xhr.send();
};
} else {
module.exports = function (_ref, cb) {
let {
...options
} = _ref;
const p = require("phin");
const allOptions = {
compression: true,
...options
};
try {
p(allOptions, (err, res) => {
if (err) {
cb(err);
} else {
cb(null, res, res.body);
}
import "isomorphic-fetch";
export default ((_ref, cb) => {
let {
url,
...options
} = _ref;
fetch(url, options).then(response => {
if (response.ok) {
return response.arrayBuffer().catch(error => {
throw new Error(`Response is not a buffer for url ${url}. Error: ${error.message}`);
});
} catch (error) {
cb(error);
}
};
}
throw new Error(`HTTP Status ${response.status} for url ${url}`);
}).then(data => cb(null, data)).catch(error => cb(error));
});
//# sourceMappingURL=request.js.map
{
"name": "@jimp/core",
"version": "0.21.4--canary.1163.d07ed6254d130e2995d24101e93427ec091016e6.0",
"version": "0.22.0",
"description": "Jimp core",

@@ -32,3 +32,3 @@ "main": "dist/index.js",

"dependencies": {
"@jimp/utils": "0.21.4--canary.1163.d07ed6254d130e2995d24101e93427ec091016e6.0",
"@jimp/utils": "^0.22.0",
"any-base": "^1.1.0",

@@ -38,4 +38,4 @@ "buffer": "^5.2.0",

"file-type": "^16.5.4",
"isomorphic-fetch": "^3.0.0",
"mkdirp": "^0.5.1",
"phin": "^2.9.1",
"pixelmatch": "^4.0.2",

@@ -47,3 +47,3 @@ "tinycolor2": "^1.4.1"

},
"gitHead": "d07ed6254d130e2995d24101e93427ec091016e6"
"gitHead": "d4ed418ae57e5345e42734cd8d7256f558e1eef8"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc