@axman/res 0.0.1 → 0.0.3

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