function splitWorkerEnv
Since 0.2.0
splitWorkerEnv(env: Readonly<Record<string, unknown>>): SplitWorkerEnv

Partitions a Workers env record by value type.

Values that are neither a string nor a non-null object (a number, a boolean, null, undefined) land in neither half: coercing them to a string would put a value in env that was never a variable, and treating them as a binding would hand a caller something with no methods.

Examples

Example 1

const { vars, bindings } = splitWorkerEnv({ API_KEY: 'k', CACHE: kvNamespace });
// vars     → { API_KEY: 'k' }
// bindings → { CACHE: kvNamespace }

Parameters

env: Readonly<Record<string, unknown>>

The record the Worker's env provides

Return Type

The string variables and the object bindings, separated

Usage

import { splitWorkerEnv } from "common/src/index.ts";