How to use the spm-jquery.each function in spm-jquery

To help you get started, we’ve selected a few spm-jquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aralejs / validator / src / utils.js View on Github external
function parseJSON(str) {
    if (!str)
        return null;

    var NOTICE = 'Invalid option object "' + str + '".';

    // remove braces
    str = str.slice(1, -1);

    var result = {};

    var arr = str.split(',');
    $.each(arr, function (i, v) {
        arr[i] = $.trim(v);
        if (!arr[i])
            throw new Error(NOTICE);

        var arr2 = arr[i].split(':');

        var key = $.trim(arr2[0]),
            value = $.trim(arr2[1]);

        if (!key || !value)
            throw new Error(NOTICE);

        result[getValue(key)] = $.trim(getValue(value));
    });

    // 'abc' -> 'abc'  '"abc"' -> 'abc'
github aralejs / validator / src / item.js View on Github external
truly = !!ele.val();
        }

        // 非必要且没有值的时候, 直接 callback
        if (!truly) {
            callback && callback(null, null);
            return;
        }
    }

    if (!$.isArray(rules))
        throw new Error('No validation rule specified or not specified as an array.');

    var tasks = [];

    $.each(rules, function (i, item) {
        var obj = utils.parseRule(item),
            ruleName = obj.name,
            param = obj.param;

        var ruleOperator = Rule.getOperator(ruleName);
        if (!ruleOperator)
            throw new Error('Validation rule with name "' + ruleName + '" cannot be found.');

        var options = getMsgOptions(param, ruleName, self);

        tasks.push(function (cb) {
            // cb 为 async.series 每个 tasks 函数 的 callback!!
            // callback(err, results)
            // self._validator 为当前 Item 对象所在的 Validator 对象
            ruleOperator.call(self._validator, options, cb);
        });
github aralejs / validator / src / rule.js View on Github external
function compileTpl(obj, tpl) {
    var result = tpl;

    var regexp1 = /\{\{[^\{\}]*\}\}/g,
        regexp2 = /\{\{(.*)\}\}/;

    var arr = tpl.match(regexp1);
    arr && $.each(arr, function (i, v) {
        var key = v.match(regexp2)[1];
        var value = obj[$.trim(key)];
        result = result.replace(v, value);
    });
    return result;
}
github aralejs / validator / src / rule.js View on Github external
function setMessage(name, msg) {
    if ($.isPlainObject(name)) {
        $.each(name, function (i, v) {
            setMessage(i, v);
        });
        return this;
    }

    if ($.isPlainObject(msg)) {
        messages[name] = msg;
    } else {
        messages[name] = {
            failure: msg
        };
    }
    return this;
}
github aralejs / validator / src / rule.js View on Github external
function addRule(name, operator, message) {
    if ($.isPlainObject(name)) {
        $.each(name, function (i, v) {
            if ($.isArray(v))
                addRule(i, v[0], v[1]);
            else
                addRule(i, v);
        });
        return this;
    }

    if (operator instanceof Rule) {
        rules[name] = new Rule(name, operator.operator);
    } else {
        rules[name] = new Rule(name, operator);
    }
    setMessage(name, message);

    return this;

spm-jquery

JavaScript library for DOM operations

MIT
Latest version published 9 years ago

Package Health Score

69 / 100
Full package analysis