xyjax-field-obtainerdeprecated

Obtain object field by path passed as string

Usage no npm install needed!

<script type="module">
  import xyjaxFieldObtainer from 'https://cdn.skypack.dev/xyjax-field-obtainer';
</script>

README

npm npm bundle size npm NPM

About

xyjax-field-obtainer is the standalone and lightweight package which provides obtaining object fields by its' string paths in object at any nested level. This package was originally developed for Xyjax NPM package.

Methods

There is one method you can import:

1. obtainField(target, pathToField)

Returns object field by its' string path.

Arguments description:

  • target is the source object
  • pathToField is the string containing path to target field with dot as delimiter ('a.b.c')

Usage example

Click here to take a look at RunKit + NPM embed example.

import { obtainField } from 'xyjax-field-obtainer'

var target = {a: {b: 2}, c: 5}
var a_field = obtainField(target, 'a') // {b: 2}
var a_b_field = obtainField(target, 'a.b') // 2
var c_field = obtainField(target, 'c') // 5
var not_existing_field = obtainField(target, 'd') //undefined
var not_existing_nested_field = obtainField(target, 'd.e.f') //undefined