import { validateEnvironment } from "https://deno.land/x/enzastdlib@v0.0.4/environment/mod.ts";
Throws an exception if any validation errors occured regarding the specified environment variables, otherwise returns the values of those environment variables.
NOTE: To specify environment variables to validate you MUST supply a JSON Schema that defines a top-level object.
NOTE: Only second-level keys are used for validate environment variables.
Examples
terminal
terminal
export MY_STRING='Hello World!'
schema.ts
import type { JSONSchema, typeofschema } from 'https://deno.land/x/enzastdlib/schema/mod.ts';
export const MY_STRING_SCHEMA = {
type: 'object',
properties: {
MY_STRING: {
type: 'string',
minLength: 1,
},
},
} as const satisfies JSONSchema;
export type MyStringType = typeofschema<typeof MY_STRING_SCHEMA>;
mod.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import { validateEnvironment } from 'https://deno.land/x/enzastdlib/environment/mod.ts';
import type { MyStringType } from "./schema.ts";
import { MY_STRING_SCHEMA } from './schema.ts';
assertEquals(
validateEnvironment<MyStringType>(MY_STRING_SCHEMA),
{ MY_STRING: 'Hello World!' },
);
Parameters
schema: JSONSchemaObject