ginlibs-set-key
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

NPM version NPM Weekly Downloads License

ginlibs-set-key

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

API

setKey(key, val, obj)

  • key 是赋值的路径
  • val 是要赋予的值
  • obj 是要处理的对象
setKey('a.b[0]', 1, obj)

getKey(key, obj)

  • key 是赋值的路径
  • obj 是要处理的对象
getKey('a.b[0]', obj)

Test Report

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.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i ginlibs-set-key

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

6.27 kB

Total Files

6

Last publish

Collaborators

  • gintamamadao