@kaumlaut/pure 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -2,6 +2,4 @@
2
2
 
3
3
  Types and functions for a state runtime inspired by Elm and functional programming
4
4
 
5
- ## Maybe
6
-
7
- A Simple implementation of the Maybe type and associated functions.
5
+ - [API Reference](./docs/README.md)
@@ -1,5 +1,15 @@
1
+ /**
2
+ * Provides value cloning capabilities
3
+ * @module clone
4
+ */
5
+ /**
6
+ * Defines the Cloneable type
7
+ */
1
8
  export type Cloneable = string | number | boolean | null | Cloneable[] | {
2
9
  [key: string]: Cloneable;
3
10
  };
11
+ /**
12
+ * Recursively clones values to prevent changing of the original value.
13
+ */
4
14
  export declare function clone<T extends Cloneable>(value: T): T;
5
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clone/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAkBtD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clone/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAkBtD"}
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Provides value cloning capabilities
3
+ * @module clone
4
+ */
5
+ /**
6
+ * Recursively clones values to prevent changing of the original value.
7
+ */
1
8
  export function clone(value) {
2
9
  if (value === null || typeof value !== "object") {
3
10
  return value;
@@ -1,26 +1,74 @@
1
+ /**
2
+ * Provides types and functions to represent fetch request states
3
+ * @module fetch-state
4
+ */
1
5
  import type { Guard } from "@kaumlaut/pure/guard";
6
+ /**
7
+ * Represents a failed fetch request
8
+ */
2
9
  export type Failed = {
3
10
  error: Readonly<string>;
4
11
  type: "Failed";
5
12
  };
13
+ /**
14
+ * Represents a fetch request that has not been executed
15
+ */
6
16
  export type None = {
7
17
  type: "None";
8
18
  };
19
+ /**
20
+ * Represents a fetch request that is currently still running
21
+ */
9
22
  export type Loading = {
10
23
  type: "Loading";
11
24
  };
25
+ /**
26
+ * Represents a fetch request that succeeded
27
+ */
12
28
  export type Success<T> = {
13
29
  data: Readonly<T>;
14
30
  type: "Success";
15
31
  };
32
+ /**
33
+ * Represents all possible states of a fetch request
34
+ */
16
35
  export type FetchState<T> = Failed | None | Loading | Success<T>;
36
+ /**
37
+ * Checks whether or not the fetch state is Loading via a type guard
38
+ */
17
39
  export declare function isLoading<T>(state: FetchState<T>): state is Loading;
40
+ /**
41
+ * Checks whether or not the fetch state is Failed via a type guard
42
+ */
18
43
  export declare function isFailed<T>(state: FetchState<T>): state is Failed;
44
+ /**
45
+ * Checks whether or not the fetch state is None via a type guard
46
+ */
19
47
  export declare function isNone<T>(state: FetchState<T>): state is None;
48
+ /**
49
+ * Checks whether or not the fetch state is Success via a type guard
50
+ */
20
51
  export declare function isSuccess<T>(state: FetchState<T>): state is Success<T>;
52
+ /**
53
+ * Creates a fetch state of type Failed
54
+ */
21
55
  export declare function fail(error: string): Failed;
56
+ /**
57
+ * Creates a fetch state of type Loading
58
+ */
22
59
  export declare function load(): Loading;
60
+ /**
61
+ * Creates a fetch state of type None
62
+ */
23
63
  export declare function none(): None;
64
+ /**
65
+ * Attempts to create a fetch state of type Success if the given guard passes.
66
+ * Otherwise creates a fetch state of type Failed with the provided error.
67
+ */
24
68
  export declare function attempt<T>(guard: Guard<T>, error?: string): (data: unknown) => Success<T> | Failed;
69
+ /**
70
+ * A Utility function that allows to map the Failed fetch state to any other fetch state.
71
+ * The mapper function is only called if the given fetch state is Failed.
72
+ */
25
73
  export declare function mapFailed<T>(mapper: (state: Failed) => FetchState<T>): (state: FetchState<T>) => FetchState<T>;
26
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetch-state/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjE,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,OAAO,CAEnE;AACD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,CAEjE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,E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,31 +1,56 @@
1
+ /**
2
+ * Checks whether or not the fetch state is Loading via a type guard
3
+ */
1
4
  export function isLoading(state) {
2
5
  return state.type === "Loading";
3
6
  }
7
+ /**
8
+ * Checks whether or not the fetch state is Failed via a type guard
9
+ */
4
10
  export function isFailed(state) {
5
11
  return state.type === "Failed";
6
12
  }
13
+ /**
14
+ * Checks whether or not the fetch state is None via a type guard
15
+ */
7
16
  export function isNone(state) {
8
17
  return state.type === "None";
9
18
  }
19
+ /**
20
+ * Checks whether or not the fetch state is Success via a type guard
21
+ */
10
22
  export function isSuccess(state) {
11
23
  return state.type === "Success";
12
24
  }
25
+ /**
26
+ * Creates a fetch state of type Failed
27
+ */
13
28
  export function fail(error) {
14
29
  return {
15
30
  type: "Failed",
16
31
  error,
17
32
  };
18
33
  }
34
+ /**
35
+ * Creates a fetch state of type Loading
36
+ */
19
37
  export function load() {
20
38
  return {
21
39
  type: "Loading",
22
40
  };
23
41
  }
42
+ /**
43
+ * Creates a fetch state of type None
44
+ */
24
45
  export function none() {
25
46
  return {
26
47
  type: "None",
27
48
  };
28
49
  }
50
+ /**
51
+ * Attempts to create a fetch state of type Success if the given guard passes.
52
+ * Otherwise creates a fetch state of type Failed with the provided error.
53
+ */
29
54
  export function attempt(guard, error = "Guard did not pass. Ensure the attempted data has the correct type") {
30
55
  return (data) => {
31
56
  if (guard(data)) {
@@ -40,6 +65,10 @@ export function attempt(guard, error = "Guard did not pass. Ensure the attempted
40
65
  };
41
66
  };
42
67
  }
68
+ /**
69
+ * A Utility function that allows to map the Failed fetch state to any other fetch state.
70
+ * The mapper function is only called if the given fetch state is Failed.
71
+ */
43
72
  export function mapFailed(mapper) {
44
73
  return (state) => {
45
74
  if (isFailed(state)) {
@@ -1,26 +1,105 @@
1
+ /**
2
+ * Represents a type guard
3
+ */
1
4
  export type Guard<T> = (value: unknown) => value is T;
5
+ /**
6
+ * Confirms that the given value passes all guards.
7
+ */
2
8
  export declare function isAll<T>(guards: Guard<T>[]): (value: unknown) => value is T;
9
+ /**
10
+ * Confirms that the value is a string.
11
+ */
3
12
  export declare function isString(value: unknown): value is string;
13
+ /**
14
+ * Confirms that the value is a string with specified length.
15
+ */
4
16
  export declare function isStringOfLength(length: number): (value: unknown) => value is string;
17
+ /**
18
+ * Confirms that the value is a number.
19
+ */
5
20
  export declare function isNumber(value: unknown): value is number;
21
+ /**
22
+ * Confirms that the value is an integer.
23
+ */
6
24
  export declare function isInt(value: unknown): value is number;
25
+ /**
26
+ * Confirms that the value is a floating point number.
27
+ */
7
28
  export declare function isFloat(value: unknown): value is number;
29
+ /**
30
+ * Confirms that the value is an object containing the specified key.
31
+ */
8
32
  export declare function isObjectWithKey<T extends object>(key: keyof T): (value: unknown) => value is T;
33
+ /**
34
+ * Confirms that the value is an object containing the specified keys.
35
+ */
9
36
  export declare function isObjectWithKeys<T extends object>(keys: (keyof T)[]): (value: unknown) => value is T;
37
+ /**
38
+ * Confirms that the value is an object whose key value pairs match the corresponding type guards.
39
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
40
+ */
10
41
  export declare function isObjectWithKeysMatchingGuard<T extends object>(guards: {
11
42
  [K in keyof T]: Guard<T[K]>;
12
43
  }): (value: unknown) => value is T;
44
+ /**
45
+ * Confirms the value exactly matched the given string.
46
+ */
13
47
  export declare function isExactString<T extends string>(expectedString: string): (value: unknown) => value is T;
48
+ /**
49
+ * Confirms the value is one of the given valid values.
50
+ */
14
51
  export declare function isOneStringOf<T extends string>(validValues: string[]): (value: unknown) => value is T;
52
+ /**
53
+ * Always passes.
54
+ */
15
55
  export declare function isAlways<T>(value: unknown): value is T;
56
+ /**
57
+ * Never passes.
58
+ */
16
59
  export declare function isNever<T>(value: unknown): value is T;
60
+ /**
61
+ * Confirms the value is a boolean.
62
+ */
17
63
  export declare function isBool(value: unknown): value is boolean;
64
+ /**
65
+ * Confirms the value is null.
66
+ */
18
67
  export declare function isNull(value: unknown): value is null;
68
+ /**
69
+ * Confirms the value is a list of items that all pass the given guard.
70
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
71
+ */
19
72
  export declare function isListOf<T>(guard: Guard<T>): (value: unknown) => value is T[];
73
+ /**
74
+ * Confirms the value passes at least one of the given Guards.
75
+ */
20
76
  export declare function isOneOf<T1, T2>(a: Guard<T1>, b: Guard<T2>): (value: unknown) => value is T1 | T2;
77
+ /**
78
+ * Confirms the value is either null or passes the given Guard.
79
+ */
21
80
  export declare function isNullOr<T>(guard: Guard<T>): (value: unknown) => value is T | null;
81
+ /**
82
+ * Confirms the value is an object where every value matches the given guard.
83
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
84
+ */
22
85
  export declare function isObjectWithAllKeysMatchingGuard<B, T extends {
23
86
  [key: string]: B;
24
87
  }>(guard: Guard<B>): (value: unknown) => value is T;
88
+ /**
89
+ * Confirms the value is a string and matches the given regular expression.
90
+ */
25
91
  export declare function isStringWithPattern(pattern: RegExp): Guard<string>;
92
+ /**
93
+ * Confirms the value is undefined.
94
+ */
95
+ export declare function isUndefined(value: unknown): value is undefined;
96
+ /**
97
+ * Confirms the value is a list with atleast one item and all items match the given guard.
98
+ */
99
+ export declare function isNonEmptyListOf<T>(guard: Guard<T>): (value: unknown) => value is T;
100
+ /**
101
+ * Confirms the value is number between min and max inclusive.
102
+ * Meaning if the value equals min or max the guard passes.
103
+ */
104
+ export declare function isNumberBetweenInclusive<T>(min: number, max: number): (value: unknown) => value is T;
26
105
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;AAEtD,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAE3E;AAED,wBAAgB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,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAYjD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAGlE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GACd,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAGhC;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAGhC"}
@@ -1,22 +1,44 @@
1
+ /**
2
+ * Provides easily composable generic type guards
3
+ * @module guard
4
+ */
1
5
  import { asFloat, asInt } from "@kaumlaut/pure/parse";
2
6
  import { isOk } from "@kaumlaut/pure/result";
7
+ /**
8
+ * Confirms that the given value passes all guards.
9
+ */
3
10
  export function isAll(guards) {
4
11
  return (value) => guards.every((guard) => guard(value));
5
12
  }
13
+ /**
14
+ * Confirms that the value is a string.
15
+ */
6
16
  export function isString(value) {
7
17
  return typeof value === "string";
8
18
  }
19
+ /**
20
+ * Confirms that the value is a string with specified length.
21
+ */
9
22
  export function isStringOfLength(length) {
10
23
  return (value) => isString(value) && value.length === length;
11
24
  }
25
+ /**
26
+ * Confirms that the value is a number.
27
+ */
12
28
  export function isNumber(value) {
13
29
  return typeof value === "number";
14
30
  }
31
+ /**
32
+ * Confirms that the value is an integer.
33
+ */
15
34
  export function isInt(value) {
16
35
  return (isNumber(value) &&
17
36
  !numberIncludesCommaSeparator(value) &&
18
37
  isOk(asInt(value.toString())));
19
38
  }
39
+ /**
40
+ * Confirms that the value is a floating point number.
41
+ */
20
42
  export function isFloat(value) {
21
43
  return (isNumber(value) &&
22
44
  numberIncludesCommaSeparator(value) &&
@@ -25,12 +47,22 @@ export function isFloat(value) {
25
47
  function numberIncludesCommaSeparator(value) {
26
48
  return `${value}`.includes(".");
27
49
  }
50
+ /**
51
+ * Confirms that the value is an object containing the specified key.
52
+ */
28
53
  export function isObjectWithKey(key) {
29
54
  return (value) => typeof value === "object" && key in value;
30
55
  }
56
+ /**
57
+ * Confirms that the value is an object containing the specified keys.
58
+ */
31
59
  export function isObjectWithKeys(keys) {
32
60
  return (value) => typeof value === "object" && keys.every((key) => key in value);
33
61
  }
62
+ /**
63
+ * Confirms that the value is an object whose key value pairs match the corresponding type guards.
64
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
65
+ */
34
66
  export function isObjectWithKeysMatchingGuard(guards) {
35
67
  return (value) => typeof value === "object" &&
36
68
  Object.keys(guards).filter((key) => {
@@ -41,24 +73,46 @@ export function isObjectWithKeysMatchingGuard(guards) {
41
73
  return result;
42
74
  }).length === Object.keys(guards).length;
43
75
  }
76
+ /**
77
+ * Confirms the value exactly matched the given string.
78
+ */
44
79
  export function isExactString(expectedString) {
45
80
  return (value) => isString(value) && value === expectedString;
46
81
  }
82
+ /**
83
+ * Confirms the value is one of the given valid values.
84
+ */
47
85
  export function isOneStringOf(validValues) {
48
86
  return (value) => isString(value) && validValues.includes(value);
49
87
  }
88
+ /**
89
+ * Always passes.
90
+ */
50
91
  export function isAlways(value) {
51
92
  return true;
52
93
  }
94
+ /**
95
+ * Never passes.
96
+ */
53
97
  export function isNever(value) {
54
98
  return false;
55
99
  }
100
+ /**
101
+ * Confirms the value is a boolean.
102
+ */
56
103
  export function isBool(value) {
57
104
  return typeof value === "boolean";
58
105
  }
106
+ /**
107
+ * Confirms the value is null.
108
+ */
59
109
  export function isNull(value) {
60
110
  return value === null;
61
111
  }
112
+ /**
113
+ * Confirms the value is a list of items that all pass the given guard.
114
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
115
+ */
62
116
  export function isListOf(guard) {
63
117
  return (value) => Array.isArray(value) &&
64
118
  value.filter((item, index) => {
@@ -69,12 +123,22 @@ export function isListOf(guard) {
69
123
  return result;
70
124
  }).length === value.length;
71
125
  }
126
+ /**
127
+ * Confirms the value passes at least one of the given Guards.
128
+ */
72
129
  export function isOneOf(a, b) {
73
130
  return (value) => a(value) || b(value);
74
131
  }
132
+ /**
133
+ * Confirms the value is either null or passes the given Guard.
134
+ */
75
135
  export function isNullOr(guard) {
76
136
  return isOneOf(isNull, guard);
77
137
  }
138
+ /**
139
+ * Confirms the value is an object where every value matches the given guard.
140
+ * Calls console.debug with an error message to improve debugging when a large type does not match.
141
+ */
78
142
  export function isObjectWithAllKeysMatchingGuard(guard) {
79
143
  return (value) => typeof value === "object" &&
80
144
  Object.keys(value).filter((key) => {
@@ -85,6 +149,28 @@ export function isObjectWithAllKeysMatchingGuard(guard) {
85
149
  return result;
86
150
  }).length === Object.keys(value).length;
87
151
  }
152
+ /**
153
+ * Confirms the value is a string and matches the given regular expression.
154
+ */
88
155
  export function isStringWithPattern(pattern) {
89
156
  return (value) => isString(value) && pattern.test(value);
90
157
  }
158
+ /**
159
+ * Confirms the value is undefined.
160
+ */
161
+ export function isUndefined(value) {
162
+ return value === undefined;
163
+ }
164
+ /**
165
+ * Confirms the value is a list with atleast one item and all items match the given guard.
166
+ */
167
+ export function isNonEmptyListOf(guard) {
168
+ return (value) => isListOf(guard)(value) && value.length > 0;
169
+ }
170
+ /**
171
+ * Confirms the value is number between min and max inclusive.
172
+ * Meaning if the value equals min or max the guard passes.
173
+ */
174
+ export function isNumberBetweenInclusive(min, max) {
175
+ return (value) => isNumber(value) && value >= min && value <= max;
176
+ }
@@ -1,5 +1,11 @@
1
+ /**
2
+ * Provides types representing the Maybe concept as well as functions to work with it.
3
+ * @module maybe
4
+ */
1
5
  import { Result } from "@kaumlaut/pure/result";
6
+ import { Guard } from "../guard";
2
7
  /**
8
+ * Represents a Maybe containing a value.
3
9
  * @example
4
10
  * ```ts
5
11
  * if (isJust(maybe)) {
@@ -13,7 +19,7 @@ export type Just<T> = {
13
19
  value: T;
14
20
  };
15
21
  /**
16
- * @public
22
+ * Represents a Maybe not containing a value.
17
23
  * @example
18
24
  if (isNothing(maybe)) {
19
25
  // no value property exists on maybe
@@ -23,14 +29,60 @@ export type Just<T> = {
23
29
  export type Nothing = {
24
30
  type: "maybe-nothing";
25
31
  };
32
+ /**
33
+ * Represents the Maybe type.
34
+ */
26
35
  export type Maybe<T> = Just<T> | Nothing;
36
+ /**
37
+ * Creates a maybe not containing a value. (Nothing)
38
+ */
27
39
  export declare function nothing(): Nothing;
40
+ /**
41
+ * Creates a maybe containing a value. (Just)
42
+ */
28
43
  export declare function just<T>(value: T): Just<T>;
44
+ /**
45
+ * A Guard confirming that the given maybe value is a Nothing.
46
+ */
29
47
  export declare function isNothing<T>(maybe: Maybe<T>): maybe is Nothing;
48
+ /**
49
+ * A Guard confirming that the given maybe value is a Just.
50
+ */
30
51
  export declare function isJust<T>(maybe: Maybe<T>): maybe is Just<T>;
52
+ /**
53
+ * A Guard confirming that the given value is a Maybe.
54
+ */
31
55
  export declare function isMaybe<T>(value: unknown): value is Maybe<T>;
56
+ /**
57
+ * Applies the func function to the value if the given Maybe is a Just and returns it wrapped in a Just. Otherwise returns the given Maybe.
58
+ */
32
59
  export declare function map<T, R>(func: (value: T) => R): (maybe: Maybe<T>) => Maybe<R>;
60
+ /**
61
+ * Converts the given Maybe into a Nothing if it is Just but does not pass the given function.
62
+ */
33
63
  export declare function filter<T>(func: (value: T) => boolean): (maybe: Maybe<T>) => Maybe<T>;
64
+ /**
65
+ * Unwraps a Maybe, returning the value if it is a Just or the default value if it is a Nothing.
66
+ */
34
67
  export declare function withDefault<T>(defaultValue: T): (maybe: Maybe<T>) => T;
68
+ /**
69
+ * Converts the given Maybe to a Result.
70
+ * A Nothing becomes an Err with the given error.
71
+ * A Just becomes an Ok with the contained value.
72
+ */
35
73
  export declare function toResult<T, E>(error: E): (maybe: Maybe<T>) => Result<T, E>;
74
+ /**
75
+ * Creates a Just if the Guard passes for the given value. Otherwise Creates a Nothing.
76
+ */
77
+ export declare function maybeByGuard<T>(guard: Guard<T>): (value: unknown) => Maybe<T>;
78
+ /**
79
+ * Maps the a value contained within a Just using the given function without wrapping it in another Just.
80
+ * Returns the given Maybe if it is a Nothing.
81
+ */
82
+ export declare function mapToMaybe<T, R>(func: (value: T) => Maybe<R>): (maybe: Maybe<T>) => Maybe<R>;
83
+ /**
84
+ * Maps the a value contained within a Just using the given function without wrapping it in another Just.
85
+ * Returns the given Maybe if it is a Nothing.
86
+ */
87
+ export declare function tryMap<T, R>(func: (value: T) => R): (maybe: Maybe<T>) => Maybe<R>;
36
88
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/maybe/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAEzC,wBAAgB,OAAO,IAAI,OAAO,CAIjC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAKzC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,OAAO,CAE9D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE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,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAE1E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAI7E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,GAC3B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAQ/B;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAa/B"}
@@ -1,25 +1,47 @@
1
+ /**
2
+ * Provides types representing the Maybe concept as well as functions to work with it.
3
+ * @module maybe
4
+ */
1
5
  import { err, ok } from "@kaumlaut/pure/result";
6
+ /**
7
+ * Creates a maybe not containing a value. (Nothing)
8
+ */
2
9
  export function nothing() {
3
10
  return {
4
11
  type: "maybe-nothing",
5
12
  };
6
13
  }
14
+ /**
15
+ * Creates a maybe containing a value. (Just)
16
+ */
7
17
  export function just(value) {
8
18
  return {
9
19
  type: "maybe-just",
10
20
  value,
11
21
  };
12
22
  }
23
+ /**
24
+ * A Guard confirming that the given maybe value is a Nothing.
25
+ */
13
26
  export function isNothing(maybe) {
14
27
  return maybe.type === "maybe-nothing";
15
28
  }
29
+ /**
30
+ * A Guard confirming that the given maybe value is a Just.
31
+ */
16
32
  export function isJust(maybe) {
17
33
  return maybe.type === "maybe-just";
18
34
  }
35
+ /**
36
+ * A Guard confirming that the given value is a Maybe.
37
+ */
19
38
  export function isMaybe(value) {
20
39
  //@ts-expect-error is validated
21
40
  return value.type === "maybe-just" || value.type === "maybe-nothing";
22
41
  }
42
+ /**
43
+ * Applies the func function to the value if the given Maybe is a Just and returns it wrapped in a Just. Otherwise returns the given Maybe.
44
+ */
23
45
  export function map(func) {
24
46
  return (maybe) => {
25
47
  if (isJust(maybe)) {
@@ -28,6 +50,9 @@ export function map(func) {
28
50
  return maybe;
29
51
  };
30
52
  }
53
+ /**
54
+ * Converts the given Maybe into a Nothing if it is Just but does not pass the given function.
55
+ */
31
56
  export function filter(func) {
32
57
  return (maybe) => {
33
58
  if (!isJust(maybe)) {
@@ -39,6 +64,9 @@ export function filter(func) {
39
64
  return nothing();
40
65
  };
41
66
  }
67
+ /**
68
+ * Unwraps a Maybe, returning the value if it is a Just or the default value if it is a Nothing.
69
+ */
42
70
  export function withDefault(defaultValue) {
43
71
  return (maybe) => {
44
72
  if (isJust(maybe)) {
@@ -47,6 +75,49 @@ export function withDefault(defaultValue) {
47
75
  return defaultValue;
48
76
  };
49
77
  }
78
+ /**
79
+ * Converts the given Maybe to a Result.
80
+ * A Nothing becomes an Err with the given error.
81
+ * A Just becomes an Ok with the contained value.
82
+ */
50
83
  export function toResult(error) {
51
84
  return (maybe) => (isJust(maybe) ? ok(maybe.value) : err(error));
52
85
  }
86
+ /**
87
+ * Creates a Just if the Guard passes for the given value. Otherwise Creates a Nothing.
88
+ */
89
+ export function maybeByGuard(guard) {
90
+ return (value) => {
91
+ return guard(value) ? just(value) : nothing();
92
+ };
93
+ }
94
+ /**
95
+ * Maps the a value contained within a Just using the given function without wrapping it in another Just.
96
+ * Returns the given Maybe if it is a Nothing.
97
+ */
98
+ export function mapToMaybe(func) {
99
+ return (maybe) => {
100
+ if (isJust(maybe)) {
101
+ return func(maybe.value);
102
+ }
103
+ return maybe;
104
+ };
105
+ }
106
+ /**
107
+ * Maps the a value contained within a Just using the given function without wrapping it in another Just.
108
+ * Returns the given Maybe if it is a Nothing.
109
+ */
110
+ export function tryMap(func) {
111
+ return (maybe) => {
112
+ if (isJust(maybe)) {
113
+ try {
114
+ return just(func(maybe.value));
115
+ }
116
+ catch (e) {
117
+ console.error(e);
118
+ return nothing();
119
+ }
120
+ }
121
+ return maybe;
122
+ };
123
+ }
@@ -1,4 +1,10 @@
1
1
  import { type Result } from "@kaumlaut/pure/result";
2
+ /**
3
+ * Attempts to parse a string as an interger. Returning ok if successful or err if not.
4
+ */
2
5
  export declare function asInt(value: string): Result<number, string>;
6
+ /**
7
+ * Attempts to parse a string as an float. Returning ok if successful or err if not.
8
+ */
3
9
  export declare function asFloat(value: string): Result<number, string>;
4
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parse/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE7D,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ3D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ7D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parse/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ3D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ7D"}
@@ -1,4 +1,7 @@
1
1
  import { err, ok } from "@kaumlaut/pure/result";
2
+ /**
3
+ * Attempts to parse a string as an interger. Returning ok if successful or err if not.
4
+ */
2
5
  export function asInt(value) {
3
6
  const parsed = parseInt(value, 10);
4
7
  if (Number.isNaN(parsed)) {
@@ -6,6 +9,9 @@ export function asInt(value) {
6
9
  }
7
10
  return ok(parsed);
8
11
  }
12
+ /**
13
+ * Attempts to parse a string as an float. Returning ok if successful or err if not.
14
+ */
9
15
  export function asFloat(value) {
10
16
  const parsed = parseFloat(value);
11
17
  if (Number.isNaN(parsed)) {
@@ -1,7 +1,20 @@
1
- type Pipe<IT> = {
1
+ /**
2
+ * Represents a function pipeline
3
+ */
4
+ export type Pipe<IT> = {
2
5
  into: <RT>(func: (input: IT) => RT) => Pipe<RT>;
3
6
  out: () => IT;
4
7
  };
8
+ /**
9
+ * Creates a Pipe that allows you to chain multiple functions using into.
10
+ * Is meant to make larger functions more readable.
11
+ * @example
12
+ * const output = put("3")
13
+ .into(asInt)
14
+ .into(toMaybe)
15
+ .into(withDefault(0))
16
+ .into((input) => input * 3.14)
17
+ .into((input) => input.toPrecision());
18
+ */
5
19
  export declare function put<IT>(data: IT): Pipe<IT>;
6
- export {};
7
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipe/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,EAAE,IAAI;IACd,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,wBAAgB,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAO1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipe/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,EAAE,IAAI;IACrB,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAO1C"}
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Creates a Pipe that allows you to chain multiple functions using into.
3
+ * Is meant to make larger functions more readable.
4
+ * @example
5
+ * const output = put("3")
6
+ .into(asInt)
7
+ .into(toMaybe)
8
+ .into(withDefault(0))
9
+ .into((input) => input * 3.14)
10
+ .into((input) => input.toPrecision());
11
+ */
1
12
  export function put(data) {
2
13
  return {
3
14
  into: (func) => {
@@ -1,19 +1,58 @@
1
1
  import { Maybe } from "@kaumlaut/pure/maybe";
2
+ /**
3
+ * Represents the Result of an action that succeeded and contains a corresponding value.
4
+ */
2
5
  export type Ok<T> = {
3
6
  type: "ok-result";
4
7
  value: T;
5
8
  };
9
+ /**
10
+ * Represents the Result of an action that failed and contains a corresponding error.
11
+ */
6
12
  export type Err<T> = {
7
13
  type: "error-result";
8
14
  error: T;
9
15
  };
16
+ /**
17
+ * Represents the Result of an action that can fail.
18
+ */
19
+ export type Result<T, E> = Ok<T> | Err<E>;
20
+ /**
21
+ * A Guard conforming that the given Result is of type Ok.
22
+ */
10
23
  export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
24
+ /**
25
+ * A Guard conforming that the given Result is of type Err.
26
+ */
11
27
  export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
28
+ /**
29
+ * Creates a Result of type Ok containg the given value.
30
+ */
12
31
  export declare function ok<T>(value: T): Ok<T>;
32
+ /**
33
+ * Creates a Result of type Err containg the given error.
34
+ */
13
35
  export declare function err<E>(error: E): Err<E>;
14
- export type Result<T, E> = Ok<T> | Err<E>;
36
+ /**
37
+ * When Result is Ok: Applies the func function to the contained value and wraps it in Ok again.
38
+ * When Result is Err: Returns the given Result.
39
+ */
15
40
  export declare function map<T, E, R>(func: (value: T) => R): (result: Result<T, E>) => Result<R, E>;
41
+ /**
42
+ * When Result is Ok: Returns the given Result.
43
+ * When Result is Err: Applies the func function to the contained error and wraps it in Err again.
44
+ */
16
45
  export declare function mapErr<T, E, R>(func: (value: E) => R): (result: Result<T, E>) => Result<T, R>;
46
+ /**
47
+ * Unwrap a result to either its contained value or the default value.
48
+ * When Result is Ok: Returns the nested value.
49
+ * When Result is Err: Returns the given default value.
50
+ */
17
51
  export declare function withDefault<T, E>(defaultValue: T): (result: Result<T, E>) => T;
52
+ /**
53
+ * Converts the given Result to a Maybe
54
+ * When Result is Ok: Returns a Just containing the value.
55
+ * When Result is Err: Returns a Nothing.
56
+ */
18
57
  export declare function toMaybe<T, E>(result: Result<T, E>): Maybe<T>;
19
58
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAW,MAAM,sBAAsB,CAAC;AAE5D,MAAM,MAAM,EAAE,CAAC,CAAC,IAAI;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACnB,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,EAAE,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AC,CAAC,EAAE,CAAC,CAAC,CAQxC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,YAAY,EAAE,CAAC,GACd,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAQ7B;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAE5D"}
@@ -1,22 +1,38 @@
1
1
  import { just, nothing } from "@kaumlaut/pure/maybe";
2
+ /**
3
+ * A Guard conforming that the given Result is of type Ok.
4
+ */
2
5
  export function isOk(result) {
3
6
  return result.type === "ok-result";
4
7
  }
8
+ /**
9
+ * A Guard conforming that the given Result is of type Err.
10
+ */
5
11
  export function isErr(result) {
6
12
  return result.type === "error-result";
7
13
  }
14
+ /**
15
+ * Creates a Result of type Ok containg the given value.
16
+ */
8
17
  export function ok(value) {
9
18
  return {
10
19
  type: "ok-result",
11
20
  value,
12
21
  };
13
22
  }
23
+ /**
24
+ * Creates a Result of type Err containg the given error.
25
+ */
14
26
  export function err(error) {
15
27
  return {
16
28
  type: "error-result",
17
29
  error,
18
30
  };
19
31
  }
32
+ /**
33
+ * When Result is Ok: Applies the func function to the contained value and wraps it in Ok again.
34
+ * When Result is Err: Returns the given Result.
35
+ */
20
36
  export function map(func) {
21
37
  return (result) => {
22
38
  if (isOk(result)) {
@@ -25,6 +41,10 @@ export function map(func) {
25
41
  return result;
26
42
  };
27
43
  }
44
+ /**
45
+ * When Result is Ok: Returns the given Result.
46
+ * When Result is Err: Applies the func function to the contained error and wraps it in Err again.
47
+ */
28
48
  export function mapErr(func) {
29
49
  return (result) => {
30
50
  if (isErr(result)) {
@@ -33,6 +53,11 @@ export function mapErr(func) {
33
53
  return result;
34
54
  };
35
55
  }
56
+ /**
57
+ * Unwrap a result to either its contained value or the default value.
58
+ * When Result is Ok: Returns the nested value.
59
+ * When Result is Err: Returns the given default value.
60
+ */
36
61
  export function withDefault(defaultValue) {
37
62
  return (result) => {
38
63
  if (isErr(result)) {
@@ -41,6 +66,11 @@ export function withDefault(defaultValue) {
41
66
  return result.value;
42
67
  };
43
68
  }
69
+ /**
70
+ * Converts the given Result to a Maybe
71
+ * When Result is Ok: Returns a Just containing the value.
72
+ * When Result is Err: Returns a Nothing.
73
+ */
44
74
  export function toMaybe(result) {
45
75
  return isOk(result) ? just(result.value) : nothing();
46
76
  }
@@ -1,18 +1,17 @@
1
1
  import { Guard } from "@kaumlaut/pure/guard";
2
2
  import { ReceiveEffectResult, Effect } from "@kaumlaut/pure/runtime/effect";
3
3
  import { Message } from "@kaumlaut/pure/runtime";
4
- type HttpError = {
4
+ export type HttpError = {
5
5
  code: number;
6
6
  message: string;
7
7
  };
8
- type MalformedPayloadError = {
8
+ export type MalformedPayloadError = {
9
9
  message: string;
10
10
  };
11
- type FetchError = HttpError | MalformedPayloadError;
11
+ export type FetchError = HttpError | MalformedPayloadError;
12
12
  export declare function isNotFound(error: FetchError): boolean;
13
13
  export declare function isHttp(error: FetchError): error is HttpError;
14
14
  export declare function isClient(error: FetchError): boolean;
15
15
  export declare function isServer(error: FetchError): boolean;
16
16
  export declare function fetchJson<T, M extends Message>(url: string, headers: [string, string][], method: string, guard: Guard<T>, receiver: ReceiveEffectResult<T, FetchError, M>): Effect<M>;
17
- export {};
18
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/effect/fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EACL,mBAAmB,EACnB,MAAM,EAEP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,KAAK,SAAS,GAAG;IACf,IAAI,EA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;AAE3D,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAErD;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,IAAI,SAAS,CAK5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAEnD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAEnD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAC5C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,GAC9C,MAAM,CAAC,CAAC,CAAC,CA4CX"}
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Returns the given value.
3
+ */
1
4
  export declare function id<T>(value: T): T;
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEjC"}
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"}
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Returns the given value.
3
+ */
1
4
  export function id(value) {
2
5
  return value;
3
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaumlaut/pure",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
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",
@@ -23,18 +23,18 @@
23
23
  "lint": "eslint -c eslint.config.js --fix",
24
24
  "format": "prettier . --write",
25
25
  "test": "vitest",
26
- "release": "npm run build && npm publish --access public"
26
+ "release": "npm run docs && npm run build && npm publish --access public"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@eslint/js": "^9.22.0",
30
- "@types/node": "^22.13.10",
30
+ "@types/node": "^24.3.0",
31
31
  "eslint": "^9.22.0",
32
32
  "globals": "^16.0.0",
33
- "prettier": "3.5.3",
34
- "typedoc": "^0.27.9",
35
- "typedoc-plugin-markdown": "^4.4.2",
33
+ "prettier": "3.6.2",
34
+ "typedoc": "^0.28.12",
35
+ "typedoc-plugin-markdown": "^4.8.1",
36
36
  "typescript": "^5.8.2",
37
37
  "typescript-eslint": "^8.26.1",
38
38
  "vitest": "^3.0.8"
39
39
  }
40
- }
40
+ }