summaryrefslogtreecommitdiff
path: root/lib/internal/createTester.js
blob: 3dbf78d5ced3b5eaea256ecead2d251ea9e3422c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export default function _createTester(eachfn, check, getResult) {
    return function(arr, limit, iterator, cb) {
        function done() {
            if (cb) cb(getResult(false, void 0));
        }
        function iteratee(x, _, callback) {
            if (!cb) return callback();
            iterator(x, function (v) {
                if (cb && check(v)) {
                    cb(getResult(true, x));
                    cb = iterator = false;
                }
                callback();
            });
        }
        if (arguments.length > 3) {
            eachfn(arr, limit, iteratee, done);
        } else {
            cb = iterator;
            iterator = limit;
            eachfn(arr, iteratee, done);
        }
    };
}