transit-im
Version:
express-like framework for AIM bots creation (ICQ as well)
62 lines (52 loc) • 1.67 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var isRegular, isSimplified, isWithoutOptions, normalize,
__slice = [].slice;
isRegular = function(f) {
return f.length >= 3;
};
isWithoutOptions = function(f) {
return f.length === 2;
};
isSimplified = function(f) {
return f.length <= 1;
};
normalize = function(r) {
if (isWithoutOptions(r)) {
return function(data, options, next) {
return r(data, next);
};
} else if (isSimplified(r)) {
return function(data, options, next) {
return next(r(data));
};
} else {
return r;
}
};
module.exports = function() {
var formatters;
formatters = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return function(data, options, cb) {
var formattersToProcess, sendFurther;
if (data._isPrivate) {
return cb(new Error("Invalid usage of formatters chain - register it with 'formatOutput' instead of 'use'"));
}
formattersToProcess = formatters.slice().map(normalize);
formattersToProcess.push(function(data) {
return cb(null, data);
});
sendFurther = function(data, idx) {
var format;
format = formattersToProcess[idx];
return format(data, options, (function(data) {
return sendFurther(data, idx + 1);
}));
};
return sendFurther(data, 0);
};
};
module.exports.wrapHtml = require('../format_wrap_html/formatWrapHtml');
module.exports.json = require('../format_json/formatJson');
module.exports.splitByPortions = require('../format_split_by_portions/formatSplitByPortions');
}).call(this);