ngx-deep-equals-pure 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,320 +1,321 @@
1
- # NgxDeepEqualsPure
2
-
3
- Note:
4
- - Please use version 0.2.5 for projects using Angular 11.0 and below.
5
- - Please use version 0.3.0+ for Angular 12.0+ projects.
6
- - Version 0.4.0+ supports use in Web Workers (see example project in this repository).
7
- - Version 0.4.2 is malformed and should not be used.
8
- - Version 0.4.3+ supports Standalone Components.
9
- - Version 0.5.0 supports Angular 16.
10
- - Version 1.0.0 supports Angular 17.
11
-
12
- This is a package intended to provide a deep equals function for JavaScript objects without requiring numerous dependencies. Other packages which provide a deep equals function, like Lodash or deep-equal, require a large number of dependencies or they are themselves very large. This contributes to unnecessary bloat and, ultimately, poor application load performance.
13
-
14
- Unlike deep-equal and Lodash, ngx-deep-equals-pure can correctly handle function properties. Furthermore, ngx-deep-equals-pure properly determines equality for arrays of complex objects when the order of the data differs where deep-equal and Lodash fail to do so.
15
-
16
- Repository:
17
- https://github.com/puckowski/deepequalspure
18
-
19
- Bugs:
20
- https://github.com/puckowski/deepequalspure/issues
21
-
22
- ## Size
23
-
24
- The minified ES2015 size of ngx-deep-equals-pure is 9.18KB which includes ESM5, ESM2015, FESM5, and FESM2015 bundles.
25
-
26
- |ngx-deep-equals-pure |deep-equal |Lodash |
27
- |---------------------|-----------|-------|
28
- |9.18KB |3.44KB |528KB |
29
-
30
- ## npm Package
31
-
32
- https://www.npmjs.com/package/ngx-deep-equals-pure
33
-
34
- ## Usage
35
-
36
- In the appropriate module, such as ```AppModule```, add the following to ```providers```:
37
-
38
- ```javascript
39
- providers: [NgxDeepEqualsPureService],
40
- ```
41
-
42
- In a component part of a module where NgxDeepEqualsPureService is provided, inject the deep equals service in the constructor like so:
43
-
44
- ```javascript
45
- constructor(private ngxDeepEquals: NgxDeepEqualsPureService) {
46
- ```
47
-
48
- Then use NgxDeepEqualsPure like so:
49
-
50
- ```javascript
51
- this.ngxDeepEquals.deepEquals(this.obj1, this.obj2);
52
- ```
53
-
54
- Alternatively, construct a standalone component like the following:
55
-
56
- ```javascript
57
- import { Component } from '@angular/core';
58
- import { NgxDeepEqualsPureModule, NgxDeepEqualsPureService } from 'NgxDeepEqualsPure';
59
-
60
- @Component({
61
- selector: 'app-standalone-test',
62
- templateUrl: './standalone-test.component.html',
63
- styleUrls: ['./standalone-test.component.scss'],
64
- standalone: true,
65
- imports: [NgxDeepEqualsPureModule]
66
- })
67
- export class StandaloneTestComponent {
68
-
69
- private obj8: any = { b: 'a', c: 2 };
70
- private obj9: any = { c: 2, b: 'a' };
71
-
72
- public isStandaloneMatch: boolean;
73
-
74
- constructor(private ngxDeepEquals: NgxDeepEqualsPureService) {
75
- this.isStandaloneMatch = this.ngxDeepEquals.deepEquals(this.obj8, this.obj9);
76
- }
77
- }
78
- ```
79
-
80
- ## Performance
81
-
82
- The following is the latest performance result of 2,000 comparisons run in a web worker.
83
-
84
- |ngx-deep-equals-pure |deep-equal |Lodash isEqual |
85
- |---------------------|-----------|---------------|
86
- | 0.023 | 0.006 | 0.091 |
87
- | 0.007 | 0.008 | 0.107 |
88
- | 0.006 | 0.004 | 0.106 |
89
- | 0.006 | 0.001 | 0.115 |
90
- | 0.006 | 0.001 | 0.115 |
91
- | 0.006 | 0.001 | 0.117 |
92
- | 0.005 | 0.001 | 0.117 |
93
- | 0.006 | 0.001 | 0.12 |
94
- | 0.006 | 0.001 | 0.118 |
95
- | 0.006 | 0.001 | 0.117 |
96
- | 0.006 | 0.001 | 0.117 |
97
- | 0.006 | 0.001 | 0.116 |
98
- | 0.006 | 0.001 | 0.118 |
99
- | 0.006 | 0.001 | 0.118 |
100
- | 0.006 | 0.001 | 0.118 |
101
- | 0.005 | 0.001 | 0.118 |
102
- | 0.006 | 0.001 | 0.119 |
103
- | 0.006 | 0.001 | 0.118 |
104
- | 0.006 | 0 | 0.118 |
105
- | 0.006 | 0.002 | 0.117 |
106
- | **Avg: 0.0068s** | **Avg: 0.00175s** | **Avg: 0.1149s** |
107
-
108
- ## Tests
109
- ```javascript
110
- this.isMatch.push(this.deep.deepEquals(obj1, obj2));
111
- this.isMatch.push(this.deep.deepEquals(obj1, obj3));
112
- this.isMatch.push(this.deep.deepEquals(obj1, obj4));
113
- this.isMatch.push(this.deep.deepEquals(obj1, obj5));
114
- this.isMatch.push(this.deep.deepEquals(obj1, obj6));
115
- this.isMatch.push(this.deep.deepEquals(obj1, obj7));
116
- this.isMatch.push(this.deep.deepEquals(obj8, obj9));
117
-
118
- this.isMatchLodash.push(_.isEqual(obj1, obj2));
119
- this.isMatchLodash.push(_.isEqual(obj1, obj3));
120
- this.isMatchLodash.push(_.isEqual(obj1, obj4));
121
- this.isMatchLodash.push(_.isEqual(obj1, obj5));
122
- this.isMatchLodash.push(_.isEqual(obj1, obj6));
123
- this.isMatchLodash.push(_.isEqual(obj1, obj7));
124
- this.isMatchLodash.push(_.isEqual(obj8, obj9));
125
-
126
- this.isMatchDeepEqual.push(deepEqual(obj1, obj2));
127
- this.isMatchDeepEqual.push(deepEqual(obj1, obj3));
128
- this.isMatchDeepEqual.push(deepEqual(obj1, obj4));
129
- this.isMatchDeepEqual.push(deepEqual(obj1, obj5));
130
- this.isMatchDeepEqual.push(deepEqual(obj1, obj6));
131
- this.isMatchDeepEqual.push(deepEqual(obj1, obj7));
132
- this.isMatchDeepEqual.push(deepEqual(obj8, obj9));
133
- ```
134
-
135
- ## Results
136
- |#|Actual |ngx-deep-equals-pure |deep-equal |Lodash isEqual |
137
- |---|-------------|---------------------|-----------|---------------|
138
- |1 | true | true | false | false |
139
- |2 | false | false | false | false |
140
- |3 | false | false | false | false |
141
- |4 | false | false | false | false |
142
- |5 | false | false | false | false |
143
- |6 | true | true | false | false |
144
- |7 | true | true | true | true |
145
-
146
- ## Input objects
147
- ```javascript
148
- const obj1: any = {
149
- b: () => {
150
- console.log('foo');
151
- },
152
- e: 'abcbc',
153
- a: [
154
- { 'a': 12.7 },
155
- { 'c': 37.6 }
156
- ],
157
- c: 126.8,
158
- f: ['f', 'a'],
159
- g: [
160
- { t: () => { console.log('h'); }, g: 'a', j: 12 },
161
- ['b', 2, { p: '123' }],
162
- '789',
163
- 12.6,
164
- 809,
165
- () => { console.log('er'); }
166
- ]
167
- };
168
-
169
- const obj2: any = {
170
- g: [
171
- [{ p: '123' }, 2, 'b'],
172
- '789',
173
- 12.6,
174
- () => { console.log('er'); },
175
- { g: 'a', t: () => { console.log('h'); }, j: 12 },
176
- 809
177
- ],
178
- e: 'abcbc',
179
- b: () => {
180
- console.log('foo');
181
- },
182
- a: [
183
- { 'c': 37.6 },
184
- { 'a': 12.7 }
185
- ],
186
- f: ['f', 'a'],
187
- c: 126.8
188
- };
189
-
190
- const obj3: any = {
191
- g: [
192
- [{ p: '123' }, 2, 'b'],
193
- '789',
194
- 12.6,
195
- () => { console.log('er'); },
196
- { t: () => { console.log('h'); }, j: 12 },
197
- 809
198
- ],
199
- e: 'abcbc',
200
- b: () => {
201
- console.log('foo');
202
- },
203
- a: [
204
- { 'c': 37.6 },
205
- { 'a': 12.7 }
206
- ],
207
- f: ['f', 'a'],
208
- c: 126.8
209
- };
210
-
211
- const obj4: any = {
212
- g: [
213
- [{ p: '123' }, 2, 'b'],
214
- '789',
215
- 12.6,
216
- () => { console.log('er'); },
217
- { g: '6', t: () => { console.log('h'); }, j: 12 },
218
- 809
219
- ],
220
- e: 'abcbc',
221
- b: () => {
222
- console.log('foo');
223
- },
224
- a: [
225
- { 'c': 37.6 },
226
- { 'a': 12.7 }
227
- ],
228
- f: ['f', 'a'],
229
- c: 126.8
230
- };
231
-
232
- const obj5: any = {
233
- g: [
234
- [{ u: '123' }, 2, 'b'],
235
- '789',
236
- 12.6,
237
- () => { console.log('er'); },
238
- { g: 'a', t: () => { console.log('h'); }, j: 12 },
239
- 809
240
- ],
241
- e: 'abcbc',
242
- b: () => {
243
- console.log('foo');
244
- },
245
- a: [
246
- { 'c': 37.6 },
247
- { 'a': 12.7 }
248
- ],
249
- f: ['f', 'a'],
250
- c: 126.8
251
- };
252
-
253
- const obj6: any = {
254
- g: [
255
- [{ p: '123' }, 2, 'b'],
256
- '789',
257
- 12.6,
258
- () => { console.log('er'); },
259
- { g: 'a', y: () => { console.log('h'); }, j: 12 },
260
- 809
261
- ],
262
- e: 'abcbc',
263
- b: () => {
264
- console.log('foo');
265
- },
266
- a: [
267
- { 'c': 37.6 },
268
- { 'a': 12.7 }
269
- ],
270
- f: ['f', 'a'],
271
- c: 126.8
272
- };
273
-
274
- const obj7: any = {
275
- b: () => {
276
- console.log('foo');
277
- },
278
- e: 'abcbc',
279
- a: [
280
- { 'a': 12.7 },
281
- { 'c': 37.6 }
282
- ],
283
- c: 126.8,
284
- f: ['f', 'a'],
285
- g: [
286
- { t: () => { console.log('h'); }, g: 'a', j: 12 },
287
- ['b', 2, { p: '123' }],
288
- '789',
289
- 12.6,
290
- 809,
291
- () => { console.log('er'); }
292
- ]
293
- };
294
-
295
- const obj8: any = { b: 'a', c: 2 };
296
- const obj9: any = { c: 2, b: 'a' };
297
- ```
298
-
299
- ## Building library
300
-
301
- Use command:
302
-
303
- ```
304
- ng build NgxDeepEqualsPure --configuration production
305
- ```
306
-
307
- ## Running benchmark
308
-
309
- Use command:
310
-
311
- ```
312
- ng serve
313
- ```
314
-
315
- Then navigate to localhost:4200 in your preferred browser.
316
-
317
- Note:
318
- It may be necessary to run the build command before trying to run the benchmark.
319
-
320
- See the GitHub repository at https://github.com/puckowski/deepequalspure for example usage of ngx-deep-equals-pure in an Angular application and for example usage in a Web Worker.
1
+ # NgxDeepEqualsPure
2
+
3
+ Note:
4
+ - Please use version 0.2.5 for projects using Angular 11.0 and below.
5
+ - Please use version 0.3.0+ for Angular 12.0+ projects.
6
+ - Version 0.4.0+ supports use in Web Workers (see example project in this repository).
7
+ - Version 0.4.2 is malformed and should not be used.
8
+ - Version 0.4.3+ supports Standalone Components.
9
+ - Version 0.5.0 supports Angular 16.
10
+ - Version 1.0.0 supports Angular 17.
11
+ - Version 2.0.0 supports Angular 18.
12
+
13
+ This is a package intended to provide a deep equals function for JavaScript objects without requiring numerous dependencies. Other packages which provide a deep equals function, like Lodash or deep-equal, require a large number of dependencies or they are themselves very large. This contributes to unnecessary bloat and, ultimately, poor application load performance.
14
+
15
+ Unlike deep-equal and Lodash, ngx-deep-equals-pure can correctly handle function properties. Furthermore, ngx-deep-equals-pure properly determines equality for arrays of complex objects when the order of the data differs where deep-equal and Lodash fail to do so.
16
+
17
+ Repository:
18
+ https://github.com/puckowski/deepequalspure
19
+
20
+ Bugs:
21
+ https://github.com/puckowski/deepequalspure/issues
22
+
23
+ ## Size
24
+
25
+ The minified ES2015 size of ngx-deep-equals-pure is 9.18KB which includes ESM5, ESM2015, FESM5, and FESM2015 bundles.
26
+
27
+ |ngx-deep-equals-pure |deep-equal |Lodash |
28
+ |---------------------|-----------|-------|
29
+ |9.18KB |3.44KB |528KB |
30
+
31
+ ## npm Package
32
+
33
+ https://www.npmjs.com/package/ngx-deep-equals-pure
34
+
35
+ ## Usage
36
+
37
+ In the appropriate module, such as ```AppModule```, add the following to ```providers```:
38
+
39
+ ```javascript
40
+ providers: [NgxDeepEqualsPureService],
41
+ ```
42
+
43
+ In a component part of a module where NgxDeepEqualsPureService is provided, inject the deep equals service in the constructor like so:
44
+
45
+ ```javascript
46
+ constructor(private ngxDeepEquals: NgxDeepEqualsPureService) {
47
+ ```
48
+
49
+ Then use NgxDeepEqualsPure like so:
50
+
51
+ ```javascript
52
+ this.ngxDeepEquals.deepEquals(this.obj1, this.obj2);
53
+ ```
54
+
55
+ Alternatively, construct a standalone component like the following:
56
+
57
+ ```javascript
58
+ import { Component } from '@angular/core';
59
+ import { NgxDeepEqualsPureModule, NgxDeepEqualsPureService } from 'NgxDeepEqualsPure';
60
+
61
+ @Component({
62
+ selector: 'app-standalone-test',
63
+ templateUrl: './standalone-test.component.html',
64
+ styleUrls: ['./standalone-test.component.scss'],
65
+ standalone: true,
66
+ imports: [NgxDeepEqualsPureModule]
67
+ })
68
+ export class StandaloneTestComponent {
69
+
70
+ private obj8: any = { b: 'a', c: 2 };
71
+ private obj9: any = { c: 2, b: 'a' };
72
+
73
+ public isStandaloneMatch: boolean;
74
+
75
+ constructor(private ngxDeepEquals: NgxDeepEqualsPureService) {
76
+ this.isStandaloneMatch = this.ngxDeepEquals.deepEquals(this.obj8, this.obj9);
77
+ }
78
+ }
79
+ ```
80
+
81
+ ## Performance
82
+
83
+ The following is the latest performance result of 2,000 comparisons run in a web worker.
84
+
85
+ |ngx-deep-equals-pure |deep-equal |Lodash isEqual |
86
+ |---------------------|-----------|---------------|
87
+ | 0.023 | 0.006 | 0.091 |
88
+ | 0.007 | 0.008 | 0.107 |
89
+ | 0.006 | 0.004 | 0.106 |
90
+ | 0.006 | 0.001 | 0.115 |
91
+ | 0.006 | 0.001 | 0.115 |
92
+ | 0.006 | 0.001 | 0.117 |
93
+ | 0.005 | 0.001 | 0.117 |
94
+ | 0.006 | 0.001 | 0.12 |
95
+ | 0.006 | 0.001 | 0.118 |
96
+ | 0.006 | 0.001 | 0.117 |
97
+ | 0.006 | 0.001 | 0.117 |
98
+ | 0.006 | 0.001 | 0.116 |
99
+ | 0.006 | 0.001 | 0.118 |
100
+ | 0.006 | 0.001 | 0.118 |
101
+ | 0.006 | 0.001 | 0.118 |
102
+ | 0.005 | 0.001 | 0.118 |
103
+ | 0.006 | 0.001 | 0.119 |
104
+ | 0.006 | 0.001 | 0.118 |
105
+ | 0.006 | 0 | 0.118 |
106
+ | 0.006 | 0.002 | 0.117 |
107
+ | **Avg: 0.0068s** | **Avg: 0.00175s** | **Avg: 0.1149s** |
108
+
109
+ ## Tests
110
+ ```javascript
111
+ this.isMatch.push(this.deep.deepEquals(obj1, obj2));
112
+ this.isMatch.push(this.deep.deepEquals(obj1, obj3));
113
+ this.isMatch.push(this.deep.deepEquals(obj1, obj4));
114
+ this.isMatch.push(this.deep.deepEquals(obj1, obj5));
115
+ this.isMatch.push(this.deep.deepEquals(obj1, obj6));
116
+ this.isMatch.push(this.deep.deepEquals(obj1, obj7));
117
+ this.isMatch.push(this.deep.deepEquals(obj8, obj9));
118
+
119
+ this.isMatchLodash.push(_.isEqual(obj1, obj2));
120
+ this.isMatchLodash.push(_.isEqual(obj1, obj3));
121
+ this.isMatchLodash.push(_.isEqual(obj1, obj4));
122
+ this.isMatchLodash.push(_.isEqual(obj1, obj5));
123
+ this.isMatchLodash.push(_.isEqual(obj1, obj6));
124
+ this.isMatchLodash.push(_.isEqual(obj1, obj7));
125
+ this.isMatchLodash.push(_.isEqual(obj8, obj9));
126
+
127
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj2));
128
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj3));
129
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj4));
130
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj5));
131
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj6));
132
+ this.isMatchDeepEqual.push(deepEqual(obj1, obj7));
133
+ this.isMatchDeepEqual.push(deepEqual(obj8, obj9));
134
+ ```
135
+
136
+ ## Results
137
+ |#|Actual |ngx-deep-equals-pure |deep-equal |Lodash isEqual |
138
+ |---|-------------|---------------------|-----------|---------------|
139
+ |1 | true | true | false | false |
140
+ |2 | false | false | false | false |
141
+ |3 | false | false | false | false |
142
+ |4 | false | false | false | false |
143
+ |5 | false | false | false | false |
144
+ |6 | true | true | false | false |
145
+ |7 | true | true | true | true |
146
+
147
+ ## Input objects
148
+ ```javascript
149
+ const obj1: any = {
150
+ b: () => {
151
+ console.log('foo');
152
+ },
153
+ e: 'abcbc',
154
+ a: [
155
+ { 'a': 12.7 },
156
+ { 'c': 37.6 }
157
+ ],
158
+ c: 126.8,
159
+ f: ['f', 'a'],
160
+ g: [
161
+ { t: () => { console.log('h'); }, g: 'a', j: 12 },
162
+ ['b', 2, { p: '123' }],
163
+ '789',
164
+ 12.6,
165
+ 809,
166
+ () => { console.log('er'); }
167
+ ]
168
+ };
169
+
170
+ const obj2: any = {
171
+ g: [
172
+ [{ p: '123' }, 2, 'b'],
173
+ '789',
174
+ 12.6,
175
+ () => { console.log('er'); },
176
+ { g: 'a', t: () => { console.log('h'); }, j: 12 },
177
+ 809
178
+ ],
179
+ e: 'abcbc',
180
+ b: () => {
181
+ console.log('foo');
182
+ },
183
+ a: [
184
+ { 'c': 37.6 },
185
+ { 'a': 12.7 }
186
+ ],
187
+ f: ['f', 'a'],
188
+ c: 126.8
189
+ };
190
+
191
+ const obj3: any = {
192
+ g: [
193
+ [{ p: '123' }, 2, 'b'],
194
+ '789',
195
+ 12.6,
196
+ () => { console.log('er'); },
197
+ { t: () => { console.log('h'); }, j: 12 },
198
+ 809
199
+ ],
200
+ e: 'abcbc',
201
+ b: () => {
202
+ console.log('foo');
203
+ },
204
+ a: [
205
+ { 'c': 37.6 },
206
+ { 'a': 12.7 }
207
+ ],
208
+ f: ['f', 'a'],
209
+ c: 126.8
210
+ };
211
+
212
+ const obj4: any = {
213
+ g: [
214
+ [{ p: '123' }, 2, 'b'],
215
+ '789',
216
+ 12.6,
217
+ () => { console.log('er'); },
218
+ { g: '6', t: () => { console.log('h'); }, j: 12 },
219
+ 809
220
+ ],
221
+ e: 'abcbc',
222
+ b: () => {
223
+ console.log('foo');
224
+ },
225
+ a: [
226
+ { 'c': 37.6 },
227
+ { 'a': 12.7 }
228
+ ],
229
+ f: ['f', 'a'],
230
+ c: 126.8
231
+ };
232
+
233
+ const obj5: any = {
234
+ g: [
235
+ [{ u: '123' }, 2, 'b'],
236
+ '789',
237
+ 12.6,
238
+ () => { console.log('er'); },
239
+ { g: 'a', t: () => { console.log('h'); }, j: 12 },
240
+ 809
241
+ ],
242
+ e: 'abcbc',
243
+ b: () => {
244
+ console.log('foo');
245
+ },
246
+ a: [
247
+ { 'c': 37.6 },
248
+ { 'a': 12.7 }
249
+ ],
250
+ f: ['f', 'a'],
251
+ c: 126.8
252
+ };
253
+
254
+ const obj6: any = {
255
+ g: [
256
+ [{ p: '123' }, 2, 'b'],
257
+ '789',
258
+ 12.6,
259
+ () => { console.log('er'); },
260
+ { g: 'a', y: () => { console.log('h'); }, j: 12 },
261
+ 809
262
+ ],
263
+ e: 'abcbc',
264
+ b: () => {
265
+ console.log('foo');
266
+ },
267
+ a: [
268
+ { 'c': 37.6 },
269
+ { 'a': 12.7 }
270
+ ],
271
+ f: ['f', 'a'],
272
+ c: 126.8
273
+ };
274
+
275
+ const obj7: any = {
276
+ b: () => {
277
+ console.log('foo');
278
+ },
279
+ e: 'abcbc',
280
+ a: [
281
+ { 'a': 12.7 },
282
+ { 'c': 37.6 }
283
+ ],
284
+ c: 126.8,
285
+ f: ['f', 'a'],
286
+ g: [
287
+ { t: () => { console.log('h'); }, g: 'a', j: 12 },
288
+ ['b', 2, { p: '123' }],
289
+ '789',
290
+ 12.6,
291
+ 809,
292
+ () => { console.log('er'); }
293
+ ]
294
+ };
295
+
296
+ const obj8: any = { b: 'a', c: 2 };
297
+ const obj9: any = { c: 2, b: 'a' };
298
+ ```
299
+
300
+ ## Building library
301
+
302
+ Use command:
303
+
304
+ ```
305
+ ng build NgxDeepEqualsPure --configuration production
306
+ ```
307
+
308
+ ## Running benchmark
309
+
310
+ Use command:
311
+
312
+ ```
313
+ ng serve
314
+ ```
315
+
316
+ Then navigate to localhost:4200 in your preferred browser.
317
+
318
+ Note:
319
+ It may be necessary to run the build command before trying to run the benchmark.
320
+
321
+ See the GitHub repository at https://github.com/puckowski/deepequalspure for example usage of ngx-deep-equals-pure in an Angular application and for example usage in a Web Worker.