@bbn/bbn 1.0.178 → 1.0.181

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.
@@ -0,0 +1,2 @@
1
+ declare const mutateArray: (a1: any, a2: any) => any;
2
+ export { mutateArray };
@@ -0,0 +1,38 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { isArray } from '../type/isArray.js';
11
+ import { hash } from '../string/hash.js';
12
+ var mutateArray = function (a1, a2) {
13
+ if (!isArray(a1) || !isArray(a2)) {
14
+ throw new TypeError('mutateArray can only be called with arrays');
15
+ }
16
+ // Create a map from the second array using the identity function to get the key
17
+ var mapA2 = new Map(a2.map(function (item) { return [hash(item), item]; }));
18
+ var mapA1 = new Map(a1.map(function (item) { return [hash(item), item]; }));
19
+ // Result array to build the correct order
20
+ var result = [];
21
+ // Iterate over a2 and build the result array
22
+ for (var _i = 0, a2_1 = a2; _i < a2_1.length; _i++) {
23
+ var item = a2_1[_i];
24
+ var key = hash(item);
25
+ if (mapA1.has(key)) {
26
+ // If the item is in a1, use the item from a2 to preserve the order
27
+ result.push(mapA2.get(key));
28
+ }
29
+ else {
30
+ // If the item is not in a1, it's a new item to be added
31
+ result.push(item);
32
+ }
33
+ }
34
+ // Clear a1 and push the ordered results into it
35
+ a1.splice.apply(a1, __spreadArray([0, a1.length], result, false));
36
+ return a1;
37
+ };
38
+ export { mutateArray };
package/dist/fn.d.ts CHANGED
@@ -184,6 +184,7 @@ declare const fn: {
184
184
  money: (val: number, kilo?: boolean, currency?: string, novalue?: string | false, decimal?: string, thousands?: string, precision?: number) => string;
185
185
  move: (arr: any[], fromIndex: number, toIndex: number) => any[];
186
186
  multiorder: (arr: object[], orders: any) => object[];
187
+ mutateArray: (a1: any, a2: any) => any;
187
188
  nl2br: (st: any, keepNl: any) => string;
188
189
  numProperties: (obj: object) => number;
189
190
  objectToFormData: (obj: any, key?: string, ignoreList?: any) => FormData;
package/dist/fn.js CHANGED
@@ -169,6 +169,7 @@ import { md5 } from './fn/string/md5.js';
169
169
  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
+ import { mutateArray } from './fn/object/mutateArray.js';
172
173
  import { nl2br } from './fn/string/nl2br.js';
173
174
  import { numProperties } from './fn/object/numProperties.js';
174
175
  import { objectToFormData } from './fn/form/objectToFormData.js';
@@ -398,6 +399,7 @@ var fn = {
398
399
  money: money,
399
400
  move: move,
400
401
  multiorder: multiorder,
402
+ mutateArray: mutateArray,
401
403
  nl2br: nl2br,
402
404
  numProperties: numProperties,
403
405
  objectToFormData: objectToFormData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.178",
3
+ "version": "1.0.181",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",