@axman/res 0.0.4 → 0.0.6

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/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e,r){const[l,u]=e;return u!==null?r.err(u):r.ok(l)}function o(e){return[e,null]}function n(e){return[null,e]}function c(e){return t(e,{ok:r=>r,err:r=>{throw r}})}function i(e){try{return o(e())}catch(r){return r instanceof Error?n(r):n(new Error(String(r)))}}const a=Object.freeze(Object.defineProperty({__proto__:null,err:n,match:t,ok:o,unwrap:c,wrap:i},Symbol.toStringTag,{value:"Module"}));exports.err=n;exports.match=t;exports.ok=o;exports.res=a;exports.unwrap=c;exports.wrap=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(n,r){const[t,c]=n;return c!==null?r.err(c):r.ok(t)}function o(n){return[n,null]}function e(n){return[null,n]}function i(n){return u(n,{ok:r=>r,err:r=>{throw r}})}function l(n){try{const r=n();return r instanceof Promise?r.then(t=>o(t)).catch(t=>t instanceof Error?e(t):e(new Error(String(t)))):o(r)}catch(r){return r instanceof Error?e(r):e(new Error(String(r)))}}const a=Object.freeze(Object.defineProperty({__proto__:null,err:e,match:u,ok:o,unwrap:i,wrap:l},Symbol.toStringTag,{value:"Module"}));exports.err=e;exports.match=u;exports.ok=o;exports.res=a;exports.unwrap=i;exports.wrap=l;
package/dist/index.es.js CHANGED
@@ -1,41 +1,42 @@
1
- function o(n, r) {
2
- const [c, t] = n;
3
- return t !== null ? r.err(t) : r.ok(c);
1
+ function c(n, r) {
2
+ const [t, u] = n;
3
+ return u !== null ? r.err(u) : r.ok(t);
4
4
  }
5
- function u(n) {
5
+ function o(n) {
6
6
  return [n, null];
7
7
  }
8
8
  function e(n) {
9
9
  return [null, n];
10
10
  }
11
11
  function i(n) {
12
- return o(n, {
12
+ return c(n, {
13
13
  ok: (r) => r,
14
14
  err: (r) => {
15
15
  throw r;
16
16
  }
17
17
  });
18
18
  }
19
- function l(n) {
19
+ function f(n) {
20
20
  try {
21
- return u(n());
21
+ const r = n();
22
+ return r instanceof Promise ? r.then((t) => o(t)).catch((t) => t instanceof Error ? e(t) : e(new Error(String(t)))) : o(r);
22
23
  } catch (r) {
23
24
  return r instanceof Error ? e(r) : e(new Error(String(r)));
24
25
  }
25
26
  }
26
- const f = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27
+ const l = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27
28
  __proto__: null,
28
29
  err: e,
29
- match: o,
30
- ok: u,
30
+ match: c,
31
+ ok: o,
31
32
  unwrap: i,
32
- wrap: l
33
+ wrap: f
33
34
  }, Symbol.toStringTag, { value: "Module" }));
34
35
  export {
35
36
  e as err,
36
- o as match,
37
- u as ok,
38
- f as res,
37
+ c as match,
38
+ o as ok,
39
+ l as res,
39
40
  i as unwrap,
40
- l as wrap
41
+ f as wrap
41
42
  };
package/dist/res.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type Ok<T> = [T, null];
2
2
  export type Err = [null, Error];
3
3
  export type Res<T> = Ok<T> | Err;
4
+ export declare function ok(): Ok<void>;
4
5
  export declare function ok<T>(value: T): Ok<T>;
5
6
  export declare function err(error: Error): Err;
package/dist/wrap.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Res } from './res';
2
+ export declare function wrap<T>(fn: () => Promise<T>): Promise<Res<T>>;
2
3
  export declare function wrap<T>(fn: () => T): Res<T>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axman/res",
3
3
  "author": "akhmanov",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "Go style Result for TypeScript",
6
6
  "license": "MIT",
7
7
  "private": false,