0.2.5 • Published 5 years ago

@cat5th/key-serializer v0.2.5

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

key-serializer

serilize keys and query keys deep in an object

documentation

npm version coverage npm downloads Build Status

how to use

It is very easy to get value of keys deep into your object, or stringify keys to a string from array

import serializer

import keySerializer from '@cat5th/key-serializer'

stringify keys

keySerializer.stringify(['a', 1, 'b', 0])
// result: "a[1].b[0]"

parse keys

keySerializer.parse('a[1].b[0]')
// result: ['a', 1, 'b', 0]

query object

const obj = { a: [{ b: [1, 2], c: [3, 4] }, { b: [5, 6], c: [7, 8] }] }
keySerializer.query(obj, 'a[1].b[0]')
// result: { value: 5, key: 0, target: [5, 6]}

get value

keySerializer.get(obj, 'a[1].b[0]')
// result: 5

set value

keySerializer.set(obj, 'a[1].b[0]', 1)
console.log(obj.a[1].b[0])
// result: 1

notice: get/set/query function will throw TypeError when target is null or undefined, keep in mind, and always use get/query in try block

0.2.5

5 years ago

0.2.1

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.0

6 years ago

0.1.7

6 years ago

0.1.8

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.0

6 years ago