Skip to content
/ getn Public

Helper for get a value from an object by its path, support dot paths

Notifications You must be signed in to change notification settings

allex/getn

Repository files navigation

getn

Helper for get a value from an object by its path, support dot paths

Installation

yarn add getn -D

Usage

import { getv, parseNs } from 'getn'

const o = {
  a: {
    c: {
      n: 'a.c.n',
      d: {
        n: 'a.c.d.n'
      }
    },
    'c.d': {
      f: 4,
      'k.n': 5,
      'o.b': {
        k1: '6'
      }
    }
  }
}

const path = 'a.c.d.o.b.k1'
const model = parseNs(o, path.split('.'))

console.log(model) // { o: o.a['c.d']['o.b'], k: 'k1', v: 6, n: 0 }
console.log(getv(o, 'a.c.d.n')) // 'a.c.d.n'
console.log(getv(o, 'a.c.d.o.b.k1')) // 6

License

MIT Copyright (c) Allex Wang

About

Helper for get a value from an object by its path, support dot paths

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published