object-path icon indicating copy to clipboard operation
object-path copied to clipboard

Missing support for ES2015 Map and Set

Open lmammino opened this issue 8 years ago • 0 comments

The code doesn't seem to work when the underlying object (or an object along the path) is of type Set or Map.

We could support both by following this approach:

  • with Set, convert it into an array and access it as it is an array (some logic and memory considerations need to be made here)
  • with Map, you can simply use the get and has fields to access the data.

Code to replicate the issue:

var objectPath = require("object-path");

var s = new Set(['a','b','c']);
console.log(objectPath.get(s, '0')); // undefined
console.log((Array.from(s))[0]); // 'a'

var m = new Map();
m.set('a','b');
console.log(objectPath.get(m, 'a')); // undefined
console.log(m.get('a')); // 'b'

lmammino avatar Jan 29 '17 17:01 lmammino