{"id":15705997,"url":"https://github.com/delucis/if-env","last_synced_at":"2025-05-12T21:07:08.313Z","repository":{"id":57107413,"uuid":"133825184","full_name":"delucis/if-env","owner":"delucis","description":":runner::question: Run NPM scripts conditionally based on environment variables","archived":false,"fork":false,"pushed_at":"2020-07-17T08:10:37.000Z","size":205,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-12T21:06:40.810Z","etag":null,"topics":["environment-variables","npm-scripts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delucis.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}},"created_at":"2018-05-17T14:27:30.000Z","updated_at":"2024-04-18T12:09:28.000Z","dependencies_parsed_at":"2022-08-20T17:11:19.876Z","dependency_job_id":null,"html_url":"https://github.com/delucis/if-env","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delucis%2Fif-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delucis%2Fif-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delucis%2Fif-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delucis%2Fif-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delucis","download_url":"https://codeload.github.com/delucis/if-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253823425,"owners_count":21969846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-variables","npm-scripts"],"created_at":"2024-10-03T20:21:00.685Z","updated_at":"2025-05-12T21:07:08.270Z","avatar_url":"https://github.com/delucis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @delucis/if-env\n\n\n[![latest npm release version](https://img.shields.io/npm/v/@delucis/if-env.svg)](https://www.npmjs.com/package/@delucis/if-env) [![Build Status](https://travis-ci.com/delucis/if-env.svg?branch=master)](https://travis-ci.com/delucis/if-env) [![Coverage Status](https://coveralls.io/repos/github/delucis/if-env/badge.svg?branch=master)](https://coveralls.io/github/delucis/if-env?branch=master)  ![npms.io package score](https://badges.npms.io/%40delucis%2Fif-env.svg)\n\n\u003e Run an npm script if an environment variable matches a pattern\n\nThis is a fork of Eric Clemmons’s [`if-env`](https://github.com/ericclemmons/if-env). It allows you to match environment variables using wildcards (`*`) rather than using simple string equality. See Sindre Sorhus’s [`matcher`](https://github.com/sindresorhus/matcher) for details about how the matching works.\n\n## Installation\n\n```\nnpm install --save @delucis/if-env\n```\n\n## Usage\n\nThis package installs `if-env`, a script which lets you easily match environment variable values against a pattern using wildcards. It also includes `if-env-cs`, which is [case sensitive](#case-sensitivity).\n\nIf you want to to run an NPM script conditionally, depending on the value of an environment variable, you can use `if-env` in your `package.json`. In this example, we only want to run our `test` script when the `SOME_VAR` variable starts with `new`:\n\n```json\n\"scripts\": {\n  \"test\": \"if-env SOME_VAR=new* \u0026\u0026 npm run test-suite\"\n}\n```\n\n### Multiple conditions\n\nIf you want several conditions to be met you can pass them all to `if-env`:\n\n```json\n\"scripts\": {\n  \"yay\": \"if-env VAR1=woo* VAR2=*hoo \u0026\u0026 echo yay\"\n}\n```\n\nIf you want to run a script if either one or another condition is met, you can use the `||` operator:\n\n```json\n\"scripts\": {\n  \"moo\": \"if-env ANIMAL=cow || if-env ANIMAL=bull* \u0026\u0026 echo moo\"\n}\n```\n\nIf you want to do different things depending on the value of a variable, you can also use the `||` operator:\n\n```json\n\"scripts\": {\n  \"joy\": \"if-env MOOD=happy \u0026\u0026 echo 😄 || echo 😭\"\n}\n```\n\n### Negating conditions\n\nIf you want to do something if a variable does **_not_** match a pattern, you have two options. Note the single quotes in the first example; they escape `!` for your shell.\n\n```json\n\"scripts\": {\n  \"ifenv\": \"if-env MOOD='!happy' \u0026\u0026 echo 😭\",\n  \"shell\": \"if-env MOOD=happy || echo 😭\"\n}\n```\n\n### Escaping characters\n\nIf you need to have spaces in your pattern, make sure you wrap it in quotes:\n\n```json\n\"scripts\": {\n  \"spacious\": \"if-env SENTENCE='I want * spaces.' \u0026\u0026 echo You get spaces!\"\n}\n```\n\n### Case sensitivity\n\n`if-env` is case insensitive, which means `if-env VAR=foo` will match both `foo` and `FOO`. If you need to test a variable and case is important, use the `if-env-cs` command:\n\n```json\n\"scripts\": {\n  \"case\": \"if-env-cs WORD=lower \u0026\u0026 echo nice! || echo STOP SHOUTING!\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelucis%2Fif-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelucis%2Fif-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelucis%2Fif-env/lists"}