All files / lib map.js

100% Statements 18/18
100% Branches 2/2
100% Functions 8/8
100% Lines 17/17

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 301x 4x 5x 7x 7x   11x   4x     1x 3x 3x   3x 3x     3x     1x 4x 4x     4x    
export const serializeMap = map => {
    const reducer = m =>
        [...m].reduce((a, v) => {
            a[v[0]] = v[1];
            return a;
        }, {});
    const replacer = (key, value) => (value instanceof Map ? reducer(value) : value);
 
    return JSON.stringify(map, replacer);
};
 
export const deserialiseMap = o => {
    const json = JSON.parse(o);
    const m = new Map();
 
    Object.keys(json).forEach(k => {
        m.set(k, json[k]);
    });
 
    return m;
};
 
export const populateMap = (map, data) => {
    Object.keys(data).forEach(k => {
        map.set(k, data[k]);
    });
 
    return map;
};