Environment
Public constants and binding helpers for UCD.js packages and apps
Environment
The @ucdjs/env package provides shared runtime constants and a small binding-validation helper used across the UCD.js workspace.
Installation
npm install @ucdjs/envUse this package for shared UCD.js URLs, HTTP metadata header names, and simple required-binding validation.
Constants
import {
DEFAULT_USER_AGENT,
UCDJS_API_BASE_URL,
UCDJS_DOCS_URL,
UCDJS_STORE_BASE_URL,
UCD_STAT_CHILDREN_DIRS_HEADER,
UCD_STAT_CHILDREN_FILES_HEADER,
UCD_STAT_CHILDREN_HEADER,
UCD_STAT_SIZE_HEADER,
UCD_STAT_TYPE_HEADER,
} from "@ucdjs/env";Base URL constants:
UCDJS_API_BASE_URLUCDJS_DOCS_URLUCDJS_STORE_BASE_URL
Other constants:
DEFAULT_USER_AGENTUCD_STAT_TYPE_HEADERUCD_STAT_SIZE_HEADERUCD_STAT_CHILDREN_HEADERUCD_STAT_CHILDREN_FILES_HEADERUCD_STAT_CHILDREN_DIRS_HEADER
In Node-like runtimes, the base URL constants can be overridden through:
UCDJS_API_BASE_URLUCDJS_DOCS_URLUCDJS_STORE_BASE_URL
If process is unavailable, the package falls back to the built-in defaults.
Validation
import { requiredEnv } from "@ucdjs/env";
const env = requiredEnv({
API_TOKEN: "secret",
LOG_LEVEL: "debug",
}, ["API_TOKEN"]);
env.API_TOKEN; // string
env.LOG_LEVEL; // string | undefinedrequiredEnv() throws when any required key is null or undefined and returns the original object with the required keys narrowed to non-nullable values.