@tempots/std 0.11.0 → 0.13.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/validation.d.ts CHANGED
@@ -1,24 +1,92 @@
1
1
  import { Result } from './result';
2
2
 
3
+ /**
4
+ * Represents a valid result.
5
+ * @public
6
+ */
3
7
  export interface Valid {
4
8
  type: 'valid';
5
9
  }
10
+ /**
11
+ * Represents an invalid value with an associated error.
12
+ * @typeParam E - The type of the error.
13
+ * @public
14
+ */
6
15
  export interface Invalid<E> {
7
16
  type: 'invalid';
8
17
  error: E;
9
18
  }
19
+ /**
20
+ * Represents a type that can either be `Valid` or `Invalid`.
21
+ * @typeParam E - The type of the error associated with an `Invalid` value.
22
+ * @public
23
+ */
10
24
  export type Validation<E> = Valid | Invalid<E>;
25
+ /**
26
+ * Represents a promise that resolves to a `Validation` object.
27
+ * @typeParam E - The type of the error value in the `Validation` object.
28
+ * @public
29
+ */
11
30
  export type PromiseValidation<E> = PromiseLike<Validation<E>>;
31
+ /**
32
+ * Utility functions for working with `Validation` types.
33
+ * @public
34
+ */
12
35
  export declare const Validation: {
36
+ /**
37
+ * Creates a valid `Validation`.
38
+ * @returns A `Validation` that is `Valid`.
39
+ */
13
40
  valid: {
14
41
  type: "valid";
15
42
  };
43
+ /**
44
+ * Creates an invalid `Validation`.
45
+ * @param error - The error associated with the invalid value.
46
+ * @returns A `Validation` that is `Invalid`.
47
+ */
16
48
  invalid<E>(error: E): Validation<E>;
49
+ /**
50
+ * Checks if a `Validation` is `Valid`.
51
+ * @param r - The `Validation` to check.
52
+ * @returns `true` if the `Validation` is `Valid`, otherwise `false`.
53
+ */
17
54
  isValid<E>(r: Validation<E>): r is Valid;
55
+ /**
56
+ * Checks if a `Validation` is `Invalid`.
57
+ * @param r - The `Validation` to check.
58
+ * @returns `true` if the `Validation` is `Invalid`, otherwise `false`.
59
+ */
18
60
  isInvalid<E>(r: Validation<E>): r is Invalid<E>;
19
- cmatch: <V, E>(valid: () => V, invalid: (error: E) => V) => (r: Validation<E>) => V;
61
+ /**
62
+ * Maps the value of a `Validation` to a new value.
63
+ * @param r - The `Validation` to map.
64
+ * @param valid - The mapping function for a valid value.
65
+ * @param invalid - The mapping function for an invalid value.
66
+ * @returns The mapped value.
67
+ */
20
68
  match: <V, E>(r: Validation<E>, valid: () => V, invalid: (error: E) => V) => V;
21
- toResult: <T, E>(value: T) => ((validation: Validation<E>) => Result<T, E>);
22
- whenValid: <E>(apply: () => void) => (r: Validation<E>) => Validation<E>;
23
- whenInvalid: <E>(apply: (e: E) => void) => (r: Validation<E>) => Validation<E>;
69
+ /**
70
+ * Maps the value of a `Validation` to a new `Validation`.
71
+ * @param validation - The `Validation` to map.
72
+ * @param value - The value to map.
73
+ * @returns A new `Validation` with the mapped value.
74
+ */
75
+ toResult: <T, E>(validation: Validation<E>, value: T) => Result<T, E>;
76
+ /**
77
+ * Execute a function when the `Validation` is valid.
78
+ *
79
+ * @param r - The `Validation` to check.
80
+ * @param apply - The function to execute when the `Validation` is valid.
81
+ * @returns The `Validation` object.
82
+ */
83
+ whenValid: <E>(r: Validation<E>, apply: () => void) => Validation<E>;
84
+ /**
85
+ * Execute a function when the `Validation` is invalid.
86
+ *
87
+ * @param r - The `Validation` to check.
88
+ * @param apply - The function to execute when the `Validation` is invalid.
89
+ * @returns The `Validation` object.
90
+ */
91
+ whenInvalid: <E>(r: Validation<E>, apply: (e: E) => void) => Validation<E>;
24
92
  };
package/validation.js CHANGED
@@ -1,25 +1,4 @@
1
- import { Result as a } from "./result.js";
2
- const r = {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- valid: { type: "valid" },
5
- invalid(i) {
6
- return { type: "invalid", error: i };
7
- },
8
- isValid(i) {
9
- return i.type === "valid";
10
- },
11
- isInvalid(i) {
12
- return i.type === "invalid";
13
- },
14
- cmatch: (i, e) => (t) => r.isValid(t) ? i() : e(t.error),
15
- match: (i, e, t) => r.isValid(i) ? e() : t(i.error),
16
- toResult: (i) => r.cmatch(
17
- () => a.success(i),
18
- (e) => a.failure(e)
19
- ),
20
- whenValid: (i) => (e) => (r.isValid(e) && i(), e),
21
- whenInvalid: (i) => (e) => (r.isInvalid(e) && i(e.error), e)
22
- };
1
+ import { V as i } from "./result-Czm7RKNP.js";
23
2
  export {
24
- r as Validation
3
+ i as Validation
25
4
  };
package/maybe.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={nothing:void 0,just:t=>t,isNothing:t=>t==null,isJust:t=>t!=null};exports.Maybe=e;
package/maybe.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export type Maybe<T> = Just<T> | Nothing;
2
- export type Nothing = undefined;
3
- export type Just<T> = NonNullable<T>;
4
- export declare const Maybe: {
5
- nothing: Maybe<never>;
6
- just: <T>(value: T) => Maybe<T>;
7
- isNothing: <T>(maybe: Maybe<T>) => maybe is Nothing;
8
- isJust: <T>(maybe: Maybe<T>) => maybe is Just<T>;
9
- };
package/maybe.js DELETED
@@ -1,9 +0,0 @@
1
- const t = {
2
- nothing: void 0,
3
- just: (n) => n,
4
- isNothing: (n) => n == null,
5
- isJust: (n) => n != null
6
- };
7
- export {
8
- t as Maybe
9
- };