@e280/stz 0.2.27 → 0.2.29

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.
Files changed (65) hide show
  1. package/README.md +40 -0
  2. package/package.json +2 -2
  3. package/s/assert.ts +10 -0
  4. package/s/dig/dig.ts +25 -0
  5. package/s/dig/test.ts +52 -0
  6. package/s/drill.ts +4 -1
  7. package/s/index.ts +4 -1
  8. package/s/ok/fns/err.ts +8 -0
  9. package/s/ok/fns/grab.ts +10 -0
  10. package/s/ok/fns/need.ts +20 -0
  11. package/s/ok/fns/ok.ts +8 -0
  12. package/s/ok/index.ts +10 -0
  13. package/s/ok/test.ts +47 -0
  14. package/s/ok/types/err.ts +4 -0
  15. package/s/ok/types/ok.ts +4 -0
  16. package/s/ok/types/result.ts +10 -0
  17. package/s/tests.test.ts +6 -2
  18. package/s/thrown.ts +7 -0
  19. package/x/assert.d.ts +1 -0
  20. package/x/assert.js +5 -0
  21. package/x/assert.js.map +1 -0
  22. package/x/dig/dig.d.ts +2 -0
  23. package/x/dig/dig.js +15 -0
  24. package/x/dig/dig.js.map +1 -0
  25. package/x/dig/test.d.ts +14 -0
  26. package/x/dig/test.js +39 -0
  27. package/x/dig/test.js.map +1 -0
  28. package/x/drill.d.ts +4 -1
  29. package/x/drill.js +4 -1
  30. package/x/drill.js.map +1 -1
  31. package/x/index.d.ts +4 -0
  32. package/x/index.js +4 -0
  33. package/x/index.js.map +1 -1
  34. package/x/ok/fns/err.d.ts +3 -0
  35. package/x/ok/fns/err.js +5 -0
  36. package/x/ok/fns/err.js.map +1 -0
  37. package/x/ok/fns/grab.d.ts +3 -0
  38. package/x/ok/fns/grab.js +7 -0
  39. package/x/ok/fns/grab.js.map +1 -0
  40. package/x/ok/fns/need.d.ts +3 -0
  41. package/x/ok/fns/need.js +13 -0
  42. package/x/ok/fns/need.js.map +1 -0
  43. package/x/ok/fns/ok.d.ts +3 -0
  44. package/x/ok/fns/ok.js +5 -0
  45. package/x/ok/fns/ok.js.map +1 -0
  46. package/x/ok/index.d.ts +7 -0
  47. package/x/ok/index.js +8 -0
  48. package/x/ok/index.js.map +1 -0
  49. package/x/ok/test.d.ts +12 -0
  50. package/x/ok/test.js +39 -0
  51. package/x/ok/test.js.map +1 -0
  52. package/x/ok/types/err.d.ts +5 -0
  53. package/x/ok/types/err.js +2 -0
  54. package/x/ok/types/err.js.map +1 -0
  55. package/x/ok/types/ok.d.ts +5 -0
  56. package/x/ok/types/ok.js +2 -0
  57. package/x/ok/types/ok.js.map +1 -0
  58. package/x/ok/types/result.d.ts +4 -0
  59. package/x/ok/types/result.js +2 -0
  60. package/x/ok/types/result.js.map +1 -0
  61. package/x/tests.test.js +6 -2
  62. package/x/tests.test.js.map +1 -1
  63. package/x/thrown.d.ts +1 -0
  64. package/x/thrown.js +10 -0
  65. package/x/thrown.js.map +1 -0
