@matthew-hre/env 0.1.0

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) 2025 Matthew Hrehirchuk
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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @matthew-hre/env
2
+
3
+ Type safe environment variable validation for NextJS projects.
4
+
5
+ > This package is mostly for my own projects, and I wouldn't recommend using it yourself in its current state. It may be improved in the future. May.
package/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ loadEnv: () => loadEnv
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_zod = require("zod");
27
+ function loadEnv(schema, env = process.env) {
28
+ try {
29
+ return schema.parse(env);
30
+ } catch (err) {
31
+ if (err instanceof import_zod.ZodError) {
32
+ let message = "Invalid environment variables:\n";
33
+ err.issues.forEach((issue) => {
34
+ message += ` - ${String(issue.path[0])} (${issue.message})
35
+ `;
36
+ });
37
+ console.error(message);
38
+ } else {
39
+ console.error("Unexpected error while parsing env:", err);
40
+ }
41
+ process.exit(1);
42
+ }
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ loadEnv
47
+ });
@@ -0,0 +1,5 @@
1
+ import { ZodRawShape, ZodObject, z } from 'zod';
2
+
3
+ declare function loadEnv<T extends ZodRawShape>(schema: ZodObject<T>, env?: Record<string, string | undefined>): z.output<typeof schema>;
4
+
5
+ export { loadEnv };
@@ -0,0 +1,5 @@
1
+ import { ZodRawShape, ZodObject, z } from 'zod';
2
+
3
+ declare function loadEnv<T extends ZodRawShape>(schema: ZodObject<T>, env?: Record<string, string | undefined>): z.output<typeof schema>;
4
+
5
+ export { loadEnv };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ // src/index.ts
2
+ import { ZodError } from "zod";
3
+ function loadEnv(schema, env = process.env) {
4
+ try {
5
+ return schema.parse(env);
6
+ } catch (err) {
7
+ if (err instanceof ZodError) {
8
+ let message = "Invalid environment variables:\n";
9
+ err.issues.forEach((issue) => {
10
+ message += ` - ${String(issue.path[0])} (${issue.message})
11
+ `;
12
+ });
13
+ console.error(message);
14
+ } else {
15
+ console.error("Unexpected error while parsing env:", err);
16
+ }
17
+ process.exit(1);
18
+ }
19
+ }
20
+ export {
21
+ loadEnv
22
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@matthew-hre/env",
3
+ "version": "0.1.0",
4
+ "description": "Type safe environment variable validation for NextJS projects",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format esm,cjs --dts",
13
+ "dev": "tsup src/index.ts --watch --dts"
14
+ },
15
+ "keywords": [
16
+ "nextjs",
17
+ "zod",
18
+ "env",
19
+ "typed",
20
+ "validation"
21
+ ],
22
+ "author": "Matthew Hrehirchuk",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "zod": "^4.1.9"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^24.5.2",
29
+ "tsup": "^8.5.0",
30
+ "typescript": "^5.9.2"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }