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

chai-exclude

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-exclude - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

38

lib/chai-exclude.js

@@ -5,2 +5,18 @@ module.exports = (chai, utils) => {

/**
* Remove keys from an object or an array.
*
* @param {Object|Array} val object or array to remove keys
* @param {Array} props array of keys to remove
* @param {Boolean} recursive true if property needs to be removed recursively
* @returns {Object}
*/
function removeKeysFrom (val, props, recursive = false) {
if (isObject(val)) {
return removeKeysFromObject(val, props, recursive)
}
return removeKeysFromArray(val, props, recursive)
}
/**
* Remove keys from an object and return a new object.

@@ -54,5 +70,5 @@ *

if (isObject(array[i])) {
val = removeKeysFromObject(array[i], props, true)
val = removeKeysFromObject(array[i], props, recursive)
} else if (isArray(array[i])) {
val = removeKeysFromArray(array[i], props, true)
val = removeKeysFromArray(array[i], props, recursive)
} else {

@@ -96,8 +112,6 @@ val = array[i]

return function (val) {
if (utils.type(val).toLowerCase() === 'object') {
if (utils.flag(this, 'excluding')) {
val = removeKeysFromObject(val, utils.flag(this, 'excludingProps'))
} else if (utils.flag(this, 'excludingEvery')) {
val = removeKeysFromObject(val, utils.flag(this, 'excludingProps'), true)
}
if (utils.flag(this, 'excluding')) {
val = removeKeysFrom(val, utils.flag(this, 'excludingProps'))
} else if (utils.flag(this, 'excludingEvery')) {
val = removeKeysFrom(val, utils.flag(this, 'excludingProps'), true)
}

@@ -113,3 +127,3 @@

Assertion.addMethod('excluding', function (props) {
utils.expectTypes(this, ['object'])
utils.expectTypes(this, ['object', 'array'])

@@ -127,3 +141,3 @@ const obj = this._obj

this._obj = removeKeysFromObject(obj, props)
this._obj = removeKeysFrom(obj, props)

@@ -140,3 +154,3 @@ utils.flag(this, 'excluding', true)

Assertion.addMethod('excludingEvery', function (props) {
utils.expectTypes(this, ['object'])
utils.expectTypes(this, ['object', 'array'])

@@ -154,3 +168,3 @@ const obj = this._obj

this._obj = removeKeysFromObject(obj, props, true)
this._obj = removeKeysFrom(obj, props, true)

@@ -157,0 +171,0 @@ utils.flag(this, 'excludingEvery', true)

{
"name": "chai-exclude",
"version": "1.0.4",
"version": "1.0.5",
"description": "Exclude keys to compare from a deep equal operation with chai expect",

@@ -5,0 +5,0 @@ "main": "lib/chai-exclude.js",

@@ -6,2 +6,3 @@ # chai-exclude

[![Build Status](https://travis-ci.org/mesaugat/chai-exclude.svg?branch=master)](https://travis-ci.org/mesaugat/chai-exclude)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/18c8dd78120442688cb4b19f758c4b96)](https://www.codacy.com/app/mesaugat/chai-exclude?utm_source=github.com&utm_medium=referral&utm_content=mesaugat/chai-exclude&utm_campaign=badger)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

@@ -17,2 +18,4 @@

Works with both array of objects and objects.
## Installation

@@ -66,4 +69,9 @@

```js
// Object
expect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ b: 'b' })
expect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ a: 'z', b: 'b' })
// Array
expect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ b: 'b' }])
expect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ a: 'z', b: 'b' }])
```

@@ -83,4 +91,20 @@

// Object
expect(obj).excluding(['a', 'c']).to.deep.equal({ b: 'b' })
expect(obj).excluding(['a', 'c']).to.deep.equal({ a:'z', b: 'b' })
const array = [
{
a: 'a',
b: 'b',
c: {
d: 'd',
e: 'e'
}
}
]
// Array
expect(array).excluding(['a', 'c']).to.deep.equal([{ b: 'b' }])
expect(array).excluding(['a', 'c']).to.deep.equal([{ a: 'z', b: 'b' }])
```

@@ -93,3 +117,3 @@

```js
const actual = {
const actualObj = {
a: 'a',

@@ -111,3 +135,5 @@ b: 'b',

const expected = {
const actualArray = [actualObj]
const expectedObj = {
a: 'z', // a is excluded from comparison

@@ -126,3 +152,9 @@ b: 'b',

expect(actual).excludingEvery('a').to.deep.equal(expected)
const expectedObj = [expectedObj]
// Object
expect(actualObj).excludingEvery('a').to.deep.equal(expectedObj)
// Array
expect(actualArray).excludingEvery('a').to.deep.equal(expectedArray)
```

@@ -133,3 +165,3 @@

```js
const actual = {
const actualObj = {
a: 'a',

@@ -151,3 +183,5 @@ b: 'b',

const expected = {
const actualArray = [actualObj]
const expectedObj = {
b: 'b',

@@ -158,4 +192,11 @@ c: {

}
}
expect(actual).excludingEvery(['a', 'd']).to.deep.equal(expected)
const expectedArray = [expectedObj]
// Object
expect(actualObj).excludingEvery(['a', 'd']).to.deep.equal(expectedObj)
// Array
expect(actualArray).excludingEvery(['a', 'd']).to.deep.equal(expectedArray)
```

@@ -162,0 +203,0 @@

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