has-required-props
Assert that your object props have non-undefined values for each required prop
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)
hasRequiredProps(requiredProps, [props, props])
requiredProps = ['prop1', 'prop2', 'prop3']
hasRequiredProps(requiredProps, props)
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)
props = { a: 1, b: 2 }
requiredProps = 'a'
hasRequiredProps(requiredProps, props)
props.a = undefined
hasRequiredProps(requiredProps, props)
props.a = null
hasRequiredProps(requiredProps, props)
const curry = require('lodash/curry')
const duckCharacteristics = ['bill', 'plumage', 'webbedFeet']
const quacksLikeADuck = curry(hasRequiredProps(duckCharacteristics))
quacksLikeADuck({ bill: {}, plumage: {}, webbedFeet: {} })
quacksLikeADuck({ bill: {}, plumage: {} })