Socket
Socket
Sign inDemoInstall

shallowequal

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    shallowequal

Like lodash isEqualWith but for shallow equal.


Version published
Weekly downloads
7.3M
decreased by-1.24%
Maintainers
1
Install size
8.18 kB
Created
Weekly downloads
 

Package description

What is shallowequal?

The shallowequal npm package is a simple utility for performing shallow equality checks on objects or values. It is primarily used to compare the values of two objects to determine if they are equivalent in terms of their direct properties, without deeply traversing any nested objects. This can be particularly useful in optimizations where a deep equality check is unnecessary or too costly in terms of performance.

What are shallowequal's main functionalities?

Shallow Equality Check for Objects

This feature allows you to compare two objects to see if they have the same top-level properties with the same values, without checking for deep equality.

const shallowequal = require('shallowequal');
const obj1 = { a: 1, b: 2 };
const obj2 = { a: 1, b: 2 };
const areEqual = shallowequal(obj1, obj2); // true

Shallow Equality Check with Custom Comparer

This feature allows you to perform a shallow equality check between two objects, but with a custom comparison function for the values, enabling more flexible comparisons.

const shallowequal = require('shallowequal');
const obj1 = { a: 1, b: '2' };
const obj2 = { a: 1, b: 2 };
const areEqual = shallowequal(obj1, obj2, (val1, val2) => String(val1) === String(val2)); // true

Other packages similar to shallowequal

Readme

Source

shallowequal Build Status Downloads npm version

Greenkeeper badge

shallowequal is like lodash's isEqualWith but for shallow (strict) equal.

shallowequal(value, other, [customizer], [thisArg])

Performs a shallow equality comparison between two values (i.e. value and other) to determine if they are equivalent.

The equality is performed by iterating through keys on the given value, and returning false whenever any key has values which are not strictly equal between value and other. Otherwise, return true whenever the values of all keys are strictly equal.

If customizer (expected to be a function) is provided it is invoked to compare values. If customizer returns undefined (i.e. void 0), then comparisons are handled by the shallowequal function instead.

The customizer is bound to thisArg and invoked with three arguments: (value, other, key).

NOTE: Docs are (shamelessly) adapted from lodash's v3.x docs

Install

$ yarn add shallowequal
# npm v5+
$ npm install shallowequal
# before npm v5
$ npm install --save shallowequal

Usage

const shallowequal = require('shallowequal');

const object = { 'user': 'fred' };
const other = { 'user': 'fred' };

object == other;
// → false

shallowequal(object, other);
// → true

Credit

Code for shallowEqual originated from https://github.com/gaearon/react-pure-render/ and has since been refactored to have the exact same API as lodash.isEqualWith (as of v4.17.4).

Development

Chores

  • Lint: yarn lint
  • Test: yarn test
  • Pretty: yarn pretty
  • Pre-publish: yarn prepublish

License

MIT.

Keywords

FAQs

Last updated on 23 Jun 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc