/object-deep-contain

Test object fully contained in other object

Primary LanguageJavaScriptMIT LicenseMIT

object-deep-contain

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

Test Object deep contained in other object.

Install

Install with npm:

$ npm install --save object-deep-contain

Usage

const deepContain = require('object-deep-contain');

deepContain({ a: [1, 2], b: 'c' }, { a: [1, 2] });
// => true

deepContain({ a: [1, 2], b: 'c' }, { a: [1] });
// => false

Considerations

Lists are only "contained" if they are the same length and every element is contained in the corresponding element.

Non List object types are "contained" all keys in the needle exist in the haystack and their values are contained.

All other object types are "contained" if thye match exactly (===).