Compare commits

...

12 Commits

Author SHA1 Message Date
Jeffrey Warren
4162a14df6 Update Module.js 2021-02-15 13:18:08 -05:00
Jeffrey Warren
031bf0d118 make expressions/options case insensitive 2021-02-15 12:29:10 -05:00
Jeffrey Warren
28f98d2790 Update options-test.js 2021-02-15 12:17:04 -05:00
Jeffrey Warren
0cbefa37bb update options test to correctly label varied options 2021-02-15 12:10:19 -05:00
Jeffrey Warren
24f33f0545 Merge branch 'main' into expr-eval 2021-02-15 11:50:18 -05:00
Jeffrey Warren
e95bbded68 Merge branch 'main' into expr-eval 2021-02-06 16:05:52 -05:00
Harsh Khandeparkar
d002549a15 Merge branch 'main' into expr-eval 2021-01-07 00:21:12 +05:30
Jeffrey Warren
39213b2e52 Update Module.js 2020-10-28 19:51:25 -04:00
Jeffrey Warren
85758fc45f Merge branch 'main' into expr-eval 2020-10-28 19:43:37 -04:00
Jeffrey Warren
fd097b9ce1 Merge branch 'main' into expr-eval 2020-10-18 16:19:40 -04:00
jywarren
ac1b837aea added expr-eval module 2020-10-17 18:58:32 +00:00
Jeffrey Warren
670fed4a25 switch to expr-eval for dynamic module 2020-10-17 14:53:13 -04:00
4 changed files with 13 additions and 9 deletions

5
package-lock.json generated
View File

@@ -6315,6 +6315,11 @@
"integrity": "sha512-6Ey4Xy2xvmuQu7z7YQtMsaMV0EHJRpVxIDOd5GRrm04/I3nkTKIutELfECsLp6le+b3SSa3cXhPiw6PgqzxYWA==",
"dev": true
},
"expr-eval": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/expr-eval/-/expr-eval-2.0.2.tgz",
"integrity": "sha512-4EMSHGOPSwAfBiibw3ndnP0AvjDWLsMvGOvWEZ2F96IGk0bIVdjQisOHxReSkE13mHcfbuCiXw+G4y0zv6N8Eg=="
},
"ext-list": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz",

View File

@@ -46,6 +46,7 @@
"data-uri-to-buffer": "^3.0.0",
"downloadjs": "^1.4.7",
"eslint": "^6.1.0",
"expr-eval": "^2.0.2",
"fisheyegl": "^0.1.2",
"font-awesome": "~4.7.0",
"geotiff": "^1.0.0-beta.6",

View File

@@ -14,20 +14,18 @@ module.exports = function Dynamic(options, UI) {
options.blue = options.blue || defaults.blue;
options.green = options.green || defaults.green;
const Parser = require('expr-eval').Parser;
function generator(expression) {
var func = 'f = function (r, g, b, a) { var R = r, G = g, B = b, A = a; return ' + expression + ';}';
var f;
eval(func);
return f;
let expr = Parser.parse('R = r; G = g; B = b; A = a; ' + expression);
return expr.toJSFunction("r,g,b,a,R,G,B,A");
}
var channels = ['red', 'green', 'blue', 'alpha'];
channels.forEach(function(channel) {
if (channel === 'alpha'){
options['alpha_function'] = function() { return 255; };
}
else{
} else {
options[channel + '_function'] = generator(options[channel]);
}
});

View File

@@ -37,7 +37,7 @@ module.exports = (moduleName, options, benchmark, input) => {
looksSame(result, benchmark[0], function(err, res) {
if (err) console.log(err);
t.equal(res.equal, true, `${moduleName} module works correctly with initial option ${options[0][moduleName]}`);
t.equal(res.equal, true, `${moduleName} module works correctly with initial option ${JSON.stringify(options[0])}`);
});
// Change the option of the given module.
sequencer.steps[1].setOptions(options[1]);
@@ -54,7 +54,7 @@ module.exports = (moduleName, options, benchmark, input) => {
looksSame(newResult, benchmark[1], function(err, res) {
if (err) console.log(err);
t.equal(res.equal, true, `${moduleName} module works correctly when the option is changed to ${options[1][moduleName]}`);
t.equal(res.equal, true, `${moduleName} module works correctly when the option is changed to ${JSON.stringify(options[1])}`);
sequencer = null;
t.end();
});