mariocasciaro / object-path

A tiny JavaScript utility to access deep properties using a path (for Node and the Browser)
MIT License
1.06k stars 84 forks source link

Enhancement: move #81

Open danielb2 opened 7 years ago

danielb2 commented 7 years ago
objectPath.move(obj, 'old.path', 'new.path');

instead of:

 const path = objectPath.get(obj, 'old.path');
 objectPath.set(obj, 'new.path', path);
 objectPath.del(obj, 'old.path');
danielb2 commented 7 years ago
ObjectPath.mv = function (obj, src, dst) {

    const data = ObjectPath.get(obj, src);
    if (!data) {
        return;
    }
    ObjectPath.set(obj, dst, data);
    ObjectPath.del(obj, src);
};