All files / lib object.js

30% Statements 6/20
0% Branches 0/15
40% Functions 2/5
31.57% Lines 6/19

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          2x 9x 24x 22x       2x     2x                                      
// returns a copy of the original map without the specified keys
// export const omit = (keys, map) => {
//     return keys.reduce((o, k) => (({ [k]: _, ...r } = o), r), map);
// };
 
export const omit = (keys, map) =>
    keys.reduce((acc, key) => {
        const { [key]: value, ...rest } = acc;
        return rest;
    }, map);
 
 
const isSerializable = value =>
    !(value === null || value === undefined || typeof value !== "object");
 
const deepSerialize = obj => {
    if (!isSerializable(obj)) {
        return obj;
    }
    if (obj?.toJSON && typeof obj.toJSON === "function") {
        return obj.toJSON();
    }
    if (Array.isArray(obj)) {
        return obj.map(item => deepSerialize(item));
    }
    const result = {};
    for (const key in obj) {
        if (obj.hasOwnProperty(key)) {
            // Serialize and parse each property
            const value = deepSerialize(obj[key]);
            result[key] = isSerializable(value) ? JSON.parse(JSON.stringify(value)) : value;
        }
    }
    return result;
};