1.0.3 • Published 3 years ago

@mentoc/xtract v1.0.3

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
3 years ago

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

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago