"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var enginers = {};
function reigsterTplEnginer(name, enginer) {
    enginers[name] = enginer;
}
exports.reigsterTplEnginer = reigsterTplEnginer;
function filter(tpl, data) {
    if (data === void 0) { data = {}; }
    if (!tpl || typeof tpl !== 'string') {
        return '';
    }
    var keys = Object.keys(enginers);
    for (var i = 0, len = keys.length; i < len; i++) {
        var enginer = enginers[keys[i]];
        if (enginer.test(tpl)) {
            return enginer.compile(tpl, data);
        }
    }
    return tpl;
}
exports.filter = filter;
function evalExpression(expression, data) {
    /* jshint evil:true */
    try {
        var fn = new Function("data", "with(data) {return !!(" + expression + ");}");
        data = data || {};
        return fn.call(data, data);
    }
    catch (e) {
        return false;
    }
}
exports.evalExpression = evalExpression;
function evalJS(js, data) {
    /* jshint evil:true */
    try {
        var fn = new Function("data", "with(data) {" + (~js.indexOf('return') ? '' : 'return ') + js + ";}");
        data = data || {};
        return fn.call(data, data);
    }
    catch (e) {
        return null;
    }
}
exports.evalJS = evalJS;
//# sourceMappingURL=./utils/tpl.js.map
