Comparing version 0.6.1 to 0.7.0
{ | ||
"name": "impro", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Image processing engine", | ||
@@ -5,0 +5,0 @@ "author": "Andreas Lind <andreaslindpetersen@gmail.com>", |
@@ -64,7 +64,5 @@ const _ = require('lodash'); | ||
if (operations) { | ||
if (typeof operations === 'string') { | ||
operations = this.parse(operations).operations; | ||
} else if (!Array.isArray(operations)) { | ||
if (!Array.isArray(operations)) { | ||
throw new Error( | ||
'Pipeline creation can only be supplied an operations array or string' | ||
'Pipeline creation can only be supplied an operations array' | ||
); | ||
@@ -171,81 +169,2 @@ } | ||
} | ||
parse(queryString, allowOperation) { | ||
allowOperation = | ||
typeof allowOperation === 'function' | ||
? allowOperation | ||
: this.allowOperation; | ||
var keyValuePairs = queryString.split('&'); | ||
var operations = []; | ||
var leftOverQueryStringFragments = []; | ||
var consumedQueryStringFragments = []; | ||
keyValuePairs.forEach(function(keyValuePair) { | ||
var matchKeyValuePair = keyValuePair.match(/^([^=]+)(?:=(.*))?/); | ||
if (matchKeyValuePair) { | ||
var operationName = decodeURIComponent(matchKeyValuePair[1]); | ||
// Split by non-URL encoded comma or plus: | ||
var operationArgs = matchKeyValuePair[2] | ||
? matchKeyValuePair[2].split(/[+,]/).map(function(arg) { | ||
arg = decodeURIComponent(arg); | ||
if (/^\d+$/.test(arg)) { | ||
return parseInt(arg, 10); | ||
} else if (arg === 'true') { | ||
return true; | ||
} else if (arg === 'false') { | ||
return false; | ||
} else { | ||
return arg; | ||
} | ||
}) | ||
: []; | ||
if (operationName in this.engineByName) { | ||
// engines accept only a single options object argument, so | ||
// in cases where the query string contains options intended | ||
// for the engine itself we must put them in an object which | ||
// we can then pass as that only supported argument | ||
const engineOptions = {}; | ||
operationArgs.forEach(arg => { | ||
if (typeof arg !== 'string' || arg.indexOf('=') === -1) return; | ||
const [optionKey, optionValue] = arg.split('='); | ||
if (this.restrictedOptions.includes(optionKey)) return; | ||
engineOptions[optionKey] = optionValue; | ||
}); | ||
if (Object.keys(engineOptions).length > 0) { | ||
operationArgs = [engineOptions]; | ||
} else { | ||
operationArgs = []; | ||
} | ||
} | ||
// empty resize args must be passed to engines as null | ||
if (operationName === 'resize') { | ||
operationArgs = operationArgs.map(arg => arg || null); | ||
} | ||
if ( | ||
!this.isValidOperation(operationName, operationArgs) || | ||
(typeof allowOperation === 'function' && | ||
!allowOperation(operationName, operationArgs)) | ||
) { | ||
leftOverQueryStringFragments.push(keyValuePair); | ||
} else { | ||
operations.push({ | ||
name: operationName, | ||
args: operationArgs | ||
}); | ||
consumedQueryStringFragments.push(keyValuePair); | ||
} | ||
} | ||
}, this); | ||
return { | ||
operations: operations, | ||
leftover: leftOverQueryStringFragments.join('&'), | ||
consumed: consumedQueryStringFragments.join('&') | ||
}; | ||
} | ||
}; |
@@ -18,1 +18,2 @@ const Impro = require('./Impro'); | ||
module.exports.engines = engines; | ||
module.exports.queryString = require('./queryString'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67169
20
1782