@bb-labs/zod-env 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 +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/z-env/index.d.ts +7 -0
- package/dist/z-env/index.js +20 -0
- package/package.json +37 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./z-env";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./z-env";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z, ZodType } from "zod";
|
|
2
|
+
type EnvSchema = Record<string, ZodType<unknown>>;
|
|
3
|
+
type InferEnv<T extends EnvSchema> = {
|
|
4
|
+
[K in keyof T]: z.infer<T[K]>;
|
|
5
|
+
};
|
|
6
|
+
export declare function zEnv<T extends EnvSchema>(env: NodeJS.ProcessEnv, schema: T): InferEnv<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function zEnv(env, schema) {
|
|
2
|
+
const result = {};
|
|
3
|
+
const errors = [];
|
|
4
|
+
for (const key of Object.keys(schema)) {
|
|
5
|
+
const value = env[key];
|
|
6
|
+
const zodSchema = schema[key];
|
|
7
|
+
const parsed = zodSchema.safeParse(value);
|
|
8
|
+
if (!parsed.success) {
|
|
9
|
+
const issues = parsed.error.issues.map((i) => i.message).join(", ");
|
|
10
|
+
errors.push(`${key}: ${issues}`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
result[key] = parsed.data;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (errors.length > 0) {
|
|
17
|
+
throw new Error(`Environment validation failed:\n${errors.join("\n")}`);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bb-labs/zod-env",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A library for parsing environment variables using Zod",
|
|
5
|
+
"homepage": "https://github.com/beepbop-labs/zod-env",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"zod-env",
|
|
8
|
+
"zod",
|
|
9
|
+
"env"
|
|
10
|
+
],
|
|
11
|
+
"author": "Beepbop",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/beepbop-labs/zod-env.git"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
25
|
+
"pack": "npm run build && npm pack --pack-destination ./archive/"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/bun": "latest",
|
|
29
|
+
"@types/node": "^25.0.3"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"typescript": "^5"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"zod": "^4.2.1"
|
|
36
|
+
}
|
|
37
|
+
}
|