Socket
Socket
Sign inDemoInstall

babel-plugin-transform-user-env-inline

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-user-env-inline

Inlines user defined environment variables and optionally/statically evaluates conditionals


Version published
Weekly downloads
3
Maintainers
1
Install size
2.82 kB
Created
Weekly downloads
 

Readme

Source

babel-plugin-transform-user-env-inline

npm version

Similar to, and based on babel-plugin-transform-node-env-inline, this plugin inlines user provided environment variables referenced as process.env.ENV_VAR_NAME, and if used as part of a binary expression, optionally & statically evaluates it and then replaces expression with result.

Usage

By default only NODE_ENV is enabled for inlining & evaluation, but any other env vars can be specified via plugin options:

{
    "plugins": [
        [
            "transform-user-env-inline",
            {
                // try to evaluate
                "ASSERTS": true,
                // don't try evaluate
                "API_KEY": false
            }
        ],
    ]
}

Example

Given above config (in .babelrc) and following code:

process.env.NODE_ENV === "development";
process.env.NODE_ENV === "production";
process.env.ASSERTS === "1";
process.env.API_KEY === "foo";
NODE_ENV=development \
ASSERTS=1 \
API_KEY=foo \
babel in.js

Result:

true;
false;
true;
"foo" === "foo"

Authors

Karsten Schmidt, 2020, MIT licensed

Keywords

FAQs

Last updated on 06 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc