equatable
NOTE:
equatable
has been deprecated in favor of@esfx/equatable
,@esfx/equatable-shim
, and@esfx/collections
. Please update your references.
The equatable
package provides a low level API for defining equality.
Installation
npm i equatable
Usage
Basic Usage
; ;people.sortComparer.defaultComparer.compare;console.logpeople; // Bob Clark,Alice Johnson ;;obj1 === obj2; // falseEqualer.defaultEqualer.equalsobj1, obj2; // true
Collections
This package includes a module of collection types in equatable/collections
that can leverage these low level APIs:
HashSet/HashMap
; // NOTE: see definition of Person above;; ; // native ECMAScript Setset.addobj1;set.addobj2;set.length; // 2 ;hashSet.addobj1;hashSet.addobj2;hashSet.length; // 1
SortedSet/SortedMap
; // NOTE: see definition of Person above;; // ECMAScript native set iterates in insertion order; // native ECMAScript Setset.addobj1;set.addobj2;; // Alice Johnson,Bob Clark // SortedSet uses Comparable.compareTo if available;sortedSet.addobj1;sortedSet.addobj2;; // Bob Clark,Alice Johnson
Global Shim
The global shim adds a default implementation of Equatable
to Object.prototype
and default implementations of
Comparable
to String.prototype
, Number.prototype
, Boolean.prototype
, and BigInt.prototype
.
To install the global shim, import equatable/global
:
; // triggers global-scope side effects; 123 // 123