std-env
Advanced tools
Comparing version 3.3.3 to 3.4.0
@@ -1,11 +0,7 @@ | ||
type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr"; | ||
type ProviderInfo = { | ||
name: ProviderName; | ||
[meta: string]: any; | ||
}; | ||
type EnvObject = Record<string, string | undefined>; | ||
declare const env: EnvObject; | ||
declare const nodeENV: string; | ||
/** Value of process.platform */ | ||
declare const platform: NodeJS.Platform; | ||
/** Current provider name */ | ||
declare const provider: ProviderName; | ||
/** Detect if `CI` environment variable is set or a provider CI detected */ | ||
@@ -33,3 +29,39 @@ declare const isCI: boolean; | ||
declare const isMacOS: boolean; | ||
/** Color Support */ | ||
declare const isColorSupported: boolean; | ||
/** Node.js versions */ | ||
declare const nodeVersion: string | null; | ||
declare const nodeMajorVersion: number | null; | ||
export { ProviderInfo, ProviderName, hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider }; | ||
interface Process extends Partial<Omit<typeof globalThis.process, "versions">> { | ||
env: EnvObject; | ||
versions: Record<string, string>; | ||
} | ||
declare const process: Process; | ||
type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr"; | ||
type ProviderInfo = { | ||
name: ProviderName; | ||
ci?: boolean; | ||
[meta: string]: any; | ||
}; | ||
/** Current provider info */ | ||
declare const providerInfo: ProviderInfo; | ||
declare const provider: ProviderName; | ||
type RuntimeName = "workerd" | "deno" | "lagon" | "netlify" | "node" | "bun" | "edge-light" | "fastly" | ""; | ||
type RuntimeInfo = { | ||
name: RuntimeName; | ||
}; | ||
declare const isNetlify: boolean; | ||
declare const isEdgeLight: boolean; | ||
declare const isWorkerd: boolean; | ||
declare const isDeno: boolean; | ||
declare const isLagon: boolean; | ||
declare const isNode: boolean; | ||
declare const isBun: boolean; | ||
declare const isFastly: boolean; | ||
declare const runtimeInfo: RuntimeInfo | undefined; | ||
declare const runtime: string; | ||
export { EnvObject, Process, ProviderInfo, ProviderName, RuntimeInfo, RuntimeName, env, hasTTY, hasWindow, isBun, isCI, isColorSupported, isDebug, isDeno, isDevelopment, isEdgeLight, isFastly, isLagon, isLinux, isMacOS, isMinimal, isNetlify, isNode, isProduction, isTest, isWindows, isWorkerd, nodeENV, nodeMajorVersion, nodeVersion, platform, process, provider, providerInfo, runtime, runtimeInfo }; |
{ | ||
"name": "std-env", | ||
"version": "3.3.3", | ||
"description": "Detect current Javascript environment", | ||
"version": "3.4.0", | ||
"description": "Runtime agnostic JS utils", | ||
"repository": "unjs/std-env", | ||
@@ -24,18 +24,22 @@ "license": "MIT", | ||
"prepack": "unbuild", | ||
"play:bun": "bun playground/bun.ts", | ||
"play:deno": "pnpm build && deno run -A playground/deno.ts", | ||
"play:node": "pnpm build && node playground/node.mjs", | ||
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags", | ||
"test": "pnpm lint && vitest run --coverage" | ||
"test": "pnpm lint && pnpm typecheck && vitest run --coverage", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.16.3", | ||
"@vitest/coverage-c8": "^0.31.0", | ||
"changelogen": "^0.5.3", | ||
"eslint": "^8.39.0", | ||
"eslint-config-unjs": "^0.1.0", | ||
"jiti": "^1.18.2", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.0.4", | ||
"unbuild": "^1.2.1", | ||
"vitest": "^0.31.0" | ||
"@types/node": "^20.5.0", | ||
"@vitest/coverage-v8": "^0.34.2", | ||
"changelogen": "^0.5.4", | ||
"eslint": "^8.47.0", | ||
"eslint-config-unjs": "^0.2.1", | ||
"jiti": "^1.19.2", | ||
"prettier": "^3.0.2", | ||
"typescript": "^5.1.6", | ||
"unbuild": "^2.0.0-rc.0", | ||
"vitest": "^0.34.2" | ||
}, | ||
"packageManager": "pnpm@8.4.0" | ||
"packageManager": "pnpm@8.6.12" | ||
} |
@@ -7,3 +7,3 @@ # std-env | ||
> Detect current Javascript environment | ||
> Runtime agnostic JS utils | ||
@@ -13,7 +13,10 @@ ## Installation | ||
```sh | ||
# Using Yarn | ||
yarn add std-env | ||
# Using npm | ||
npm i std-env | ||
# Using pnpm | ||
pnpm i std-env | ||
# Using yarn | ||
yarn add std-env | ||
``` | ||
@@ -25,13 +28,12 @@ | ||
// ESM | ||
import { isWindows } from 'std-env' | ||
import { env, isDevelopment, isProduction } from "std-env"; | ||
// CommonJS | ||
const { isCI } = require('std-env') | ||
const { env, isDevelopment, isProduction } = require("std-env"); | ||
``` | ||
Available exports: | ||
## Flags | ||
- `hasTTY` | ||
- `hasWindow` | ||
- `isCI` | ||
- `isDebug` | ||
@@ -46,11 +48,71 @@ - `isDevelopment` | ||
- `platform` | ||
- `provider` | ||
- `isColorSupported` | ||
- `nodeVersion` | ||
- `nodeMajorVersion` | ||
You can read more about how each flag works from [./src/index.ts](./src/index.ts). | ||
You can read more about how each flag works from [./src/flags.ts](./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: | ||
```ts | ||
import { isCI, provider, providerInfo } from "std-env"; | ||
console.log({ | ||
isCI, // true | ||
provider, // "github_actions" | ||
providerInfo, // { name: "github_actions", isCI: true } | ||
}); | ||
``` | ||
List of well known providers can be found from [./src/providers.ts](./src/providers.ts). | ||
## Runtime Detection | ||
`std-env` can automatically detect the current JavaScript runtime based on global variables, following the [WinterCG Runtime Keys proposal](https://runtime-keys.proposal.wintercg.org/): | ||
```ts | ||
import { runtime, runtimeInfo } from "std-env"; | ||
// "" | "node" | "deno" | "bun" | "workerd" | "lagon" ... | ||
console.log(runtime); | ||
// { name: "node" } | ||
console.log(runtimeInfo); | ||
``` | ||
You can also use individual named exports for each runtime detection: | ||
- `isNetlify` | ||
- `isEdgeLight` | ||
- `isWorkerd` | ||
- `isDeno` | ||
- `isLagon` | ||
- `isNode` | ||
- `isBun` | ||
- `isFastly` | ||
List of well known providers can be found from [./src/runtimes.ts](./src/runtimes.ts). | ||
## Platform-Agnostic `env` | ||
`std-env` provides a lightweight proxy to access environment variables in a platform agnostic way. | ||
```ts | ||
import { env } from "std-env"; | ||
``` | ||
## Platform-Agnostic `process` | ||
`std-env` provides a lightweight proxy to access [`process`](https://nodejs.org/api/process.html) object in a platform agnostic way. | ||
```ts | ||
import { process } from "std-env"; | ||
``` | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22286
8
115
94
1