Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/AttributeMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cloneDeep = require('lodash.clonedeep');
import isEqual = require('lodash.isequal');
import { isEqual } from './utils/isEqual';

interface AttributeMap {
[key: string]: unknown;
Expand Down
2 changes: 1 addition & 1 deletion src/Delta.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
33 changes: 33 additions & 0 deletions src/utils/isEqual.ts
Original file line number Diff line number Diff line change
@@ -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;
}