@mentoc/xtract

1.0.3 • Public • Published

xtract

Using a simple syntax, it's possible to fetch a value that is deep within a known structure hierarchy.

Installation

npm install @mentoc/xtract

Usage

const { xt } = require('@mentoc/xtract')
let grocery_list = {
	products: [
		{
			id: 1,
			name: 'apples'
		},
		{
			id: 2,
			name: 'juice'
		},
		{
			id: 3,
			name: 'pears'
		}
	],
	budget: 150.00
}

// To grab the first product's name:
let apples = xt(grocery_list,'products.0.name')

// To grab the entire products array:
let products = xt(grocery_list,'products')

// Grab the budget
let budget = xt(grocery_list,'budget')

What happens if the key is missing?

We simply return null if you attempt to grab something that isn't there.

Version

1.0.2

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @mentoc/xtract

      Weekly Downloads

      1

      Version

      1.0.3

      License

      GPL-3.0-or-later

      Unpacked Size

      2.76 kB

      Total Files

      4

      Last publish

      Collaborators

      • mtndew