Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extract-dat

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-dat

Runs an extractor function against a value in order to pull out some other value. If the extractor function fails to pull the data out for any reason, `extract-dat` will suppress any errors and simply return the default value. Because SOMETIMES... you jus

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Extract Dat!

Runs an extractor function against a value in order to pull out some other value. If the extractor function fails to pull the data out for any reason, extract-dat will suppress any errors and simply return the default value. Because SOMETIMES... you just want a value without all the whining.

Getting Started

  • npm install --save extract-dat
  • import extract from "extract-dat";

Interface

extract(dataValue, extractorFn, [defaultValue=null])
// => value or defaultValue
ArgumentTypeDescription
dataValueAnyValue to be passed into extractorFn as the first parameter.
extractorFnFunctionFunction to extract a value from dataValue.
defaultValueAnyValue to be returned if extractorFn produces an error or returns undefined.

Example

import extract from "extract-dat";

const user = {
  phone: {type: 'home', number: '123-456-7890'},
  greet: 'Hello World',
  roles: ['editor', 'contributor']
};

const name = extract(user, x => x.name, 'Bob');
// => "Bob"

const greeting = extract(user, x => x.greet, 'HI!');
// => "Hello World"

const email = extract(user, x => x.email);
// => null

const isAdmin = extract(user, x => x.roles.includes('admin'), false);
// => false

const isEditor = extract(user, x => x.roles.includes('editor'), false);
// => true

const formattedPhone = extract(user, x => `${x.phone.number} (${x.phone.type})`, 'No Phone Number');
// => "123-456-7890 (home)"

Lib Dat!

extract-dat is part of lib-dat, a suite of tools that all...

  • Have ZERO dependencies.
  • Do one task well.
  • Make it easier to work with data.

Keywords

FAQs

Package last updated on 31 Jul 2020

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