neverpanic 0.0.4 → 0.0.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bruno Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -5,6 +5,14 @@ export type Result<T = unknown, E = unknown> = {
5
5
  success: false;
6
6
  error: E;
7
7
  };
8
+ type DataOf<R extends Result> = R extends {
9
+ success: true;
10
+ data: infer D;
11
+ } ? D : never;
12
+ type ErrorOf<R extends Result> = R extends {
13
+ success: false;
14
+ error: infer E;
15
+ } ? E : never;
8
16
  /**
9
17
  * Create a safe function from an unsafe one.
10
18
  *
@@ -47,8 +55,10 @@ declare function safeFn<T extends Result | Promise<Result>, A extends unknown[],
47
55
  * }
48
56
  */
49
57
  declare function fromUnsafe<T, E = null, R = T extends Promise<unknown> ? Promise<Result<Awaited<T>, E>> : Result<T, E>>(cb: () => T, eh?: (err: unknown) => E): R;
58
+ declare function resultsToResult<R extends Result[]>(results: R): Result<DataOf<R[number]>[], ErrorOf<R[number]>[]>;
50
59
  export declare const n: {
51
60
  safeFn: typeof safeFn;
52
61
  fromUnsafe: typeof fromUnsafe;
62
+ resultsToResult: typeof resultsToResult;
53
63
  };
54
64
  export {};
package/dist/index.js CHANGED
@@ -74,4 +74,19 @@ function fromUnsafe(cb, eh) {
74
74
  return createErrorResult(e);
75
75
  }
76
76
  }
77
- export const n = { safeFn, fromUnsafe };
77
+ function resultsToResult(results) {
78
+ let success = true;
79
+ const error = [];
80
+ const data = [];
81
+ for (const result of results) {
82
+ if (!result.success) {
83
+ success = false;
84
+ error.push(result.error);
85
+ }
86
+ else {
87
+ data.push(result.data);
88
+ }
89
+ }
90
+ return success ? { success: true, data } : { success: false, error };
91
+ }
92
+ export const n = { safeFn, fromUnsafe, resultsToResult };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "neverpanic",
3
3
  "module": "index.ts",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "url": "https://github.com/bgrcs/neverpanic"
@@ -10,7 +10,7 @@
10
10
  "build": "tsc",
11
11
  "test": "bun test"
12
12
  },
13
- "files": ["dist"],
13
+ "files": ["dist", "LICENSE"],
14
14
  "exports": {
15
15
  ".": "./dist/index.js"
16
16
  },