resumon 2.1.0 → 2.1.2

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
@@ -17,9 +17,6 @@
17
17
  <a href="https://opensource.org/licenses/MIT">
18
18
  <img alt="MIT" src="https://img.shields.io/npm/l/resumon?color=%234DC71F">
19
19
  </a>
20
- <a href="https://bundlephobia.com/package/resumon">
21
- <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/resumon">
22
- </a>
23
20
  </p>
24
21
 
25
22
  ## Installation
@@ -0,0 +1,73 @@
1
+ //#region src/result.d.ts
2
+ interface Result<D, E> extends Succeedable<D>, Failable<E> {
3
+ readonly isOk: boolean;
4
+ readonly isError: boolean;
5
+ andThen: <T>(map: (data: D) => Result<T, E>) => Result<T, E>;
6
+ map: <T>(map: (data: D) => T) => Result<T, E>;
7
+ mapError: <U>(map: (error: E) => U) => Result<D, U>;
8
+ }
9
+ interface Succeedable<D> {
10
+ get: () => D;
11
+ getOrElse: (other: D) => D;
12
+ getOrNull: () => D | null;
13
+ getOrUndefined: () => D | undefined;
14
+ }
15
+ interface Succeeded<D> extends Succeedable<D> {
16
+ getOrElse: () => D;
17
+ getOrNull: () => D;
18
+ getOrUndefined: () => D;
19
+ }
20
+ interface Failable<E> {
21
+ getError: () => E;
22
+ getErrorOrElse: (other: E) => E;
23
+ getErrorOrNull: () => E | null;
24
+ getErrorOrUndefined: () => E | undefined;
25
+ }
26
+ interface Failed<E> extends Failable<E> {
27
+ getErrorOrElse: () => E;
28
+ getErrorOrNull: () => E;
29
+ getErrorOrUndefined: () => E;
30
+ }
31
+ declare class IllegalStateError extends Error {}
32
+ //#endregion
33
+ //#region src/err.d.ts
34
+ declare class Err<D, E> implements Result<D, E>, Failed<E> {
35
+ readonly isOk = false;
36
+ readonly isError = true;
37
+ private readonly error;
38
+ constructor(error: E);
39
+ get(): D;
40
+ getOrElse(other: D): D;
41
+ getOrNull(): null;
42
+ getOrUndefined(): undefined;
43
+ getError(): E;
44
+ getErrorOrElse(): E;
45
+ getErrorOrNull(): E;
46
+ getErrorOrUndefined(): E;
47
+ andThen<T>(): Result<T, E>;
48
+ map<T>(): Result<T, E>;
49
+ mapError<T, U>(map: (error: E) => U): Result<T, U>;
50
+ }
51
+ declare function err<D, E>(error: E): Result<D, E>;
52
+ //#endregion
53
+ //#region src/ok.d.ts
54
+ declare class Ok<D, E> implements Result<D, E>, Succeeded<D> {
55
+ readonly isOk = true;
56
+ readonly isError = false;
57
+ private readonly data;
58
+ constructor(data: D);
59
+ get(): D;
60
+ getOrElse(): D;
61
+ getOrNull(): D;
62
+ getOrUndefined(): D;
63
+ getError(): E;
64
+ getErrorOrElse(other: E): E;
65
+ getErrorOrNull(): null;
66
+ getErrorOrUndefined(): undefined;
67
+ andThen<T>(map: (data: D) => Result<T, E>): Result<T, E>;
68
+ map<T>(map: (data: D) => T): Result<T, E>;
69
+ mapError<U>(): Result<D, U>;
70
+ }
71
+ declare function ok<D, E>(data: D): Result<D, E>;
72
+ //#endregion
73
+ export { Err, Failable, Failed, IllegalStateError, Ok, Result, Succeedable, Succeeded, err, ok };
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ //#region src/result.ts
2
+ var IllegalStateError = class extends Error {};
3
+
4
+ //#endregion
5
+ //#region src/err.ts
6
+ var Err = class Err {
7
+ isOk = false;
8
+ isError = true;
9
+ error;
10
+ constructor(error) {
11
+ this.error = error;
12
+ }
13
+ get() {
14
+ throw new IllegalStateError("Cannot get data or Err");
15
+ }
16
+ getOrElse(other) {
17
+ return other;
18
+ }
19
+ getOrNull() {
20
+ return null;
21
+ }
22
+ getOrUndefined() {}
23
+ getError() {
24
+ return this.error;
25
+ }
26
+ getErrorOrElse() {
27
+ return this.error;
28
+ }
29
+ getErrorOrNull() {
30
+ return this.error;
31
+ }
32
+ getErrorOrUndefined() {
33
+ return this.error;
34
+ }
35
+ andThen() {
36
+ return this;
37
+ }
38
+ map() {
39
+ return this;
40
+ }
41
+ mapError(map) {
42
+ return new Err(map(this.error));
43
+ }
44
+ };
45
+ function err(error) {
46
+ return new Err(error);
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/ok.ts
51
+ var Ok = class Ok {
52
+ isOk = true;
53
+ isError = false;
54
+ data;
55
+ constructor(data) {
56
+ this.data = data;
57
+ }
58
+ get() {
59
+ return this.data;
60
+ }
61
+ getOrElse() {
62
+ return this.data;
63
+ }
64
+ getOrNull() {
65
+ return this.data;
66
+ }
67
+ getOrUndefined() {
68
+ return this.data;
69
+ }
70
+ getError() {
71
+ throw new IllegalStateError("Cannot get error of Ok");
72
+ }
73
+ getErrorOrElse(other) {
74
+ return other;
75
+ }
76
+ getErrorOrNull() {
77
+ return null;
78
+ }
79
+ getErrorOrUndefined() {}
80
+ andThen(map) {
81
+ return map(this.data);
82
+ }
83
+ map(map) {
84
+ return new Ok(map(this.data));
85
+ }
86
+ mapError() {
87
+ return this;
88
+ }
89
+ };
90
+ function ok(data) {
91
+ return new Ok(data);
92
+ }
93
+
94
+ //#endregion
95
+ export { Err, IllegalStateError, Ok, err, ok };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "resumon",
3
3
  "type": "module",
4
- "version": "2.1.0",
4
+ "version": "2.1.2",
5
5
  "description": "A tiny TypeScript result monad.",
6
6
  "author": {
7
7
  "name": "Jan Müller",
@@ -26,31 +26,29 @@
26
26
  "exports": {
27
27
  ".": {
28
28
  "import": {
29
- "types": "./dist/types/index.d.mts",
30
- "default": "./dist/index.mjs"
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
31
  }
32
32
  }
33
33
  },
34
- "types": "dist/types/index.d.mts",
34
+ "types": "dist/index.d.ts",
35
35
  "files": [
36
36
  "dist"
37
37
  ],
38
38
  "devDependencies": {
39
- "@types/node": "22.13.8",
40
- "@vue/component-compiler-utils": "3.3.0",
41
- "typescript": "5.8.2",
42
- "vite": "6.2.0",
43
- "@yeger/tsconfig": "2.1.0",
44
- "vite-plugin-lib": "2.1.6"
39
+ "tsdown": "0.15.11",
40
+ "typescript": "5.9.3",
41
+ "@yeger/tsconfig": "2.1.1",
42
+ "@yeger/vitest-utils": "1.0.0"
45
43
  },
46
44
  "publishConfig": {
47
45
  "access": "public"
48
46
  },
49
47
  "scripts": {
50
- "build": "vite build",
48
+ "build": "tsdown",
51
49
  "check:publish": "publint run --strict",
52
50
  "check:tsc": "tsc",
53
- "dev": "vite build --watch",
51
+ "dev": "tsdown --watch",
54
52
  "lint": "yeger-lint",
55
53
  "test": "vitest"
56
54
  }
package/dist/index.mjs DELETED
@@ -1,98 +0,0 @@
1
- var a = Object.defineProperty;
2
- var i = (t, r, n) => r in t ? a(t, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[r] = n;
3
- var e = (t, r, n) => i(t, typeof r != "symbol" ? r + "" : r, n);
4
- class u extends Error {
5
- }
6
- class o {
7
- constructor(r) {
8
- e(this, "isOk", !1);
9
- e(this, "isError", !0);
10
- e(this, "error");
11
- this.error = r;
12
- }
13
- get() {
14
- throw new u("Cannot get data or Err");
15
- }
16
- getOrElse(r) {
17
- return r;
18
- }
19
- getOrNull() {
20
- return null;
21
- }
22
- getOrUndefined() {
23
- }
24
- getError() {
25
- return this.error;
26
- }
27
- getErrorOrElse() {
28
- return this.error;
29
- }
30
- getErrorOrNull() {
31
- return this.error;
32
- }
33
- getErrorOrUndefined() {
34
- return this.error;
35
- }
36
- andThen() {
37
- return this;
38
- }
39
- map() {
40
- return this;
41
- }
42
- mapError(r) {
43
- return new o(r(this.error));
44
- }
45
- }
46
- function d(t) {
47
- return new o(t);
48
- }
49
- class s {
50
- constructor(r) {
51
- e(this, "isOk", !0);
52
- e(this, "isError", !1);
53
- e(this, "data");
54
- this.data = r;
55
- }
56
- get() {
57
- return this.data;
58
- }
59
- getOrElse() {
60
- return this.data;
61
- }
62
- getOrNull() {
63
- return this.data;
64
- }
65
- getOrUndefined() {
66
- return this.data;
67
- }
68
- getError() {
69
- throw new u("Cannot get error of Ok");
70
- }
71
- getErrorOrElse(r) {
72
- return r;
73
- }
74
- getErrorOrNull() {
75
- return null;
76
- }
77
- getErrorOrUndefined() {
78
- }
79
- andThen(r) {
80
- return r(this.data);
81
- }
82
- map(r) {
83
- return new s(r(this.data));
84
- }
85
- mapError() {
86
- return this;
87
- }
88
- }
89
- function h(t) {
90
- return new s(t);
91
- }
92
- export {
93
- o as Err,
94
- u as IllegalStateError,
95
- s as Ok,
96
- d as err,
97
- h as ok
98
- };
@@ -1,19 +0,0 @@
1
- import { Failed, Result } from './result.mjs';
2
- export declare class Err<D, E> implements Result<D, E>, Failed<E> {
3
- readonly isOk = false;
4
- readonly isError = true;
5
- private readonly error;
6
- constructor(error: E);
7
- get(): D;
8
- getOrElse(other: D): D;
9
- getOrNull(): null;
10
- getOrUndefined(): undefined;
11
- getError(): E;
12
- getErrorOrElse(): E;
13
- getErrorOrNull(): E;
14
- getErrorOrUndefined(): E;
15
- andThen<T>(): Result<T, E>;
16
- map<T>(): Result<T, E>;
17
- mapError<T, U>(map: (error: E) => U): Result<T, U>;
18
- }
19
- export declare function err<D, E>(error: E): Result<D, E>;
@@ -1,3 +0,0 @@
1
- export * from './err.mjs';
2
- export * from './ok.mjs';
3
- export * from './result.mjs';
@@ -1,19 +0,0 @@
1
- import { Result, Succeeded } from './result.mjs';
2
- export declare class Ok<D, E> implements Result<D, E>, Succeeded<D> {
3
- readonly isOk = true;
4
- readonly isError = false;
5
- private readonly data;
6
- constructor(data: D);
7
- get(): D;
8
- getOrElse(): D;
9
- getOrNull(): D;
10
- getOrUndefined(): D;
11
- getError(): E;
12
- getErrorOrElse(other: E): E;
13
- getErrorOrNull(): null;
14
- getErrorOrUndefined(): undefined;
15
- andThen<T>(map: (data: D) => Result<T, E>): Result<T, E>;
16
- map<T>(map: (data: D) => T): Result<T, E>;
17
- mapError<U>(): Result<D, U>;
18
- }
19
- export declare function ok<D, E>(data: D): Result<D, E>;
@@ -1,31 +0,0 @@
1
- export interface Result<D, E> extends Succeedable<D>, Failable<E> {
2
- readonly isOk: boolean;
3
- readonly isError: boolean;
4
- andThen: <T>(map: (data: D) => Result<T, E>) => Result<T, E>;
5
- map: <T>(map: (data: D) => T) => Result<T, E>;
6
- mapError: <U>(map: (error: E) => U) => Result<D, U>;
7
- }
8
- export interface Succeedable<D> {
9
- get: () => D;
10
- getOrElse: (other: D) => D;
11
- getOrNull: () => D | null;
12
- getOrUndefined: () => D | undefined;
13
- }
14
- export interface Succeeded<D> extends Succeedable<D> {
15
- getOrElse: () => D;
16
- getOrNull: () => D;
17
- getOrUndefined: () => D;
18
- }
19
- export interface Failable<E> {
20
- getError: () => E;
21
- getErrorOrElse: (other: E) => E;
22
- getErrorOrNull: () => E | null;
23
- getErrorOrUndefined: () => E | undefined;
24
- }
25
- export interface Failed<E> extends Failable<E> {
26
- getErrorOrElse: () => E;
27
- getErrorOrNull: () => E;
28
- getErrorOrUndefined: () => E;
29
- }
30
- export declare class IllegalStateError extends Error {
31
- }