Operate object specific path
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
jest.config.json
package.json
tsconfig.base.json
tsconfig.json
tslint.json
yarn.lock

README.md

object-path-operator npm GitHub license Build Status Coverage Status

Operate Object specific path.

Installation

yarn add object-path-operator
import * as ObjectPathOperator from 'object-path-operator'
import {
  getPropertyByPathList, setPropertyByPathList, removePropertyByPathList
, getPropertyByPathString, setPropertyByPathString, removePropertyByPathString
} from 'object-path-operator'

API

Table of Contents

getPropertyByPathList

Get specific object property by path list.

Parameters

Examples

let obj = {
  a: ['hello']
}
getPropertyByPathList(obj, ['a', '0']) // hello

Returns Object Specific object property

setPropertyByPathList

Set specific object property by path list.

Parameters

Examples

let obj = {
  a: ['hello']
}
setPropertyByPathList(obj, ['a', '1'], 'world')
obj.a // ['hello', 'world']

Returns boolean Return true when no exception

removePropertyByPathList

Remove specific object property by path list.

Parameters

Examples

let obj = {
  a: ['hello']
}
removePropertyByPathList(obj, ['a', '0'])
obj.a // []

Returns boolean Always return true

getPropertyByPathString

Get specific property by path string. Path string parsed by eval().

Parameters

  • obj Object Target object
  • path stirng Path string

Examples

let obj = {
  a: ['hello']
}
getPropertyByPathString(obj, 'a[0]') // hello

Returns Object Specific object property

setPropertyByPathString

Set specific property by path string. Path string parsed by eval().

Parameters

  • obj Object Target object
  • path stirng Path string
  • value Object The value will be assigned

Examples

let obj = {
  a: ['hello']
}
setPropertyByPathString(obj, 'a[1]', 'world')
obj.a // ['hello', 'world']

Returns boolean Return true when no exception

removePropertyByPathString

Remove specific object property by path string. Path string parsed by eval().

Parameters

Examples

let obj = {
  a: ['hello']
}
removePropertyByPathString(obj, 'a[0]')
obj.a // []

Returns boolean Always return true