CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash--baseisequal

Deep equality comparison utility function for comprehensive value equality checking in JavaScript

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

lodash._baseisequal

lodash._baseisequal provides the internal baseIsEqual function from the lodash utility library as a standalone module for deep equality comparisons between JavaScript values. It implements a sophisticated equality algorithm that handles primitives, objects, arrays, dates, regular expressions, typed arrays, and other complex data types with proper circular reference detection and type-specific comparison logic.

Package Information

  • Package Name: lodash._baseisequal
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash._baseisequal

Core Imports

var baseIsEqual = require('lodash._baseisequal');

Basic Usage

var baseIsEqual = require('lodash._baseisequal');

// Basic equality comparisons
baseIsEqual('hello', 'hello'); // true
baseIsEqual(123, 123); // true
baseIsEqual(true, true); // true

// Deep object comparison
baseIsEqual({a: 1, b: 2}, {a: 1, b: 2}); // true
baseIsEqual({a: 1, b: 2}, {a: 1, b: 3}); // false

// Array comparison
baseIsEqual([1, 2, 3], [1, 2, 3]); // true
baseIsEqual([1, 2, 3], [1, 2, 4]); // false

// Complex nested structures
var obj1 = {
  user: {
    name: 'Alice',
    settings: {
      theme: 'dark',
      notifications: true
    },
    tags: ['admin', 'user']
  }
};

var obj2 = {
  user: {
    name: 'Alice', 
    settings: {
      theme: 'dark',
      notifications: true
    },
    tags: ['admin', 'user']
  }
};

baseIsEqual(obj1, obj2); // true

Capabilities

Deep Equality Comparison

Performs comprehensive deep equality comparison between two values, handling all JavaScript data types with proper circular reference detection.

/**
 * The base implementation of _.isEqual without support for `this` binding
 * `customizer` functions.
 * 
 * @param {*} value - The value to compare
 * @param {*} other - The other value to compare  
 * @param {Function} [customizer] - The function to customize comparing values
 * @param {boolean} [isLoose] - Specify performing partial comparisons
 * @param {Array} [stackA] - Tracks traversed value objects
 * @param {Array} [stackB] - Tracks traversed other objects
 * @returns {boolean} Returns true if the values are equivalent, else false
 */
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB);

Supported Data Types:

  • Primitives: Strings, numbers, booleans, null, undefined
  • Objects: Plain objects with constructor checking and property comparison
  • Arrays: Regular and sparse arrays with element-by-element comparison
  • Dates: Timestamp-based comparison
  • Regular Expressions: Source pattern and flags comparison
  • Error Objects: Name and message comparison
  • Typed Arrays: Element-wise comparison for typed array types
  • Arguments Objects: Treated as regular objects for comparison
  • Functions: Identity comparison (===)

Special Features:

  • Circular Reference Detection: Safely handles objects with circular references
  • NaN Handling: Treats NaN === NaN as true (unlike native ===)
  • Negative Zero: Distinguishes between +0 and -0 when appropriate
  • Constructor Checking: Validates object constructors for non-Object instances
  • Partial Comparison: Optional loose mode for partial matching

Usage Examples:

var baseIsEqual = require('lodash._baseisequal');

// Handle circular references safely
var obj1 = {name: 'test'};
obj1.self = obj1;
var obj2 = {name: 'test'};
obj2.self = obj2;
baseIsEqual(obj1, obj2); // true

// Date comparison
baseIsEqual(new Date('2023-01-01'), new Date('2023-01-01')); // true
baseIsEqual(new Date('2023-01-01'), new Date('2023-01-02')); // false

// RegExp comparison
baseIsEqual(/hello/gi, /hello/gi); // true
baseIsEqual(/hello/gi, /hello/g); // false

// Error objects
var err1 = new Error('test message');
var err2 = new Error('test message');
baseIsEqual(err1, err2); // true

// Typed arrays
baseIsEqual(new Int32Array([1, 2, 3]), new Int32Array([1, 2, 3])); // true

// NaN handling (different from native ===)
baseIsEqual(NaN, NaN); // true
baseIsEqual(0, -0); // true

Custom Comparison Logic

When provided with a customizer function, allows for specialized equality logic while maintaining the robust foundation of the base comparison algorithm.

/**
 * Custom comparison example with customizer function
 * @param {*} value - First value to compare
 * @param {*} other - Second value to compare  
 * @param {Function} customizer - Function that returns comparison result or undefined to defer to default logic
 * @returns {boolean} Comparison result
 */
baseIsEqual(value, other, customizer);

Usage Example:

// Custom comparison that ignores case for string values
function customizer(objValue, othValue) {
  if (typeof objValue === 'string' && typeof othValue === 'string') {
    return objValue.toLowerCase() === othValue.toLowerCase();
  }
  // Return undefined to defer to default comparison logic
  return undefined;
}

baseIsEqual('Hello', 'hello', customizer); // true
baseIsEqual({msg: 'Hello'}, {msg: 'hello'}, customizer); // true

Partial Comparison Mode

Supports partial comparison mode via the isLoose parameter for scenarios where partial matching is required.

/**
 * Partial comparison example
 * @param {*} value - Value to compare
 * @param {*} other - Other value to compare
 * @param {Function} [customizer] - Optional customizer function
 * @param {boolean} isLoose - Enable partial comparison mode
 * @returns {boolean} Comparison result allowing partial matches
 */
baseIsEqual(value, other, customizer, isLoose);

Usage Example:

// Partial array comparison (subset matching)
baseIsEqual([1, 2], [1, 2, 3], null, true); // true (partial match)
baseIsEqual([1, 2], [1, 2, 3], null, false); // false (exact match required)

Dependencies

This package depends on three other lodash utilities:

  • lodash.isarray: Array type checking functionality
  • lodash.istypedarray: Typed array detection and validation
  • lodash.keys: Object property enumeration

These dependencies are automatically installed and do not require separate imports.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash._baseisequal@3.0.x
Publish Source
CLI
Badge
tessl/npm-lodash--baseisequal badge