dialplan
Version:
Write safe asterisk dialplan quickly on javascript
55 lines (45 loc) • 1.28 kB
JavaScript
// Generated by CoffeeScript 1.8.0
(function() {
var AppList, Application, append, applications, name, validate, validateCount;
AppList = require('./application.json');
applications = {};
Application = function(name, attrs) {
var attrsAsString;
attrsAsString = attrs.join(',');
return "" + name + "(" + attrsAsString + ")";
};
validate = function(name, args) {
var rules;
rules = AppList[name].validate;
if (rules) {
if (rules['count']) {
return validateCount(rules['count'], args);
}
}
};
validateCount = function(count, args) {
if (typeof count === 'number' && args.length !== count) {
throw new Error('Check count args');
}
if (typeof count === 'object') {
if (count['max'] && args.length > count['max']) {
throw new Error('So many args');
}
if (count['min'] && args.length < count['min']) {
throw new Error('Not enough args');
}
}
};
append = function(name) {
return applications[name] = function() {
var args;
args = [].slice.call(arguments, 0);
validate(name, args);
return Application(name, args);
};
};
for (name in AppList) {
append(name);
}
module.exports = applications;
}).call(this);