@axman/res 0.0.2 → 0.0.4

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