Class

Environment

Environment()

Constructor

# new Environment()

Extends ObjectAccumulator to merge configuration objects while resolving values from Node or browser environment variables on demand.

Environment accumulator that lazily reads from runtime sources.

sequenceDiagram participant Client participant Env as Environment participant Process as process.env participant Browser as globalThis.ENV Client->>Env: accumulate(partialConfig) Env->>Env: expand(values) Client->>Env: Config.logging.level alt Browser runtime Env->>Browser: lookup ENV key Browser-->>Env: resolved value else Node runtime Env->>Process: lookup ENV key Process-->>Env: resolved value end Env-->>Client: merged value

View Source environment.ts, line 6

Example
const Config = Environment.accumulate({ logging: { level: "info" } });
console.log(Config.logging.level);
console.log(String(Config.logging.level)); // => LOGGING__LEVEL key when serialized

Members

# protected factory

Defines how new instances of the Environment class should be created.

A factory function for creating Environment instances.

View Source environment.ts, line 43

Methods

# expand(value) → {void}

Defines lazy properties that first consult runtime variables before falling back to seeded values.

Expands an object into the environment.

Parameters:
Name Type Description
value V

Object to expose through environment getters and setters.

View Source environment.ts, line 103

void

# fromEnv(k) → {unknown}

Handles browser and Node.js environments by normalizing keys and parsing values.

Retrieves a value from the runtime environment.

Parameters:
Name Type Description
k string

Key to resolve from the environment.

View Source environment.ts, line 66

Value resolved from the environment or undefined when absent.

unknown

# orThrow() → {this}

Accessing a property that resolves to undefined or an empty string when declared in the model throws an error.

Returns a proxy enforcing required environment variables.

View Source environment.ts, line 133

Proxy of the environment enforcing required variables.

this

# parseEnvValue(val) → {unknown}

Interprets booleans and numbers while leaving other types unchanged.

Converts stringified environment values into native types.

Parameters:
Name Type Description
val unknown

Raw value retrieved from the environment.

View Source environment.ts, line 84

Parsed value converted to boolean, number, or left as-is.

unknown

# static accumulate(value) → {Environment}

Adds new properties, hiding raw descriptors to avoid leaking enumeration semantics.

Accumulates the given value into the environment.

Parameters:
Name Type Description
value V

Object to merge into the environment.

View Source environment.ts, line 269

Updated environment reference.

Environment

# static buildEnvProxy(current, path) → {any}

Allows chained property access to emit uppercase ENV identifiers while honoring existing runtime overrides.

Builds a proxy that composes environment keys for nested properties.

Parameters:
Name Type Description
current any

Seed model segment used when projecting nested structures.

path Array.<string>

Accumulated path segments leading to the proxy.

View Source environment.ts, line 298

Proxy that resolves environment values or composes additional proxies for deeper paths.

any

# static get(key) → {unknown}

Delegates to the singleton instance to access stored configuration.

Retrieves a value using a dot-path key from the accumulated environment.

Parameters:
Name Type Description
key string

Key to resolve from the environment store.

View Source environment.ts, line 288

Stored value corresponding to the provided key.

unknown

# protected static instance(…args) → {E}

Ensures only one Environment instance is created, wrapping it in a proxy to compose ENV keys on demand.

Retrieves or creates the singleton instance of the Environment class.

Parameters:
Name Type Attributes Description
args Array.<unknown> <repeatable>

Arguments forwarded to the factory when instantiating the singleton.

View Source environment.ts, line 231

Singleton environment instance.

E

# static keys(toEnvopt) → {Array.<string>}

Gets all keys in the environment, with an option to format them for environment variables.

Retrieves the keys of the environment, optionally converting them to ENV format.

Parameters:
Name Type Attributes Default Description
toEnv boolean <optional>
true

Whether to convert the keys to ENV format.

View Source environment.ts, line 361

An array of keys from the environment.

Array.<string>