{"_id":"@bkrmadtya/safe-env","_rev":"4-55989904d6a5ee401540b415c62ccefc","name":"@bkrmadtya/safe-env","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@bkrmadtya/safe-env","version":"1.0.0","description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"dev":"nodemon src/index.ts","build":"tsup ./src","test":"vitest --config ./vite.config.ts"},"keywords":["dotenv","safe","safe-env","production","typescript"],"author":{"name":"@bkrmadtya 2023"},"license":"ISC","dependencies":{"dotenv":"^16.3.1"},"devDependencies":{"nodemon":"^2.0.22","ts-node":"^10.9.1","tsup":"^7.1.0","typescript":"^5.1.6","vitest":"^0.33.0"},"gitHead":"a7e8a297a5b83331154b5696cd1eb6bd03aa6482","bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"homepage":"https://github.com/bkrmadtya/safe-env#readme","_id":"@bkrmadtya/safe-env@1.0.0","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-kV4xuEa9DdYnaOH2f0b7nlPLyDRnUX7Jevr5D7Xlu/LhAypp8jifeRSG+37INs4QM2TBn4LZbyi4UZ0W6ygFMQ==","shasum":"488529f0df7badd845b4d30902ccaeb52339d3be","tarball":"https://registry.npmjs.org/@bkrmadtya/safe-env/-/safe-env-1.0.0.tgz","fileCount":14,"unpackedSize":11762,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC3M/kSq0vmzWZGcHkmHIPFkzwE4LBeroo1DeC7iTFs9wIhAO/U57XZR563LrdV/XDCZfJlI5mc+Uz9RdPoRaiAH2JO"}]},"_npmUser":{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"},"directories":{},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-env_1.0.0_1690576503047_0.7651841113012356"},"_hasShrinkwrap":false},"1.0.1":{"name":"@bkrmadtya/safe-env","version":"1.0.1","description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"dev":"nodemon src/index.ts","build":"tsup ./src","test":"vitest --config ./vite.config.ts"},"keywords":["dotenv","safe","safe-env","production","typescript"],"author":{"name":"@bkrmadtya 2023"},"license":"ISC","dependencies":{"dotenv":"^16.3.1"},"devDependencies":{"nodemon":"^2.0.22","ts-node":"^10.9.1","tsup":"^7.1.0","typescript":"^5.1.6","vitest":"^0.33.0"},"gitHead":"016da0a4814c563ab716b88310ceadd1a44afbbe","bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"homepage":"https://github.com/bkrmadtya/safe-env#readme","_id":"@bkrmadtya/safe-env@1.0.1","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-V1hEHYoXUyTtbpgOuy+w6siVdDILMB3DJng4mp4l8wGx17aC4V9Mafxe56HsEjwWbh+E+CG12wFX4YN9t0LrJQ==","shasum":"8a76c3aa91ba71472732aec7e85c0b1fcda7104c","tarball":"https://registry.npmjs.org/@bkrmadtya/safe-env/-/safe-env-1.0.1.tgz","fileCount":14,"unpackedSize":11841,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBmweJyRn6rTfGk4fK4GMLvJVg7j7kUCvvBxmqCKKM5fAiEAq1ilnATJ4DbFZYsmm3ynsNQyyGy/fqNM0+YQGZVhntk="}]},"_npmUser":{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"},"directories":{},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-env_1.0.1_1690576954440_0.808681143800932"},"_hasShrinkwrap":false},"1.0.2":{"name":"@bkrmadtya/safe-env","version":"1.0.2","description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"dev":"nodemon src/index.ts","build":"tsup ./src","test":"vitest --config ./vite.config.ts"},"keywords":["dotenv","safe","safe-env","production","typescript"],"author":{"name":"@bkrmadtya 2023"},"license":"ISC","dependencies":{"dotenv":"^16.3.1"},"devDependencies":{"nodemon":"^2.0.22","ts-node":"^10.9.1","tsup":"^7.1.0","typescript":"^5.1.6","vitest":"^0.33.0"},"gitHead":"bc06a1b15688815c89a0ff91722fa217f5ba4f34","bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"homepage":"https://github.com/bkrmadtya/safe-env#readme","_id":"@bkrmadtya/safe-env@1.0.2","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-eskv3VanmHAh2H4GgIhKrFshw4M5ZaqSokXwut0PDi32n3aueU8R4+CXGgcbIMjKXNzJ3nbpruRIokkB5e2pDw==","shasum":"9a78e1e1592f5a0167d633dafb37c6705eb64ab2","tarball":"https://registry.npmjs.org/@bkrmadtya/safe-env/-/safe-env-1.0.2.tgz","fileCount":32,"unpackedSize":2777913,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGAzyULJ9rrxjbK787K1KGvWz9lltHrPMl5SwsvqwtfAAiEA7X9+qcO90Kkp6PtbIkbhFbiozTmEE/Z4RxEHvRLlrhQ="}]},"_npmUser":{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"},"directories":{},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-env_1.0.2_1691008686667_0.33567382964614323"},"_hasShrinkwrap":false},"1.0.3":{"name":"@bkrmadtya/safe-env","version":"1.0.3","description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"dev":"nodemon src/index.ts","build":"tsup ./src","test":"vitest --config ./vite.config.ts"},"keywords":["dotenv","safe","safe-env","production","typescript"],"author":{"name":"@bkrmadtya 2023"},"license":"ISC","dependencies":{"dotenv":"^16.3.1"},"devDependencies":{"nodemon":"^2.0.22","ts-node":"^10.9.1","tsup":"^7.1.0","typescript":"^5.1.6","vitest":"^0.33.0"},"gitHead":"89fb4f68fdab961d303263b854acea9e064a6014","bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"homepage":"https://github.com/bkrmadtya/safe-env#readme","_id":"@bkrmadtya/safe-env@1.0.3","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-ap1c63WgntkyeV1+8Ew0oNIFRtRfHFr6Hb9JCRPKYi7Z8AgTyINIFe8ev84x0TFnSeQE+hos9OkkZLl1BMEivA==","shasum":"13088d5a78032eefdb3f8f7aae73f2f1b4721c8f","tarball":"https://registry.npmjs.org/@bkrmadtya/safe-env/-/safe-env-1.0.3.tgz","fileCount":14,"unpackedSize":12387,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDV0JJLIFcMHC5h6ksXXVDtq+f4y/q2ZtdIXXP8TOp05AIga5RJNdxwg0Ce0vV3ZhXiNwHJ1pBqGt2IQ2sZRamdft8="}]},"_npmUser":{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"},"directories":{},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-env_1.0.3_1691074318078_0.031942128498162914"},"_hasShrinkwrap":false},"1.0.4":{"name":"@bkrmadtya/safe-env","version":"1.0.4","description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"dev":"nodemon src/index.ts","build":"tsup ./src","test":"vitest --config ./vite.config.ts"},"keywords":["dotenv","safe","safe-env","production","typescript"],"author":{"name":"@bkrmadtya 2023"},"license":"ISC","dependencies":{"dotenv":"^16.3.1"},"devDependencies":{"nodemon":"^2.0.22","ts-node":"^10.9.1","tsup":"^7.1.0","typescript":"^5.1.6","vitest":"^0.33.0"},"gitHead":"8c624ea6704280716fb94825b1c71b3f74a4f2ee","bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"homepage":"https://github.com/bkrmadtya/safe-env#readme","_id":"@bkrmadtya/safe-env@1.0.4","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-xinjUqwvAxhthzQtDPCmZcrWLjPBXcixYbAAe4WVLYArpsFKRYPk3T5r04NoxT0q2S6CSJCJKznB9nIuOuWDCA==","shasum":"3fb0dae489795a35ca39493dc96565083539b01f","tarball":"https://registry.npmjs.org/@bkrmadtya/safe-env/-/safe-env-1.0.4.tgz","fileCount":14,"unpackedSize":12398,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDx7VPFc6nHtXSQ2XPH8IquXsRqzqswGDMSu1JQim9NlQIhAPIrS9V/dvwyqLuh0FOBXdOru1Aacbikgxq6PCpYBo10"}]},"_npmUser":{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"},"directories":{},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-env_1.0.4_1691168635729_0.7146898158362847"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-28T20:35:02.990Z","1.0.0":"2023-07-28T20:35:03.230Z","modified":"2023-08-04T17:03:56.023Z","1.0.1":"2023-07-28T20:42:34.588Z","1.0.2":"2023-08-02T20:38:06.920Z","1.0.3":"2023-08-03T14:51:58.223Z","1.0.4":"2023-08-04T17:03:55.908Z"},"maintainers":[{"name":"bkrmadtya","email":"karki.bikram007@gmail.com"}],"description":"A thin wrapper around dotenv to make it easy, safe and verbose to access environment variables.","homepage":"https://github.com/bkrmadtya/safe-env#readme","keywords":["dotenv","safe","safe-env","production","typescript"],"repository":{"type":"git","url":"git+https://github.com/bkrmadtya/safe-env.git"},"author":{"name":"@bkrmadtya 2023"},"bugs":{"url":"https://github.com/bkrmadtya/safe-env/issues"},"license":"ISC","readme":"# safe-env\n\nA thin [typescript](https://www.typescriptlang.org/) wrapper around [dotenv](https://github.com/motdotla/dotenv). Making it safe, easy and verbose to load and use environment variables.\n\n- [Install](#install)\n- [Configuration](#configuration-optional)\n- [Schema](#schema)\n- [Usage](#usage)\n\n## Install\n\n```bash\nnpm install @bkrmadtya/safe-env\n# or\npnpm add @bkrmadtya/safe-env\n# or\nyarn add @bkrmadtya/safe-env\n```\n\n## Configuration (optional)\n\nThe configuration object is optional. It takes all the same options as [dotenv](https://github.com/motdotla/dotenv)'s `config` function along with an additional `message` object with `notFound` and `missingRequired` methods which can be used to customize the error messages.\n\n```typescript\nimport { type Config, loadEnv } from '@bkrmadtya/safe-env';\n\nconst config: Config = {\n  path: '/path/to/.env',\n  ...allDotenvConfigOptions,\n  message: {\n    notFound: (key: string) =>\n      `Variable '${key}' not definded in env schema and env file`,\n    missingRequired: (key: string) => `Missing required env variable '${key}'`,\n  },\n};\n```\n\n## Schema\n\nThe schema object is used to define the environment variables expected in the application. A default value can be provided for optional variables or a required flag can be passed for variables that are expected to be present in `.env` file. The same key cannot have both a default value and a required flag.\n\nIncase, a required variable is not found in the `.env` file or a random key not present in the schema is provided, an error is thrown with a default or a custom message.\n\nLet's take following `.env` file as an example:\n\n```dosini\nNODE_ENV=production\n```\n\nThe schema object for the above `.env` file can be defined as follows:\n\n```typescript\nconst schema = {\n  NODE_ENV: { default: 'development' }, // exists in .env\n  NAME: { default: 'Ven' }, // doesn't exists\n  TEST: { required: true }, // doesn't exist\n} satisfies Schema; // 'satisfies' recommended as it provides better ts intellisense\n```\n\n## Usage\n\nRecommended usage is to create a `env.ts` file in the root of your project which can act as a single source of truth for all your environment variables.\n\n```typescript\nimport { loadEnv, type Config, type Schema } from '@bkrmadtya/safe-env';\n\nconst config: Config = {\n  path: '/path/to/.env',\n};\n\nconst schema = {\n  NODE_ENV: { default: 'development' }, // exists in .env with value 'production'\n  NAME: { default: 'Ven' }, // doesn't exists\n  TEST: { required: true }, // doesn't exist\n} satisfies Schema;\n\nconst { getEnv } = loadEnv(schema, config);\n\n// returns production\nexport const NODE_ENV = getEnv('NODE_ENV');\n\n// returns 'Ven'\nexport const NAME = getEnv('NAME');\n\n// throws error since its required\nexport const TEST = getEnv('TEST');\n\n// shows ts compile error and throws error at runtime since it doesn't exist in schema\nexport const RANDOM = getEnv('RANDOM');\n```\n\n### `env` object\n\nThe `env` object from the response `dotenv.config()` is also returned by the `loadEnv` function.\n\n```typescript\nimport { loadEnv } from '@bkrmadtya/safe-env';\n\nconst schema = { ... };\n\nconst { env } = loadEnv(schema);\n\n// Do something with env\n```\n\n## License\n\nMIT © [bkrmadtya 2023](https://github.com/bkrmadtya)\n","readmeFilename":"README.md"}