🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@del-wang/equals

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

@del-wang/equals

đźź° Deep and shallow equal comparison for JavaScript

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

@del-wang/equals

đźź° Deep and shallow equal comparison for JavaScript

Installation

npm install -D @del-wang/equals

Usage

import { shallowEqual, deepEqual } from "@del-wang/equals";

// Shallow comparison - only first level
const obj1 = { a: 1, b: { x: 2 } };
const obj2 = { a: 1, b: { x: 2 } };
console.log(shallowEqual(obj1, obj2)); // false (different object references)

const sharedRef = { x: 2 };
const obj3 = { a: 1, b: sharedRef };
const obj4 = { a: 1, b: sharedRef };
console.log(shallowEqual(obj3, obj4)); // true (same reference)

// Deep comparison - all levels
console.log(deepEqual(obj1, obj2)); // true (deep equality)

React Integration

The shallowEqual function is identical to React's internal implementation, perfect for optimizing React components:

import { shallowEqual } from "@del-wang/equals";
import { useEffect, useRef } from "react";

function useCustomHook(props: object) {
  const prevProps = useRef(props);

  useEffect(() => {
    if (!shallowEqual(prevProps.current, props)) {
      // Only execute when props actually change
      prevProps.current = props;
    }
  });
}

Performance

  • shallowEqual: O(n) - first-level properties only
  • deepEqual: O(m) - all nested properties

It's recommended to use shallowEqual in most React scenarios unless deep comparison is specifically needed.

License

MIT License © 2025-PRESENT Del Wang

Keywords

equals

FAQs

Package last updated on 28 Jan 2026

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