@terrygonguet/utils 0.0.5 → 0.0.7

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,8 +1,8 @@
1
- var g = Object.defineProperty;
2
- var p = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var f = (t, e, r) => (p(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- const a = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", h = "@terrygonguet/utils/functional/maybe/None";
5
- function i(t) {
1
+ var p = Object.defineProperty;
2
+ var S = (t, e, r) => e in t ? p(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var f = (t, e, r) => (S(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ const s = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", h = "@terrygonguet/utils/functional/maybe/None";
5
+ function u(t) {
6
6
  return Object.create(
7
7
  {
8
8
  isSome: () => !0,
@@ -11,56 +11,56 @@ function i(t) {
11
11
  return this.value;
12
12
  },
13
13
  map(e) {
14
- return i(e(this.value));
14
+ return u(e(this.value));
15
15
  },
16
16
  flatMap(e) {
17
17
  return e(this.value);
18
18
  },
19
19
  toJSON() {
20
- return { $_kind: a, $_variant: _, value: this.value };
20
+ return { $_kind: s, $_variant: _, value: this.value };
21
21
  }
22
22
  },
23
23
  {
24
- $_kind: { value: a, enumerable: !1, writable: !1 },
24
+ $_kind: { value: s, enumerable: !1, writable: !1 },
25
25
  $_variant: { value: _, enumerable: !1, writable: !1 },
26
26
  value: { value: t, writable: !1 }
27
27
  }
28
28
  );
29
29
  }
30
- const n = Object.create(
30
+ const a = Object.create(
31
31
  {
32
32
  isSome: () => !1,
33
33
  isNone: () => !0,
34
34
  orDefault: $,
35
- map: () => n,
36
- flatMap: () => n,
37
- toJSON: () => ({ $_kind: a, $_variant: h })
35
+ map: () => a,
36
+ flatMap: () => a,
37
+ toJSON: () => ({ $_kind: s, $_variant: h })
38
38
  },
39
39
  {
40
- $_kind: { value: a, enumerable: !1, writable: !1 },
40
+ $_kind: { value: s, enumerable: !1, writable: !1 },
41
41
  $_variant: { value: h, enumerable: !1, writable: !1 }
42
42
  }
43
- ), k = {
44
- Some: i,
45
- None: n,
43
+ ), y = {
44
+ Some: u,
45
+ None: a,
46
46
  from(t) {
47
47
  switch (t) {
48
48
  case null:
49
49
  case void 0:
50
- return n;
50
+ return a;
51
51
  default:
52
- return i(t);
52
+ return u(t);
53
53
  }
54
54
  },
55
55
  JSONReviver(t, e) {
56
- if ((e == null ? void 0 : e.$_kind) == a) {
56
+ if ((e == null ? void 0 : e.$_kind) == s) {
57
57
  const r = e == null ? void 0 : e.$_variant;
58
- return r == _ ? i(e == null ? void 0 : e.value) : r == h ? n : e;
58
+ return r == _ ? u(e == null ? void 0 : e.value) : r == h ? a : e;
59
59
  } else
60
60
  return e;
61
61
  }
62
- }, s = "@terrygonguet/utils/functional/result", u = "@terrygonguet/utils/functional/result/Success", b = "@terrygonguet/utils/functional/result/Failure";
63
- function l(t) {
62
+ }, i = "@terrygonguet/utils/functional/result", o = "@terrygonguet/utils/functional/result/Success", b = "@terrygonguet/utils/functional/result/Failure";
63
+ function c(t) {
64
64
  return Object.create(
65
65
  {
66
66
  isSuccess: () => !0,
@@ -69,18 +69,18 @@ function l(t) {
69
69
  return e(this.value);
70
70
  },
71
71
  map(e) {
72
- return l(e(this.value));
72
+ return c(e(this.value));
73
73
  },
74
74
  flatMap(e) {
75
75
  return e(this.value);
76
76
  },
77
77
  toJSON() {
78
- return { $_kind: s, $_variant: u, value: this.value };
78
+ return { $_kind: i, $_variant: o, value: this.value };
79
79
  }
80
80
  },
81
81
  {
82
- $_kind: { value: s, enumerable: !1, writable: !1 },
83
- $_variant: { value: u, enumerable: !1, writable: !1 },
82
+ $_kind: { value: i, enumerable: !1, writable: !1 },
83
+ $_variant: { value: o, enumerable: !1, writable: !1 },
84
84
  value: { value: t, writable: !1 }
85
85
  }
86
86
  );
@@ -100,31 +100,31 @@ function m(t) {
100
100
  return this;
101
101
  },
102
102
  toJSON() {
103
- return { $_kind: s, $_variant: b, reason: this.reason };
103
+ return { $_kind: i, $_variant: b, reason: this.reason };
104
104
  }
105
105
  },
106
106
  {
107
- $_kind: { value: s, enumerable: !1, writable: !1 },
108
- $_variant: { value: u, enumerable: !1, writable: !1 },
107
+ $_kind: { value: i, enumerable: !1, writable: !1 },
108
+ $_variant: { value: o, enumerable: !1, writable: !1 },
109
109
  reason: { value: t, writable: !1 }
110
110
  }
111
111
  );
112
112
  }
113
- const F = {
114
- Success: l,
113
+ const v = {
114
+ Success: c,
115
115
  Failure: m,
116
116
  try(t) {
117
- return new S(t);
117
+ return new d(t);
118
118
  },
119
119
  JSONReviver(t, e) {
120
- if ((e == null ? void 0 : e.$_kind) == s) {
120
+ if ((e == null ? void 0 : e.$_kind) == i) {
121
121
  const r = e == null ? void 0 : e.$_variant;
122
- return r == u ? l(e == null ? void 0 : e.value) : r == b ? m(e == null ? void 0 : e.reason) : e;
122
+ return r == o ? c(e == null ? void 0 : e.value) : r == b ? m(e == null ? void 0 : e.reason) : e;
123
123
  } else
124
124
  return e;
125
125
  }
126
126
  };
127
- class S {
127
+ class d {
128
128
  constructor(e) {
129
129
  f(this, "tryFn");
130
130
  f(this, "catchFn");
@@ -133,33 +133,35 @@ class S {
133
133
  catch(e) {
134
134
  return this.catchFn = e, this;
135
135
  }
136
- exec() {
136
+ exec(e) {
137
137
  try {
138
- return l(this.tryFn());
139
- } catch (e) {
140
- return m(this.catchFn(e));
138
+ const r = c(this.tryFn());
139
+ return e == null || e(r), r;
140
+ } catch (r) {
141
+ const n = m(this.catchFn(r));
142
+ return e == null || e(n), n;
141
143
  }
142
144
  }
143
145
  }
144
- var v = d;
145
- function d(t, e) {
146
+ var N = w;
147
+ function w(t, e) {
146
148
  if (!arguments.length)
147
149
  throw new Error(
148
150
  "expected at least one (and probably more) function arguments"
149
151
  );
150
152
  var r = arguments;
151
153
  return function() {
152
- for (var o = r[0].apply(this, arguments), y = r.length, c = 1; c < y; c++)
153
- o = r[c].call(this, o);
154
- return o;
154
+ for (var n = r[0].apply(this, arguments), g = r.length, l = 1; l < g; l++)
155
+ n = r[l].call(this, n);
156
+ return n;
155
157
  };
156
158
  }
157
159
  function $(t) {
158
160
  return t;
159
161
  }
160
162
  export {
161
- k as Maybe,
162
- F as Result,
163
- v as compose,
163
+ y as Maybe,
164
+ v as Result,
165
+ N as compose,
164
166
  $ as identity
165
167
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrygonguet/utils",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -23,12 +23,12 @@
23
23
  ],
24
24
  "exports": {
25
25
  ".": {
26
- "types": "./types/main.js",
27
- "import": "./dist/main.d.ts"
26
+ "types": "./types/main.d.ts",
27
+ "import": "./dist/main.js"
28
28
  },
29
29
  "./async": {
30
- "types": "./types/async.js",
31
- "import": "./dist/async.d.ts"
30
+ "types": "./types/async.d.ts",
31
+ "import": "./dist/async.js"
32
32
  },
33
33
  "./functional": {
34
34
  "types": "./types/functional/index.d.ts",
@@ -99,11 +99,15 @@ class TryCatch<S, F> {
99
99
  return this
100
100
  }
101
101
 
102
- exec(): Result<S, F> {
102
+ exec(finallyFn?: (result: Result<S, F>) => void): Result<S, F> {
103
103
  try {
104
- return Success<S, F>(this.tryFn())
104
+ const result = Success<S, F>(this.tryFn())
105
+ finallyFn?.(result)
106
+ return result
105
107
  } catch (error) {
106
- return Failure<S, F>(this.catchFn(error))
108
+ const result = Failure<S, F>(this.catchFn(error))
109
+ finallyFn?.(result)
110
+ return result
107
111
  }
108
112
  }
109
113
  }
@@ -26,6 +26,6 @@ declare class TryCatch<S, F> {
26
26
  catchFn: (err: unknown) => F;
27
27
  constructor(tryFn: () => S);
28
28
  catch(catchFn: (err: unknown) => F): this;
29
- exec(): Result<S, F>;
29
+ exec(finallyFn?: (result: Result<S, F>) => void): Result<S, F>;
30
30
  }
31
31
  export {};