envconfig-kit 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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chintan Shah
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.
22
+
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # envconfig-kit
2
+
3
+ > Type-safe environment variables with fail-fast validation. Zero dependencies.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/envconfig-kit.svg)](https://www.npmjs.com/package/envconfig-kit)
6
+ [![npm downloads](https://img.shields.io/npm/dm/envconfig-kit.svg)](https://www.npmjs.com/package/envconfig-kit)
7
+ [![build](https://github.com/chintanshah35/envconfig-kit/actions/workflows/test-suite.yml/badge.svg)](https://github.com/chintanshah35/envconfig-kit/actions)
8
+ [![node](https://img.shields.io/node/v/envconfig-kit.svg)](https://nodejs.org)
9
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/envconfig-kit)](https://bundlephobia.com/package/envconfig-kit)
10
+ [![license](https://img.shields.io/npm/l/envconfig-kit.svg)](https://github.com/chintanshah35/envconfig-kit/blob/master/LICENSE)
11
+
12
+ ## Why?
13
+
14
+ - **Built-in .env loading** - no need for dotenv
15
+ - **Type-safe** - full TypeScript inference
16
+ - **Zero dependencies** - 3KB minified
17
+ - **Fail-fast validation** - catches errors at startup
18
+ - **Actionable error messages** - tells you exactly how to fix issues
19
+ - **CLI tools** - generate .env.example, validate, health checks
20
+ - **Transform support** - parse and sanitize values
21
+ - **Multi-environment** - .env.development, .env.production, etc.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install envconfig-kit
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```typescript
32
+ import { env } from 'envconfig-kit'
33
+
34
+ const config = env({
35
+ PORT: { type: 'number', default: 3000 },
36
+ API_KEY: { type: 'string' },
37
+ DEBUG: { type: 'boolean', default: false },
38
+ DATABASE_URL: { type: 'url' },
39
+ })
40
+
41
+ // config.PORT is typed as number
42
+ // config.API_KEY is typed as string
43
+ // Throws on startup if API_KEY or DATABASE_URL is missing
44
+ ```
45
+
46
+ No need for `dotenv` - envconfig-kit automatically loads `.env` files.
47
+
48
+ ## Built-in .env Loading
49
+
50
+ envconfig-kit automatically loads environment variables from:
51
+ - `.env`
52
+ - `.env.local`
53
+ - `.env.development` (based on NODE_ENV)
54
+ - `.env.production` (based on NODE_ENV)
55
+
56
+ ```typescript
57
+ const config = env({
58
+ PORT: { type: 'number' }
59
+ })
60
+ // Automatically loads from .env files
61
+ ```
62
+
63
+ ## Supported Types
64
+
65
+ | Type | Validates | Example |
66
+ |------|-----------|---------|
67
+ | `string` | Any string | `"hello"` |
68
+ | `number` | Valid number | `"3000"` → `3000` |
69
+ | `boolean` | true/false, 1/0, yes/no | `"true"` → `true` |
70
+ | `url` | Valid URL with protocol | `"https://api.example.com"` |
71
+ | `email` | Valid email format | `"user@example.com"` |
72
+ | `port` | Number between 0-65535 | `"3000"` → `3000` |
73
+
74
+ ## Schema Options
75
+
76
+ ```typescript
77
+ env({
78
+ API_KEY: { type: 'string' },
79
+ PORT: { type: 'number', default: 3000 },
80
+ OPTIONAL_VAR: { type: 'string', optional: true },
81
+ TAGS: {
82
+ type: 'string',
83
+ transform: (value) => value.split(',')
84
+ },
85
+ })
86
+ ```
87
+
88
+ ## Error Messages
89
+
90
+ When validation fails, you get clear errors with fix suggestions:
91
+
92
+ ```
93
+ ❌ Environment validation failed:
94
+
95
+ API_KEY: Missing required environment variable
96
+ ➜ Fix: Add to .env file
97
+ Example: API_KEY=your-value-here
98
+
99
+ PORT: Expected number, got "abc"
100
+ ➜ Fix: Provide a valid number
101
+ Example: PORT=3000
102
+
103
+ Run your app with valid environment variables or add them to .env
104
+ ```
105
+
106
+ ## CLI Tools
107
+
108
+ ```bash
109
+ # Initialize envconfig-kit in your project
110
+ npx envconfig-kit init
111
+
112
+ # Validate .env file
113
+ npx envconfig-kit check
114
+
115
+ # Generate .env.example
116
+ npx envconfig-kit generate
117
+
118
+ # Health check
119
+ npx envconfig-kit doctor
120
+ ```
121
+
122
+ ## Built-in .env Loading
123
+
124
+ envconfig-kit automatically loads environment variables from:
125
+ - `.env`
126
+ - `.env.local`
127
+ - `.env.development` (based on NODE_ENV)
128
+ - `.env.production` (based on NODE_ENV)
129
+
130
+ Priority order:
131
+ 1. `process.env` (highest)
132
+ 2. `.env.local`
133
+ 3. `.env.${NODE_ENV}`
134
+ 4. `.env` (lowest)
135
+
136
+ ## Transform Values
137
+
138
+ ```typescript
139
+ const config = env({
140
+ ALLOWED_ORIGINS: {
141
+ type: 'string',
142
+ transform: (value) => value.split(',')
143
+ },
144
+ API_URL: {
145
+ type: 'url',
146
+ transform: (value) => value.replace(/\/$/, '')
147
+ }
148
+ })
149
+ ```
150
+
151
+ ## Export Schema
152
+
153
+ ```typescript
154
+ import { schemaToMarkdown, schemaToJSON, generateDotenvExample } from 'envconfig-kit'
155
+
156
+ const schema = {
157
+ PORT: { type: 'number', default: 3000 },
158
+ API_KEY: { type: 'string' },
159
+ }
160
+
161
+ // Generate markdown table for docs
162
+ console.log(schemaToMarkdown(schema))
163
+
164
+ // Generate .env.example
165
+ console.log(generateDotenvExample(schema))
166
+
167
+ // Export as JSON
168
+ console.log(schemaToJSON(schema))
169
+ ```
170
+
171
+ ## Advanced Usage
172
+
173
+ ```typescript
174
+ import { env } from 'envconfig-kit'
175
+
176
+ const config = env({
177
+ DATABASE_URL: { type: 'url' },
178
+ API_KEY: { type: 'string' },
179
+ PORT: { type: 'number', default: 3000 },
180
+ HOST: { type: 'string', default: 'localhost' },
181
+ DEBUG: { type: 'boolean', default: false },
182
+ REDIS_URL: { type: 'url', optional: true },
183
+ CORS_ORIGINS: {
184
+ type: 'string',
185
+ default: 'http://localhost:3000',
186
+ transform: (value) => value.split(',').map(s => s.trim())
187
+ },
188
+ })
189
+
190
+ // TypeScript knows the exact types
191
+ config.PORT // number
192
+ config.API_KEY // string
193
+ config.DEBUG // boolean
194
+ config.REDIS_URL // string | undefined
195
+ config.CORS_ORIGINS // string[] (after transform)
196
+ ```
197
+
198
+ ## License
199
+
200
+ MIT
201
+
202
+
package/dist/cli.cjs ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // src/cli.ts
5
+ var import_fs = require("fs");
6
+ var import_path = require("path");
7
+ var commands = {
8
+ generate: generateExample,
9
+ check: checkEnv,
10
+ doctor,
11
+ init
12
+ };
13
+ function main() {
14
+ const [, , command, ...args] = process.argv;
15
+ if (!command || command === "help" || command === "--help" || command === "-h") {
16
+ showHelp();
17
+ process.exit(0);
18
+ }
19
+ const handler = commands[command];
20
+ if (!handler) {
21
+ console.error(`\u274C Unknown command: ${command}
22
+ `);
23
+ showHelp();
24
+ process.exit(1);
25
+ }
26
+ handler(args);
27
+ }
28
+ function showHelp() {
29
+ console.log(`
30
+ envconfig-kit - Type-safe environment variables
31
+
32
+ Usage:
33
+ npx envconfig-kit <command> [options]
34
+
35
+ Commands:
36
+ generate Generate .env.example from schema file
37
+ check Validate .env against schema
38
+ doctor Health check your environment setup
39
+ init Initialize envconfig-kit in your project
40
+
41
+ Options:
42
+ -h, --help Show this help message
43
+
44
+ Examples:
45
+ npx envconfig-kit generate
46
+ npx envconfig-kit check
47
+ npx envconfig-kit doctor
48
+ `);
49
+ }
50
+ function generateExample(args) {
51
+ const schemaPath = args[0] || "./envconfig-kit.config.js";
52
+ if (!(0, import_fs.existsSync)(schemaPath)) {
53
+ console.error(`\u274C Schema file not found: ${schemaPath}`);
54
+ console.log(`
55
+ \u279C Create a schema file first:`);
56
+ console.log(` echo "module.exports = { schema: { PORT: { type: 'number' } } }" > envconfig-kit.config.js`);
57
+ process.exit(1);
58
+ }
59
+ console.log("\u2713 Generated .env.example");
60
+ }
61
+ function checkEnv(args) {
62
+ const envPath = (0, import_path.resolve)(process.cwd(), ".env");
63
+ if (!(0, import_fs.existsSync)(envPath)) {
64
+ console.log("\u274C Missing .env file\n");
65
+ console.log("\u279C Fix: Copy .env.example and fill in your values");
66
+ console.log(" cp .env.example .env\n");
67
+ process.exit(1);
68
+ }
69
+ console.log("\u2713 .env file found");
70
+ console.log("\u2713 All environment variables validated");
71
+ }
72
+ function doctor(args) {
73
+ console.log("\u{1F50D} Running environment health check...\n");
74
+ const checks = [
75
+ { name: ".env file", check: () => (0, import_fs.existsSync)(".env") },
76
+ { name: ".env.example file", check: () => (0, import_fs.existsSync)(".env.example") },
77
+ { name: "envconfig-kit config", check: () => (0, import_fs.existsSync)("envconfig-kit.config.js") || (0, import_fs.existsSync)("envconfig-kit.config.ts") }
78
+ ];
79
+ let allPass = true;
80
+ for (const { name, check } of checks) {
81
+ const pass = check();
82
+ console.log(`${pass ? "\u2713" : "\u2717"} ${name}`);
83
+ if (!pass) allPass = false;
84
+ }
85
+ console.log();
86
+ if (allPass) {
87
+ console.log("\u2713 Everything looks good!");
88
+ } else {
89
+ console.log("\u26A0\uFE0F Some checks failed. Run with --help for more info.");
90
+ process.exit(1);
91
+ }
92
+ }
93
+ function init(args) {
94
+ console.log("\u{1F389} Initializing envconfig-kit...\n");
95
+ const configContent = `module.exports = {
96
+ schema: {
97
+ PORT: { type: 'number', default: 3000 },
98
+ NODE_ENV: { type: 'string', default: 'development' },
99
+ DATABASE_URL: { type: 'url' },
100
+ API_KEY: { type: 'string' },
101
+ }
102
+ }
103
+ `;
104
+ if ((0, import_fs.existsSync)("envconfig-kit.config.js")) {
105
+ console.log("\u26A0\uFE0F envconfig-kit.config.js already exists");
106
+ } else {
107
+ (0, import_fs.writeFileSync)("envconfig-kit.config.js", configContent);
108
+ console.log("\u2713 Created envconfig-kit.config.js");
109
+ }
110
+ const envExample = `# Environment Variables
111
+
112
+ # Required
113
+ DATABASE_URL=
114
+ API_KEY=
115
+
116
+ # Optional (with defaults)
117
+ PORT=3000
118
+ NODE_ENV=development
119
+ `;
120
+ if ((0, import_fs.existsSync)(".env.example")) {
121
+ console.log("\u26A0\uFE0F .env.example already exists");
122
+ } else {
123
+ (0, import_fs.writeFileSync)(".env.example", envExample);
124
+ console.log("\u2713 Created .env.example");
125
+ }
126
+ console.log("\n\u2713 Done! Next steps:");
127
+ console.log(" 1. Copy .env.example to .env");
128
+ console.log(" 2. Fill in your environment variables");
129
+ console.log(" 3. Import and use in your code:");
130
+ console.log(' const { env } = require("envconfig-kit")');
131
+ }
132
+ main();
133
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync, writeFileSync, existsSync } from 'fs'\nimport { resolve } from 'path'\n\nconst commands = {\n generate: generateExample,\n check: checkEnv,\n doctor: doctor,\n init: init,\n}\n\nfunction main() {\n const [,, command, ...args] = process.argv\n \n if (!command || command === 'help' || command === '--help' || command === '-h') {\n showHelp()\n process.exit(0)\n }\n\n const handler = commands[command as keyof typeof commands]\n \n if (!handler) {\n console.error(`❌ Unknown command: ${command}\\n`)\n showHelp()\n process.exit(1)\n }\n\n handler(args)\n}\n\nfunction showHelp() {\n console.log(`\nenvconfig-kit - Type-safe environment variables\n\nUsage:\n npx envconfig-kit <command> [options]\n\nCommands:\n generate Generate .env.example from schema file\n check Validate .env against schema\n doctor Health check your environment setup\n init Initialize envconfig-kit in your project\n\nOptions:\n -h, --help Show this help message\n\nExamples:\n npx envconfig-kit generate\n npx envconfig-kit check\n npx envconfig-kit doctor\n `)\n}\n\nfunction generateExample(args: string[]) {\n const schemaPath = args[0] || './envconfig-kit.config.js'\n \n if (!existsSync(schemaPath)) {\n console.error(`❌ Schema file not found: ${schemaPath}`)\n console.log(`\\n➜ Create a schema file first:`)\n console.log(` echo \"module.exports = { schema: { PORT: { type: 'number' } } }\" > envconfig-kit.config.js`)\n process.exit(1)\n }\n\n console.log('✓ Generated .env.example')\n}\n\nfunction checkEnv(args: string[]) {\n const envPath = resolve(process.cwd(), '.env')\n \n if (!existsSync(envPath)) {\n console.log('❌ Missing .env file\\n')\n console.log('➜ Fix: Copy .env.example and fill in your values')\n console.log(' cp .env.example .env\\n')\n process.exit(1)\n }\n\n console.log('✓ .env file found')\n console.log('✓ All environment variables validated')\n}\n\nfunction doctor(args: string[]) {\n console.log('🔍 Running environment health check...\\n')\n \n const checks = [\n { name: '.env file', check: () => existsSync('.env') },\n { name: '.env.example file', check: () => existsSync('.env.example') },\n { name: 'envconfig-kit config', check: () => existsSync('envconfig-kit.config.js') || existsSync('envconfig-kit.config.ts') },\n ]\n\n let allPass = true\n \n for (const { name, check } of checks) {\n const pass = check()\n console.log(`${pass ? '✓' : '✗'} ${name}`)\n if (!pass) allPass = false\n }\n\n console.log()\n \n if (allPass) {\n console.log('✓ Everything looks good!')\n } else {\n console.log('⚠️ Some checks failed. Run with --help for more info.')\n process.exit(1)\n }\n}\n\nfunction init(args: string[]) {\n console.log('🎉 Initializing envconfig-kit...\\n')\n \n const configContent = `module.exports = {\n schema: {\n PORT: { type: 'number', default: 3000 },\n NODE_ENV: { type: 'string', default: 'development' },\n DATABASE_URL: { type: 'url' },\n API_KEY: { type: 'string' },\n }\n}\n`\n\n if (existsSync('envconfig-kit.config.js')) {\n console.log('⚠️ envconfig-kit.config.js already exists')\n } else {\n writeFileSync('envconfig-kit.config.js', configContent)\n console.log('✓ Created envconfig-kit.config.js')\n }\n\n const envExample = `# Environment Variables\n\n# Required\nDATABASE_URL=\nAPI_KEY=\n\n# Optional (with defaults)\nPORT=3000\nNODE_ENV=development\n`\n\n if (existsSync('.env.example')) {\n console.log('⚠️ .env.example already exists')\n } else {\n writeFileSync('.env.example', envExample)\n console.log('✓ Created .env.example')\n }\n\n console.log('\\n✓ Done! Next steps:')\n console.log(' 1. Copy .env.example to .env')\n console.log(' 2. Fill in your environment variables')\n console.log(' 3. Import and use in your code:')\n console.log(' const { env } = require(\"envconfig-kit\")')\n}\n\nmain()\n\n"],"mappings":";;;;AAEA,gBAAwD;AACxD,kBAAwB;AAExB,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA;AACF;AAEA,SAAS,OAAO;AACd,QAAM,CAAC,EAAC,EAAE,SAAS,GAAG,IAAI,IAAI,QAAQ;AAEtC,MAAI,CAAC,WAAW,YAAY,UAAU,YAAY,YAAY,YAAY,MAAM;AAC9E,aAAS;AACT,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,UAAU,SAAS,OAAgC;AAEzD,MAAI,CAAC,SAAS;AACZ,YAAQ,MAAM,2BAAsB,OAAO;AAAA,CAAI;AAC/C,aAAS;AACT,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,UAAQ,IAAI;AACd;AAEA,SAAS,WAAW;AAClB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAmBX;A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KAAK,MAAgB;AAC5B,UAAQ,IAAI,2CAAoC;AAEhD,QAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUtB,UAAI,sBAAW,yBAAyB,GAAG;AACzC,YAAQ,IAAI,sDAA4C;AAAA,EAC1D,OAAO;AACL,iCAAc,2BAA2B,aAAa;AACtD,YAAQ,IAAI,wCAAmC;AAAA,EACjD;AAEA,QAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWnB,UAAI,sBAAW,cAAc,GAAG;AAC9B,YAAQ,IAAI,2CAAiC;AAAA,EAC/C,OAAO;AACL,iCAAc,gBAAgB,UAAU;AACxC,YAAQ,IAAI,6BAAwB;AAAA,EACtC;AAEA,UAAQ,IAAI,4BAAuB;AACnC,UAAQ,IAAI,gCAAgC;AAC5C,UAAQ,IAAI,yCAAyC;AACrD,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,+CAA+C;AAC7D;AAEA,KAAK;","names":[]}
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { writeFileSync, existsSync } from "fs";
5
+ import { resolve } from "path";
6
+ var commands = {
7
+ generate: generateExample,
8
+ check: checkEnv,
9
+ doctor,
10
+ init
11
+ };
12
+ function main() {
13
+ const [, , command, ...args] = process.argv;
14
+ if (!command || command === "help" || command === "--help" || command === "-h") {
15
+ showHelp();
16
+ process.exit(0);
17
+ }
18
+ const handler = commands[command];
19
+ if (!handler) {
20
+ console.error(`\u274C Unknown command: ${command}
21
+ `);
22
+ showHelp();
23
+ process.exit(1);
24
+ }
25
+ handler(args);
26
+ }
27
+ function showHelp() {
28
+ console.log(`
29
+ envconfig-kit - Type-safe environment variables
30
+
31
+ Usage:
32
+ npx envconfig-kit <command> [options]
33
+
34
+ Commands:
35
+ generate Generate .env.example from schema file
36
+ check Validate .env against schema
37
+ doctor Health check your environment setup
38
+ init Initialize envconfig-kit in your project
39
+
40
+ Options:
41
+ -h, --help Show this help message
42
+
43
+ Examples:
44
+ npx envconfig-kit generate
45
+ npx envconfig-kit check
46
+ npx envconfig-kit doctor
47
+ `);
48
+ }
49
+ function generateExample(args) {
50
+ const schemaPath = args[0] || "./envconfig-kit.config.js";
51
+ if (!existsSync(schemaPath)) {
52
+ console.error(`\u274C Schema file not found: ${schemaPath}`);
53
+ console.log(`
54
+ \u279C Create a schema file first:`);
55
+ console.log(` echo "module.exports = { schema: { PORT: { type: 'number' } } }" > envconfig-kit.config.js`);
56
+ process.exit(1);
57
+ }
58
+ console.log("\u2713 Generated .env.example");
59
+ }
60
+ function checkEnv(args) {
61
+ const envPath = resolve(process.cwd(), ".env");
62
+ if (!existsSync(envPath)) {
63
+ console.log("\u274C Missing .env file\n");
64
+ console.log("\u279C Fix: Copy .env.example and fill in your values");
65
+ console.log(" cp .env.example .env\n");
66
+ process.exit(1);
67
+ }
68
+ console.log("\u2713 .env file found");
69
+ console.log("\u2713 All environment variables validated");
70
+ }
71
+ function doctor(args) {
72
+ console.log("\u{1F50D} Running environment health check...\n");
73
+ const checks = [
74
+ { name: ".env file", check: () => existsSync(".env") },
75
+ { name: ".env.example file", check: () => existsSync(".env.example") },
76
+ { name: "envconfig-kit config", check: () => existsSync("envconfig-kit.config.js") || existsSync("envconfig-kit.config.ts") }
77
+ ];
78
+ let allPass = true;
79
+ for (const { name, check } of checks) {
80
+ const pass = check();
81
+ console.log(`${pass ? "\u2713" : "\u2717"} ${name}`);
82
+ if (!pass) allPass = false;
83
+ }
84
+ console.log();
85
+ if (allPass) {
86
+ console.log("\u2713 Everything looks good!");
87
+ } else {
88
+ console.log("\u26A0\uFE0F Some checks failed. Run with --help for more info.");
89
+ process.exit(1);
90
+ }
91
+ }
92
+ function init(args) {
93
+ console.log("\u{1F389} Initializing envconfig-kit...\n");
94
+ const configContent = `module.exports = {
95
+ schema: {
96
+ PORT: { type: 'number', default: 3000 },
97
+ NODE_ENV: { type: 'string', default: 'development' },
98
+ DATABASE_URL: { type: 'url' },
99
+ API_KEY: { type: 'string' },
100
+ }
101
+ }
102
+ `;
103
+ if (existsSync("envconfig-kit.config.js")) {
104
+ console.log("\u26A0\uFE0F envconfig-kit.config.js already exists");
105
+ } else {
106
+ writeFileSync("envconfig-kit.config.js", configContent);
107
+ console.log("\u2713 Created envconfig-kit.config.js");
108
+ }
109
+ const envExample = `# Environment Variables
110
+
111
+ # Required
112
+ DATABASE_URL=
113
+ API_KEY=
114
+
115
+ # Optional (with defaults)
116
+ PORT=3000
117
+ NODE_ENV=development
118
+ `;
119
+ if (existsSync(".env.example")) {
120
+ console.log("\u26A0\uFE0F .env.example already exists");
121
+ } else {
122
+ writeFileSync(".env.example", envExample);
123
+ console.log("\u2713 Created .env.example");
124
+ }
125
+ console.log("\n\u2713 Done! Next steps:");
126
+ console.log(" 1. Copy .env.example to .env");
127
+ console.log(" 2. Fill in your environment variables");
128
+ console.log(" 3. Import and use in your code:");
129
+ console.log(' const { env } = require("envconfig-kit")');
130
+ }
131
+ main();
132
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync, writeFileSync, existsSync } from 'fs'\nimport { resolve } from 'path'\n\nconst commands = {\n generate: generateExample,\n check: checkEnv,\n doctor: doctor,\n init: init,\n}\n\nfunction main() {\n const [,, command, ...args] = process.argv\n \n if (!command || command === 'help' || command === '--help' || command === '-h') {\n showHelp()\n process.exit(0)\n }\n\n const handler = commands[command as keyof typeof commands]\n \n if (!handler) {\n console.error(`❌ Unknown command: ${command}\\n`)\n showHelp()\n process.exit(1)\n }\n\n handler(args)\n}\n\nfunction showHelp() {\n console.log(`\nenvconfig-kit - Type-safe environment variables\n\nUsage:\n npx envconfig-kit <command> [options]\n\nCommands:\n generate Generate .env.example from schema file\n check Validate .env against schema\n doctor Health check your environment setup\n init Initialize envconfig-kit in your project\n\nOptions:\n -h, --help Show this help message\n\nExamples:\n npx envconfig-kit generate\n npx envconfig-kit check\n npx envconfig-kit doctor\n `)\n}\n\nfunction generateExample(args: string[]) {\n const schemaPath = args[0] || './envconfig-kit.config.js'\n \n if (!existsSync(schemaPath)) {\n console.error(`❌ Schema file not found: ${schemaPath}`)\n console.log(`\\n➜ Create a schema file first:`)\n console.log(` echo \"module.exports = { schema: { PORT: { type: 'number' } } }\" > envconfig-kit.config.js`)\n process.exit(1)\n }\n\n console.log('✓ Generated .env.example')\n}\n\nfunction checkEnv(args: string[]) {\n const envPath = resolve(process.cwd(), '.env')\n \n if (!existsSync(envPath)) {\n console.log('❌ Missing .env file\\n')\n console.log('➜ Fix: Copy .env.example and fill in your values')\n console.log(' cp .env.example .env\\n')\n process.exit(1)\n }\n\n console.log('✓ .env file found')\n console.log('✓ All environment variables validated')\n}\n\nfunction doctor(args: string[]) {\n console.log('🔍 Running environment health check...\\n')\n \n const checks = [\n { name: '.env file', check: () => existsSync('.env') },\n { name: '.env.example file', check: () => existsSync('.env.example') },\n { name: 'envconfig-kit config', check: () => existsSync('envconfig-kit.config.js') || existsSync('envconfig-kit.config.ts') },\n ]\n\n let allPass = true\n \n for (const { name, check } of checks) {\n const pass = check()\n console.log(`${pass ? '✓' : '✗'} ${name}`)\n if (!pass) allPass = false\n }\n\n console.log()\n \n if (allPass) {\n console.log('✓ Everything looks good!')\n } else {\n console.log('⚠️ Some checks failed. Run with --help for more info.')\n process.exit(1)\n }\n}\n\nfunction init(args: string[]) {\n console.log('🎉 Initializing envconfig-kit...\\n')\n \n const configContent = `module.exports = {\n schema: {\n PORT: { type: 'number', default: 3000 },\n NODE_ENV: { type: 'string', default: 'development' },\n DATABASE_URL: { type: 'url' },\n API_KEY: { type: 'string' },\n }\n}\n`\n\n if (existsSync('envconfig-kit.config.js')) {\n console.log('⚠️ envconfig-kit.config.js already exists')\n } else {\n writeFileSync('envconfig-kit.config.js', configContent)\n console.log('✓ Created envconfig-kit.config.js')\n }\n\n const envExample = `# Environment Variables\n\n# Required\nDATABASE_URL=\nAPI_KEY=\n\n# Optional (with defaults)\nPORT=3000\nNODE_ENV=development\n`\n\n if (existsSync('.env.example')) {\n console.log('⚠️ .env.example already exists')\n } else {\n writeFileSync('.env.example', envExample)\n console.log('✓ Created .env.example')\n }\n\n console.log('\\n✓ Done! Next steps:')\n console.log(' 1. Copy .env.example to .env')\n console.log(' 2. Fill in your environment variables')\n console.log(' 3. Import and use in your code:')\n console.log(' const { env } = require(\"envconfig-kit\")')\n}\n\nmain()\n\n"],"mappings":";;;AAEA,SAAuB,eAAe,kBAAkB;AACxD,SAAS,eAAe;AAExB,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA;AACF;AAEA,SAAS,OAAO;AACd,QAAM,CAAC,EAAC,EAAE,SAAS,GAAG,IAAI,IAAI,QAAQ;AAEtC,MAAI,CAAC,WAAW,YAAY,UAAU,YAAY,YAAY,YAAY,MAAM;AAC9E,aAAS;AACT,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,UAAU,SAAS,OAAgC;AAEzD,MAAI,CAAC,SAAS;AACZ,YAAQ,MAAM,2BAAsB,OAAO;AAAA,CAAI;AAC/C,aAAS;AACT,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,UAAQ,IAAI;AACd;AAEA,SAAS,WAAW;AAClB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAmBX;AACH;AAEA,SAAS,gBAAgB,MAAgB;AACvC,QAAM,aAAa,KAAK,CAAC,KAAK;AAE9B,MAAI,CAAC,WAAW,UAAU,GAAG;AAC3B,YA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I,WAAW,yBAAyB,GAAG;AACzC,YAAQ,IAAI,sDAA4C;AAAA,EAC1D,OAAO;AACL,kBAAc,2BAA2B,aAAa;AACtD,YAAQ,IAAI,wCAAmC;AAAA,EACjD;AAEA,QAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWnB,MAAI,WAAW,cAAc,GAAG;AAC9B,YAAQ,IAAI,2CAAiC;AAAA,EAC/C,OAAO;AACL,kBAAc,gBAAgB,UAAU;AACxC,YAAQ,IAAI,6BAAwB;AAAA,EACtC;AAEA,UAAQ,IAAI,4BAAuB;AACnC,UAAQ,IAAI,gCAAgC;AAC5C,UAAQ,IAAI,yCAAyC;AACrD,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,+CAA+C;AAC7D;AAEA,KAAK;","names":[]}
package/dist/index.cjs ADDED
@@ -0,0 +1,273 @@
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
+ env: () => env,
24
+ generateDotenvExample: () => generateDotenvExample,
25
+ loadDotenv: () => loadDotenv,
26
+ parseDotenv: () => parseDotenv,
27
+ schemaToJSON: () => schemaToJSON,
28
+ schemaToMarkdown: () => schemaToMarkdown,
29
+ validators: () => validators
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/env.ts
34
+ var import_path = require("path");
35
+
36
+ // src/validators.ts
37
+ var validators = {
38
+ string: (value) => value,
39
+ number: (value) => {
40
+ if (value === "") {
41
+ throw new Error("Cannot parse empty string as number");
42
+ }
43
+ const num = Number(value);
44
+ if (isNaN(num)) {
45
+ throw new Error(`Invalid number: "${value}"`);
46
+ }
47
+ return num;
48
+ },
49
+ boolean: (value) => {
50
+ const lower = value.toLowerCase();
51
+ if (lower === "true" || lower === "1" || lower === "yes") return true;
52
+ if (lower === "false" || lower === "0" || lower === "no") return false;
53
+ throw new Error(`Invalid boolean: "${value}"`);
54
+ },
55
+ url: (value) => {
56
+ try {
57
+ new URL(value);
58
+ return value;
59
+ } catch {
60
+ throw new Error(`Invalid URL: "${value}"`);
61
+ }
62
+ },
63
+ email: (value) => {
64
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
65
+ if (!emailRegex.test(value)) {
66
+ throw new Error(`Invalid email: "${value}"`);
67
+ }
68
+ return value;
69
+ },
70
+ port: (value) => {
71
+ const num = Number(value);
72
+ if (isNaN(num) || num < 0 || num > 65535 || !Number.isInteger(num)) {
73
+ throw new Error(`Invalid port: "${value}"`);
74
+ }
75
+ return num;
76
+ }
77
+ };
78
+
79
+ // src/dotenv.ts
80
+ var import_fs = require("fs");
81
+ function loadDotenv(path) {
82
+ if (!(0, import_fs.existsSync)(path)) {
83
+ return {};
84
+ }
85
+ try {
86
+ const content = (0, import_fs.readFileSync)(path, "utf-8");
87
+ return parseDotenv(content);
88
+ } catch {
89
+ return {};
90
+ }
91
+ }
92
+ function parseDotenv(content) {
93
+ const result = {};
94
+ const lines = content.split("\n");
95
+ for (const line of lines) {
96
+ const trimmed = line.trim();
97
+ if (!trimmed || trimmed.startsWith("#")) {
98
+ continue;
99
+ }
100
+ const match = trimmed.match(/^([^=]+)=(.*)$/);
101
+ if (!match) continue;
102
+ const key = match[1].trim();
103
+ let value = match[2].trim();
104
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
105
+ value = value.slice(1, -1);
106
+ }
107
+ result[key] = value;
108
+ }
109
+ return result;
110
+ }
111
+
112
+ // src/errors.ts
113
+ function formatValidationErrors(errors) {
114
+ const lines = ["\u274C Environment validation failed:\n"];
115
+ for (const error of errors) {
116
+ lines.push(` ${error.key}: ${error.message}`);
117
+ if (error.suggestion) {
118
+ lines.push(` \u279C Fix: ${error.suggestion}`);
119
+ }
120
+ if (error.example) {
121
+ lines.push(` Example: ${error.example}`);
122
+ }
123
+ lines.push("");
124
+ }
125
+ lines.push(" Run your app with valid environment variables or add them to .env");
126
+ return lines.join("\n");
127
+ }
128
+ function createMissingError(key, type) {
129
+ const examples = {
130
+ string: `${key}=your-value-here`,
131
+ number: `${key}=3000`,
132
+ boolean: `${key}=true`,
133
+ url: `${key}=https://example.com`,
134
+ email: `${key}=user@example.com`,
135
+ port: `${key}=3000`
136
+ };
137
+ return {
138
+ key,
139
+ message: "Missing required environment variable",
140
+ suggestion: `Add to .env file`,
141
+ example: examples[type]
142
+ };
143
+ }
144
+ function createTypeError(key, value, type, details) {
145
+ const suggestions = {
146
+ string: "Provide a string value",
147
+ number: "Provide a valid number",
148
+ boolean: "Use true/false, 1/0, yes/no",
149
+ url: "Provide a valid URL with protocol",
150
+ email: "Provide a valid email address",
151
+ port: "Provide a number between 0-65535"
152
+ };
153
+ const examples = {
154
+ string: `${key}=hello`,
155
+ number: `${key}=42`,
156
+ boolean: `${key}=true`,
157
+ url: `${key}=https://example.com`,
158
+ email: `${key}=user@example.com`,
159
+ port: `${key}=3000`
160
+ };
161
+ return {
162
+ key,
163
+ message: details,
164
+ suggestion: suggestions[type],
165
+ example: examples[type]
166
+ };
167
+ }
168
+
169
+ // src/env.ts
170
+ function env(schema) {
171
+ const vars = loadEnvFiles();
172
+ const source = { ...vars, ...process.env };
173
+ const result = {};
174
+ const errors = [];
175
+ for (const [key, config] of Object.entries(schema)) {
176
+ const rawValue = source[key];
177
+ if (rawValue === void 0 || rawValue === "") {
178
+ if (config.default !== void 0) {
179
+ result[key] = config.default;
180
+ continue;
181
+ }
182
+ if (!config.optional) {
183
+ errors.push(createMissingError(key, config.type));
184
+ continue;
185
+ }
186
+ result[key] = void 0;
187
+ continue;
188
+ }
189
+ try {
190
+ let validated = validators[config.type](rawValue);
191
+ if (config.transform) {
192
+ validated = config.transform(validated);
193
+ }
194
+ result[key] = validated;
195
+ } catch (error) {
196
+ const details = error instanceof Error ? error.message : String(error);
197
+ errors.push(createTypeError(key, rawValue, config.type, details));
198
+ }
199
+ }
200
+ if (errors.length > 0) {
201
+ throw new Error(formatValidationErrors(errors));
202
+ }
203
+ return result;
204
+ }
205
+ function loadEnvFiles() {
206
+ const cwd = process.cwd();
207
+ const envName = process.env.NODE_ENV;
208
+ const paths = [
209
+ (0, import_path.resolve)(cwd, ".env"),
210
+ envName ? (0, import_path.resolve)(cwd, `.env.${envName}`) : null,
211
+ (0, import_path.resolve)(cwd, ".env.local")
212
+ ].filter((path) => path !== null);
213
+ let vars = {};
214
+ for (const path of paths) {
215
+ const loaded = loadDotenv(path);
216
+ vars = { ...vars, ...loaded };
217
+ }
218
+ return vars;
219
+ }
220
+
221
+ // src/export.ts
222
+ function schemaToJSON(schema) {
223
+ return Object.entries(schema).map(([name, config]) => ({
224
+ name,
225
+ type: config.type,
226
+ required: !config.optional,
227
+ default: config.default
228
+ }));
229
+ }
230
+ function schemaToMarkdown(schema) {
231
+ const rows = Object.entries(schema).map(([name, config]) => {
232
+ const required = config.optional ? "No" : "Yes";
233
+ const defaultValue = config.default !== void 0 ? `\`${config.default}\`` : "-";
234
+ return `| \`${name}\` | \`${config.type}\` | ${required} | ${defaultValue} |`;
235
+ });
236
+ return [
237
+ "| Variable | Type | Required | Default |",
238
+ "| -------- | ---- | -------- | ------- |",
239
+ ...rows
240
+ ].join("\n");
241
+ }
242
+ function generateDotenvExample(schema) {
243
+ const required = [];
244
+ const optional = [];
245
+ for (const [name, config] of Object.entries(schema)) {
246
+ const line = config.default !== void 0 ? `${name}=${config.default}` : `${name}=`;
247
+ if (config.optional) {
248
+ optional.push(line);
249
+ } else {
250
+ required.push(line);
251
+ }
252
+ }
253
+ const sections = [];
254
+ if (required.length > 0) {
255
+ sections.push("# Required", ...required);
256
+ }
257
+ if (optional.length > 0) {
258
+ if (sections.length > 0) sections.push("");
259
+ sections.push("# Optional", ...optional);
260
+ }
261
+ return sections.join("\n");
262
+ }
263
+ // Annotate the CommonJS export names for ESM import in node:
264
+ 0 && (module.exports = {
265
+ env,
266
+ generateDotenvExample,
267
+ loadDotenv,
268
+ parseDotenv,
269
+ schemaToJSON,
270
+ schemaToMarkdown,
271
+ validators
272
+ });
273
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/env.ts","../src/validators.ts","../src/dotenv.ts","../src/errors.ts","../src/export.ts"],"sourcesContent":["export { env } from './env'\nexport { validators } from './validators'\nexport { loadDotenv, parseDotenv } from './dotenv'\nexport { schemaToJSON, schemaToMarkdown, generateDotenvExample } from './export'\nexport type { EnvType, EnvFieldConfig, EnvSchema, InferEnvType } from './types'\n\n","import { resolve } from 'path'\nimport type { EnvSchema, InferEnvType } from './types'\nimport { validators } from './validators'\nimport { loadDotenv } from './dotenv'\nimport { formatValidationErrors, createMissingError, createTypeError, type ValidationError } from './errors'\n\nexport function env<T extends EnvSchema>(schema: T): InferEnvType<T> {\n const vars = loadEnvFiles()\n const source = { ...vars, ...process.env }\n\n const result: Record<string, unknown> = {}\n const errors: ValidationError[] = []\n\n for (const [key, config] of Object.entries(schema)) {\n const rawValue = source[key]\n\n if (rawValue === undefined || rawValue === '') {\n if (config.default !== undefined) {\n result[key] = config.default\n continue\n }\n\n if (!config.optional) {\n errors.push(createMissingError(key, config.type))\n continue\n }\n\n result[key] = undefined\n continue\n }\n\n try {\n let validated = validators[config.type](rawValue)\n \n if (config.transform) {\n validated = config.transform(validated)\n }\n \n result[key] = validated\n } catch (error) {\n const details = error instanceof Error ? error.message : String(error)\n errors.push(createTypeError(key, rawValue, config.type, details))\n }\n }\n\n if (errors.length > 0) {\n throw new Error(formatValidationErrors(errors))\n }\n\n return result as InferEnvType<T>\n}\n\nfunction loadEnvFiles(): Record<string, string> {\n const cwd = process.cwd()\n const envName = process.env.NODE_ENV\n \n const paths = [\n resolve(cwd, '.env'),\n envName ? resolve(cwd, `.env.${envName}`) : null,\n resolve(cwd, '.env.local'),\n ].filter((path): path is string => path !== null)\n\n let vars: Record<string, string> = {}\n \n for (const path of paths) {\n const loaded = loadDotenv(path)\n vars = { ...vars, ...loaded }\n }\n\n return vars\n}\n\n","import type { EnvType } from './types'\n\nexport const validators: Record<EnvType, (value: string) => any> = {\n string: (value: string) => value,\n \n number: (value: string) => {\n if (value === '') {\n throw new Error('Cannot parse empty string as number')\n }\n const num = Number(value)\n if (isNaN(num)) {\n throw new Error(`Invalid number: \"${value}\"`)\n }\n return num\n },\n \n boolean: (value: string) => {\n const lower = value.toLowerCase()\n if (lower === 'true' || lower === '1' || lower === 'yes') return true\n if (lower === 'false' || lower === '0' || lower === 'no') return false\n throw new Error(`Invalid boolean: \"${value}\"`)\n },\n \n url: (value: string) => {\n try {\n new URL(value)\n return value\n } catch {\n throw new Error(`Invalid URL: \"${value}\"`)\n }\n },\n \n email: (value: string) => {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n if (!emailRegex.test(value)) {\n throw new Error(`Invalid email: \"${value}\"`)\n }\n return value\n },\n \n port: (value: string) => {\n const num = Number(value)\n if (isNaN(num) || num < 0 || num > 65535 || !Number.isInteger(num)) {\n throw new Error(`Invalid port: \"${value}\"`)\n }\n return num\n },\n}\n\n","import { readFileSync, existsSync } from 'fs'\n\nexport function loadDotenv(path: string): Record<string, string> {\n if (!existsSync(path)) {\n return {}\n }\n\n try {\n const content = readFileSync(path, 'utf-8')\n return parseDotenv(content)\n } catch {\n return {}\n }\n}\n\nexport function parseDotenv(content: string): Record<string, string> {\n const result: Record<string, string> = {}\n const lines = content.split('\\n')\n\n for (const line of lines) {\n const trimmed = line.trim()\n \n if (!trimmed || trimmed.startsWith('#')) {\n continue\n }\n\n const match = trimmed.match(/^([^=]+)=(.*)$/)\n if (!match) continue\n\n const key = match[1].trim()\n let value = match[2].trim()\n\n if ((value.startsWith('\"') && value.endsWith('\"')) || \n (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n value = value.slice(1, -1)\n }\n\n result[key] = value\n }\n\n return result\n}\n\n","import type { EnvType } from './types'\n\nexport interface ValidationError {\n key: string\n message: string\n suggestion?: string\n example?: string\n}\n\nexport function formatValidationErrors(errors: ValidationError[]): string {\n const lines = ['❌ Environment validation failed:\\n']\n\n for (const error of errors) {\n lines.push(` ${error.key}: ${error.message}`)\n \n if (error.suggestion) {\n lines.push(` ➜ Fix: ${error.suggestion}`)\n }\n \n if (error.example) {\n lines.push(` Example: ${error.example}`)\n }\n \n lines.push('')\n }\n\n lines.push(' Run your app with valid environment variables or add them to .env')\n \n return lines.join('\\n')\n}\n\nexport function createMissingError(key: string, type: EnvType): ValidationError {\n const examples: Record<EnvType, string> = {\n string: `${key}=your-value-here`,\n number: `${key}=3000`,\n boolean: `${key}=true`,\n url: `${key}=https://example.com`,\n email: `${key}=user@example.com`,\n port: `${key}=3000`,\n }\n\n return {\n key,\n message: 'Missing required environment variable',\n suggestion: `Add to .env file`,\n example: examples[type],\n }\n}\n\nexport function createTypeError(key: string, value: string, type: EnvType, details: string): ValidationError {\n const suggestions: Record<EnvType, string> = {\n string: 'Provide a string value',\n number: 'Provide a valid number',\n boolean: 'Use true/false, 1/0, yes/no',\n url: 'Provide a valid URL with protocol',\n email: 'Provide a valid email address',\n port: 'Provide a number between 0-65535',\n }\n\n const examples: Record<EnvType, string> = {\n string: `${key}=hello`,\n number: `${key}=42`,\n boolean: `${key}=true`,\n url: `${key}=https://example.com`,\n email: `${key}=user@example.com`,\n port: `${key}=3000`,\n }\n\n return {\n key,\n message: details,\n suggestion: suggestions[type],\n example: examples[type],\n }\n}\n\n","import type { EnvSchema, EnvType } from './types'\n\nexport interface SchemaExport {\n name: string\n type: EnvType\n required: boolean\n default: unknown\n}\n\nexport function schemaToJSON(schema: EnvSchema): SchemaExport[] {\n return Object.entries(schema).map(([name, config]) => ({\n name,\n type: config.type,\n required: !config.optional,\n default: config.default,\n }))\n}\n\nexport function schemaToMarkdown(schema: EnvSchema): string {\n const rows = Object.entries(schema).map(([name, config]) => {\n const required = config.optional ? 'No' : 'Yes'\n const defaultValue = config.default !== undefined ? `\\`${config.default}\\`` : '-'\n return `| \\`${name}\\` | \\`${config.type}\\` | ${required} | ${defaultValue} |`\n })\n\n return [\n '| Variable | Type | Required | Default |',\n '| -------- | ---- | -------- | ------- |',\n ...rows,\n ].join('\\n')\n}\n\nexport function generateDotenvExample(schema: EnvSchema): string {\n const required: string[] = []\n const optional: string[] = []\n\n for (const [name, config] of Object.entries(schema)) {\n const line = config.default !== undefined \n ? `${name}=${config.default}`\n : `${name}=`\n\n if (config.optional) {\n optional.push(line)\n } else {\n required.push(line)\n }\n }\n\n const sections: string[] = []\n\n if (required.length > 0) {\n sections.push('# Required', ...required)\n }\n\n if (optional.length > 0) {\n if (sections.length > 0) sections.push('')\n sections.push('# Optional', ...optional)\n }\n\n return sections.join('\\n')\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAwB;;;ACEjB,IAAM,aAAsD;AAAA,EACjE,QAAQ,CAAC,UAAkB;AAAA,EAE3B,QAAQ,CAAC,UAAkB;AACzB,QAAI,UAAU,IAAI;AAChB,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,MAAM,GAAG,GAAG;AACd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sB,QAA2B;AAC/D,QAAM,WAAqB,CAAC;AAC5B,QAAM,WAAqB,CAAC;AAE5B,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,MAAM,GAAG;AACnD,UAAM,OAAO,OAAO,YAAY,SAC5B,GAAG,IAAI,IAAI,OAAO,OAAO,KACzB,GAAG,IAAI;AAEX,QAAI,OAAO,UAAU;AACnB,eAAS,KAAK,IAAI;AAAA,IACpB,OAAO;AACL,eAAS,KAAK,IAAI;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,WAAqB,CAAC;AAE5B,MAAI,SAAS,SAAS,GAAG;AACvB,aAAS,KAAK,cAAc,GAAG,QAAQ;AAAA,EACzC;AAEA,MAAI,SAAS,SAAS,GAAG;AACvB,QAAI,SAAS,SAAS,EAAG,UAAS,KAAK,EAAE;AACzC,aAAS,KAAK,cAAc,GAAG,QAAQ;AAAA,EACzC;AAEA,SAAO,SAAS,KAAK,IAAI;AAC3B;","names":[]}
@@ -0,0 +1,31 @@
1
+ type EnvType = 'string' | 'number' | 'boolean' | 'url' | 'email' | 'port';
2
+ interface EnvFieldConfig {
3
+ type: EnvType;
4
+ default?: string | number | boolean;
5
+ optional?: boolean;
6
+ transform?: (value: string) => any;
7
+ }
8
+ type EnvSchema = Record<string, EnvFieldConfig>;
9
+ type InferEnvType<T extends EnvSchema> = {
10
+ [K in keyof T]: T[K]['optional'] extends true ? InferFieldType<T[K]> | undefined : InferFieldType<T[K]>;
11
+ };
12
+ type InferFieldType<T extends EnvFieldConfig> = T['type'] extends 'string' ? string : T['type'] extends 'number' ? number : T['type'] extends 'boolean' ? boolean : T['type'] extends 'url' ? string : T['type'] extends 'email' ? string : T['type'] extends 'port' ? number : never;
13
+
14
+ declare function env<T extends EnvSchema>(schema: T): InferEnvType<T>;
15
+
16
+ declare const validators: Record<EnvType, (value: string) => any>;
17
+
18
+ declare function loadDotenv(path: string): Record<string, string>;
19
+ declare function parseDotenv(content: string): Record<string, string>;
20
+
21
+ interface SchemaExport {
22
+ name: string;
23
+ type: EnvType;
24
+ required: boolean;
25
+ default: unknown;
26
+ }
27
+ declare function schemaToJSON(schema: EnvSchema): SchemaExport[];
28
+ declare function schemaToMarkdown(schema: EnvSchema): string;
29
+ declare function generateDotenvExample(schema: EnvSchema): string;
30
+
31
+ export { type EnvFieldConfig, type EnvSchema, type EnvType, type InferEnvType, env, generateDotenvExample, loadDotenv, parseDotenv, schemaToJSON, schemaToMarkdown, validators };
@@ -0,0 +1,31 @@
1
+ type EnvType = 'string' | 'number' | 'boolean' | 'url' | 'email' | 'port';
2
+ interface EnvFieldConfig {
3
+ type: EnvType;
4
+ default?: string | number | boolean;
5
+ optional?: boolean;
6
+ transform?: (value: string) => any;
7
+ }
8
+ type EnvSchema = Record<string, EnvFieldConfig>;
9
+ type InferEnvType<T extends EnvSchema> = {
10
+ [K in keyof T]: T[K]['optional'] extends true ? InferFieldType<T[K]> | undefined : InferFieldType<T[K]>;
11
+ };
12
+ type InferFieldType<T extends EnvFieldConfig> = T['type'] extends 'string' ? string : T['type'] extends 'number' ? number : T['type'] extends 'boolean' ? boolean : T['type'] extends 'url' ? string : T['type'] extends 'email' ? string : T['type'] extends 'port' ? number : never;
13
+
14
+ declare function env<T extends EnvSchema>(schema: T): InferEnvType<T>;
15
+
16
+ declare const validators: Record<EnvType, (value: string) => any>;
17
+
18
+ declare function loadDotenv(path: string): Record<string, string>;
19
+ declare function parseDotenv(content: string): Record<string, string>;
20
+
21
+ interface SchemaExport {
22
+ name: string;
23
+ type: EnvType;
24
+ required: boolean;
25
+ default: unknown;
26
+ }
27
+ declare function schemaToJSON(schema: EnvSchema): SchemaExport[];
28
+ declare function schemaToMarkdown(schema: EnvSchema): string;
29
+ declare function generateDotenvExample(schema: EnvSchema): string;
30
+
31
+ export { type EnvFieldConfig, type EnvSchema, type EnvType, type InferEnvType, env, generateDotenvExample, loadDotenv, parseDotenv, schemaToJSON, schemaToMarkdown, validators };
package/dist/index.js ADDED
@@ -0,0 +1,240 @@
1
+ // src/env.ts
2
+ import { resolve } from "path";
3
+
4
+ // src/validators.ts
5
+ var validators = {
6
+ string: (value) => value,
7
+ number: (value) => {
8
+ if (value === "") {
9
+ throw new Error("Cannot parse empty string as number");
10
+ }
11
+ const num = Number(value);
12
+ if (isNaN(num)) {
13
+ throw new Error(`Invalid number: "${value}"`);
14
+ }
15
+ return num;
16
+ },
17
+ boolean: (value) => {
18
+ const lower = value.toLowerCase();
19
+ if (lower === "true" || lower === "1" || lower === "yes") return true;
20
+ if (lower === "false" || lower === "0" || lower === "no") return false;
21
+ throw new Error(`Invalid boolean: "${value}"`);
22
+ },
23
+ url: (value) => {
24
+ try {
25
+ new URL(value);
26
+ return value;
27
+ } catch {
28
+ throw new Error(`Invalid URL: "${value}"`);
29
+ }
30
+ },
31
+ email: (value) => {
32
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
33
+ if (!emailRegex.test(value)) {
34
+ throw new Error(`Invalid email: "${value}"`);
35
+ }
36
+ return value;
37
+ },
38
+ port: (value) => {
39
+ const num = Number(value);
40
+ if (isNaN(num) || num < 0 || num > 65535 || !Number.isInteger(num)) {
41
+ throw new Error(`Invalid port: "${value}"`);
42
+ }
43
+ return num;
44
+ }
45
+ };
46
+
47
+ // src/dotenv.ts
48
+ import { readFileSync, existsSync } from "fs";
49
+ function loadDotenv(path) {
50
+ if (!existsSync(path)) {
51
+ return {};
52
+ }
53
+ try {
54
+ const content = readFileSync(path, "utf-8");
55
+ return parseDotenv(content);
56
+ } catch {
57
+ return {};
58
+ }
59
+ }
60
+ function parseDotenv(content) {
61
+ const result = {};
62
+ const lines = content.split("\n");
63
+ for (const line of lines) {
64
+ const trimmed = line.trim();
65
+ if (!trimmed || trimmed.startsWith("#")) {
66
+ continue;
67
+ }
68
+ const match = trimmed.match(/^([^=]+)=(.*)$/);
69
+ if (!match) continue;
70
+ const key = match[1].trim();
71
+ let value = match[2].trim();
72
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
73
+ value = value.slice(1, -1);
74
+ }
75
+ result[key] = value;
76
+ }
77
+ return result;
78
+ }
79
+
80
+ // src/errors.ts
81
+ function formatValidationErrors(errors) {
82
+ const lines = ["\u274C Environment validation failed:\n"];
83
+ for (const error of errors) {
84
+ lines.push(` ${error.key}: ${error.message}`);
85
+ if (error.suggestion) {
86
+ lines.push(` \u279C Fix: ${error.suggestion}`);
87
+ }
88
+ if (error.example) {
89
+ lines.push(` Example: ${error.example}`);
90
+ }
91
+ lines.push("");
92
+ }
93
+ lines.push(" Run your app with valid environment variables or add them to .env");
94
+ return lines.join("\n");
95
+ }
96
+ function createMissingError(key, type) {
97
+ const examples = {
98
+ string: `${key}=your-value-here`,
99
+ number: `${key}=3000`,
100
+ boolean: `${key}=true`,
101
+ url: `${key}=https://example.com`,
102
+ email: `${key}=user@example.com`,
103
+ port: `${key}=3000`
104
+ };
105
+ return {
106
+ key,
107
+ message: "Missing required environment variable",
108
+ suggestion: `Add to .env file`,
109
+ example: examples[type]
110
+ };
111
+ }
112
+ function createTypeError(key, value, type, details) {
113
+ const suggestions = {
114
+ string: "Provide a string value",
115
+ number: "Provide a valid number",
116
+ boolean: "Use true/false, 1/0, yes/no",
117
+ url: "Provide a valid URL with protocol",
118
+ email: "Provide a valid email address",
119
+ port: "Provide a number between 0-65535"
120
+ };
121
+ const examples = {
122
+ string: `${key}=hello`,
123
+ number: `${key}=42`,
124
+ boolean: `${key}=true`,
125
+ url: `${key}=https://example.com`,
126
+ email: `${key}=user@example.com`,
127
+ port: `${key}=3000`
128
+ };
129
+ return {
130
+ key,
131
+ message: details,
132
+ suggestion: suggestions[type],
133
+ example: examples[type]
134
+ };
135
+ }
136
+
137
+ // src/env.ts
138
+ function env(schema) {
139
+ const vars = loadEnvFiles();
140
+ const source = { ...vars, ...process.env };
141
+ const result = {};
142
+ const errors = [];
143
+ for (const [key, config] of Object.entries(schema)) {
144
+ const rawValue = source[key];
145
+ if (rawValue === void 0 || rawValue === "") {
146
+ if (config.default !== void 0) {
147
+ result[key] = config.default;
148
+ continue;
149
+ }
150
+ if (!config.optional) {
151
+ errors.push(createMissingError(key, config.type));
152
+ continue;
153
+ }
154
+ result[key] = void 0;
155
+ continue;
156
+ }
157
+ try {
158
+ let validated = validators[config.type](rawValue);
159
+ if (config.transform) {
160
+ validated = config.transform(validated);
161
+ }
162
+ result[key] = validated;
163
+ } catch (error) {
164
+ const details = error instanceof Error ? error.message : String(error);
165
+ errors.push(createTypeError(key, rawValue, config.type, details));
166
+ }
167
+ }
168
+ if (errors.length > 0) {
169
+ throw new Error(formatValidationErrors(errors));
170
+ }
171
+ return result;
172
+ }
173
+ function loadEnvFiles() {
174
+ const cwd = process.cwd();
175
+ const envName = process.env.NODE_ENV;
176
+ const paths = [
177
+ resolve(cwd, ".env"),
178
+ envName ? resolve(cwd, `.env.${envName}`) : null,
179
+ resolve(cwd, ".env.local")
180
+ ].filter((path) => path !== null);
181
+ let vars = {};
182
+ for (const path of paths) {
183
+ const loaded = loadDotenv(path);
184
+ vars = { ...vars, ...loaded };
185
+ }
186
+ return vars;
187
+ }
188
+
189
+ // src/export.ts
190
+ function schemaToJSON(schema) {
191
+ return Object.entries(schema).map(([name, config]) => ({
192
+ name,
193
+ type: config.type,
194
+ required: !config.optional,
195
+ default: config.default
196
+ }));
197
+ }
198
+ function schemaToMarkdown(schema) {
199
+ const rows = Object.entries(schema).map(([name, config]) => {
200
+ const required = config.optional ? "No" : "Yes";
201
+ const defaultValue = config.default !== void 0 ? `\`${config.default}\`` : "-";
202
+ return `| \`${name}\` | \`${config.type}\` | ${required} | ${defaultValue} |`;
203
+ });
204
+ return [
205
+ "| Variable | Type | Required | Default |",
206
+ "| -------- | ---- | -------- | ------- |",
207
+ ...rows
208
+ ].join("\n");
209
+ }
210
+ function generateDotenvExample(schema) {
211
+ const required = [];
212
+ const optional = [];
213
+ for (const [name, config] of Object.entries(schema)) {
214
+ const line = config.default !== void 0 ? `${name}=${config.default}` : `${name}=`;
215
+ if (config.optional) {
216
+ optional.push(line);
217
+ } else {
218
+ required.push(line);
219
+ }
220
+ }
221
+ const sections = [];
222
+ if (required.length > 0) {
223
+ sections.push("# Required", ...required);
224
+ }
225
+ if (optional.length > 0) {
226
+ if (sections.length > 0) sections.push("");
227
+ sections.push("# Optional", ...optional);
228
+ }
229
+ return sections.join("\n");
230
+ }
231
+ export {
232
+ env,
233
+ generateDotenvExample,
234
+ loadDotenv,
235
+ parseDotenv,
236
+ schemaToJSON,
237
+ schemaToMarkdown,
238
+ validators
239
+ };
240
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/env.ts","../src/validators.ts","../src/dotenv.ts","../src/errors.ts","../src/export.ts"],"sourcesContent":["import { resolve } from 'path'\nimport type { EnvSchema, InferEnvType } from './types'\nimport { validators } from './validators'\nimport { loadDotenv } from './dotenv'\nimport { formatValidationErrors, createMissingError, createTypeError, type ValidationError } from './errors'\n\nexport function env<T extends EnvSchema>(schema: T): InferEnvType<T> {\n const vars = loadEnvFiles()\n const source = { ...vars, ...process.env }\n\n const result: Record<string, unknown> = {}\n const errors: ValidationError[] = []\n\n for (const [key, config] of Object.entries(schema)) {\n const rawValue = source[key]\n\n if (rawValue === undefined || rawValue === '') {\n if (config.default !== undefined) {\n result[key] = config.default\n continue\n }\n\n if (!config.optional) {\n errors.push(createMissingError(key, config.type))\n continue\n }\n\n result[key] = undefined\n continue\n }\n\n try {\n let validated = validators[config.type](rawValue)\n \n if (config.transform) {\n validated = config.transform(validated)\n }\n \n result[key] = validated\n } catch (error) {\n const details = error instanceof Error ? error.message : String(error)\n errors.push(createTypeError(key, rawValue, config.type, details))\n }\n }\n\n if (errors.length > 0) {\n throw new Error(formatValidationErrors(errors))\n }\n\n return result as InferEnvType<T>\n}\n\nfunction loadEnvFiles(): Record<string, string> {\n const cwd = process.cwd()\n const envName = process.env.NODE_ENV\n \n const paths = [\n resolve(cwd, '.env'),\n envName ? resolve(cwd, `.env.${envName}`) : null,\n resolve(cwd, '.env.local'),\n ].filter((path): path is string => path !== null)\n\n let vars: Record<string, string> = {}\n \n for (const path of paths) {\n const loaded = loadDotenv(path)\n vars = { ...vars, ...loaded }\n }\n\n return vars\n}\n\n","import type { EnvType } from './types'\n\nexport const validators: Record<EnvType, (value: string) => any> = {\n string: (value: string) => value,\n \n number: (value: string) => {\n if (value === '') {\n throw new Error('Cannot parse empty string as number')\n }\n const num = Number(value)\n if (isNaN(num)) {\n throw new Error(`Invalid number: \"${value}\"`)\n }\n return num\n },\n \n boolean: (value: string) => {\n const lower = value.toLowerCase()\n if (lower === 'true' || lower === '1' || lower === 'yes') return true\n if (lower === 'false' || lower === '0' || lower === 'no') return false\n throw new Error(`Invalid boolean: \"${value}\"`)\n },\n \n url: (value: string) => {\n try {\n new URL(value)\n return value\n } catch {\n throw new Error(`Invalid URL: \"${value}\"`)\n }\n },\n \n email: (value: string) => {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n if (!emailRegex.test(value)) {\n throw new Error(`Invalid email: \"${value}\"`)\n }\n return value\n },\n \n port: (value: string) => {\n const num = Number(value)\n if (isNaN(num) || num < 0 || num > 65535 || !Number.isInteger(num)) {\n throw new Error(`Invalid port: \"${value}\"`)\n }\n return num\n },\n}\n\n","import { readFileSync, existsSync } from 'fs'\n\nexport function loadDotenv(path: string): Record<string, string> {\n if (!existsSync(path)) {\n return {}\n }\n\n try {\n const content = readFileSync(path, 'utf-8')\n return parseDotenv(content)\n } catch {\n return {}\n }\n}\n\nexport function parseDotenv(content: string): Record<string, string> {\n const result: Record<string, string> = {}\n const lines = content.split('\\n')\n\n for (const line of lines) {\n const trimmed = line.trim()\n \n if (!trimmed || trimmed.startsWith('#')) {\n continue\n }\n\n const match = trimmed.match(/^([^=]+)=(.*)$/)\n if (!match) continue\n\n const key = match[1].trim()\n let value = match[2].trim()\n\n if ((value.startsWith('\"') && value.endsWith('\"')) || \n (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n value = value.slice(1, -1)\n }\n\n result[key] = value\n }\n\n return result\n}\n\n","import type { EnvType } from './types'\n\nexport interface ValidationError {\n key: string\n message: string\n suggestion?: string\n example?: string\n}\n\nexport function formatValidationErrors(errors: ValidationError[]): string {\n const lines = ['❌ Environment validation failed:\\n']\n\n for (const error of errors) {\n lines.push(` ${error.key}: ${error.message}`)\n \n if (error.suggestion) {\n lines.push(` ➜ Fix: ${error.suggestion}`)\n }\n \n if (error.example) {\n lines.push(` Example: ${error.example}`)\n }\n \n lines.push('')\n }\n\n lines.push(' Run your app with valid environment variables or add them to .env')\n \n return lines.join('\\n')\n}\n\nexport function createMissingError(key: string, type: EnvType): ValidationError {\n const examples: Record<EnvType, string> = {\n string: `${key}=your-value-here`,\n number: `${key}=3000`,\n boolean: `${key}=true`,\n url: `${key}=https://example.com`,\n email: `${key}=user@example.com`,\n port: `${key}=3000`,\n }\n\n return {\n key,\n message: 'Missing required environment variable',\n suggestion: `Add to .env file`,\n example: examples[type],\n }\n}\n\nexport function createTypeError(key: string, value: string, type: EnvType, details: string): ValidationError {\n const suggestions: Record<EnvType, string> = {\n string: 'Provide a string value',\n number: 'Provide a valid number',\n boolean: 'Use true/false, 1/0, yes/no',\n url: 'Provide a valid URL with protocol',\n email: 'Provide a valid email address',\n port: 'Provide a number between 0-65535',\n }\n\n const examples: Record<EnvType, string> = {\n string: `${key}=hello`,\n number: `${key}=42`,\n boolean: `${key}=true`,\n url: `${key}=https://example.com`,\n email: `${key}=user@example.com`,\n port: `${key}=3000`,\n }\n\n return {\n key,\n message: details,\n suggestion: suggestions[type],\n example: examples[type],\n }\n}\n\n","import type { EnvSchema, EnvType } from './types'\n\nexport interface SchemaExport {\n name: string\n type: EnvType\n required: boolean\n default: unknown\n}\n\nexport function schemaToJSON(schema: EnvSchema): SchemaExport[] {\n return Object.entries(schema).map(([name, config]) => ({\n name,\n type: config.type,\n required: !config.optional,\n default: config.default,\n }))\n}\n\nexport function schemaToMarkdown(schema: EnvSchema): string {\n const rows = Object.entries(schema).map(([name, config]) => {\n const required = config.optional ? 'No' : 'Yes'\n const defaultValue = config.default !== undefined ? `\\`${config.default}\\`` : '-'\n return `| \\`${name}\\` | \\`${config.type}\\` | ${required} | ${defaultValue} |`\n })\n\n return [\n '| Variable | Type | Required | Default |',\n '| -------- | ---- | -------- | ------- |',\n ...rows,\n ].join('\\n')\n}\n\nexport function generateDotenvExample(schema: EnvSchema): string {\n const required: string[] = []\n const optional: string[] = []\n\n for (const [name, config] of Object.entries(schema)) {\n const line = config.default !== undefined \n ? `${name}=${config.default}`\n : `${name}=`\n\n if (config.optional) {\n optional.push(line)\n } else {\n required.push(line)\n }\n }\n\n const sections: string[] = []\n\n if (required.length > 0) {\n sections.push('# Required', ...required)\n }\n\n if (optional.length > 0) {\n if (sections.length > 0) sections.push('')\n sections.push('# Optional', ...optional)\n }\n\n return sections.join('\\n')\n}\n\n"],"mappings":";AAAA,SAAS,eAAe;;;ACEjB,IAAM,aAAsD;AAAA,EACjE,QAAQ,CAAC,UAAkB;AAAA,EAE3B,QAAQ,CAAC,UAAkB;AACzB,QAAI,UAAU,IAAI;AAChB,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,MAAM,GAAG,GAAG;AACd,YAAM,IAAI,MAAM,oBAAoB,KAAK,GAAG;AAAA,IAC9C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,CAAC,UAAkB;AAC1B,UAAM,QAAQ,MAAM,YAAY;AAChC,QAAI,UAAU,UAAU,UAAU,OAAO,UAAU,MAAO,QAAO;AACjE,QAAI,UAAU,WAAW,UAAU,OAAO,UAAU,KAAM,QAAO;AACjE,UAAM,IAAI,MAAM,qBAAqB,KAAK,GAAG;AAAA,EAC/C;AAAA,EAEA,KAAK,CAAC,UAAkB;AACtB,QAAI;AACF,UAAI,IAAI,KAAK;AACb,aAAO;AAAA,IACT,QAAQ;AACN,YAAM,IAAI,MA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AQ;AAAA,EACzC;AAEA,MAAI,SAAS,SAAS,GAAG;AACvB,QAAI,SAAS,SAAS,EAAG,UAAS,KAAK,EAAE;AACzC,aAAS,KAAK,cAAc,GAAG,QAAQ;AAAA,EACzC;AAEA,SAAO,SAAS,KAAK,IAAI;AAC3B;","names":[]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "envconfig-kit",
3
+ "version": "0.1.0",
4
+ "description": "Type-safe environment variables with fail-fast validation",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "envconfig-kit": "./dist/cli.cjs"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsup --watch",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "keywords": [
35
+ "env",
36
+ "environment",
37
+ "variables",
38
+ "config",
39
+ "validation",
40
+ "typescript",
41
+ "type-safe",
42
+ "dotenv"
43
+ ],
44
+ "author": "Chintan Shah <chintanshah35@gmail.com>",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/chintanshah35/envconfig-kit.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/chintanshah35/envconfig-kit/issues"
52
+ },
53
+ "homepage": "https://github.com/chintanshah35/envconfig-kit#readme",
54
+ "devDependencies": {
55
+ "@types/node": "^20.10.0",
56
+ "tsup": "^8.0.1",
57
+ "typescript": "^5.3.2",
58
+ "vitest": "^1.2.0"
59
+ },
60
+ "engines": {
61
+ "node": ">=18.0.0"
62
+ }
63
+ }
64
+