{"id":27157110,"url":"https://github.com/remscodes/env-mode","last_synced_at":"2026-01-27T02:34:45.465Z","repository":{"id":258574638,"uuid":"874982140","full_name":"remscodes/env-mode","owner":"remscodes","description":"🕶️A tiny, handy and strongly typed library for working with the env mode (NODE_ENV)","archived":false,"fork":false,"pushed_at":"2024-10-27T14:42:10.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-19T17:15:55.710Z","etag":null,"topics":["environment","javascript","typescript"],"latest_commit_sha":null,"homepage":"https://npm.im/@remscodes/env-mode","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remscodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-18T20:39:37.000Z","updated_at":"2024-10-27T14:42:13.000Z","dependencies_parsed_at":"2025-05-29T06:06:33.558Z","dependency_job_id":null,"html_url":"https://github.com/remscodes/env-mode","commit_stats":null,"previous_names":["remscodes/env-mode"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/remscodes/env-mode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remscodes%2Fenv-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remscodes%2Fenv-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remscodes%2Fenv-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remscodes%2Fenv-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remscodes","download_url":"https://codeload.github.com/remscodes/env-mode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remscodes%2Fenv-mode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28796977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T01:07:07.743Z","status":"online","status_checked_at":"2026-01-27T02:00:07.755Z","response_time":168,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","javascript","typescript"],"created_at":"2025-04-08T20:53:36.603Z","updated_at":"2026-01-27T02:34:45.451Z","avatar_url":"https://github.com/remscodes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eEnv Mode\u003c/h1\u003e\n    \u003cp\u003eA tiny, handy and strongly typed library for working with the env mode (NODE_ENV)\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![github ci](https://img.shields.io/github/actions/workflow/status/remscodes/env-mode/npm-ci.yml.svg?\u0026logo=github\u0026label=CI\u0026style=for-the-badge)](https://github.com/remscodes/env-mode/actions/workflows/npm-ci.yml)\n[![npm version](https://img.shields.io/npm/v/@remscodes/env-mode.svg?\u0026style=for-the-badge\u0026logo=npm)](https://www.npmjs.org/package/@remscodes/env-mode)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/@remscodes/env-mode.svg?style=for-the-badge)](https://bundlephobia.com/package/@remscodes/env-mode)\n[![license](https://img.shields.io/github/license/remscodes/env-mode.svg?style=for-the-badge)](LICENSE)\n\n\u003c/div\u003e\n\n## Installation\n\n```shell\nnpm install @remscodes/env-mode\n```\n\n### Note\n\nThis library does not load environment variables from a `.env` files.\n\nIt is supposed to be used in addition to any module or framework that load these variables.\n\n## Usage\n\n[//]: # (@formatter:off)\n```js\n// .env\nNODE_ENV=dev\n```\n[//]: # (@formatter:on)\n\n#### Current value\n\nGet the env mode value.\n\n```ts\nimport EnvMode from '@remscodes/env-mode';\n\nEnvMode.get(); // \"dev\"\nEnvMode.getOrThrow(); // \"dev\"\n```\n\n#### Conditions\n\nBuild conditions based on the env mode.\n\n```ts\nimport EnvMode from '@remscodes/env-mode';\n\nEnvMode.is('dev'); // true\nEnvMode.isNot('dev'); // false\n\nEnvMode.in(['dev', 'prod']); // true\nEnvMode.notIn(['dev', 'prod']); // false\n```\n\n#### Selection\n\nSelect a specific value depending on the env mode.\n\n```ts\nimport EnvMode from '@remscodes/env-mode';\n\nconst color = EnvMode.select({ // \"blue\"\n  dev: 'blue',\n  default: 'red',\n});\n```\n\n## Typed usage\n\nCreate a declaration file and add all your env mode values as follows.\n\n```ts\n// global.d.ts \ndeclare global {\n  namespace NSEnvMode {\n    interface ModeMap {\n      dev,\n      prod,\n    }\n  }\n}\n\nexport {};\n```\n\nInclude it into your `tsconfig.json`.\n\n```\n// tsconfig.json\n{\n  // ...\n  \"include\": [\n    \"global.d.ts\"\n  ]\n}\n```\n\nNow your env modes can be autocompleted through methods.\n\n## Configuration\n\n### Throw\n\nBy default, if the env mode is empty (`undefined` or `\"\"`), the methods work with this empty value.\n\nYou can choose to throw an exception from every methods if env mode is empty.\n\nExample :\n\n[//]: # (@formatter:off)\n```js\n// .env\nNODE_ENV=\n```\n[//]: # (@formatter:on)\n\n```ts\nEnvMode.is('dev'); // false\n```\n\n```ts\nEnvMode.configure({ throwIfEmpty: true });\nEnvMode.is('dev'); // [EnvModeException: \"NODE_ENV\" is not defined in \"globalThis.process.env\".]\n```\n\n### Key\n\nBy default, it works with the `NODE_ENV` key.\n\nYou can change it as follows.\n\nExample :\n\n[//]: # (@formatter:off)\n```js\n// .env\nDENO_ENV=dev\n```\n[//]: # (@formatter:on)\n\n```ts\nEnvMode.configure({ key: 'DENO_ENV' });\nEnvMode.get(); // \"dev\"\n```\n\n### Source\n\nBy default, it works with the `globalThis.process.env` source.\n\nYou can change it as follows.\n\nExample :\n\n```ts\n// environment.ts\nexport const myEnvironment = {\n  NODE_ENV: 'dev',\n};\n```\n\n```ts\nimport { myEnvironment } from './environement.ts';\n\nEnvMode.configure({ source: myEnvironment });\nEnvMode.get(); // \"dev\"\n```\n\n## License\n\n[MIT](LICENSE) © Rémy Abitbol.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremscodes%2Fenv-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremscodes%2Fenv-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremscodes%2Fenv-mode/lists"}