All files / lib/stack utils.js

100% Statements 38/38
100% Branches 34/34
100% Functions 6/6
100% Lines 38/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75  55x 13x 13x   5x 3x 3x 3x 3x   2x     6x 4x 4x 4x 4x   2x     2x               30x 29x 110x     30x         7x 7x 10x 22x 3x 19x 1x   18x       7x 7x           49x 49x   13x 13x 4x   13x   36x   49x      
export function transform(type) {
    return function() {
        this._query[type] = this._query[type] || {};
        switch (arguments.length) {
            case 1:
                if (Array.isArray(arguments[0]) || typeof arguments[0] === "string") {
                    let query = this._query[type]['BASE'] || [];
                    query = query.concat(arguments[0]);
                    this._query[type]['BASE'] = query;
                    return this;
                } else {
                    throw Error("Kindly provide valid parameters");
                }
            case 2:
                if (typeof arguments[0] === "string" && (Array.isArray(arguments[1]) || typeof arguments[1] === "string")) {
                    let query = this._query[type][arguments[0]] || [];
                    query = query.concat(arguments[1]);
                    this._query[type][arguments[0]] = query;
                    return this;
                } else {
                    throw Error("Kindly provide valid parameters");
                }
            default:
                throw Error("Kindly provide valid parameters");
        }
    };
}
 
 
// merge two objects
export function merge(target, source) {
    if (target && source) {
        for (let key in source) {
            target[key] = source[key];
        }
    }
    return target;
};
 
// merge two objects
export function mergeDeep(target, source) {
    let self = this;
    let _merge_recursive = function(target, source) {
        for (let key in source) {
            if (self._type(source[key]) == 'object' && self._type(target[key]) == self._type(source[key])) {
                _merge_recursive(target[key], source[key])
            } else if (self._type(source[key]) == 'array' && self._type(target[key]) == self._type(source[key])) {
                target[key] = target[key].concat(source[key]);
            } else {
                target[key] = source[key];
            }
        }
    };
    _merge_recursive(target, source);
    return target;
};
 
 
export function _type(val) {
    let _typeof,
        __typeof = typeof val;
    switch (__typeof) {
        case 'object':
            _typeof = __typeof;
            if (Array.isArray(val)) {
                __typeof = 'array';
            }
            break;
        default:
            _typeof = __typeof;
    }
    return __typeof;
};