@pnpm/config.env-replace
Replaces env variable placeholders in configuration settings
Last updated 2 months ago by pnpmuser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @pnpm/config.env-replace 
SYNC missed versions from official npm registry.

@pnpm/config.env-replace

Replaces env variable placeholders in configuration settings

envReplace

Strict mode — throws when a ${VAR} placeholder has no value and no default.

function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string;
import { envReplace } from '@pnpm/config.env-replace'

envReplace('${foo}', process.env)

envReplaceLossy

Lossy mode — replaces unresolved ${VAR} placeholders with '' and reports them in unresolved instead of throwing. Resolvable placeholders and ${VAR-default} / ${VAR:-default} fallbacks elsewhere in the same string still expand normally; only the genuinely unresolved bare ones are dropped.

Use this when leaving the literal ${VAR} in the substituted value would be worse than dropping it (e.g. auth tokens in .npmrc under OIDC trusted publishing).

function envReplaceLossy(
  settingValue: string,
  env: NodeJS.ProcessEnv
): { value: string; unresolved: string[] };
import { envReplaceLossy } from '@pnpm/config.env-replace'

const { value, unresolved } = envReplaceLossy('${foo}-${missing}', process.env)
// value:      'foo_value-'
// unresolved: ['${missing}']

Placeholder syntax

  • ${NAME} — strict; the env var must be set (otherwise envReplace throws, or envReplaceLossy substitutes '' and records the placeholder).
  • ${NAME-fallback} — fallback if NAME is unset.
  • ${NAME:-fallback} — fallback if NAME is unset or an empty string.
  • A leading \ escapes the placeholder (\${NAME} stays literal).

{ NAME: undefined } in env is treated as unset for both functions — the same as the key being absent. This matches the Record<string, string | undefined> shape of NodeJS.ProcessEnv, where callers (notably tests) routinely model an unset variable as a present-but-undefined property.

License

MIT

Current Tags

  • 1100.0.0                                ...           latest (2 months ago)

10 Versions

  • 1100.0.0                                ...           2 months ago
  • 4.1.0                                ...           6 months ago
  • 4.0.0                                ...           8 months ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (2)
Downloads
Total 22
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 10
Last Month 10
Dependencies (0)
None
Dev Dependencies (2)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE