New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

caravaggio

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caravaggio - npm Package Compare versions

Comparing version 2.3.6 to 2.4.0

src/normalizers/overlay.js

5

CHANGELOG.md
# Changelog
## 2.4.0
- Add `overlay` option. Now you acn add watermarks to your images!
## 2.3.6

@@ -4,0 +9,0 @@

2

package.json
{
"name": "caravaggio",
"version": "2.3.6",
"version": "2.4.0",
"description": "A blazing fast image processor service",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -22,7 +22,7 @@ const md5 = require('md5');

get: async (url, options) => {
get: async (url) => {
const resource = await persistor.read(cache.getFileName(url));
return resource && {
...resource,
name: cache.getFileName(url, options),
name: cache.getFileName(url),
};

@@ -29,0 +29,0 @@ },

@@ -1,25 +0,27 @@

const UnknownOperationError = require('../errors/UnknownOperationError');
const blurNormalizer = require('./blur');
const extractNormalizer = require('./extract');
const flipNormalizer = require('./flip');
const oNormalizer = require('./o');
const overlayNormalizer = require('./overlay');
const progressiveNormalizer = require('./progressive');
const qNormalizer = require('./q');
const resizeNormalizer = require('./resize');
const extractNormalizer = require('./extract');
const rotateNormalizer = require('./rotate');
const progressiveNormalizer = require('./progressive');
const UnknownOperationError = require('../errors/UnknownOperationError');
const normalizers = {
blur: blurNormalizer,
flip: flipNormalizer,
o: oNormalizer,
q: qNormalizer,
rs: resizeNormalizer,
resize: resizeNormalizer,
ex: extractNormalizer,
extract: extractNormalizer,
rotate: rotateNormalizer,
progressive: progressiveNormalizer,
};
module.exports = (config) => {
const normalizers = {
blur: blurNormalizer,
ex: extractNormalizer,
extract: extractNormalizer,
flip: flipNormalizer,
o: oNormalizer,
overlay: overlayNormalizer(config),
progressive: progressiveNormalizer,
q: qNormalizer,
resize: resizeNormalizer,
rotate: rotateNormalizer,
rs: resizeNormalizer,
};
const defaultTransformations = config.get('defaultTransformations');

@@ -26,0 +28,0 @@

const normalizerFactory = require('./normalizers');
const BLOCK_DELIMITER = '"';
const BLOCK_DELIMITER_REMOVER_REGEXP = new RegExp(`^${BLOCK_DELIMITER}|${BLOCK_DELIMITER}$`, 'mg');
/**
* If the option is in the format a_b_"c_d" it mu be splitted in "a", "b, "c_d"
* This function takes care of joining all the parameter splitted by a dumb split
* @param {Array} options
*/
const joinOptionsSplittedAMongSeparator = options => options.reduce((acc, opt) => {
if (Array.isArray(acc[acc.length - 1])) {
let lastOpt = [
...acc.slice(acc.length - 1)[0],
opt,
];
if (opt.lastIndexOf(BLOCK_DELIMITER) === opt.length - 1) {
lastOpt = lastOpt.join('_').replace(BLOCK_DELIMITER_REMOVER_REGEXP, '');
}
return [
...acc.slice(0, acc.length - 1),
lastOpt,
];
}
if (opt.indexOf(BLOCK_DELIMITER) === 0) {
if (opt.length > 1 && opt.lastIndexOf(BLOCK_DELIMITER) === opt.length - 1) {
return [
...acc,
opt.replace(BLOCK_DELIMITER_REMOVER_REGEXP, ''),
];
}
return [
...acc,
[opt],
];
}
return [
...acc,
opt,
];
}, []);
module.exports = (config) => {

@@ -11,3 +54,5 @@ const normalizer = normalizerFactory(config);

o: 'original',
operations: optsAsArray.map(o => o.split('_')),
operations: optsAsArray.map(
o => joinOptionsSplittedAMongSeparator(o.split('_')),
),
rawNormalizedOptions: opts,

@@ -14,0 +59,0 @@ };

const logger = require('../logger');
const { stringifyParams } = require('../utils');

@@ -11,3 +12,3 @@ const reducer = async (acc, { name, operation, params }) => acc.then(async (pipeline) => {

}
logger.debug(`Applying transformation "${name}:${operation}" with parameters: ${JSON.stringify(params, null, '')}`);
logger.debug(`Applying transformation "${name}:${operation}" with parameters: ${stringifyParams(params)}`);
return pipeline.applyOperation(operation, ...params);

@@ -14,0 +15,0 @@ });

@@ -13,3 +13,3 @@ const { URL } = require('url');

try {
const options = parseOptions(req.params._[0]);
const options = parseOptions(decodeURIComponent(req.params._[0]));
const url = new URL(decodeURIComponent(req.params._[1]));

@@ -16,0 +16,0 @@ const resource = await cache.get(url, options);

@@ -0,1 +1,11 @@

const jsonReplacer = (key, value) => {
if (Buffer.isBuffer(value)) {
return `<Buffer of ${value.length} bytes>`;
}
if (Array.isArray(value)) {
return value.map(v => jsonReplacer(null, v));
}
return value;
};
module.exports = {

@@ -14,3 +24,5 @@ compose: (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))),

percentageToPixel: (percentage, size) => Math.round(percentage * size),
stringifyParams: params => JSON.stringify(params, jsonReplacer, ''),
};
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