cwebp
Version:
node.js wrapper for cwebp and dwebp binaries from WebP image processing utility
70 lines (67 loc) • 2.06 kB
JavaScript
// Generated by CoffeeScript 1.12.7
var slice = [].slice;
exports.mixin = function(cls, proto) {
var method, name;
for (name in proto) {
method = proto[name];
cls.prototype[name] = method;
}
};
exports.compile = function(methods) {
var fn, name, params, proto;
proto = {};
fn = function(name, params) {
var alias, aliases, description, exclude, i, key, len, method, ref, results, type;
key = params.key, type = params.type, description = params.description, exclude = params.exclude, aliases = params.aliases;
key || (key = name);
method = type === 'boolean' ? function(val) {
var i, k, len, ref;
if (val || arguments.length === 0) {
if (exclude) {
ref = [].concat(exclude);
for (i = 0, len = ref.length; i < len; i++) {
k = ref[i];
delete this._args[methods[k].key || k];
}
}
this._args[key] = [];
} else {
delete this._args[key];
}
return this;
} : (!Array.isArray(type) ? type = [type || 'string'] : void 0, function() {
var args, i, len, nval, t, val, vals;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (args.length < type.length) {
throw new Error('Not enough arguments');
}
vals = [];
for (i = 0, len = type.length; i < len; i++) {
t = type[i];
val = args.shift();
if ((t === 'number') && (Number.isFinite(nval = Number(val)))) {
val = nval;
}
if (typeof val !== t) {
throw new Error("Expected " + t + ", got " + (typeof val));
}
vals.push(val);
}
this._args[key] = vals;
return this;
});
method.description = description;
ref = [].concat(name, aliases || []);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
alias = ref[i];
results.push(proto[alias] = method);
}
return results;
};
for (name in methods) {
params = methods[name];
fn(name, params);
}
return proto;
};