@serkonda7/ts-result 1.0.0 → 1.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 +1,24 @@
1
1
  # ts-result
2
+ [![CI][ci-badge]][ci-status]
3
+ [![npm version][npm-badge]][npm-link]
4
+ [![npm updated][npm-date-badge]][npm-link]
5
+
6
+ Minimalistic Result type for TypeScript.
7
+
8
+
9
+ ## 📦 Installation
10
+ ```sh
11
+ npm install @serkonda7/ts-result
12
+ ```
13
+
14
+
15
+ ## 📜 License
16
+ This repo is licensed under the [MIT License](LICENSE.txt).
17
+
18
+
19
+ <!-- links -->
20
+ [ci-badge]: https://github.com/serkonda7/ts-result/actions/workflows/ci.yml/badge.svg
21
+ [ci-status]: https://github.com/serkonda7/ts-result/actions/workflows/ci.yml
22
+ [npm-badge]: https://nodei.co/npm/@serkonda7/ts-result.svg?style=shields&data=v&color=blue
23
+ [npm-date-badge]: https://nodei.co/npm/@serkonda7/ts-result.svg?style=shields&data=u,d&color=blue
24
+ [npm-link]: https://www.npmjs.com/package/@serkonda7/ts-result
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Result utilities inspired by Rust's Result<T, E> type.
3
+ *
4
+ * This module provides a way to enforce explicit error handling.
5
+ */
6
+ /** */
7
+ type Ok<V> = {
8
+ value: V;
9
+ error?: never;
10
+ };
11
+ type Err<E> = {
12
+ error: E;
13
+ value?: never;
14
+ };
15
+ /**
16
+ * Union type representing either success or failure.
17
+ */
18
+ export type Result<V, E = Error> = Ok<V> | Err<E>;
19
+ /**
20
+ * Helper to create a successful Result.
21
+ */
22
+ export declare const ok: <V>(value: V) => Ok<V>;
23
+ /**
24
+ * Helper to create a failed Result.
25
+ */
26
+ export declare const err: <E>(error: E) => Err<E>;
27
+ /**
28
+ * Returns the `value` from a Result.
29
+ *
30
+ * In case of an error, it is thrown.
31
+ */
32
+ export declare function unwrap<V, E extends Error>(result: Result<V, E>): V;
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.0",
4
+ "version": "1.0.1",
5
5
  "license": "MIT",
6
6
  "author": "serkonda7",
7
7
  "homepage": "https://github.com/serkonda7/ts-result",
@@ -14,17 +14,18 @@
14
14
  },
15
15
  "keywords": [],
16
16
  "type": "module",
17
- "files": [
18
- "dist/",
19
- "README.md"
20
- ],
17
+ "main": "dist/result.js",
18
+ "types": "dist/result.d.ts",
19
+ "files": ["dist/"],
21
20
  "scripts": {
22
21
  "lint:fix": "biome check --write",
23
22
  "lint:ci": "biome ci",
24
- "check": "bunx tsgo",
25
- "build": "bun run check && bun run scripts/build.ts",
23
+ "build": "bunx tsgo && bun run scripts/build.ts",
26
24
  "prepack": "bun run build"
27
25
  },
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
28
29
  "packageManager": "bun@1.3.5",
29
30
  "dependencies": {},
30
31
  "devDependencies": {