UNPKG

svelte-ux

Version:

- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`

19 lines (18 loc) 523 B
/** * Get the value at path of Map. Useful for nested maps (d3-array group, etc). * Similar to lodash get() but for Map instead of Object */ export function get(map, path) { let key = null; let value = map; const currentPath = [...path]; // Copy since .shift() mutates original array while ((key = currentPath.shift())) { if (value instanceof Map && value.has(key)) { value = value.get(key); } else { return undefined; } } return value; }