@kaumlaut/pure 2.2.7 → 2.2.10

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,3 +1,5 @@
1
+ import { ErrorAwareGuard } from "../error-aware-guard";
2
+ import { Maybe } from "../maybe";
1
3
  /**
2
4
  * Returns the given value.
3
5
  */
@@ -22,4 +24,20 @@ export declare function includes(searchString: string): (value: string) => boole
22
24
  * // returns the string "Peter"
23
25
  */
24
26
  export declare function field<T extends object>(key: keyof T): (value: T) => T[keyof T];
27
+ /**
28
+ * Takes an object with partial keys of type T and a list of keys for the wanted object type T.
29
+ * Returns a new object with all keys of T present. The values are Just if the key was present and includes the value, or nothing if the key was not present.
30
+ */
31
+ export declare function coerceOptionalFieldsAsMaybe<T extends object>(value: Partial<T>, keys: (keyof T)[]): {
32
+ [Property in keyof T]: Maybe<T[keyof T]>;
33
+ };
34
+ /**
35
+ * Takes an object with partial keys of type T and an object of ErrorAwareGuards used to validate T.
36
+ * Returns a new object with all keys of T present. The values are Just with the value if the key was present and the value passed the corresponding ErrorAwareGuard or nothing if the key was not present.
37
+ */
38
+ export declare function coerceOptionalFieldsAsMaybeByGuard<T extends object>(value: Partial<T>, guards: {
39
+ [K in keyof T]: ErrorAwareGuard<T[K]>;
40
+ }): {
41
+ [Property in keyof T]: Maybe<T[keyof T]>;
42
+ };
25
43
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEjC;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAGvD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC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AAM,EAC1D,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAChB;KAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CAAE,CAQ9C;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,SAAS,MAAM,EACjE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,MAAM,EAAE;KACL,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtC,GACA;KAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CAAE,CAY9C"}
@@ -1,3 +1,4 @@
1
+ import { just, nothing } from "../maybe";
1
2
  /**
2
3
  * Returns the given value.
3
4
  */
@@ -35,3 +36,27 @@ export function includes(searchString) {
35
36
  export function field(key) {
36
37
  return (value) => value[key];
37
38
  }
39
+ /**
40
+ * Takes an object with partial keys of type T and a list of keys for the wanted object type T.
41
+ * Returns a new object with all keys of T present. The values are Just if the key was present and includes the value, or nothing if the key was not present.
42
+ */
43
+ export function coerceOptionalFieldsAsMaybe(value, keys) {
44
+ return keys.reduce((object, key) => {
45
+ object[key] = key in value ? just(value[key]) : nothing();
46
+ return object;
47
+ }, {});
48
+ }
49
+ /**
50
+ * Takes an object with partial keys of type T and an object of ErrorAwareGuards used to validate T.
51
+ * Returns a new object with all keys of T present. The values are Just with the value if the key was present and the value passed the corresponding ErrorAwareGuard or nothing if the key was not present.
52
+ */
53
+ export function coerceOptionalFieldsAsMaybeByGuard(value, guards) {
54
+ return Object.entries(guards).reduce((object, [key, guard]) => {
55
+ object[key] =
56
+ key in value &&
57
+ guard(value[key]).success
58
+ ? just(value[key])
59
+ : nothing();
60
+ return object;
61
+ }, {});
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaumlaut/pure",
3
- "version": "2.2.7",
3
+ "version": "2.2.10",
4
4
  "description": "Types and functions for a state runtime inspired by Elm and functional programming",
5
5
  "author": "Max Kaemmerer",
6
6
  "license": "MIT",
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import * as clone from "./clone";
2
- import * as errorAwareGuard from "./error-aware-guard";
3
- import * as fetchState from "./fetch-state";
4
- import * as guard from "./guard";
5
- import * as maybe from "./maybe";
6
- import * as parse from "./parse";
7
- import * as result from "./result";
8
- import * as pipe from "./pipe";
9
- import * as runtime from "./runtime";
10
- import * as util from "./util";
11
- export { clone, errorAwareGuard, fetchState, guard, maybe, parse, result, pipe, runtime, util, };
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,EACH,KAAK,EACL,eAAe,EACf,UAAU,EACV,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,GACP,CAAA"}
package/dist/index.js DELETED
@@ -1,11 +0,0 @@
1
- import * as clone from "./clone";
2
- import * as errorAwareGuard from "./error-aware-guard";
3
- import * as fetchState from "./fetch-state";
4
- import * as guard from "./guard";
5
- import * as maybe from "./maybe";
6
- import * as parse from "./parse";
7
- import * as result from "./result";
8
- import * as pipe from "./pipe";
9
- import * as runtime from "./runtime";
10
- import * as util from "./util";
11
- export { clone, errorAwareGuard, fetchState, guard, maybe, parse, result, pipe, runtime, util, };