package/README.md CHANGED
@@ -315,6 +315,46 @@ const stop = cycle(async() => {
315
315
  stop()
316
316
  ```
317
317
 
318
+ ### 🍏 ok
319
+ > tiny result toolkit for saying "this worked" or "this did not work"
320
+
321
+ rust-inspired pattern for explicit error handling instead of the usual js yolo vibes
322
+
323
+ #### result shapes
324
+ - `Ok<Value>` — `{ok: true, value}`
325
+ - `Err<E>` — `{ok: false, error}`
326
+ - `Result<Value, E>` — either of the above
327
+
328
+ #### constructors
329
+ - `ok(value)` — make a successful result
330
+ ```ts
331
+ const result = ok("fusion stable")
332
+ // {ok: true, value: "fusion stable"}
333
+ ```
334
+ - `err(error)` — make a failed result
335
+ ```ts
336
+ const result = err("containment lost")
337
+ // {ok: false, error: "containment lost"}
338
+ ```
339
+
340
+ #### helpers
341
+ - `grab(result)` — get the value, or `undefined`
342
+ ```ts
343
+ grab(ok(123))
344
+ // 123
345
+
346
+ grab(err("nope"))
347
+ // undefined
348
+ ```
349
+ - `need(result)` — get the value, or throw
350
+ ```ts
351
+ need(ok(123))
352
+ // 123
353
+
354
+ need(err("containment lost"))
355
+ // throws Error("containment lost")
356
+ ```
357
+
318
358
 
319
359
 
320
360
  <br/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/stz",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "description": "everyday ts fns for everything",
5
5
  "license": "MIT",
6
6
  "author": "Chase Moskal <chasemoskal@gmail.com>",
@@ -22,7 +22,7 @@
22
22
  "count": "find s -path '*/_archive' -prune -o -name '*.ts' -exec wc -l {} +"
23
23
  },
24
24
  "devDependencies": {
25
- "@e280/science": "^0.1.9",
25
+ "@e280/science": "^0.1.10",
26
26
  "@types/node": "^25.5.0",
27
27
  "typescript": "^6.0.2"
28
28
  },
package/s/assert.ts ADDED
@@ -0,0 +1,10 @@
1
+
2
+ export function assert<Value>(
3
+ value: Value,
4
+ message = "assert fail",
5
+ ): asserts value {
6
+
7
+ if (!value)
8
+ throw new Error(message)
9
+ }
10
+
package/s/dig/dig.ts ADDED
@@ -0,0 +1,25 @@
1
+
2
+ import {is} from "../is.js"
3
+ import {ok, err} from "../ok/index.js"
4
+
5
+ /** drill into an object/array tree and return the value at the given path */
6
+ export function dig<Value>(
7
+ target: any,
8
+ path: (string | number)[],
9
+ ) {
10
+
11
+ let current: any = target
12
+
13
+ for (const key of path) {
14
+ if (!(is.object(current) || is.array(current)))
15
+ return err("not traversable" as const)
16
+
17
+ if (!Object.hasOwn(current, key))
18
+ return err("not found" as const)
19
+
20
+ current = current[key]
21
+ }
22
+
23
+ return ok(current as Value)
24
+ }
25
+
package/s/dig/test.ts ADDED
@@ -0,0 +1,52 @@
1
+
2
+ import {suite, expect, assert} from "@e280/science"
3
+ import {dig} from "./dig.js"
4
+ import {need} from "../ok/index.js"
5
+
6
+ const check = (t: any, path: (string | number)[]) => ({
7
+ ok: (value: any) => async() => {
8
+ const result = dig(t, path)
9
+ expect(need(result)).is(value)
10
+ },
11
+ err: (e: any) => async() => {
12
+ const result = dig(t, path)
13
+ assert(!result.ok)
14
+ expect(result.error).is(e)
15
+ },
16
+ })
17
+
18
+ export default suite({
19
+ "get value": check({a: 2}, ["a"])
20
+ .ok(2),
21
+
22
+ "get undefined": check({a: undefined}, ["a"])
23
+ .ok(undefined),
24
+
25
+ "get null": check({a: null}, ["a"])
26
+ .ok(null),
27
+
28
+ "nested get value": check({a: {b: 2}}, ["a", "b"])
29
+ .ok(2),
30
+
31
+ "array get value": check(["a", "b"], [1])
32
+ .ok("b"),
33
+
34
+ "null not traversable": check(null, ["a"])
35
+ .err("not traversable"),
36
+
37
+ "undefined not traversable": check(undefined, ["a"])
38
+ .err("not traversable"),
39
+
40
+ "missing key not found": check({a: 2}, ["b"])
41
+ .err("not found"),
42
+
43
+ "array index not found": check(["a", "b"], [2])
44
+ .err("not found"),
45
+
46
+ "midway not traversable": check({a: 5}, ["a", "b"])
47
+ .err("not traversable"),
48
+
49
+ "midway not found": check({a: {}}, ["a", "b"])
50
+ .err("not found"),
51
+ })
52
+
package/s/drill.ts CHANGED
@@ -1,7 +1,10 @@
1
1
 
2
2
  import {is} from "./is.js"
3
3
 
4
- /** return a value within an object tree, found at the given path. */
4
+ /**
5
+ * return a value within an object tree, found at the given path.
6
+ * @deprecated prefer `dig` instead
7
+ */
5
8
  export function drill<xResult>(
6
9
  object: {[key: string]: any},
7
10
  path: string[],
package/s/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./debounce/microbounce.js"
15
15
  export * from "./debounce/types.js"
16
16
 
17
17
  export * from "./deep/index.js"
18
+ export * from "./dig/dig.js"
18
19
 
19
20
  export * from "./g/map.js"
20
21
  export * from "./g/pool.js"
@@ -23,11 +24,12 @@ export * from "./g/weak-map.js"
23
24
 
24
25
  export * from "./queue/queue.js"
25
26
 
27
+ export * from "./ok/index.js"
26
28
  export * from "./toq/index.js"
27
-
28
29
  export * from "./maybe/index.js"
29
30
 
30
31
  export * from "./all.js"
32
+ export * from "./assert.js"
31
33
  export * from "./coalesce.js"
32
34
  export * from "./collect.js"
33
35
  export * from "./concurrent.js"
@@ -53,6 +55,7 @@ export * from "./provide.js"
53
55
  export * from "./pubsub.js"
54
56
  export * from "./scope.js"
55
57
  export * from "./templating.js"
58
+ export * from "./thrown.js"
56
59
  export * from "./time.js"
57
60
  export * from "./trash.js"
58
61
  export * from "./types.js"
@@ -0,0 +1,8 @@
1
+
2
+ import type {Err} from "../types/err.js"
3
+
4
+ /** failure */
5
+ export function err<E = string>(error: E): Err<E> {
6
+ return {ok: false, error}
7
+ }
8
+
@@ -0,0 +1,10 @@
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
+
@@ -0,0 +1,20 @@
1
+
2
+ import type {Result} from "../types/result.js"
3
+
4
+ /** get value or throw error */
5
+ export function need<Value, E>(result: Result<Value, E>): Value {
6
+ if (result.ok)
7
+ return result.value
8
+
9
+ const {error} = result
10
+
11
+ if (error instanceof Error)
12
+ throw error
13
+
14
+ else if (typeof error === "string")
15
+ throw new Error(error)
16
+
17
+ else
18
+ throw new Error("unknown")
19
+ }
20
+
package/s/ok/fns/ok.ts ADDED
@@ -0,0 +1,8 @@
1
+
2
+ import type {Ok} from "../types/ok.js"
3
+
4
+ /** success */
5
+ export function ok<Value>(value: Value): Ok<Value> {
6
+ return {ok: true, value}
7
+ }
8
+
package/s/ok/index.ts ADDED
@@ -0,0 +1,10 @@
1
+
2
+ export * from "./fns/ok.js"
3
+ export * from "./fns/err.js"
4
+ export * from "./fns/grab.js"
5
+ export * from "./fns/need.js"
6
+
7
+ export * from "./types/ok.js"
8
+ export * from "./types/err.js"
9
+ export * from "./types/result.js"
10
+
package/s/ok/test.ts ADDED
@@ -0,0 +1,47 @@
1
+
2
+ import {expect, suite, test} from "@e280/science"
3
+ import {thrown} from "../thrown.js"
4
+ import {ok, err, grab, need} from "./index.js"
5
+
6
+ export default suite({
7
+ "ok": test(async() => {
8
+ expect(ok(123).ok).is(true)
9
+ expect(ok(123).value).is(123)
10
+ expect("error" in ok(123)).is(false)
11
+ }),
12
+
13
+ "err": test(async() => {
14
+ expect(err("nope").ok).is(false)
15
+ expect(err("nope").error).is("nope")
16
+ expect("value" in err("nope")).is(false)
17
+ }),
18
+
19
+ "grab": test(async() => {
20
+ expect(grab(ok(123))).is(123)
21
+ expect(grab(err("nope"))).is(undefined)
22
+ }),
23
+
24
+ "need": test(async() => {
25
+ expect(need(ok(123))).is(123)
26
+ expect(() => need(err("nope"))).throws()
27
+ }),
28
+
29
+ "need error handling": {
30
+ "rethrows errors": test(async() => {
31
+ const error = new TypeError()
32
+ expect(() => need(err(error))).throws(TypeError)
33
+ expect(thrown(() => need(err(error)))).is(error)
34
+ }),
35
+
36
+ "upgrades strings to errors": test(async() => {
37
+ expect(() => need(err("nope"))).throws(Error)
38
+ expect(thrown(() => need(err("nope"))).message).is("nope")
39
+ }),
40
+
41
+ "everything else is unknown": test(async() => {
42
+ expect(() => need(err({code: 234}))).throws(Error)
43
+ expect(thrown(() => need(err({code: 234}))).message).is("unknown")
44
+ }),
45
+ },
46
+ })
47
+
@@ -0,0 +1,4 @@
1
+
2
+ /** failure */
3
+ export type Err<E> = {ok: false, error: E}
4
+
@@ -0,0 +1,4 @@
1
+
2
+ /** success */
3
+ export type Ok<Value> = {ok: true, value: Value}
4
+
@@ -0,0 +1,10 @@
1
+
2
+ import type {Ok} from "./ok.js"
3
+ import type {Err} from "./err.js"
4
+
5
+ /** success or failure */
6
+ export type Result<Value, E = unknown> = (
7
+ | Ok<Value>
8
+ | Err<E>
9
+ )
10
+
package/s/tests.test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import {Science} from "@e280/science"
2
+ import {science} from "@e280/science"
3
3
 
4
4
  import data from "./data/data.test.js"
5
5
  import debounce from "./debounce/debounce.test.js"
@@ -8,8 +8,10 @@ import deep from "./deep/index.test.js"
8
8
  import queue from "./queue/queue.test.js"
9
9
  import toq from "./toq/toq.test.js"
10
10
  import maybe from "./maybe/test.js"
11
+ import dig from "./dig/test.js"
12
+ import ok from "./ok/test.js"
11
13
 
12
- await Science.run({
14
+ await science.run({
13
15
  data,
14
16
  debounce,
15
17
  microbounce,
@@ -17,5 +19,7 @@ await Science.run({
17
19
  queue,
18
20
  toq,
19
21
  maybe,
22
+ dig,
23
+ ok,
20
24
  })
21
25
 
package/s/thrown.ts ADDED
@@ -0,0 +1,7 @@
1
+
2
+ export function thrown(fn: () => unknown): any {
3
+ try { fn() }
4
+ catch (error) { return error }
5
+ throw new Error("didn't throw")
6
+ }
7
+
package/x/assert.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function assert<Value>(value: Value, message?: string): asserts value;
package/x/assert.js ADDED
@@ -0,0 +1,5 @@
1
+ export function assert(value, message = "assert fail") {
2
+ if (!value)
3
+ throw new Error(message);
4
+ }
5
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../s/assert.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,MAAM,CACpB,KAAY,EACZ,OAAO,GAAG,aAAa;IAGxB,IAAI,CAAC,KAAK;QACT,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;AAC1B,CAAC"}
package/x/dig/dig.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** drill into an object/array tree and return the value at the given path */
2
+ export declare function dig<Value>(target: any, path: (string | number)[]): import("../ok/index.js").Err<"not traversable"> | import("../ok/index.js").Err<"not found"> | import("../ok/index.js").Ok<Value>;
package/x/dig/dig.js ADDED
@@ -0,0 +1,15 @@
1
+ import { is } from "../is.js";
2
+ import { ok, err } from "../ok/index.js";
3
+ /** drill into an object/array tree and return the value at the given path */
4
+ export function dig(target, path) {
5
+ let current = target;
6
+ for (const key of path) {
7
+ if (!(is.object(current) || is.array(current)))
8
+ return err("not traversable");
9
+ if (!Object.hasOwn(current, key))
10
+ return err("not found");
11
+ current = current[key];
12
+ }
13
+ return ok(current);
14
+ }
15
+ //# sourceMappingURL=dig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dig.js","sourceRoot":"","sources":["../../s/dig/dig.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,UAAU,CAAA;AAC3B,OAAO,EAAC,EAAE,EAAE,GAAG,EAAC,MAAM,gBAAgB,CAAA;AAEtC,6EAA6E;AAC7E,MAAM,UAAU,GAAG,CACjB,MAAW,EACX,IAAyB;IAG1B,IAAI,OAAO,GAAQ,MAAM,CAAA;IAEzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,GAAG,CAAC,iBAA0B,CAAC,CAAA;QAEvC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;YAC/B,OAAO,GAAG,CAAC,WAAoB,CAAC,CAAA;QAEjC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED,OAAO,EAAE,CAAC,OAAgB,CAAC,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,14 @@
1
+ declare const _default: {
2
+ "get value": () => Promise<void>;
3
+ "get undefined": () => Promise<void>;
4
+ "get null": () => Promise<void>;
5
+ "nested get value": () => Promise<void>;
6
+ "array get value": () => Promise<void>;
7
+ "null not traversable": () => Promise<void>;
8
+ "undefined not traversable": () => Promise<void>;
9
+ "missing key not found": () => Promise<void>;
10
+ "array index not found": () => Promise<void>;
11
+ "midway not traversable": () => Promise<void>;
12
+ "midway not found": () => Promise<void>;
13
+ };
14
+ export default _default;
package/x/dig/test.js ADDED
@@ -0,0 +1,39 @@
1
+ import { suite, expect, assert } from "@e280/science";
2
+ import { dig } from "./dig.js";
3
+ import { need } from "../ok/index.js";
4
+ const check = (t, path) => ({
5
+ ok: (value) => async () => {
6
+ const result = dig(t, path);
7
+ expect(need(result)).is(value);
8
+ },
9
+ err: (e) => async () => {
10
+ const result = dig(t, path);
11
+ assert(!result.ok);
12
+ expect(result.error).is(e);
13
+ },
14
+ });
15
+ export default suite({
16
+ "get value": check({ a: 2 }, ["a"])
17
+ .ok(2),
18
+ "get undefined": check({ a: undefined }, ["a"])
19
+ .ok(undefined),
20
+ "get null": check({ a: null }, ["a"])
21
+ .ok(null),
22
+ "nested get value": check({ a: { b: 2 } }, ["a", "b"])
23
+ .ok(2),
24
+ "array get value": check(["a", "b"], [1])
25
+ .ok("b"),
26
+ "null not traversable": check(null, ["a"])
27
+ .err("not traversable"),
28
+ "undefined not traversable": check(undefined, ["a"])
29
+ .err("not traversable"),
30
+ "missing key not found": check({ a: 2 }, ["b"])
31
+ .err("not found"),
32
+ "array index not found": check(["a", "b"], [2])
33
+ .err("not found"),
34
+ "midway not traversable": check({ a: 5 }, ["a", "b"])
35
+ .err("not traversable"),
36
+ "midway not found": check({ a: {} }, ["a", "b"])
37
+ .err("not found"),
38
+ });
39
+ //# sourceMappingURL=test.js.map
@@ -0,0 +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;IA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,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"}
package/x/drill.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- /** return a value within an object tree, found at the given path. */
1
+ /**
2
+ * return a value within an object tree, found at the given path.
3
+ * @deprecated prefer `dig` instead
4
+ */
2
5
  export declare function drill<xResult>(object: {
3
6
  [key: string]: any;
4
7
  }, path: string[]): xResult;
package/x/drill.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { is } from "./is.js";
2
- /** return a value within an object tree, found at the given path. */
2
+ /**
3
+ * return a value within an object tree, found at the given path.
4
+ * @deprecated prefer `dig` instead
5
+ */
3
6
  export function drill(object, path) {
4
7
  let current = object;
5
8
  for (const key of path) {
package/x/drill.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"drill.js","sourceRoot":"","sources":["../s/drill.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,SAAS,CAAA;AAE1B,qEAAqE;AACrE,MAAM,UAAU,KAAK,CACnB,MAA4B,EAC5B,IAAc;IAGf,IAAI,OAAO,GAAQ,MAAM,CAAA;IAEzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACtB,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;YAClB,MAAK;IACP,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
1
+ {"version":3,"file":"drill.js","sourceRoot":"","sources":["../s/drill.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,SAAS,CAAA;AAE1B;;;GAGG;AACH,MAAM,UAAU,KAAK,CACnB,MAA4B,EAC5B,IAAc;IAGf,IAAI,OAAO,GAAQ,MAAM,CAAA;IAEzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACtB,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;YAClB,MAAK;IACP,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
package/x/index.d.ts CHANGED
@@ -12,14 +12,17 @@ export * from "./debounce/debounce.js";
12
12
  export * from "./debounce/microbounce.js";
13
13
  export * from "./debounce/types.js";
14
14
  export * from "./deep/index.js";
15
+ export * from "./dig/dig.js";
15
16
  export * from "./g/map.js";
16
17
  export * from "./g/pool.js";
17
18
  export * from "./g/set.js";
18
19
  export * from "./g/weak-map.js";
19
20
  export * from "./queue/queue.js";
21
+ export * from "./ok/index.js";
20
22
  export * from "./toq/index.js";
21
23
  export * from "./maybe/index.js";
22
24
  export * from "./all.js";
25
+ export * from "./assert.js";
23
26
  export * from "./coalesce.js";
24
27
  export * from "./collect.js";
25
28
  export * from "./concurrent.js";
@@ -45,6 +48,7 @@ export * from "./provide.js";
45
48
  export * from "./pubsub.js";
46
49
  export * from "./scope.js";
47
50
  export * from "./templating.js";
51
+ export * from "./thrown.js";
48
52
  export * from "./time.js";
49
53
  export * from "./trash.js";
50
54
  export * from "./types.js";
package/x/index.js CHANGED
@@ -12,14 +12,17 @@ export * from "./debounce/debounce.js";
12
12
  export * from "./debounce/microbounce.js";
13
13
  export * from "./debounce/types.js";
14
14
  export * from "./deep/index.js";
15
+ export * from "./dig/dig.js";
15
16
  export * from "./g/map.js";
16
17
  export * from "./g/pool.js";
17
18
  export * from "./g/set.js";
18
19
  export * from "./g/weak-map.js";
19
20
  export * from "./queue/queue.js";
21
+ export * from "./ok/index.js";
20
22
  export * from "./toq/index.js";
21
23
  export * from "./maybe/index.js";
22
24
  export * from "./all.js";
25
+ export * from "./assert.js";
23
26
  export * from "./coalesce.js";
24
27
  export * from "./collect.js";
25
28
  export * from "./concurrent.js";
@@ -45,6 +48,7 @@ export * from "./provide.js";
45
48
  export * from "./pubsub.js";
46
49
  export * from "./scope.js";
47
50
  export * from "./templating.js";
51
+ export * from "./thrown.js";
48
52
  export * from "./time.js";
49
53
  export * from "./trash.js";
50
54
  export * from "./types.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,CAAA;AAE/B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAE/B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,gBAAgB,CAAA;AAE9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kB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AA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Err } from "../types/err.js";
2
+ /** failure */
3
+ export declare function err<E = string>(error: E): Err<E>;
@@ -0,0 +1,5 @@
1
+ /** failure */
2
+ export function err(error) {
3
+ return { ok: false, error };
4
+ }
5
+ //# sourceMappingURL=err.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,13 @@
1
+ /** get value or throw error */
2
+ export function need(result) {
3
+ if (result.ok)
4
+ return result.value;
5
+ const { error } = result;
6
+ if (error instanceof Error)
7
+ throw error;
8
+ else if (typeof error === "string")
9
+ throw new Error(error);
10
+ else
11
+ throw new Error("unknown");
12
+ }
13
+ //# sourceMappingURL=need.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ import type { Ok } from "../types/ok.js";
2
+ /** success */
3
+ export declare function ok<Value>(value: Value): Ok<Value>;
package/x/ok/fns/ok.js ADDED
@@ -0,0 +1,5 @@
1
+ /** success */
2
+ export function ok(value) {
3
+ return { ok: true, value };
4
+ }
5
+ //# sourceMappingURL=ok.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ok.js","sourceRoot":"","sources":["../../../s/ok/fns/ok.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,UAAU,EAAE,CAAQ,KAAY;IACrC,OAAO,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAC,CAAA;AACzB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./fns/ok.js";
2
+ export * from "./fns/err.js";
3
+ export * from "./fns/grab.js";
4
+ export * from "./fns/need.js";
5
+ export * from "./types/ok.js";
6
+ export * from "./types/err.js";
7
+ export * from "./types/result.js";
package/x/ok/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./fns/ok.js";
2
+ export * from "./fns/err.js";
3
+ export * from "./fns/grab.js";
4
+ export * from "./fns/need.js";
5
+ export * from "./types/ok.js";
6
+ export * from "./types/err.js";
7
+ export * from "./types/result.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
package/x/ok/test.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ ok: import("@e280/science").Test;
3
+ err: import("@e280/science").Test;
4
+ grab: import("@e280/science").Test;
5
+ need: import("@e280/science").Test;
6
+ "need error handling": {
7
+ "rethrows errors": import("@e280/science").Test;
8
+ "upgrades strings to errors": import("@e280/science").Test;
9
+ "everything else is unknown": import("@e280/science").Test;
10
+ };
11
+ };
12
+ export default _default;
package/x/ok/test.js ADDED
@@ -0,0 +1,39 @@
1
+ import { expect, suite, test } from "@e280/science";
2
+ import { thrown } from "../thrown.js";
3
+ import { ok, err, grab, need } from "./index.js";
4
+ export default suite({
5
+ "ok": test(async () => {
6
+ expect(ok(123).ok).is(true);
7
+ expect(ok(123).value).is(123);
8
+ expect("error" in ok(123)).is(false);
9
+ }),
10
+ "err": test(async () => {
11
+ expect(err("nope").ok).is(false);
12
+ expect(err("nope").error).is("nope");
13
+ expect("value" in err("nope")).is(false);
14
+ }),
15
+ "grab": test(async () => {
16
+ expect(grab(ok(123))).is(123);
17
+ expect(grab(err("nope"))).is(undefined);
18
+ }),
19
+ "need": test(async () => {
20
+ expect(need(ok(123))).is(123);
21
+ expect(() => need(err("nope"))).throws();
22
+ }),
23
+ "need error handling": {
24
+ "rethrows errors": test(async () => {
25
+ const error = new TypeError();
26
+ expect(() => need(err(error))).throws(TypeError);
27
+ expect(thrown(() => need(err(error)))).is(error);
28
+ }),
29
+ "upgrades strings to errors": test(async () => {
30
+ expect(() => need(err("nope"))).throws(Error);
31
+ expect(thrown(() => need(err("nope"))).message).is("nope");
32
+ }),
33
+ "everything else is unknown": test(async () => {
34
+ expect(() => need(err({ code: 234 }))).throws(Error);
35
+ expect(thrown(() => need(err({ code: 234 }))).message).is("unknown");
36
+ }),
37
+ },
38
+ });
39
+ //# sourceMappingURL=test.js.map
@@ -0,0 +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,C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AAC,SAAS,CAAC,CAAA;QACnE,CAAC,CAAC;KACF;CACD,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /** failure */
2
+ export type Err<E> = {
3
+ ok: false;
4
+ error: E;
5
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=err.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"err.js","sourceRoot":"","sources":["../../../s/ok/types/err.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /** success */
2
+ export type Ok<Value> = {
3
+ ok: true;
4
+ value: Value;
5
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ok.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ok.js","sourceRoot":"","sources":["../../../s/ok/types/ok.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { Ok } from "./ok.js";
2
+ import type { Err } from "./err.js";
3
+ /** success or failure */
4
+ export type Result<Value, E = unknown> = (Ok<Value> | Err<E>);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../s/ok/types/result.ts"],"names":[],"mappings":""}
package/x/tests.test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Science } from "@e280/science";
1
+ import { science } from "@e280/science";
2
2
  import data from "./data/data.test.js";
3
3
  import debounce from "./debounce/debounce.test.js";
4
4
  import microbounce from "./debounce/microbounce.test.js";
@@ -6,7 +6,9 @@ import deep from "./deep/index.test.js";
6
6
  import queue from "./queue/queue.test.js";
7
7
  import toq from "./toq/toq.test.js";
8
8
  import maybe from "./maybe/test.js";
9
- await Science.run({
9
+ import dig from "./dig/test.js";
10
+ import ok from "./ok/test.js";
11
+ await science.run({
10
12
  data,
11
13
  debounce,
12
14
  microbounce,
@@ -14,5 +16,7 @@ await Science.run({
14
16
  queue,
15
17
  toq,
16
18
  maybe,
19
+ dig,
20
+ ok,
17
21
  });
18
22
  //# sourceMappingURL=tests.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tests.test.js","sourceRoot":"","sources":["../s/tests.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,OAAO,IAAI,MAAM,qBAAqB,CAAA;AACtC,OAAO,QAAQ,MAAM,6BAA6B,CAAA;AAClD,OAAO,WAAW,MAAM,gCAAgC,CAAA;AACxD,OAAO,IAAI,MAAM,sBAAsB,CAAA;AACvC,OAAO,KAAK,MAAM,uBAAuB,CAAA;AACzC,OAAO,GAAG,MAAM,mBAAmB,CAAA;AACnC,OAAO,KAAK,MAAM,iBAAiB,CAAA;AAEnC,MAAM,OAAO,CAAC,GAAG,CAAC;IACjB,IAAI;IACJ,QAAQ;IACR,WAAW;IACX,IAAI;IACJ,KAAK;IACL,GAAG;IACH,KAAK;CACL,CAAC,CAAA"}
1
+ {"version":3,"file":"tests.test.js","sourceRoot":"","sources":["../s/tests.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,OAAO,IAAI,MAAM,qBAAqB,CAAA;AACtC,OAAO,QAAQ,MAAM,6BAA6B,CAAA;AAClD,OAAO,WAAW,MAAM,gCAAgC,CAAA;AACxD,OAAO,IAAI,MAAM,sBAAsB,CAAA;AACvC,OAAO,KAAK,MAAM,uBAAuB,CAAA;AACzC,OAAO,GAAG,MAAM,mBAAmB,CAAA;AACnC,OAAO,KAAK,MAAM,iBAAiB,CAAA;AACnC,OAAO,GAAG,MAAM,eAAe,CAAA;AAC/B,OAAO,EAAE,MAAM,cAAc,CAAA;AAE7B,MAAM,OAAO,CAAC,GAAG,CAAC;IACjB,IAAI;IACJ,QAAQ;IACR,WAAW;IACX,IAAI;IACJ,KAAK;IACL,GAAG;IACH,KAAK;IACL,GAAG;IACH,EAAE;CACF,CAAC,CAAA"}
package/x/thrown.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function thrown(fn: () => unknown): any;
package/x/thrown.js ADDED
@@ -0,0 +1,10 @@
1
+ export function thrown(fn) {
2
+ try {
3
+ fn();
4
+ }
5
+ catch (error) {
6
+ return error;
7
+ }
8
+ throw new Error("didn't throw");
9
+ }
10
+ //# sourceMappingURL=thrown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thrown.js","sourceRoot":"","sources":["../s/thrown.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,MAAM,CAAC,EAAiB;IACvC,IAAI,CAAC;QAAC,EAAE,EAAE,CAAA;IAAC,CAAC;IACZ,OAAO,KAAK,EAAE,CAAC;QAAC,OAAO,KAAK,CAAA;IAAC,CAAC;IAC9B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;AAChC,CAAC"}