index.js 1.75 KB
/**
 * Created by TaoHuang on 2016/10/26.
 */


'use strict';

exports.if_cond = function(left, operator, right, options) {
    switch (operator) {
        case '==':
            return (left == right) ? options.fn(this) : options.inverse(this); // eslint-disable-line
        case '!=':
            return (left != right) ? options.fn(this) : options.inverse(this); // eslint-disable-line
        case '===':
            return (left === right) ? options.fn(this) : options.inverse(this);
        case '<':
            return (left < right) ? options.fn(this) : options.inverse(this);
        case '<=':
            return (left <= right) ? options.fn(this) : options.inverse(this);
        case '>':
            return (left > right) ? options.fn(this) : options.inverse(this);
        case '>=':
            return (left >= right) ? options.fn(this) : options.inverse(this);
        case '&&':
            return (left && right) ? options.fn(this) : options.inverse(this);
        case '||':
            return (left || right) ? options.fn(this) : options.inverse(this);
        default:
            return options.inverse(this);
    }
};

exports.escapeType = function(value) {

    let strs = value.split('');

    if (strs.length === 2) {
        strs[2] = strs[1];
        strs[1] = '&#12288;&#12288;';
        return strs.join('');
    }

    if (strs.length === 3) {
        strs[4] = strs[2];
        strs[2] = strs[1];
        strs[1] = '&nbsp;&nbsp;';
        strs[3] = '&nbsp;&nbsp;';
        return strs.join('');
    }

    return strs.join('');
};

exports.escapeLength = function(value) {
    let strs = value.split('');

    if (strs.length === 2) {
        strs[2] = strs[1];
        strs[1] = '&#12288;';
        return strs.join('');
    }

    return strs.join('');
};