From ea151f5b43600a4c426402cd5f350776186c1321 Mon Sep 17 00:00:00 2001 From: Ruslan Farkhutdinov Date: Wed, 28 May 2025 13:57:29 +0300 Subject: [PATCH] chore: replace lodash.isequal with internal isEqual utility --- package-lock.json | 32 +------------------------------- package.json | 4 +--- src/AttributeMap.ts | 2 +- src/Delta.ts | 2 +- src/utils/isEqual.ts | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 src/utils/isEqual.ts diff --git a/package-lock.json b/package-lock.json index edd2fbe..8cb9df7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,11 @@ "license": "MIT", "dependencies": { "fast-diff": "^1.3.0", - "lodash.clonedeep": "^4.5.0", - "lodash.isequal": "^4.5.0" + "lodash.clonedeep": "^4.5.0" }, "devDependencies": { "@types/jasmine": "^3.10.3", "@types/lodash.clonedeep": "^4.5.6", - "@types/lodash.isequal": "^4.5.5", "@types/node": "^17.0.21", "@typescript-eslint/eslint-plugin": "^5.14.0", "@typescript-eslint/parser": "^5.14.0", @@ -661,15 +659,6 @@ "@types/lodash": "*" } }, - "node_modules/@types/lodash.isequal": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.5.tgz", - "integrity": "sha512-4IKbinG7MGP131wRfceK6W4E/Qt3qssEFLF30LnJbjYiSfHGGRU/Io8YxXrZX109ir+iDETC8hw8QsDijukUVg==", - "dev": true, - "dependencies": { - "@types/lodash": "*" - } - }, "node_modules/@types/node": { "version": "17.0.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", @@ -2238,11 +2227,6 @@ "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", "dev": true }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -3725,15 +3709,6 @@ "@types/lodash": "*" } }, - "@types/lodash.isequal": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.5.tgz", - "integrity": "sha512-4IKbinG7MGP131wRfceK6W4E/Qt3qssEFLF30LnJbjYiSfHGGRU/Io8YxXrZX109ir+iDETC8hw8QsDijukUVg==", - "dev": true, - "requires": { - "@types/lodash": "*" - } - }, "@types/node": { "version": "17.0.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", @@ -4864,11 +4839,6 @@ "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", "dev": true }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/package.json b/package.json index eda68bf..dc82a33 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,11 @@ "main": "dist/Delta.js", "dependencies": { "fast-diff": "^1.3.0", - "lodash.clonedeep": "^4.5.0", - "lodash.isequal": "^4.5.0" + "lodash.clonedeep": "^4.5.0" }, "devDependencies": { "@types/jasmine": "^3.10.3", "@types/lodash.clonedeep": "^4.5.6", - "@types/lodash.isequal": "^4.5.5", "@types/node": "^17.0.21", "@typescript-eslint/eslint-plugin": "^5.14.0", "@typescript-eslint/parser": "^5.14.0", diff --git a/src/AttributeMap.ts b/src/AttributeMap.ts index c1b0d57..8a929bb 100644 --- a/src/AttributeMap.ts +++ b/src/AttributeMap.ts @@ -1,5 +1,5 @@ import cloneDeep = require('lodash.clonedeep'); -import isEqual = require('lodash.isequal'); +import { isEqual } from './utils/isEqual'; interface AttributeMap { [key: string]: unknown; diff --git a/src/Delta.ts b/src/Delta.ts index 56c7a7a..fb52841 100644 --- a/src/Delta.ts +++ b/src/Delta.ts @@ -1,9 +1,9 @@ import * as diff from 'fast-diff'; import cloneDeep = require('lodash.clonedeep'); -import isEqual = require('lodash.isequal'); import AttributeMap from './AttributeMap'; import Op from './Op'; import OpIterator from './OpIterator'; +import { isEqual } from './utils/isEqual'; const NULL_CHARACTER = String.fromCharCode(0); // Placeholder char for embed in diff() diff --git a/src/utils/isEqual.ts b/src/utils/isEqual.ts new file mode 100644 index 0000000..11f4d9a --- /dev/null +++ b/src/utils/isEqual.ts @@ -0,0 +1,33 @@ +export const isEqual = (a: any, b: any): boolean => { + if (a === b) return true; + + if (a == null || b == null || typeof a !== 'object' || typeof b !== 'object') { + return false; + } + + if (Array.isArray(a)) { + if (!Array.isArray(b)) return false; + if (a.length !== b.length) return false; + + for (let i = 0; i < a.length; i++) { + if (!isEqual(a[i], b[i])) return false; + } + + return true; + } + + if (Array.isArray(b)) return false; + + const aKeys = Object.keys(a); + const bKeys = Object.keys(b); + + if (aKeys.length !== bKeys.length) return false; + + for (const key of aKeys) { + if (!Object.prototype.hasOwnProperty.call(b, key)) return false; + if (!isEqual(a[key], b[key])) return false; + } + + return true; + } + \ No newline at end of file