123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- // src/helpers.ts
- function isOfType(type) {
- return (value) => typeof value === type;
- }
- var isFunction = isOfType("function");
- var isNull = (value) => {
- return value === null;
- };
- var isRegex = (value) => {
- return Object.prototype.toString.call(value).slice(8, -1) === "RegExp";
- };
- var isObject = (value) => {
- return !isUndefined(value) && !isNull(value) && (isFunction(value) || typeof value === "object");
- };
- var isUndefined = isOfType("undefined");
- // src/index.ts
- function equalArray(left, right) {
- const { length } = left;
- if (length !== right.length) {
- return false;
- }
- for (let index = length; index-- !== 0; ) {
- if (!equal(left[index], right[index])) {
- return false;
- }
- }
- return true;
- }
- function equalArrayBuffer(left, right) {
- if (left.byteLength !== right.byteLength) {
- return false;
- }
- const view1 = new DataView(left.buffer);
- const view2 = new DataView(right.buffer);
- let index = left.byteLength;
- while (index--) {
- if (view1.getUint8(index) !== view2.getUint8(index)) {
- return false;
- }
- }
- return true;
- }
- function equalMap(left, right) {
- if (left.size !== right.size) {
- return false;
- }
- for (const index of left.entries()) {
- if (!right.has(index[0])) {
- return false;
- }
- }
- for (const index of left.entries()) {
- if (!equal(index[1], right.get(index[0]))) {
- return false;
- }
- }
- return true;
- }
- function equalSet(left, right) {
- if (left.size !== right.size) {
- return false;
- }
- for (const index of left.entries()) {
- if (!right.has(index[0])) {
- return false;
- }
- }
- return true;
- }
- function equal(left, right) {
- if (left === right) {
- return true;
- }
- if (left && isObject(left) && right && isObject(right)) {
- if (left.constructor !== right.constructor) {
- return false;
- }
- if (Array.isArray(left) && Array.isArray(right)) {
- return equalArray(left, right);
- }
- if (left instanceof Map && right instanceof Map) {
- return equalMap(left, right);
- }
- if (left instanceof Set && right instanceof Set) {
- return equalSet(left, right);
- }
- if (ArrayBuffer.isView(left) && ArrayBuffer.isView(right)) {
- return equalArrayBuffer(left, right);
- }
- if (isRegex(left) && isRegex(right)) {
- return left.source === right.source && left.flags === right.flags;
- }
- if (left.valueOf !== Object.prototype.valueOf) {
- return left.valueOf() === right.valueOf();
- }
- if (left.toString !== Object.prototype.toString) {
- return left.toString() === right.toString();
- }
- const leftKeys = Object.keys(left);
- const rightKeys = Object.keys(right);
- if (leftKeys.length !== rightKeys.length) {
- return false;
- }
- for (let index = leftKeys.length; index-- !== 0; ) {
- if (!Object.prototype.hasOwnProperty.call(right, leftKeys[index])) {
- return false;
- }
- }
- for (let index = leftKeys.length; index-- !== 0; ) {
- const key = leftKeys[index];
- if (key === "_owner" && left.$$typeof) {
- continue;
- }
- if (!equal(left[key], right[key])) {
- return false;
- }
- }
- return true;
- }
- if (Number.isNaN(left) && Number.isNaN(right)) {
- return true;
- }
- return left === right;
- }
- export {
- equal as default
- };
- //# sourceMappingURL=index.mjs.map
|