
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
env-interpolation
Advanced tools
A lightweight, zero-dependency utility for recursively interpolating ${VAR:default} placeholders in strings, objects, and arrays.
Recursively resolve ${VAR} style placeholders in strings, objects, or arrays using environment variables or custom maps.
process.env automatically; pass your own variable map for custom contexts.${NAME:Guest}) including quoted values and nested placeholders.\\${VAR}) or disable escaping entirely when needed.npm install env-interpolation
# or
yarn add env-interpolation
# or
pnpm add env-interpolation
Requirements:
import) and CommonJS (require)import { interpolate } from "env-interpolation";
const greeting = interpolate("Hello ${NAME:Guest}!", { NAME: "Ada" });
// "Hello Ada!"
const config = interpolate({
url: "${API_URL:https://api.example.com}",
timeout: "${TIMEOUT:5000}",
features: ["${FEATURE_PRIMARY:alpha}", "${FEATURE_SECONDARY:beta}"],
});
// All placeholders resolved using process.env by default
const { interpolate } = require("env-interpolation");
const greeting = interpolate("Hello ${NAME:Guest}!", { NAME: "Ada" });
// "Hello Ada!"
const config = interpolate({
url: "${API_URL:https://api.example.com}",
timeout: "${TIMEOUT:5000}",
features: ["${FEATURE_PRIMARY:alpha}", "${FEATURE_SECONDARY:beta}"],
});
// All placeholders resolved using process.env by default
${VAR} — looks up VAR in the variable map or process.env.${VAR:Default} — uses Default when VAR is missing or undefined.${VAR:'Quoted value'} or ${VAR:"Quoted value"} — quotes let you keep colons or other placeholders in defaults. Both single and double quotes are stripped._) are left untouched.interpolate<T>(content, variables?, options?)content (T extends string | Record<string, unknown> | unknown[]): value (or structure) to process.variables (Record<string, string | undefined>): optional override map. Defaults to process.env when available.options:
escape (boolean, default true): when enabled, a single preceding backslash escapes a placeholder (\\${VAR} → ${VAR}). Disable to treat backslashes as literal characters.maxPasses (number, default 10): maximum interpolation passes. Lower to cap work on pathological nesting; raise to resolve deeper chains.Returns the interpolated value while preserving the original shape and TypeScript type.
${VAR:}) leave the placeholder intact so you can detect missing configuration.import { interpolate } from "env-interpolation";
interpolate("Literal \\${PASSWORD}");
// "Literal ${PASSWORD}" (escape enabled, the placeholder is left as-is)
interpolate("Literal \\${PASSWORD}", { PASSWORD: "secret" }, { escape: false });
// "Literal \\secret" (escape disabled, placeholder still resolves)
The exported function is fully typed. The returned value retains the structural type of the input, so narrowed types stay intact:
import { interpolate } from "env-interpolation";
const settings = {
port: "${PORT:3000}",
flags: ["${PRIMARY_FLAG:enabled}", "${SECONDARY_FLAG:disabled}"],
} as const;
const result = interpolate(settings);
// result has the same readonly structure as `settings`
⚠️ Warning: Interpolating secrets into logs or HTML can leak sensitive information. Prefer resolving variables at the application edge and redacting secrets in logs.
Since process.env isn't available in browsers, pass variables explicitly:
import { interpolate } from "env-interpolation";
const config = {
apiUrl: "${API_URL:https://api.example.com}",
timeout: "${TIMEOUT:5000}",
};
const result = interpolate(config, {
API_URL: "https://prod-api.example.com",
TIMEOUT: "10000",
});
npm run test – run the Vitest suite (covers string, object, and array interpolation).npm run lint – lint sources with ESLint.npm run build – produce the bundled output via tsup.Contributions and bug reports are welcome! Read the CONTRIBUTING.md guide and adhere to the CODE_OF_CONDUCT.md when participating. Issues and pull requests live at the GitHub repository.
Released under the MIT License.
FAQs
A lightweight, zero-dependency utility for recursively interpolating ${VAR:default} placeholders in strings, objects, and arrays.
We found that env-interpolation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.