* web: Check JS files. Add types. * web: Fix issues surrounding Vite/ESBuild types. * web: Clean up version constants. Tidy types * web: Clean up docs, types. * web: Clean up package paths. * web: (ESLint) no-lonely-if * web: Render slot before navbar. * web: Fix line-height alignment. * web: Truncate long headers. * web: Clean up page header declarations. Add story. Update paths. * web: Ignore out directory. * web: Lint Lit. * web: Use private alias. * web: Fix implicit CJS mode. * web: Update deps. * web: await all imports.
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * @file Utility functions for working with environment variables.
 | 
						|
 */
 | 
						|
/// <reference types="../types/node.js" />
 | 
						|
 | 
						|
//#region Constants
 | 
						|
 | 
						|
/**
 | 
						|
 * The current Node.js environment, defaulting to "development" when not set.
 | 
						|
 *
 | 
						|
 * Note, this should only be used during the build process.
 | 
						|
 *
 | 
						|
 * If you need to check the environment at runtime, use `process.env.NODE_ENV` to
 | 
						|
 * ensure that module tree-shaking works correctly.
 | 
						|
 *
 | 
						|
 * @category Environment
 | 
						|
 * @runtime node
 | 
						|
 */
 | 
						|
export const NodeEnvironment = process.env.NODE_ENV || "development";
 | 
						|
 | 
						|
/**
 | 
						|
 * A source environment variable, which can be a string, number, boolean, null, or undefined.
 | 
						|
 * @typedef {string | number | boolean | null | undefined} EnvironmentVariable
 | 
						|
 */
 | 
						|
 | 
						|
/**
 | 
						|
 * A type helper for serializing environment variables.
 | 
						|
 *
 | 
						|
 * @category Environment
 | 
						|
 * @template {EnvironmentVariable} T
 | 
						|
 * @typedef {T extends string ? `"${T}"` : T} JSONify
 | 
						|
 */
 | 
						|
 | 
						|
//#endregion
 | 
						|
 | 
						|
//#region Utilities
 | 
						|
 | 
						|
/**
 | 
						|
 * Given an object of environment variables, serializes them into a mapping of
 | 
						|
 * environment variable names to their respective runtime constants.
 | 
						|
 *
 | 
						|
 * This is useful for defining environment variables while bundling with ESBuild, Vite, etc.
 | 
						|
 *
 | 
						|
 * @category Environment
 | 
						|
 * @runtime node
 | 
						|
 *
 | 
						|
 * @template {Record<string, EnvironmentVariable>} EnvRecord
 | 
						|
 * @template {string} [Prefix='import.meta.env.']
 | 
						|
 *
 | 
						|
 * @param {EnvRecord} input
 | 
						|
 * @param {Prefix} [prefix='import.meta.env.']
 | 
						|
 *
 | 
						|
 * @returns {{[K in keyof EnvRecord as `${Prefix}${K}`]: JSONify<EnvRecord[K]>}}
 | 
						|
 */
 | 
						|
export function serializeEnvironmentVars(
 | 
						|
    input,
 | 
						|
    prefix = /** @type {Prefix} */ ("import.meta.env."),
 | 
						|
) {
 | 
						|
    const env = Object.fromEntries(
 | 
						|
        Object.entries(input).map(([key, value]) => [prefix + key, JSON.stringify(value ?? "")]),
 | 
						|
    );
 | 
						|
 | 
						|
    return /** @type {any} */ (env);
 | 
						|
}
 | 
						|
 | 
						|
//#endregion
 |