@thisisagile/easy 15.1.4 → 15.1.6

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.
@@ -4,4 +4,5 @@ export declare const toArray: <T>(...items: ArrayLike<T>) => T[];
4
4
  export declare const toObject: <T>(key: keyof T, ...items: ArrayLike<T>) => Record<string | number | symbol, T>;
5
5
  export declare const array: {
6
6
  merge: (first?: any[], second?: any[], firstKey?: string, secondKey?: string) => any[];
7
+ switch: <T>(items: T[] | undefined, item: T) => T[];
7
8
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.array = exports.toObject = exports.toArray = void 0;
4
4
  const Is_1 = require("./Is");
5
+ const Constructor_1 = require("./Constructor");
5
6
  const toArray = (...items) => items.length > 1 ? items : (0, Is_1.isArray)(items[0]) ? items[0] : (0, Is_1.isDefined)(items[0]) ? [items[0]] : [];
6
7
  exports.toArray = toArray;
7
8
  const toObject = (key, ...items) => (0, exports.toArray)(...items).reduce((o, i) => {
@@ -10,9 +11,13 @@ const toObject = (key, ...items) => (0, exports.toArray)(...items).reduce((o, i)
10
11
  }, {});
11
12
  exports.toObject = toObject;
12
13
  exports.array = {
13
- merge: (first = [], second = [], firstKey = 'id', secondKey = 'id') => first.map(f => ({
14
+ merge: (first = [], second = [], firstKey = "id", secondKey = "id") => first.map(f => ({
14
15
  ...f,
15
- ...second.find(s => (0, Is_1.isDefined)(s[secondKey]) && (0, Is_1.isDefined)(f[firstKey]) && s[secondKey] === f[firstKey]),
16
+ ...second.find(s => (0, Is_1.isDefined)(s[secondKey]) && (0, Is_1.isDefined)(f[firstKey]) && s[secondKey] === f[firstKey])
16
17
  })),
18
+ switch: (items = [], item) => (0, Constructor_1.use)([...items], res => {
19
+ (0, Constructor_1.on)(res.indexOf(item), i => (i !== -1 ? res.splice(i, 1) : res.push(item)));
20
+ return res;
21
+ })
17
22
  };
18
23
  //# sourceMappingURL=Array.js.map
@@ -1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CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;KACvG,CAAC,CAAC;IACL,MAAM,EAAE,CAAI,QAAa,EAAE,EAAE,IAAO,EAAO,EAAE,CAAC,IAAA,iBAAG,EAAC,CAAC,GAAG,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE;QAClE,IAAA,gBAAE,EAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;CACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "15.1.4",
3
+ "version": "15.1.6",
4
4
  "description": "Straightforward library for building domain-driven microservice architectures",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "devDependencies": {
34
- "@thisisagile/easy-test": "15.1.4",
34
+ "@thisisagile/easy-test": "15.1.6",
35
35
  "@types/form-urlencoded": "^4.4.0",
36
36
  "@types/jsonwebtoken": "^8.5.9",
37
37
  "@types/luxon": "3.2.0",
@@ -1,4 +1,5 @@
1
- import { isArray, isDefined } from './Is';
1
+ import { isArray, isDefined } from "./Is";
2
+ import { on, use } from "./Constructor";
2
3
 
3
4
  export type OneOrMore<T> = T | Array<T>;
4
5
  export type ArrayLike<T> = OneOrMore<T>[];
@@ -13,9 +14,15 @@ export const toObject = <T>(key: keyof T, ...items: ArrayLike<T>): Record<string
13
14
  }, {});
14
15
 
15
16
  export const array = {
16
- merge: (first: any[] = [], second: any[] = [], firstKey = 'id', secondKey = 'id'): any[] =>
17
+ merge: (first: any[] = [], second: any[] = [], firstKey = "id", secondKey = "id"): any[] =>
17
18
  first.map(f => ({
18
19
  ...f,
19
- ...second.find(s => isDefined(s[secondKey]) && isDefined(f[firstKey]) && s[secondKey] === f[firstKey]),
20
+ ...second.find(s => isDefined(s[secondKey]) && isDefined(f[firstKey]) && s[secondKey] === f[firstKey])
20
21
  })),
22
+ switch: <T>(items: T[] = [], item: T): T[] => use([...items], res => {
23
+ on(res.indexOf(item), i => (i !== -1 ? res.splice(i, 1) : res.push(item)));
24
+ return res;
25
+ })
21
26
  };
27
+
28
+ // export const objectify = <T>(items: T[], f: (a: any, p: T) => void): any => items.reduce((acc: any, p: T) => on(acc, a => f(a, p)), {});