@bbn/bbn 1.0.223 → 1.0.225
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function mutateArray(a1: any, a2: any): any;
|
|
1
|
+
export default function mutateArray(a1: any, a2: any, hashFn?: any): any;
|
|
@@ -2,11 +2,19 @@ import isArray from '../type/isArray.js';
|
|
|
2
2
|
import hash from '../string/hash.js';
|
|
3
3
|
import isSame from '../type/isSame.js';
|
|
4
4
|
import search from './search.js';
|
|
5
|
-
|
|
5
|
+
import checkType from '../type/checkType.js';
|
|
6
|
+
export default function mutateArray(a1, a2, hashFn) {
|
|
7
|
+
if (hashFn === void 0) { hashFn = null; }
|
|
6
8
|
if (!isArray(a1, a2)) {
|
|
7
9
|
throw new TypeError('mutateArray can only be called with arrays');
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
if (!hashFn) {
|
|
12
|
+
hashFn = hash;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
checkType(hashFn, 'function', 'The hash function must be a function');
|
|
16
|
+
}
|
|
17
|
+
var mapA2 = new Map(a2.map(function (item) { return [hashFn(item), item]; }));
|
|
10
18
|
var a1Ordered = [];
|
|
11
19
|
// Build a1Ordered to have the same order and contents as a2
|
|
12
20
|
a2.forEach(function (item) {
|
|
@@ -15,7 +23,7 @@ export default function mutateArray(a1, a2) {
|
|
|
15
23
|
// Remove items from a1 that are not in a2
|
|
16
24
|
var i = a1.length;
|
|
17
25
|
while (i--) {
|
|
18
|
-
if (!mapA2.has(
|
|
26
|
+
if (!mapA2.has(hashFn(a1[i]))) {
|
|
19
27
|
a1.splice(i, 1);
|
|
20
28
|
}
|
|
21
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function mutateObject(a1: any, a2: any, hashFn: any): any;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import isObject from '../type/isObject.js';
|
|
2
|
+
import hash from '../string/hash.js';
|
|
3
|
+
import isSame from '../type/isSame.js';
|
|
4
|
+
import checkType from '../type/checkType.js';
|
|
5
|
+
export default function mutateObject(a1, a2, hashFn) {
|
|
6
|
+
if (!isObject(a1, a2)) {
|
|
7
|
+
throw new TypeError('mutateObject can only be called with arrays');
|
|
8
|
+
}
|
|
9
|
+
if (hashFn) {
|
|
10
|
+
checkType(hashFn, 'function', 'The hash function must be a function');
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
hashFn = hash;
|
|
14
|
+
}
|
|
15
|
+
var mapA2 = Object.keys(a2);
|
|
16
|
+
// Remove items from a1 that are not in a2
|
|
17
|
+
for (var n in a1) {
|
|
18
|
+
if (!mapA2.includes(n)) {
|
|
19
|
+
delete a1[n];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
mapA2.forEach(function (n) {
|
|
23
|
+
if (!isSame(a1[n], a2[n])) {
|
|
24
|
+
a1[n] = a2[n];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return a1;
|
|
28
|
+
}
|
package/dist/fn.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ import money from './fn/misc/money.js';
|
|
|
170
170
|
import move from './fn/object/move.js';
|
|
171
171
|
import multiorder from './fn/object/multiorder.js';
|
|
172
172
|
import mutateArray from './fn/object/mutateArray.js';
|
|
173
|
+
import mutateObject from './fn/object/mutateObject.js';
|
|
173
174
|
import nl2br from './fn/string/nl2br.js';
|
|
174
175
|
import numProperties from './fn/object/numProperties.js';
|
|
175
176
|
import objectToFormData from './fn/form/objectToFormData.js';
|
|
@@ -401,6 +402,7 @@ declare const _default: {
|
|
|
401
402
|
move: typeof move;
|
|
402
403
|
multiorder: typeof multiorder;
|
|
403
404
|
mutateArray: typeof mutateArray;
|
|
405
|
+
mutateObject: typeof mutateObject;
|
|
404
406
|
nl2br: typeof nl2br;
|
|
405
407
|
numProperties: typeof numProperties;
|
|
406
408
|
objectToFormData: typeof objectToFormData;
|
package/dist/fn.js
CHANGED
|
@@ -170,6 +170,7 @@ import money from './fn/misc/money.js';
|
|
|
170
170
|
import move from './fn/object/move.js';
|
|
171
171
|
import multiorder from './fn/object/multiorder.js';
|
|
172
172
|
import mutateArray from './fn/object/mutateArray.js';
|
|
173
|
+
import mutateObject from './fn/object/mutateObject.js';
|
|
173
174
|
import nl2br from './fn/string/nl2br.js';
|
|
174
175
|
import numProperties from './fn/object/numProperties.js';
|
|
175
176
|
import objectToFormData from './fn/form/objectToFormData.js';
|
|
@@ -401,6 +402,7 @@ export default {
|
|
|
401
402
|
move: move,
|
|
402
403
|
multiorder: multiorder,
|
|
403
404
|
mutateArray: mutateArray,
|
|
405
|
+
mutateObject: mutateObject,
|
|
404
406
|
nl2br: nl2br,
|
|
405
407
|
numProperties: numProperties,
|
|
406
408
|
objectToFormData: objectToFormData,
|