@bbn/bbn 1.0.223 → 1.0.224

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
- export default function mutateArray(a1, a2) {
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
- var mapA2 = new Map(a2.map(function (item) { return [hash(item), item]; }));
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(hash(a1[i]))) {
26
+ if (!mapA2.has(hashFn(a1[i]))) {
19
27
  a1.splice(i, 1);
20
28
  }
21
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.223",
3
+ "version": "1.0.224",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",