@thisisagile/easy 18.7.0 → 18.8.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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  view
3
- } from "../chunk-7TW4TBFN.mjs";
3
+ } from "../chunk-XQ4F3L4F.mjs";
4
4
  import {
5
5
  RouteGateway
6
6
  } from "../chunk-QBPSI5NM.mjs";
@@ -51,5 +51,12 @@ export declare const views: {
51
51
  readonly value: (altValue: unknown) => (a: unknown, key?: string) => unknown;
52
52
  readonly func: (altFunc: Func) => (a: unknown, key?: string) => unknown;
53
53
  };
54
+ readonly to: <T = unknown>(ctorOrFunc: Constructor<T> | ((v: any) => T)) => ((a: any, key?: string) => T | undefined) & {
55
+ or: {
56
+ key: (altKey: string) => (a: unknown, key?: string) => unknown;
57
+ value: (altValue: T) => (a: unknown, key?: string) => T;
58
+ func: (altFunc: Func) => (a: unknown, key?: string) => unknown;
59
+ };
60
+ };
54
61
  };
55
62
  export {};
@@ -4,7 +4,7 @@ import {
4
4
  toViewer,
5
5
  view,
6
6
  views
7
- } from "../chunk-7TW4TBFN.mjs";
7
+ } from "../chunk-XQ4F3L4F.mjs";
8
8
  import "../chunk-QLEGIYVU.mjs";
9
9
  import "../chunk-WOUH6UVC.mjs";
10
10
  import "../chunk-TUO7ZPSP.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "18.7.0",
3
+ "version": "18.8.0",
4
4
  "description": "Straightforward library for building domain-driven microservice architectures",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
package/src/utils/View.ts CHANGED
@@ -125,4 +125,18 @@ export const views = {
125
125
  value: (altValue: unknown) => (a: unknown, key?: string) => traverse(a, key) ?? altValue,
126
126
  func: (altFunc: Func) => (a: unknown, key?: string) => traverse(a, key) ?? altFunc(a, key),
127
127
  },
128
+ to: <T = unknown>(ctorOrFunc: Constructor<T> | ((v: any) => T)) => {
129
+ const apply = (v: any): T => (isConstructor(ctorOrFunc) ? new ctorOrFunc(v) : (ctorOrFunc as (v: any) => T)(v));
130
+ const base = (a: any, key?: string): T | undefined => {
131
+ const v = traverse(a, key);
132
+ return v != null ? apply(v) : undefined;
133
+ };
134
+ return Object.assign(base, {
135
+ or: {
136
+ key: (altKey: string) => (a: unknown, key?: string) => base(a, key) ?? traverse(a, altKey),
137
+ value: (altValue: T) => (a: unknown, key?: string) => base(a, key) ?? altValue,
138
+ func: (altFunc: Func) => (a: unknown, key?: string) => base(a, key) ?? altFunc(a, key),
139
+ },
140
+ });
141
+ },
128
142
  } as const;