Skip to content

wmerfalen/xtract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages