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

has-required-props

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-required-props

Assert that your object props have non-undefined values for each required prop

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

has-required-props

Assert that your object props have non-undefined values for each required prop

Build Status npm version JavaScript Style Guide

Install

$ npm install --save has-required-props

Not using Node or a module bundler? Use a UMD build via the <script> tag.

Usage

import hasRequiredProps from 'has-required-props'

let props = { prop1: 'a', prop2: 'b' }
let requiredProps = ['prop1', 'prop2']
hasRequiredProps(requiredProps, props)  // true
hasRequiredProps(requiredProps, [props, props])  // true

requiredProps = ['prop1', 'prop2', 'prop3']
hasRequiredProps(requiredProps, props)  // false

// go crazy
props = {
  a: {
    b: 1,
    c: {
      d: 2
    }
  },
  e: 3,
  f: [
    3,
    {
      g: 1,
      h: {}
    }
  ]
}
requiredProps = ['a.b', 'a.c.d', 'e', 'f.0', 'f.1.g', 'f.1.h']
hasRequiredProps(requiredProps, props)  // true

// keep it simple
props = { a: 1, b: 2 }
requiredProps = 'a'
hasRequiredProps(requiredProps, props)  // true
props.a = undefined
hasRequiredProps(requiredProps, props)  // false
props.a = null
hasRequiredProps(requiredProps, props)  // true

// curry on
const curry = require('lodash/curry')
const duckCharacteristics = ['bill', 'plumage', 'webbedFeet']
const quacksLikeADuck = curry(hasRequiredProps(duckCharacteristics))
quacksLikeADuck({ bill: {}, plumage: {}, webbedFeet: {} }) // true
quacksLikeADuck({ bill: {}, plumage: {} }) // false

Keywords

FAQs

Package last updated on 25 Jul 2016

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