{"_id":"@edgarortega/typenv","_rev":"4-35f2b752039df14d2bbe046fe39f7145","name":"@edgarortega/typenv","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0-2024.9.15":{"name":"@edgarortega/typenv","version":"1.0.0-2024.9.15","author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"_id":"@edgarortega/typenv@1.0.0-2024.9.15","maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"dist":{"shasum":"0dc30fc814af4d05f55e091bb6c73f19fe2d599d","tarball":"https://registry.npmjs.org/@edgarortega/typenv/-/typenv-1.0.0-2024.9.15.tgz","fileCount":3,"integrity":"sha512-TRw1YetZufkZum806Mf8nEdZJqeOrjBZaRUHmf+owPbzTzv6bpQQCN+9oEQ7fNffTDTxxQJYY+ob/OS/pDBgEQ==","signatures":[{"sig":"MEQCIFcWLV85f09DSFJysZHqtBqzCMgh1clixm0s1iBIpPi3AiBG0Be0z6rtuWGkQKBSbL/SEg9ViC4VRrgCHHtpbCuiSA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5679},"type":"module","exports":{".":{"types":"./src/index.ts","import":"./dist/index.ts","require":"./dist/index.js"}},"gitHead":"42d1367636e281fea5def09938feae48cd9352d2","private":false,"scripts":{"test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --format esm --minify"},"_npmUser":{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"},"_npmVersion":"10.7.0","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{},"peerDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/typenv_1.0.0-2024.9.15_1726423438019_0.954898563140584","host":"s3://npm-registry-packages"}},"1.0.1-2024.9.15":{"name":"@edgarortega/typenv","version":"1.0.1-2024.9.15","author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"_id":"@edgarortega/typenv@1.0.1-2024.9.15","maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"dist":{"shasum":"f7c453b21bc07a53d8d2e681c2c58fe841d7f126","tarball":"https://registry.npmjs.org/@edgarortega/typenv/-/typenv-1.0.1-2024.9.15.tgz","fileCount":4,"integrity":"sha512-2D0KAzTsLu6eUf0xeV+oUVkOlo+B5Nc3XDCJjAs4PekgLsCWmSONyQUFIT1Q2Cv5WcpBJbkPg7+BzBlqGGkALA==","signatures":[{"sig":"MEYCIQDCll3kDLpczfEZg8F5Sze6jHkUP1c5HFZLDWF0RJSvKQIhAObWgj/BhGD1ZieDBESZEKmc+iHJB1hHbEz3J4IRB7CT","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8711},"type":"module","exports":{".":{"types":"./src/index.ts","import":"./dist/index.ts","require":"./dist/index.js"}},"gitHead":"bb6eab67b27c02859c0d15d00137470375f7552a","private":false,"scripts":{"test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --format esm --minify"},"_npmUser":{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"},"_npmVersion":"10.7.0","description":"`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments. It enables developers to define, validate, and access environment variables in a structured manner, ensuring that ","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{},"peerDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/typenv_1.0.1-2024.9.15_1726426489300_0.7849355271212701","host":"s3://npm-registry-packages"}},"1.0.2-2024.9.15":{"name":"@edgarortega/typenv","version":"1.0.2-2024.9.15","author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"_id":"@edgarortega/typenv@1.0.2-2024.9.15","maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"dist":{"shasum":"1f78d96fa1b4ecc3c211ded6f7a4ecd3059e96b1","tarball":"https://registry.npmjs.org/@edgarortega/typenv/-/typenv-1.0.2-2024.9.15.tgz","fileCount":4,"integrity":"sha512-KipjC3Ux+4Ae7mGoXWOXJXQG1ingzhnl+dnbk6TsCQXPyPjHJbAFP97n2lMFCYHTEh5d64kr5aWBJ1HY1cFGbw==","signatures":[{"sig":"MEYCIQDG3AoKIqY9pGOQjgQlRlzXjpLgPrDaHDPTD77cibXdQgIhAJhVdeQpBI6pNXipEeLolbjzSxDLUhrnDacytkGU4BcW","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8711},"type":"module","exports":{".":{"types":"./src/index.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"5b1dd0f0a77e1e7b6e68b1c14cc9195c2f1345f3","private":false,"scripts":{"test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --format esm --minify"},"_npmUser":{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"},"_npmVersion":"10.7.0","description":"`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments. It enables developers to define, validate, and access environment variables in a structured manner, ensuring that ","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{},"peerDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/typenv_1.0.2-2024.9.15_1726428726604_0.9185062334469503","host":"s3://npm-registry-packages"}},"1.0.3-2024.9.15":{"name":"@edgarortega/typenv","version":"1.0.3-2024.9.15","author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"_id":"@edgarortega/typenv@1.0.3-2024.9.15","maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"dist":{"shasum":"f56dfd2107c1da42477f7c687937e8a392b4f21a","tarball":"https://registry.npmjs.org/@edgarortega/typenv/-/typenv-1.0.3-2024.9.15.tgz","fileCount":4,"integrity":"sha512-tNX19SSdDF6FI3TClqq8VKU2nh6hnWYKJw49qFQoImNy+EETadtp2+Bn2OtcJ0XPMI7uCr2Y78LdSpA1e4gzBQ==","signatures":[{"sig":"MEUCIQD1x5pww0OmGL4mLc3f/Iop9rLc7OTj+jbDfqliF+VzgwIgO7xIafJh52PVIR16nRJtA5yqG0q1KtyZoKI7seGWGvE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8673},"type":"module","exports":{".":{"types":"./src/index.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"5b1dd0f0a77e1e7b6e68b1c14cc9195c2f1345f3","private":false,"scripts":{"test":"bun test","build":"bun build ./src/index.ts --outdir ./dist --format esm --minify"},"_npmUser":{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"},"_npmVersion":"10.7.0","description":"`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments. It enables developers to define, validate, and access environment variables in a structured manner, ensuring that ","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{},"peerDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/typenv_1.0.3-2024.9.15_1726429195903_0.5067791507802559","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"@edgarortega/typenv","type":"module","version":"1.0.4","author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"exports":{".":{"import":"./dist/index.js","require":"./dist/index.js","types":"./src/index.ts"}},"scripts":{"build":"bun build ./src/index.ts --outdir ./dist --format esm --minify","test":"bun test"},"devDependencies":{},"peerDependencies":{},"private":false,"_id":"@edgarortega/typenv@1.0.4","gitHead":"e9aeb0fd7b70de170cb2c7e7c895491fa5cc3ae2","description":"`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments. It enables developers to define, validate, and access environment variables in a structured manner, ensuring that ","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-88VYMViYpi5v2cPJvwqQvTTKWzRWlSEGTDn4QakbYPzcQSSPKcs4Nex4wqPsQ4lze3ZTdzF3uxLWJaBdzOLo5w==","shasum":"d20f51ac0341552a367075f2282c4dcd4dfcc6e7","tarball":"https://registry.npmjs.org/@edgarortega/typenv/-/typenv-1.0.4.tgz","fileCount":5,"unpackedSize":8761,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDc6MSIJfD7Xf00pThC6xw03a6Un/23QQlJ+Ts4wdnoNwIgByYolBmfQhdknVjDBGR8hrQGQnccEqzJTSKgdm80GdQ="}]},"_npmUser":{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"},"directories":{},"maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/typenv_1.0.4_1727099737884_0.9877750606530236"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-15T18:03:57.951Z","modified":"2024-09-23T13:55:38.259Z","1.0.0-2024.9.15":"2024-09-15T18:03:58.143Z","1.0.1-2024.9.15":"2024-09-15T18:54:49.449Z","1.0.2-2024.9.15":"2024-09-15T19:32:06.755Z","1.0.3-2024.9.15":"2024-09-15T19:39:56.060Z","1.0.4":"2024-09-23T13:55:38.096Z"},"author":{"name":"Edgar Ortega","email":"edgarortegaramirez@gmail.com"},"description":"`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments. It enables developers to define, validate, and access environment variables in a structured manner, ensuring that ","maintainers":[{"name":"edgarortega","email":"edgarortegaramirez@gmail.com"}],"readme":"# 🛠️ typenv core\n\n`typenv` is a lightweight TypeScript library designed for managing environment variables with type safety in JavaScript server environments.\nIt enables developers to define, validate, and access environment variables in a structured manner, ensuring that applications are configured correctly.\n\n## 🚀 Features\n\n- **Type Safety**: Leverage TypeScript to enforce expected types for environment variables, reducing runtime errors.\n- **Validation**: Automatically validate environment variables against defined schemas, ensuring correctness.\n- **Zero Dependencies**: Efficient and easy to integrate into your projects without external libraries.\n- **Custom Error Handling**: Receive clear and descriptive error messages when environment variables are missing or invalid.\n\n## Design Decisions\n\n- [KISS principle](https://en.wikipedia.org/wiki/KISS_principle)\n- Focused on JavaScript server environments.\n- No reliance on external schema validation libraries.\n- Does not support environment variable loading, nesting, grouping, or transformations.\n- No default values or optional environment variables.\n- Empty string variables (e.g., `AN_API_URL=` or `AN_API_URL=  `) are treated as `undefined`.\n\n## 📦 Installation\n\nYou can install `typenv` via:\n\n```sh\nnpm install --save @edgarortega/typenv\nbun add @edgarortega/typenv\n```\n\n## 📖 Usage\n\nHere's how to use `typenv` in your project:\n\n```ts\n// create a env.ts file in your root\nimport {\n  createEnv,\n  asString,\n  asEnum,\n  asBoolean,\n  asNumber,\n} from \"@edgarortega/typenv\";\n// Define your environment variables schema\nexport const env = createEnv({\n  URL: asString(), // Must be a string\n  NODE_ENV: asEnum({ values: [\"dev\", \"PROD\"] as const }), // Must be one of the specified values\n  FEATURE_FLAG: asBoolean(), // Must be a boolean\n  MAX_RETRIES: asNumber(), // Must be a number\n});\n// inferred type for the `env` variable\nconst env: {\n  URL: string;\n  NODE_ENV: \"dev\" | \"PROD\";\n  FEATURE_FLAG: boolean;\n  MAX_RETRIES: number;\n};\n// Access your validated environment variables\nconsole.log({ env });\n```\n\n## 🛠️ API\n\n### `createEnv(schema: Schema)`\n\nCreates and validates environment variables based on the provided schema.\n\n- **Parameters**:\n  - `schema`: An object defining the expected environment variables and their types.\n- **Returns**: An object containing the validated environment variables.\n\n- **Throws**: `TypenvError` if any environment variable is not defined or invalid.\n\n### Validation Functions\n\n- `asString()`: Validates and returns a string environment variable.\n- `asEnum(values: string[] as const)`: Validates and returns an environment variable that must be one of the specified enum values.\n- `asBoolean()`: Validates and returns a boolean environment variable.\n- `asNumber()`: Validates and returns a number environment variable.\n\n## ⚠️ Error Handling\n\nIf an environment variable is missing or invalid, `typenv` will throw a `TypenvError` with a descriptive message, helping you quickly identify configuration issues.\n\n---\n","readmeFilename":"README.md"}