@mkvlrn/result 4.0.0 → 4.0.1

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
@@ -1,4 +1,4 @@
1
- # Result Pattern
1
+ # @mkvlrn/result
2
2
 
3
3
  Type-safe Result pattern for TypeScript representing success or error. Anything to avoid try/catch hell.
4
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mkvlrn/result",
3
3
  "description": "Result type for TypeScript",
4
- "version": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -20,7 +20,7 @@
20
20
  "build": "rm -rf build && tsc"
21
21
  },
22
22
  "devDependencies": {
23
- "@biomejs/biome": "^2.1.2",
23
+ "@biomejs/biome": "^2.1.3",
24
24
  "@types/node": "^24.1.0",
25
25
  "typescript": "^5.8.3",
26
26
  "vitest": "^3.2.4"
@@ -1 +0,0 @@
1
- export {};
@@ -1,53 +0,0 @@
1
- // biome-ignore lint/correctness/noNodejsModules: need the timer
2
- import { setTimeout } from "node:timers/promises";
3
- import { assert, describe, it } from "vitest";
4
- import { R } from "./index.js";
5
- class CustomError extends Error {
6
- customField;
7
- constructor(customField, message) {
8
- super(message);
9
- this.name = "CustomField";
10
- this.customField = customField;
11
- }
12
- }
13
- function division(a, b) {
14
- if (b === 0) {
15
- return R.error(new Error("cannot divide by zero"));
16
- }
17
- return R.ok(a / b);
18
- }
19
- async function longRunning(shouldFail) {
20
- await setTimeout(1);
21
- return shouldFail ? R.error(new CustomError(42, "wrong")) : R.ok(3);
22
- }
23
- describe("creates a valid result", () => {
24
- describe("default Error type", () => {
25
- it("ok result", () => {
26
- const result = division(4, 2);
27
- assert.isUndefined(result.error);
28
- assert.isDefined(result.value);
29
- assert.strictEqual(result.value, 2);
30
- });
31
- it("error result", () => {
32
- const result = division(4, 0);
33
- assert.isDefined(result.error);
34
- assert.instanceOf(result.error, Error);
35
- assert.strictEqual(result.error.message, "cannot divide by zero");
36
- });
37
- });
38
- describe("custom error", () => {
39
- it("ok result", async () => {
40
- const result = await longRunning(false);
41
- assert.isUndefined(result.error);
42
- assert.isDefined(result.value);
43
- assert.strictEqual(result.value, 3);
44
- });
45
- it("error result", async () => {
46
- const result = await longRunning(true);
47
- assert.isDefined(result.error);
48
- assert.instanceOf(result.error, CustomError);
49
- assert.strictEqual(result.error.message, "wrong");
50
- assert.strictEqual(result.error.customField, 42);
51
- });
52
- });
53
- });