does lowdb support dot syntax?
imxuedi opened this issue · comments
I'm from 'electron-store', the dot syntax attracts me, like:
const store = new Store()
const obj = {
key1: 'hello',
key2: [
{subkey1: 100},
{subkey2: 200}
]
}
I can visit subkey1 by store.get("obj['key2'][0]")
, I just need to prepare a path string.
I konw that Js supports dynamic property like:
const key = 'key2'
obj[key]
but what if multi dynamic property?
I have no idea about how to realize above by lowdb or could anyone give me some suggestions? Thanks.
Definitely Sure!
I find that lodash can do this.
Lodash YYDS. LowDB YYDS.
It doesn't support it but it can be added with another library.
For example, with dot-prop:
https://github.com/sindresorhus/dot-prop
getProperty(db.data, 'foo.bar')
With lodash, see:
https://github.com/typicode/lowdb#lodash
Lodash get()
supports it.
Thanks for your generous answer. It indeed solves my problem.
You're welcome. Glad it helped :)