object-path
object-path copied to clipboard
Missing support for ES2015 Map and Set
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 theget
andhas
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'