@darkwolf/keypath

1.1.1 • Public • Published

KeyPath

Install

npm i --save @darkwolf/keypath

Usage

// ECMAScript
import KeyPath from '@darkwolf/keypath'
// CommonJS
const KeyPath = require('@darkwolf/keypath')

`${new KeyPath('ave.darkwolf.matrix[0][0][0]')}` // => 'ave.darkwolf.matrix[0][0][0]'
`${new KeyPath('ave.darkwolf', 'matrix[0][0][0]')}` // => 'ave.darkwolf.matrix[0][0][0]'
`${new KeyPath(['ave', 'darkwolf'], `['matrix']`, [0, 0, 0])}` // => 'ave.darkwolf.matrix[0][0][0]'

const object = {
  ave: {
    darkwolf: null
  },
  data: [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
}
KeyPath.exists(object, 'ave.darkwolf') // => false
KeyPath.set(object, ['ave', 'darkwolf'], 'Ave, Darkwolf!') // => true
KeyPath.get(object, `ave['darkwolf']`) // => 'Ave, Darkwolf!'
KeyPath.delete(object, new KeyPath('ave', 'darkwolf')) // => true
KeyPath.has(object, new KeyPath('ave.darkwolf')) // => false
KeyPath.get(object, 'data[0]') // => 2
KeyPath.get(object, 'data.1') // => 4
KeyPath.get(object, ['data', 2]) // => 8

const matrix = []
KeyPath.set(matrix, '[0][0][0]', Infinity) // => true
KeyPath.get(matrix, [0, 0, 0]) // => Infinity

API Documentation

Contact Me

GitHub: @PavelWolfDark

Telegram: @PavelWolfDark

Email: PavelWolfDark@gmail.com

Package Sidebar

Install

npm i @darkwolf/keypath

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

19.6 kB

Total Files

6

Last publish

Collaborators

  • pavelwolfdark