zenika-open-source / immutadot

immutadot is a JavaScript library to deal with nested immutable structures.

Home Page:https://immutadot.zenika.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for Map

nlepage opened this issue · comments

Description

Add support for JavaScript Map

Access to map keys via prop notation and bracket notation

const obj = { nested: { map: new Map() } }
const newObj = set(obj, 'nested.map.foo', 'bar')
get(newObj, 'nested.map["foo"]') // bar

Iterate over map values

const obj = { nested: { map: new Map([['foo', { val: 'bar' }], ['aze', { val: 'rty' }]]) } }
get(obj, 'nested.map[:].val') // ['bar', 'rty']

In addition it would be nice to support more literals in bracket notation, since map keys might be of any type !

How do you allow the user to put a key that is not a string or number ?

For now I have only these examples in mind:

get(obj, 'nested.map[true].val') // boolean
get(obj, 'nested.map[6.66].val') // floating number
get(obj, 'nested.map[null].val') // null

but if we allow path to be an array, we might accept any value