neverpanic 0.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 +5 -0
- package/index.ts +29 -0
- package/package.json +18 -0
- package/tsconfig.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# neverpanic
|
|
2
|
+
|
|
3
|
+
This is the next generation of error handling in JavaScript. How many times have you gotten out of bed, ready to get on with your day, only to find that you have 1243 Sentry alerts because you forgot to gracefuly handle an exception in your NodeJS backend. The truth is, these are not exceptions, these are panics. Panics not just in your code, but also to your mental health.
|
|
4
|
+
|
|
5
|
+
Try neverpanic, and live a zen life.
|
package/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type Result<T, E = unknown> =
|
|
2
|
+
| {
|
|
3
|
+
success: true;
|
|
4
|
+
data: T;
|
|
5
|
+
}
|
|
6
|
+
| { success: false; error: E };
|
|
7
|
+
|
|
8
|
+
async function safeReturn<T, E>(
|
|
9
|
+
cb: () => Promise<Result<T, E>> | Result<T, E>,
|
|
10
|
+
): Promise<Result<T, E | null>>;
|
|
11
|
+
async function safeReturn<T, E, H>(
|
|
12
|
+
cb: () => Promise<Result<T, E>> | Result<T, E>,
|
|
13
|
+
eh: (err: unknown) => H,
|
|
14
|
+
): Promise<Result<T, E | H>>;
|
|
15
|
+
async function safeReturn<T, E, H>(
|
|
16
|
+
cb: () => Promise<Result<T, E>> | Result<T, E>,
|
|
17
|
+
eh?: (err: unknown) => H,
|
|
18
|
+
): Promise<Result<T, E | H | null>> {
|
|
19
|
+
try {
|
|
20
|
+
return await cb();
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: eh?.(e) ?? null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const o = { safeReturn };
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "neverpanic",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "bun build index.ts --outdir dist"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/bun": "latest"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"typescript": "5"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
"noImplicitOverride": true,
|
|
23
|
+
|
|
24
|
+
// Some stricter flags (disabled by default)
|
|
25
|
+
"noUnusedLocals": false,
|
|
26
|
+
"noUnusedParameters": false,
|
|
27
|
+
"noPropertyAccessFromIndexSignature": false
|
|
28
|
+
}
|
|
29
|
+
}
|