QuiiBz / std-env

Runtime agnostic JS utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

std-env

npm npm bundlephobia

Runtime agnostic JS utils

Installation

# Using npm
npm i std-env

# Using pnpm
pnpm i std-env

# Using yarn
yarn add std-env

Usage

// ESM
import { env, isDevelopment, isProduction } from "std-env";

// CommonJS
const { env, isDevelopment, isProduction } = require("std-env");

Flags

  • hasTTY
  • hasWindow
  • isDebug
  • isDevelopment
  • isLinux
  • isMacOS
  • isMinimal
  • isProduction
  • isTest
  • isWindows
  • platform
  • isColorSupported
  • nodeVersion
  • nodeMajorVersion

You can read more about how each flag works from ./src/flags.ts.

Provider Detection

std-env can automatically detect the current runtime provider based on environment variables.

You can use isCI and platform exports to detect it:

import { isCI, platform, platformInfo } from "std-env";

console.log({
  isCI, // true
  platform, // "github_actions"
  platformInfo, // { name: "github_actions", isCI: true }
});

If you want to test provider based on a custom environment variable set, you can also directly use detectProvider:

import { detectProvider } from "std-env";

// { name: "vercel", ci: false }
console.log(detectProvider({ VERCEL: "1" }));

List of well known providers can be found from ./src/providers.ts.

Platform agnotic env

std-env provides a lightweight proxy to access environment variables in a platform agnostic way.

import { env } from "std-env";

Platform agnostic process

std-env provides a lightweight proxy to access process object in a platform agnostic way.

import { process } from "std-env";

License

MIT

About

Runtime agnostic JS utils

License:MIT License


Languages

Language:TypeScript 98.7%Language:JavaScript 1.3%