Socket
Socket
Sign inDemoInstall

ipx

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipx - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

68

dist/cli.js

@@ -5,6 +5,6 @@ #!/usr/bin/env node

const consola2 = require('consola');
const consola = require('consola');
const listhen = require('listhen');
const Sharp = require('sharp');
const defu2 = require('defu');
const defu = require('defu');
const imageMeta = require('image-meta');

@@ -15,26 +15,26 @@ const ufo = require('ufo');

const fsExtra = require('fs-extra');
const destr2 = require('destr');
const http2 = require('http');
const https2 = require('https');
const destr = require('destr');
const http = require('http');
const https = require('https');
const fetch = require('node-fetch');
const getEtag = require('etag');
const xss2 = require('xss');
const xss = require('xss');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
const consola2__default = /*#__PURE__*/_interopDefaultLegacy(consola2);
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
const Sharp__default = /*#__PURE__*/_interopDefaultLegacy(Sharp);
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2);
const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
const imageMeta__default = /*#__PURE__*/_interopDefaultLegacy(imageMeta);
const isValidPath__default = /*#__PURE__*/_interopDefaultLegacy(isValidPath);
const destr2__default = /*#__PURE__*/_interopDefaultLegacy(destr2);
const http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
const https2__default = /*#__PURE__*/_interopDefaultLegacy(https2);
const destr__default = /*#__PURE__*/_interopDefaultLegacy(destr);
const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
const https__default = /*#__PURE__*/_interopDefaultLegacy(https);
const fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
const getEtag__default = /*#__PURE__*/_interopDefaultLegacy(getEtag);
const xss2__default = /*#__PURE__*/_interopDefaultLegacy(xss2);
const xss__default = /*#__PURE__*/_interopDefaultLegacy(xss);
function getEnv(name, defaultValue) {
var _a;
return (_a = destr2__default['default'](process.env[name])) != null ? _a : defaultValue;
return (_a = destr__default['default'](process.env[name])) != null ? _a : defaultValue;
}

@@ -86,4 +86,4 @@ function cachedPromise(fn) {

const createHTTPSource = (options) => {
const httpsAgent = new https2__default['default'].Agent({keepAlive: true});
const httpAgent = new http2__default['default'].Agent({keepAlive: true});
const httpsAgent = new https__default['default'].Agent({keepAlive: true});
const httpAgent = new http__default['default'].Agent({keepAlive: true});
let domains = options.domains || [];

@@ -125,3 +125,3 @@ if (typeof domains === "string") {

function VArg(arg) {
return destr2__default['default'](arg);
return destr__default['default'](arg);
}

@@ -353,3 +353,3 @@ function parseArgs(args, mappers) {

};
const options = defu2__default['default'](userOptions, defaults);
const options = defu__default['default'](userOptions, defaults);
const ctx = {

@@ -396,10 +396,10 @@ sources: {}

}
let sharp2 = Sharp__default['default'](data);
Object.assign(sharp2.options, options.sharp);
let sharp = Sharp__default['default'](data);
Object.assign(sharp.options, options.sharp);
const modifierCtx = {};
for (const key in inputOpts.modifiers) {
sharp2 = applyHandler(modifierCtx, sharp2, key, inputOpts.modifiers[key]) || sharp2;
sharp = applyHandler(modifierCtx, sharp, key, inputOpts.modifiers[key]) || sharp;
}
if (SUPPORTED_FORMATS.includes(format)) {
sharp2 = sharp2.toFormat(format, {
sharp = sharp.toFormat(format, {
quality: modifierCtx.quality,

@@ -409,3 +409,3 @@ progressive: format === "jpeg"

}
const newData = await sharp2.toBuffer();
const newData = await sharp.toBuffer();
return {

@@ -424,3 +424,3 @@ data: newData,

async function handleRequest(req, res, ipx2) {
async function handleRequest(req, res, ipx) {
const url = ufo.parseURL(ufo.normalizeURL(req.url));

@@ -436,3 +436,3 @@ const params = ufo.parseQuery(url.search);

}
const img = ipx2(id, {
const img = ipx(id, {
modifiers,

@@ -455,5 +455,5 @@ source: params.source

const {data, format} = await img.data();
const etag2 = getEtag__default['default'](data);
res.setHeader("ETag", etag2);
if (etag2 && req.headers["if-none-match"] === etag2) {
const etag = getEtag__default['default'](data);
res.setHeader("ETag", etag);
if (etag && req.headers["if-none-match"] === etag) {
res.statusCode = 304;

@@ -467,7 +467,7 @@ return res.end();

}
function createIPXMiddleware(ipx2) {
function createIPXMiddleware(ipx) {
return function IPXMiddleware(req, res) {
handleRequest(req, res, ipx2).catch((err) => {
handleRequest(req, res, ipx).catch((err) => {
const statusCode = parseInt(err.statusCode) || 500;
const statusMessage = err.statusMessage ? xss2__default['default'](err.statusMessage) : `IPX Error (${statusCode})`;
const statusMessage = err.statusMessage ? xss__default['default'](err.statusMessage) : `IPX Error (${statusCode})`;
if (process.env.NODE_ENV !== "production" && statusCode === 500) {

@@ -484,5 +484,5 @@ console.error(err);

async function main() {
const ipx2 = createIPX({});
const middleware2 = createIPXMiddleware(ipx2);
await listhen.listen(middleware2, {
const ipx = createIPX({});
const middleware = createIPXMiddleware(ipx);
await listhen.listen(middleware, {
clipboard: false

@@ -492,4 +492,4 @@ });

main().catch((err) => {
consola2__default['default'].error(err);
consola__default['default'].error(err);
process.exit(1);
});

@@ -6,3 +6,3 @@ 'use strict';

const Sharp = require('sharp');
const defu2 = require('defu');
const defu = require('defu');
const imageMeta = require('image-meta');

@@ -13,8 +13,8 @@ const ufo = require('ufo');

const fsExtra = require('fs-extra');
const destr2 = require('destr');
const http2 = require('http');
const https2 = require('https');
const destr = require('destr');
const http = require('http');
const https = require('https');
const fetch = require('node-fetch');
const getEtag = require('etag');
const xss2 = require('xss');
const xss = require('xss');

@@ -24,15 +24,15 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

const Sharp__default = /*#__PURE__*/_interopDefaultLegacy(Sharp);
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2);
const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
const imageMeta__default = /*#__PURE__*/_interopDefaultLegacy(imageMeta);
const isValidPath__default = /*#__PURE__*/_interopDefaultLegacy(isValidPath);
const destr2__default = /*#__PURE__*/_interopDefaultLegacy(destr2);
const http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
const https2__default = /*#__PURE__*/_interopDefaultLegacy(https2);
const destr__default = /*#__PURE__*/_interopDefaultLegacy(destr);
const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
const https__default = /*#__PURE__*/_interopDefaultLegacy(https);
const fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
const getEtag__default = /*#__PURE__*/_interopDefaultLegacy(getEtag);
const xss2__default = /*#__PURE__*/_interopDefaultLegacy(xss2);
const xss__default = /*#__PURE__*/_interopDefaultLegacy(xss);
function getEnv(name, defaultValue) {
var _a;
return (_a = destr2__default['default'](process.env[name])) != null ? _a : defaultValue;
return (_a = destr__default['default'](process.env[name])) != null ? _a : defaultValue;
}

@@ -84,4 +84,4 @@ function cachedPromise(fn) {

const createHTTPSource = (options) => {
const httpsAgent = new https2__default['default'].Agent({keepAlive: true});
const httpAgent = new http2__default['default'].Agent({keepAlive: true});
const httpsAgent = new https__default['default'].Agent({keepAlive: true});
const httpAgent = new http__default['default'].Agent({keepAlive: true});
let domains = options.domains || [];

@@ -123,3 +123,3 @@ if (typeof domains === "string") {

function VArg(arg) {
return destr2__default['default'](arg);
return destr__default['default'](arg);
}

@@ -351,3 +351,3 @@ function parseArgs(args, mappers) {

};
const options = defu2__default['default'](userOptions, defaults);
const options = defu__default['default'](userOptions, defaults);
const ctx = {

@@ -394,10 +394,10 @@ sources: {}

}
let sharp2 = Sharp__default['default'](data);
Object.assign(sharp2.options, options.sharp);
let sharp = Sharp__default['default'](data);
Object.assign(sharp.options, options.sharp);
const modifierCtx = {};
for (const key in inputOpts.modifiers) {
sharp2 = applyHandler(modifierCtx, sharp2, key, inputOpts.modifiers[key]) || sharp2;
sharp = applyHandler(modifierCtx, sharp, key, inputOpts.modifiers[key]) || sharp;
}
if (SUPPORTED_FORMATS.includes(format)) {
sharp2 = sharp2.toFormat(format, {
sharp = sharp.toFormat(format, {
quality: modifierCtx.quality,

@@ -407,3 +407,3 @@ progressive: format === "jpeg"

}
const newData = await sharp2.toBuffer();
const newData = await sharp.toBuffer();
return {

@@ -422,3 +422,3 @@ data: newData,

async function handleRequest(req, res, ipx2) {
async function handleRequest(req, res, ipx) {
const url = ufo.parseURL(ufo.normalizeURL(req.url));

@@ -434,3 +434,3 @@ const params = ufo.parseQuery(url.search);

}
const img = ipx2(id, {
const img = ipx(id, {
modifiers,

@@ -453,5 +453,5 @@ source: params.source

const {data, format} = await img.data();
const etag2 = getEtag__default['default'](data);
res.setHeader("ETag", etag2);
if (etag2 && req.headers["if-none-match"] === etag2) {
const etag = getEtag__default['default'](data);
res.setHeader("ETag", etag);
if (etag && req.headers["if-none-match"] === etag) {
res.statusCode = 304;

@@ -465,7 +465,7 @@ return res.end();

}
function createIPXMiddleware(ipx2) {
function createIPXMiddleware(ipx) {
return function IPXMiddleware(req, res) {
handleRequest(req, res, ipx2).catch((err) => {
handleRequest(req, res, ipx).catch((err) => {
const statusCode = parseInt(err.statusCode) || 500;
const statusMessage = err.statusMessage ? xss2__default['default'](err.statusMessage) : `IPX Error (${statusCode})`;
const statusMessage = err.statusMessage ? xss__default['default'](err.statusMessage) : `IPX Error (${statusCode})`;
if (process.env.NODE_ENV !== "production" && statusCode === 500) {

@@ -472,0 +472,0 @@ console.error(err);

{
"name": "ipx",
"version": "0.6.0",
"version": "0.6.1",
"repository": "nuxt-contrib/ipx",

@@ -23,14 +23,14 @@ "license": "MIT",

"dependencies": {
"consola": "^2.15.0",
"defu": "^3.2.2",
"consola": "^2.15.3",
"defu": "^5.0.0",
"destr": "^1.1.0",
"etag": "^1.8.1",
"fs-extra": "^9.0.1",
"fs-extra": "^10.0.0",
"image-meta": "^0.0.1",
"is-valid-path": "^0.1.1",
"listhen": "^0.1.2",
"listhen": "^0.2.4",
"node-fetch": "^2.6.1",
"sharp": "^0.27.0",
"ufo": "^0.6.1",
"xss": "^1.0.8"
"sharp": "^0.28.3",
"ufo": "^0.7.5",
"xss": "^1.0.9"
},

@@ -42,6 +42,7 @@ "devDependencies": {

"@types/is-valid-path": "latest",
"@types/jest": "latest",
"@types/node-fetch": "latest",
"@types/sharp": "latest",
"eslint": "latest",
"jest": "^26.6.3",
"jest": "latest",
"jiti": "latest",

@@ -51,5 +52,5 @@ "nodemon": "latest",

"standard-version": "latest",
"ts-jest": "^26.5.0",
"ts-jest": "latest",
"typescript": "latest"
}
}

@@ -19,2 +19,4 @@ # IPX

The default server directory is the current working directory.
### Programatic Usage

@@ -34,15 +36,37 @@

> The examples assume that a `static` folder with `buffalo.png` file is present in the directory where IPX server is running.
Change format to `webp` and keep other things same as source:
`http://cdn.example.com/static/buffalo.png?format=webp`
`http://localhost:3000/static/buffalo.png?format=webp`
Keep original format (`png`) and set width to `200`:
`http://cdn.example.com/static/buffalo.png?width=200`
`http://localhost:3000/static/buffalo.png?width=200`
Resize to `200x300px` using `embed` method and change format to `webp`:
Resize to `200px` using `embed` method and change format to `webp`:
`http://cdn.example.com/static/buffalo.png?embed&format=webp&size=200x300`
`http://localhost:3000/static/buffalo.png?embed&format=webp&resize=200`
<h2 align="center">API</h2>
| Property | Reference | Example | Comments
| ---------|:---------- | :--------| :---
| Width | _ | `http://localhost:3000/buffalo.png?width=200` |
| Height | _ | `http://localhost:3000/buffalo.png?height=200` |
| Trim | [Ref](https://sharp.pixelplumbing.com/api-resize#trim) | `http://localhost:3000/buffalo.png?trim=100` |
| Format | [Ref](https://sharp.pixelplumbing.com/api-output#toformat) | `http://localhost:3000/buffalo.png?format=webp` | Supported format: jpg, jpeg, png, webp, avif, gif, heif
| Quality | _ | `http://localhost:3000/buffalo.png?quality=50` | Accepted values: 0 to 100
| Rotate | [Ref](https://sharp.pixelplumbing.com/api-operation#rotate) | `http://localhost:3000/buffalo.png?rotate=45` |
| Flip | [Ref](https://sharp.pixelplumbing.com/api-operation#flip) | `http://localhost:3000/buffalo.png?flip` |
| Flop | [Ref](https://sharp.pixelplumbing.com/api-operation#flop) | `http://localhost:3000/buffalo.png?flop` |
| Sharpen | [Ref](https://sharp.pixelplumbing.com/api-operation#sharpen) | `http://localhost:3000/buffalo.png?sharpen=30` |
| Median | [Ref](https://sharp.pixelplumbing.com/api-operation#median) | `http://localhost:3000/buffalo.png?median=10` |
| Gamma | [Ref](https://sharp.pixelplumbing.com/api-operation#gamma) | `http://localhost:3000/buffalo.png?gamma=3` |
| Negate | [Ref](https://sharp.pixelplumbing.com/api-operation#negate) | `http://localhost:3000/buffalo.png?negate` |
| Normalize | [Ref](https://sharp.pixelplumbing.com/api-operation#normalize) | `http://localhost:3000/buffalo.png?normalize` |
| Threshold | [Ref](https://sharp.pixelplumbing.com/api-operation#threshold) | `http://localhost:3000/buffalo.png?threshold=10` |
| Tint | [Ref](https://sharp.pixelplumbing.com/api-colour#tint) | `http://localhost:3000/buffalo.png?tint=1098123` |
| Grayscale | [Ref](https://sharp.pixelplumbing.com/api-colour#grayscale) | `http://localhost:3000/buffalo.png?grayscale` |
<h2 align="center">Config</h2>

@@ -52,6 +76,6 @@

- `IPX_LOCAL_DIR`
- `IPX_DIR`
- Default: `.` (current working directory)
- `IPX_REMOTE_ACCEPT`
- `IPX_DOMAINS`
- Default: `[]`

@@ -58,0 +82,0 @@

Sorry, the diff of this file is not supported yet

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