@e280/stz 0.2.30 → 0.2.31

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
@@ -338,22 +338,24 @@ rust-inspired pattern for explicit error handling instead of the usual js yolo v
338
338
  ```
339
339
 
340
340
  #### helpers
341
- - `grab(result)` — get the value, or `undefined`
341
+ - `getOk(result)` — get the value, or `undefined`
342
342
  ```ts
343
- grab(ok(123))
343
+ getOk(ok(123))
344
344
  // 123
345
345
 
346
- grab(err("nope"))
346
+ getOk(err("nope"))
347
347
  // undefined
348
348
  ```
349
- - `need(result)` — get the value, or throw
349
+ - there is also `getErr(result)`
350
+ - `needOk(result)` — get the value, or throw
350
351
  ```ts
351
- need(ok(123))
352
+ needOk(ok(123))
352
353
  // 123
353
354
 
354
- need(err("containment lost"))
355
+ needOk(err("containment lost"))
355
356
  // throws Error("containment lost")
356
357
  ```
358
+ - there is also `needErr(result)`
357
359
 
358
360
 
359
361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/stz",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "description": "everyday ts fns for everything",
5
5
  "license": "MIT",
6
6
  "author": "Chase Moskal <chasemoskal@gmail.com>",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@e280/science": "^0.1.10",
26
- "@types/node": "^25.5.2",
26
+ "@types/node": "^25.6.0",
27
27
  "typescript": "^6.0.2"
28
28
  },
29
29
  "keywords": [
package/s/dig/test.ts CHANGED
@@ -1,12 +1,12 @@
1
1
 
2
2
  import {suite, expect, assert} from "@e280/science"
3
3
  import {dig} from "./dig.js"
4
- import {need} from "../ok/index.js"
4
+ import {needOk} from "../ok/index.js"
5
5
 
6
6
  const check = (t: any, path: (string | number)[]) => ({
7
7
  ok: (value: any) => async() => {
8
8
  const result = dig(t, path)
9
- expect(need(result)).is(value)
9
+ expect(needOk(result)).is(value)
10
10
  },
11
11
  err: (e: any) => async() => {
12
12
  const result = dig(t, path)
@@ -0,0 +1,7 @@
1
+
2
+ export function errorString(error: unknown, fallback = "error"): string {
3
+ if (typeof error === "string") return error
4
+ else if (error instanceof Error) return error.message
5
+ else return fallback
6
+ }
7
+
package/s/index.ts CHANGED
@@ -42,6 +42,7 @@ export * from "./defer.js"
42
42
  export * from "./dispenser.js"
43
43
  export * from "./disposer.js"
44
44
  export * from "./drill.js"
45
+ export * from "./error-string.js"
45
46
  export * from "./escape-regex.js"
46
47
  export * from "./ev.js"
47
48
  export * from "./hat.js"
@@ -0,0 +1,29 @@
1
+
2
+ import {ok} from "./ok.js"
3
+ import {err} from "./err.js"
4
+ import {Result} from "../types/result.js"
5
+
6
+ export function attempt<Value, E = unknown>(fn: () => Value): Result<Value, E> {
7
+ try {
8
+ return ok(fn())
9
+ }
10
+ catch (error) {
11
+ return err(error as E)
12
+ }
13
+ }
14
+
15
+ export async function attemptAsync<Value, E = unknown>(
16
+ input: Promise<Value> | (() => Promise<Value>),
17
+ ): Promise<Result<Value, E>> {
18
+
19
+ try {
20
+ const promise = (typeof input === "function")
21
+ ? input()
22
+ : input
23
+ return ok(await promise)
24
+ }
25
+ catch (error) {
26
+ return err(error as E)
27
+ }
28
+ }
29
+
package/s/ok/fns/err.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type {Err} from "../types/err.js"
3
3
 
4
4
  /** failure */
5
- export function err<E = string>(error: E): Err<E> {
5
+ export function err<E>(error: E): Err<E> {
6
6
  return {ok: false, error}
7
7
  }
8
8
 
@@ -0,0 +1,20 @@
1
+
2
+ import type {Result} from "../types/result.js"
3
+
4
+ /** get value or undefined */
5
+ export function getOk<Value>(result: Result<Value, unknown>): Value | undefined {
6
+ return result.ok
7
+ ? result.value
8
+ : undefined
9
+ }
10
+
11
+ /** get error or undefined */
12
+ export function getErr<E = unknown>(result: Result<unknown, E>): E | undefined {
13
+ return result.ok
14
+ ? undefined
15
+ : result.error
16
+ }
17
+
18
+ /** @deprecated renamed to `getOk` */
19
+ export const grab = getOk
20
+
package/s/ok/fns/need.ts CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  import type {Result} from "../types/result.js"
3
3
 
4
- /** get value or throw error */
5
- export function need<Value, E>(result: Result<Value, E>): Value {
4
+ /** return ok value, otherwise throw error */
5
+ export function needOk<Value, E>(result: Result<Value, E>): Value {
6
6
  if (result.ok)
7
7
  return result.value
8
8
 
@@ -18,3 +18,12 @@ export function need<Value, E>(result: Result<Value, E>): Value {
18
18
  throw new Error("unknown")
19
19
  }
20
20
 
21
+ /** return error, otherwise throw error */
22
+ export function needErr<E>(result: Result<unknown, E>): E {
23
+ if (result.ok) throw new Error("didn't get needed error")
24
+ return result.error
25
+ }
26
+
27
+ /** @deprecated renamed to `needOk` */
28
+ export const need = needOk
29
+
package/s/ok/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
 
2
+ export * from "./fns/attempt.js"
2
3
  export * from "./fns/ok.js"
3
4
  export * from "./fns/err.js"
4
- export * from "./fns/grab.js"
5
+ export * from "./fns/get.js"
5
6
  export * from "./fns/need.js"
6
7
 
7
8
  export * from "./types/ok.js"
package/s/ok/test.ts CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  import {expect, suite, test} from "@e280/science"
3
3
  import {thrown} from "../thrown.js"
4
- import {ok, err, grab, need} from "./index.js"
4
+ import {ok, err, getOk, needOk, attempt, needErr, getErr, attemptAsync} from "./index.js"
5
5
 
6
6
  export default suite({
7
7
  "ok": test(async() => {
@@ -16,31 +16,53 @@ export default suite({
16
16
  expect("value" in err("nope")).is(false)
17
17
  }),
18
18
 
19
- "grab": test(async() => {
20
- expect(grab(ok(123))).is(123)
21
- expect(grab(err("nope"))).is(undefined)
19
+ "getOk": test(async() => {
20
+ expect(getOk(ok(123))).is(123)
21
+ expect(getOk(err("nope"))).is(undefined)
22
22
  }),
23
23
 
24
- "need": test(async() => {
25
- expect(need(ok(123))).is(123)
26
- expect(() => need(err("nope"))).throws()
24
+ "getErr": test(async() => {
25
+ expect(getErr(err("nope"))).is("nope")
26
+ expect(getErr(ok(123))).is(undefined)
27
27
  }),
28
28
 
29
- "need error handling": {
29
+ "needOk": test(async() => {
30
+ expect(needOk(ok(123))).is(123)
31
+ expect(() => needOk(err("nope"))).throws()
32
+ }),
33
+
34
+ "needErr": test(async() => {
35
+ expect(needErr(err("nope"))).is("nope")
36
+ expect(() => needErr(ok(123))).throws()
37
+ }),
38
+
39
+ "attempt": test(async() => {
40
+ expect(needOk(attempt(() => 123))).is(123)
41
+ expect(attempt(() => {throw new Error("rofl")}).ok).is(false)
42
+ expect(needErr<Error>(attempt(() => {throw new Error("rofl")})).message).is("rofl")
43
+ }),
44
+
45
+ "attemptAsync": test(async() => {
46
+ expect(needOk(await attemptAsync(async() => 123))).is(123)
47
+ expect((await attemptAsync(async() => {throw new Error("rofl")})).ok).is(false)
48
+ expect(needErr<Error>(await attemptAsync(async() => {throw new Error("rofl")})).message).is("rofl")
49
+ }),
50
+
51
+ "needOk error handling": {
30
52
  "rethrows errors": test(async() => {
31
53
  const error = new TypeError()
32
- expect(() => need(err(error))).throws(TypeError)
33
- expect(thrown(() => need(err(error)))).is(error)
54
+ expect(() => needOk(err(error))).throws(TypeError)
55
+ expect(thrown(() => needOk(err(error)))).is(error)
34
56
  }),
35
57
 
36
58
  "upgrades strings to errors": test(async() => {
37
- expect(() => need(err("nope"))).throws(Error)
38
- expect(thrown(() => need(err("nope"))).message).is("nope")
59
+ expect(() => needOk(err("nope"))).throws(Error)
60
+ expect(thrown(() => needOk(err("nope"))).message).is("nope")
39
61
  }),
40
62
 
41
63
  "everything else is unknown": test(async() => {
42
- expect(() => need(err({code: 234}))).throws(Error)
43
- expect(thrown(() => need(err({code: 234}))).message).is("unknown")
64
+ expect(() => needOk(err({code: 234}))).throws(Error)
65
+ expect(thrown(() => needOk(err({code: 234}))).message).is("unknown")
44
66
  }),
45
67
  },
46
68
  })
package/x/dig/test.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { suite, expect, assert } from "@e280/science";
2
2
  import { dig } from "./dig.js";
3
- import { need } from "../ok/index.js";
3
+ import { needOk } from "../ok/index.js";
4
4
  const check = (t, path) => ({
5
5
  ok: (value) => async () => {
6
6
  const result = dig(t, path);
7
- expect(need(result)).is(value);
7
+ expect(needOk(result)).is(value);
8
8
  },
9
9
  err: (e) => async () => {
10
10
  const result = dig(t, path);
package/x/dig/test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../../s/dig/test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,eAAe,CAAA;AACnD,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAA;AAEnC,MAAM,KAAK,GAAG,CAAC,CAAM,EAAE,IAAyB,EAAE,EAAE,CAAC,CAAC;IACrD,EAAE,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,IAAG,EAAE;QAC7B,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QAC3B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IACD,GAAG,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,KAAK,IAAG,EAAE;QAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QAC3B,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAClB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC3B,CAAC;CACD,CAAC,CAAA;AAEF,eAAe,KAAK,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC,EAAC,CAAC,EAAE,CAAC,EAAC,EAAE,CAAC,GAAG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AAI,EAAC,EAAE,CAAC,GAAG,CAAC,CAAC;SACjC,EAAE,CAAC,IAAI,CAAC;IAEV,kBAAkB,EAAE,KAAK,CAAC,EAAC,CAAC,EAAE,EAAC,CAAC,EAAE,CAAC,EAAC,EAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SAChD,EAAE,CAAC,CAAC,CAAC;IAEP,iBAAiB,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SACvC,EAAE,CAAC,GAAG,CAAC;IAET,sBAAsB,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;SACxC,GAAG,CAAC,iBAAiB,CAAC;IAExB,2BAA2B,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;SAClD,GAAG,CAAC,iBAAiB,CAAC;IAExB,uBAAuB,EAAE,KAAK,CAAC,EAAC,CAAC,EAAE,CAAC,EAAC,EAAE,CAAC,GAAG,CAAC,CAAC;SAC3C,GAAG,CAAC,WAAW,CAAC;IAElB,uBAAuB,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC7C,GAAG,CAAC,WAAW,CAAC;IAElB,wBAAwB,EAAE,KAAK,CAAC,EAAC,CAAC,EAAE,CAAC,EAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACjD,GAAG,CAAC,iBAAiB,CAAC;IAExB,kBAAkB,EAAE,KAAK,CAAC,EAAC,CAAC,EAAE,EAAE,EAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SAC5C,GAAG,CAAC,WAAW,CAAC;CAClB,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare function errorString(error: unknown, fallback?: string): string;
@@ -0,0 +1,9 @@
1
+ export function errorString(error, fallback = "error") {
2
+ if (typeof error === "string")
3
+ return error;
4
+ else if (error instanceof Error)
5
+ return error.message;
6
+ else
7
+ return fallback;
8
+ }
9
+ //# sourceMappingURL=error-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-string.js","sourceRoot":"","sources":["../s/error-string.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,QAAQ,GAAG,OAAO;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;SACtC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAA;;QAChD,OAAO,QAAQ,CAAA;AACrB,CAAC"}
package/x/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export * from "./defer.js";
35
35
  export * from "./dispenser.js";
36
36
  export * from "./disposer.js";
37
37
  export * from "./drill.js";
38
+ export * from "./error-string.js";
38
39
  export * from "./escape-regex.js";
39
40
  export * from "./ev.js";
40
41
  export * from "./hat.js";
package/x/index.js CHANGED
@@ -35,6 +35,7 @@ export * from "./defer.js";
35
35
  export * from "./dispenser.js";
36
36
  export * from "./disposer.js";
37
37
  export * from "./drill.js";
38
+ export * from "./error-string.js";
38
39
  export * from "./escape-regex.js";
39
40
  export * from "./ev.js";
40
41
  export * from "./hat.js";
package/x/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,iBAAiB,CAA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3B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Result } from "../types/result.js";
2
+ export declare function attempt<Value, E = unknown>(fn: () => Value): Result<Value, E>;
3
+ export declare function attemptAsync<Value, E = unknown>(input: Promise<Value> | (() => Promise<Value>)): Promise<Result<Value, E>>;
@@ -0,0 +1,22 @@
1
+ import { ok } from "./ok.js";
2
+ import { err } from "./err.js";
3
+ export function attempt(fn) {
4
+ try {
5
+ return ok(fn());
6
+ }
7
+ catch (error) {
8
+ return err(error);
9
+ }
10
+ }
11
+ export async function attemptAsync(input) {
12
+ try {
13
+ const promise = (typeof input === "function")
14
+ ? input()
15
+ : input;
16
+ return ok(await promise);
17
+ }
18
+ catch (error) {
19
+ return err(error);
20
+ }
21
+ }
22
+ //# sourceMappingURL=attempt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.js","sourceRoot":"","sources":["../../../s/ok/fns/attempt.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,SAAS,CAAA;AAC1B,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA;AAG5B,MAAM,UAAU,OAAO,CAAqB,EAAe;IAC1D,IAAI,CAAC;QACJ,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,KAAU,CAAC,CAAA;IACvB,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAA8C;IAG/C,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC;YAC5C,CAAC,CAAC,KAAK,EAAE;YACT,CAAC,CAAC,KAAK,CAAA;QACR,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC,CAAA;IACzB,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,KAAU,CAAC,CAAA;IACvB,CAAC;AACF,CAAC"}
package/x/ok/fns/err.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Err } from "../types/err.js";
2
2
  /** failure */
3
- export declare function err<E = string>(error: E): Err<E>;
3
+ export declare function err<E>(error: E): Err<E>;
@@ -1 +1 @@
1
- {"version":3,"file":"err.js","sourceRoot":"","sources":["../../../s/ok/fns/err.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,UAAU,GAAG,CAAa,KAAQ;IACvC,OAAO,EAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAC,CAAA;AAC1B,CAAC"}
1
+ {"version":3,"file":"err.js","sourceRoot":"","sources":["../../../s/ok/fns/err.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,UAAU,GAAG,CAAI,KAAQ;IAC9B,OAAO,EAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAC,CAAA;AAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Result } from "../types/result.js";
2
+ /** get value or undefined */
3
+ export declare function getOk<Value>(result: Result<Value, unknown>): Value | undefined;
4
+ /** get error or undefined */
5
+ export declare function getErr<E = unknown>(result: Result<unknown, E>): E | undefined;
6
+ /** @deprecated renamed to `getOk` */
7
+ export declare const grab: typeof getOk;
@@ -0,0 +1,15 @@
1
+ /** get value or undefined */
2
+ export function getOk(result) {
3
+ return result.ok
4
+ ? result.value
5
+ : undefined;
6
+ }
7
+ /** get error or undefined */
8
+ export function getErr(result) {
9
+ return result.ok
10
+ ? undefined
11
+ : result.error;
12
+ }
13
+ /** @deprecated renamed to `getOk` */
14
+ export const grab = getOk;
15
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../s/ok/fns/get.ts"],"names":[],"mappings":"AAGA,6BAA6B;AAC7B,MAAM,UAAU,KAAK,CAAQ,MAA8B;IAC1D,OAAO,MAAM,CAAC,EAAE;QACf,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,SAAS,CAAA;AACb,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,MAAM,CAAc,MAA0B;IAC7D,OAAO,MAAM,CAAC,EAAE;QACf,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,MAAM,CAAC,KAAK,CAAA;AAChB,CAAC;AAED,qCAAqC;AACrC,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAA"}
@@ -1,3 +1,7 @@
1
1
  import type { Result } from "../types/result.js";
2
- /** get value or throw error */
3
- export declare function need<Value, E>(result: Result<Value, E>): Value;
2
+ /** return ok value, otherwise throw error */
3
+ export declare function needOk<Value, E>(result: Result<Value, E>): Value;
4
+ /** return error, otherwise throw error */
5
+ export declare function needErr<E>(result: Result<unknown, E>): E;
6
+ /** @deprecated renamed to `needOk` */
7
+ export declare const need: typeof needOk;
package/x/ok/fns/need.js CHANGED
@@ -1,5 +1,5 @@
1
- /** get value or throw error */
2
- export function need(result) {
1
+ /** return ok value, otherwise throw error */
2
+ export function needOk(result) {
3
3
  if (result.ok)
4
4
  return result.value;
5
5
  const { error } = result;
@@ -10,4 +10,12 @@ export function need(result) {
10
10
  else
11
11
  throw new Error("unknown");
12
12
  }
13
+ /** return error, otherwise throw error */
14
+ export function needErr(result) {
15
+ if (result.ok)
16
+ throw new Error("didn't get needed error");
17
+ return result.error;
18
+ }
19
+ /** @deprecated renamed to `needOk` */
20
+ export const need = needOk;
13
21
  //# sourceMappingURL=need.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"need.js","sourceRoot":"","sources":["../../../s/ok/fns/need.ts"],"names":[],"mappings":"AAGA,+BAA+B;AAC/B,MAAM,UAAU,IAAI,CAAW,MAAwB;IACtD,IAAI,MAAM,CAAC,EAAE;QACZ,OAAO,MAAM,CAAC,KAAK,CAAA;IAEpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,CAAA;IAEtB,IAAI,KAAK,YAAY,KAAK;QACzB,MAAM,KAAK,CAAA;SAEP,IAAI,OAAO,KAAK,KAAK,QAAQ;QACjC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;;QAGtB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC"}
1
+ {"version":3,"file":"need.js","sourceRoot":"","sources":["../../../s/ok/fns/need.ts"],"names":[],"mappings":"AAGA,6CAA6C;AAC7C,MAAM,UAAU,MAAM,CAAW,MAAwB;IACxD,IAAI,MAAM,CAAC,EAAE;QACZ,OAAO,MAAM,CAAC,KAAK,CAAA;IAEpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,CAAA;IAEtB,IAAI,KAAK,YAAY,KAAK;QACzB,MAAM,KAAK,CAAA;SAEP,IAAI,OAAO,KAAK,KAAK,QAAQ;QACjC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;;QAGtB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,OAAO,CAAI,MAA0B;IACpD,IAAI,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACzD,OAAO,MAAM,CAAC,KAAK,CAAA;AACpB,CAAC;AAED,sCAAsC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA"}
package/x/ok/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ export * from "./fns/attempt.js";
1
2
  export * from "./fns/ok.js";
2
3
  export * from "./fns/err.js";
3
- export * from "./fns/grab.js";
4
+ export * from "./fns/get.js";
4
5
  export * from "./fns/need.js";
5
6
  export * from "./types/ok.js";
6
7
  export * from "./types/err.js";
package/x/ok/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ export * from "./fns/attempt.js";
1
2
  export * from "./fns/ok.js";
2
3
  export * from "./fns/err.js";
3
- export * from "./fns/grab.js";
4
+ export * from "./fns/get.js";
4
5
  export * from "./fns/need.js";
5
6
  export * from "./types/ok.js";
6
7
  export * from "./types/err.js";
package/x/ok/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/ok/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAE7B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/ok/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAE7B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
package/x/ok/test.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  declare const _default: {
2
2
  ok: import("@e280/science").Test;
3
3
  err: import("@e280/science").Test;
4
- grab: import("@e280/science").Test;
5
- need: import("@e280/science").Test;
6
- "need error handling": {
4
+ getOk: import("@e280/science").Test;
5
+ getErr: import("@e280/science").Test;
6
+ needOk: import("@e280/science").Test;
7
+ needErr: import("@e280/science").Test;
8
+ attempt: import("@e280/science").Test;
9
+ attemptAsync: import("@e280/science").Test;
10
+ "needOk error handling": {
7
11
  "rethrows errors": import("@e280/science").Test;
8
12
  "upgrades strings to errors": import("@e280/science").Test;
9
13
  "everything else is unknown": import("@e280/science").Test;
package/x/ok/test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { expect, suite, test } from "@e280/science";
2
2
  import { thrown } from "../thrown.js";
3
- import { ok, err, grab, need } from "./index.js";
3
+ import { ok, err, getOk, needOk, attempt, needErr, getErr, attemptAsync } from "./index.js";
4
4
  export default suite({
5
5
  "ok": test(async () => {
6
6
  expect(ok(123).ok).is(true);
@@ -12,27 +12,45 @@ export default suite({
12
12
  expect(err("nope").error).is("nope");
13
13
  expect("value" in err("nope")).is(false);
14
14
  }),
15
- "grab": test(async () => {
16
- expect(grab(ok(123))).is(123);
17
- expect(grab(err("nope"))).is(undefined);
15
+ "getOk": test(async () => {
16
+ expect(getOk(ok(123))).is(123);
17
+ expect(getOk(err("nope"))).is(undefined);
18
18
  }),
19
- "need": test(async () => {
20
- expect(need(ok(123))).is(123);
21
- expect(() => need(err("nope"))).throws();
19
+ "getErr": test(async () => {
20
+ expect(getErr(err("nope"))).is("nope");
21
+ expect(getErr(ok(123))).is(undefined);
22
22
  }),
23
- "need error handling": {
23
+ "needOk": test(async () => {
24
+ expect(needOk(ok(123))).is(123);
25
+ expect(() => needOk(err("nope"))).throws();
26
+ }),
27
+ "needErr": test(async () => {
28
+ expect(needErr(err("nope"))).is("nope");
29
+ expect(() => needErr(ok(123))).throws();
30
+ }),
31
+ "attempt": test(async () => {
32
+ expect(needOk(attempt(() => 123))).is(123);
33
+ expect(attempt(() => { throw new Error("rofl"); }).ok).is(false);
34
+ expect(needErr(attempt(() => { throw new Error("rofl"); })).message).is("rofl");
35
+ }),
36
+ "attemptAsync": test(async () => {
37
+ expect(needOk(await attemptAsync(async () => 123))).is(123);
38
+ expect((await attemptAsync(async () => { throw new Error("rofl"); })).ok).is(false);
39
+ expect(needErr(await attemptAsync(async () => { throw new Error("rofl"); })).message).is("rofl");
40
+ }),
41
+ "needOk error handling": {
24
42
  "rethrows errors": test(async () => {
25
43
  const error = new TypeError();
26
- expect(() => need(err(error))).throws(TypeError);
27
- expect(thrown(() => need(err(error)))).is(error);
44
+ expect(() => needOk(err(error))).throws(TypeError);
45
+ expect(thrown(() => needOk(err(error)))).is(error);
28
46
  }),
29
47
  "upgrades strings to errors": test(async () => {
30
- expect(() => need(err("nope"))).throws(Error);
31
- expect(thrown(() => need(err("nope"))).message).is("nope");
48
+ expect(() => needOk(err("nope"))).throws(Error);
49
+ expect(thrown(() => needOk(err("nope"))).message).is("nope");
32
50
  }),
33
51
  "everything else is unknown": test(async () => {
34
- expect(() => need(err({ code: 234 }))).throws(Error);
35
- expect(thrown(() => need(err({ code: 234 }))).message).is("unknown");
52
+ expect(() => needOk(err({ code: 234 }))).throws(Error);
53
+ expect(thrown(() => needOk(err({ code: 234 }))).message).is("unknown");
36
54
  }),
37
55
  },
38
56
  });
package/x/ok/test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../../s/ok/test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,eAAe,CAAA;AACjD,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,YAAY,CAAA;AAE9C,eAAe,KAAK,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC,KAAK,IAAG,EAAE;QACpB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QAC3B,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC,CAAC;IAEF,KAAK,EAAE,IAAI,CAAC,KAAK,IAAG,EAAE;QACrB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QAChC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;QACpC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AC,EAAE,CAAC,SAAS,CAAC,CAAA;QACrE,CAAC,CAAC;KACF;CACD,CAAC,CAAA"}
package/s/ok/fns/grab.ts DELETED
@@ -1,10 +0,0 @@
1
-
2
- import type {Result} from "../types/result.js"
3
-
4
- /** get value or undefined */
5
- export function grab<Value>(result: Result<Value, unknown>): Value | undefined {
6
- return result.ok
7
- ? result.value
8
- : undefined
9
- }
10
-
@@ -1,3 +0,0 @@
1
- import type { Result } from "../types/result.js";
2
- /** get value or undefined */
3
- export declare function grab<Value>(result: Result<Value, unknown>): Value | undefined;
package/x/ok/fns/grab.js DELETED
@@ -1,7 +0,0 @@
1
- /** get value or undefined */
2
- export function grab(result) {
3
- return result.ok
4
- ? result.value
5
- : undefined;
6
- }
7
- //# sourceMappingURL=grab.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grab.js","sourceRoot":"","sources":["../../../s/ok/fns/grab.ts"],"names":[],"mappings":"AAGA,6BAA6B;AAC7B,MAAM,UAAU,IAAI,CAAQ,MAA8B;IACzD,OAAO,MAAM,CAAC,EAAE;QACf,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,SAAS,CAAA;AACb,CAAC"}