Files
url_tracker_tool/node_modules/fast-equals/recipes/non-standard-properties.md
Andrei 58f8093689 Rebrand from 'Redirect Intelligence v2' to 'URL Tracker Tool V2' throughout UI
- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
2025-08-19 19:12:23 +00:00

1.2 KiB

Non-standard properties

Sometimes, objects require a comparison that extend beyond its own keys, or even its own properties or symbols. Using a custom object comparator with createCustomEqual allows these kinds of comparisons.

import { createCustomEqual } from 'fast-equals';
import type { TypeEqualityComparator } from 'fast-equals';

type AreObjectsEqual = TypeEqualityComparator<Record<any, any>, undefined>;

class HiddenProperty {
  visible: boolean;
  #hidden: string;

  constructor(value: string) {
    this.visible = true;
    this.#hidden = value;
  }

  get hidden() {
    return this.#hidden;
  }
}

function createAreObjectsEqual(
  areObjectsEqual: AreObjectsEqual,
): AreObjectsEqual {
  return function (a, b, state) {
    if (!areObjectsEqual(a, b, state)) {
      return false;
    }

    const aInstance = a instanceof HiddenProperty;
    const bInstance = b instanceof HiddenProperty;

    if (aInstance || bInstance) {
      return aInstance && bInstance && a.hidden === b.hidden;
    }

    return true;
  };
}

const deepEqual = createCustomEqual({
  createCustomConfig: ({ areObjectsEqual }) =>
    createAreObjectsEqual(areObjectsEqual),
});