Socket
Socket
Sign inDemoInstall

@mentoc/xtract

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mentoc/xtract

Extract values out of deep structures using a safe and simple extraction language.


Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 11 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc