-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
90 lines (79 loc) · 3.12 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var _ = require('underscore');
var opts = {
'w': ['numeric', '-w', ['>= 0']],
'width': 'w',
'h': ['numeric', '-h', ['>= 0']],
'height': 'h',
'e': ['choice', '-e', ['jpg', 'bmp', 'gif', 'png']],
'encoding': 'e',
'sh': ['numeric', '-ss', ['>= 0', '<= 6000000']],
'shutter': 'sh',
'n': ['boolean', '-n'],
'nopreview': 'n',
'op': ['numeric', '-n', ['>= 0', '<= 255']],
'opacity': 'op',
'ifx': ['choice', '-ifx', ['none', 'negative', 'solarise', 'posterise', 'whiteboard', 'blackboard', 'sketch', 'denoise', 'emboss', 'oilpaint', 'hatch', 'gpen', 'pastel', 'watercolour', 'film', 'blur', 'saturation']],
'imxfx': 'ifx',
'mm': ['choice', '-mm', ['average', 'spot', 'backlit', 'matrix']],
'metering': 'mm',
'q': ['numeric', '-q', ['>= 0', '<= 100']],
'quality': 'q',
't': ['numeric', '-t', ['>= 0']],
'timeout': 't',
'hf': ['boolean', '-hf'],
'hflip': 'hf',
'vf': ['boolean', '-vf'],
'vflip': 'vf',
'rot': ['numeric', '-rot'],
'rotation': 'rot',
'p': ['choice', '-p', ['0,0,1920,1080','0,0,1080,1920','0,608,1080,608']],
'preview': 'p'
};
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function isString(s) {
return (typeof s == 'string' || s instanceof String);
}
module.exports = function() {
return {
process: function(options) {
var result = [];
for (var i in options) {
var option = typeof opts[i] !== 'object' ? opts[opts[i]] : opts[i];
if (option[0] === 'numeric') {
if (!isNumeric(options[i])) {
throw 'property ' + i + ' is not a number';
}
_.each(option[2], function(check) {
if (!eval(options[i] + check)) {
throw 'property \'' + i + '\' should be ' + check;
}
});
if (result.indexOf(option[1]) === -1) {
result.push(option[1]);
result.push(options[i]);
}
} else if (option[0] === 'choice') {
if (option[2].indexOf(options[i]) == -1) {
throw 'property \'' + i + '\' should be one of ' + option[2];
}
if (result.indexOf(option[1]) === -1) {
result.push(option[1]);
result.push(options[i]);
}
} else if (option[0] === 'boolean') {
if ((isString(options[i]) && options[i].toLowerCase() === 'true') || options[i] === true) {
if (result.indexOf(option[1]) === -1) {
result.push(option[1]);
}
} else if ((isString(options[i]) && options[i].toLowerCase() === 'false') || options[i] === false) {
} else {
throw 'property \'' + i + '\' should be true or false';
}
}
}
return result;
}
};
};