interpolateEnvVars

View as MarkdownOpen in Claude

Interpolate ${VAR|default} environment-variable references in a raw string. Unlike substituteVars(), this method does not apply type coercion — the result is always a string. Missing env vars with no default resolve to an empty string.

This is a TS-specific helper (no Python SDK equivalent). Use it when building URLs, log messages, or any string output where numeric/boolean coercion would corrupt the value.

Parameters

input
stringRequired

The string containing ${VAR} or ${VAR|default} references.

Returns

string — the input with all env var references resolved.

Example

1import { ConfigLoader } from '@signalwire/sdk';
2
3const loader = new ConfigLoader();
4const url = loader.interpolateEnvVars(
5 'https://${HOST|api.example.com}/v1/${VERSION|latest}',
6);
7console.log(url);
8// "https://api.example.com/v1/latest" (defaults used when env vars unset)