ginlibs-set-key
可以通过路径字符串读取或修改 object 的内层的值
import { setKey, getKey } from 'ginlibs-set-key'
const obj = {}
setKey('a.b[0]', 1, obj)
// obj 的值变成
// {
// a: {
// b: [1],
// },
// }
getKey('a.b[0]', obj)
// 得到值 1
-
key
是赋值的路径 -
val
是要赋予的值 -
obj
是要处理的对象
setKey('a.b[0]', 1, obj)
-
key
是赋值的路径 -
obj
是要处理的对象
getKey('a.b[0]', obj)
Tests are using jest, to run the tests use:
$ npm run test:cov
report detail
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 95 | 100 | 100 |
index.ts | 100 | 95 | 100 | 100 | 19,50
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 4.053 s
Ran all test suites.
MIT