UNPKG

@typedotenv/core

Version:

typedotenv core library (dotenv utility for TypeScript)

77 lines (74 loc) 2.07 kB
type PropertyOptions = { patterns?: Record<string, RegExp | string>; } & ({ allowList: string[]; denyList?: undefined; required?: undefined; } | { allowList?: undefined; denyList?: string[]; required?: string[]; }); type GenerateOptions = PropertyOptions & { /** * Prefix for generated code. [default: `/* Auto generated by typedotenv *‍/`] */ prefix?: string; /** * Object that provide environment variables [default: `process.env`] * @example `import.meta.env` */ envObject?: string; /** * Disable type assertions like `as string` * @example * enableTypeAssertion: true * ```js * export const VAR = process.env.VAR as string; * ``` * enableTypeAssertion: false * ```ts * export const VAR = process.env.VAR; * ``` */ enableTypeAssertion?: boolean; /** * End of line cheracter [default: `\n`] */ eol?: string; /** * Disable runtime validation * @example * disableRuntimeTypeCheck: true * ```ts * export const VAR = process.env.VAR as string; * ``` * disableRuntimeTypeCheck: false * ```ts * export const VAR = process.env.VAR as string; * if (typeof VAR !== 'string') throw new Error('VAR is not defined in .env'); * ``` */ disableRuntimeTypeCheck?: boolean; /** * Access environment variables from index (obj["key"]) signature or dot (obj.key) signature * @example * accessFromIndexSignature: true * ```js * export const VAR = process.env["VAR"]; * ``` * accessFromIndexSignature: false * ```ts * export const VAR = process.env.VAR; * ``` */ accessFromIndexSignature?: boolean; }; /** * Generate TypeScript from dotenv contents * @param dotenv dotenv contents * @param options generate options include validation options * @returns generated TypeScript code */ declare const generate: (dotenv: string, options?: GenerateOptions) => string; export { GenerateOptions, generate };