@serkonda7/ts-result 1.0.1 → 1.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.
package/README.md CHANGED
@@ -12,6 +12,44 @@ npm install @serkonda7/ts-result
12
12
  ```
13
13
 
14
14
 
15
+ ## 🚀 Usage
16
+ ```ts
17
+ import { ok, err, unwrap, type Result } from '@serkonda7/ts-result'
18
+
19
+ // To use, wrap a functions return type into `Result<>`
20
+ function parsePort (input: string): Result<number> {
21
+ const port = Number.parseInt(input, 10)
22
+
23
+ if (!Number.isInteger(port)) {
24
+ // Return an error result by using the `err()` helper
25
+ return err('PORT must be an integer')
26
+ }
27
+
28
+ if (port < 1 || port > 65535) {
29
+ // It supports strings, Error classes or any custom object
30
+ return err(new Error('PORT must be between 1 and 65535'))
31
+ }
32
+
33
+ // Return an successful result using the `ok()` helper
34
+ return ok(port)
35
+ }
36
+
37
+ const portResult = parsePort(process.env.PORT)
38
+
39
+ // Check the result for an error:
40
+ if (portResult.error) {
41
+ console.error(portResult.error)
42
+ process.exit(1)
43
+ }
44
+
45
+ // Use the value afterwards
46
+ let port = portResult.value
47
+
48
+ // Use the `unwrap()` helper to throw any error or return the value
49
+ const port = unwrap(portResult)
50
+ ```
51
+
52
+
15
53
  ## 📜 License
16
54
  This repo is licensed under the [MIT License](LICENSE.txt).
17
55
 
@@ -29,5 +29,5 @@ export declare const err: <E>(error: E) => Err<E>;
29
29
  *
30
30
  * In case of an error, it is thrown.
31
31
  */
32
- export declare function unwrap<V, E extends Error>(result: Result<V, E>): V;
32
+ export declare function unwrap<V, E>(result: Result<V, E>): V;
33
33
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@serkonda7/ts-result",
3
3
  "description": "Minimalistic Result type for TypeScript.",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "license": "MIT",
6
6
  "author": "serkonda7",
7
7
  "homepage": "https://github.com/serkonda7/ts-result",
@@ -12,25 +12,28 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/serkonda7/ts-result/issues"
14
14
  },
15
- "keywords": [],
15
+ "keywords": ["result", "typescript", "error-handling"],
16
16
  "type": "module",
17
17
  "main": "dist/result.js",
18
- "types": "dist/result.d.ts",
19
- "files": ["dist/"],
18
+ "types": "dist/src/result.d.ts",
19
+ "files": ["dist"],
20
20
  "scripts": {
21
- "lint:fix": "biome check --write",
21
+ "lint": "biome check --write",
22
22
  "lint:ci": "biome ci",
23
- "build": "bunx tsgo && bun run scripts/build.ts",
24
- "prepack": "bun run build"
23
+ "check": "tsgo -p tsconfig.check.json",
24
+ "test": "bun test",
25
+ "build": "tsgo && bun run scripts/build.ts",
26
+ "prepack": "bun run build",
27
+ "pack": "bun pm pack --filename ts-result.tgz"
25
28
  },
26
29
  "engines": {
27
30
  "node": ">=22"
28
31
  },
29
- "packageManager": "bun@1.3.5",
32
+ "packageManager": "bun@1.3.11",
30
33
  "dependencies": {},
31
34
  "devDependencies": {
32
- "@biomejs/biome": "~2.3.11",
33
- "@types/bun": "~1.3.5",
34
- "@typescript/native-preview": "~7.0.0-dev.20260109.1"
35
+ "@biomejs/biome": "2.4.10",
36
+ "@types/bun": "~1.3.11",
37
+ "@typescript/native-preview": "~7.0.0-dev.20260325.1"
35
38
  }
36
39
  }