zod-config
Version:
Load configuration variables from multiple sources with flexible adapters, ensuring type safety with Zod.
2 lines (1 loc) • 1.04 kB
JavaScript
import{parse as y}from"dotenv";function i(e){return!e||typeof e!="object"?!1:Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null}function p(e,t){let{regex:n}=t;return n?d(e,n):e}var d=(e,t)=>{if(e==null)return{};if(!i(e))throw new TypeError(`Cannot filter ${e} by regex as it is not a record-like object`);return Object.keys(e).filter(n=>t.test(n)).reduce((n,o)=>(n[o]=e[o],n),{})};import{ZodDefault as z,ZodObject as T,ZodOptional as $}from"zod/v3";import*as f from"zod/v4/core";var k={strict:s(e=>e),lenient:s(l)};function l(e){return e.replace(/[^a-z0-9]/gi,"").toLowerCase()}function s(e){return(t,n)=>e(t)===e(n)}import{readFileSync as g}from"fs";var b="dotenv adapter",Q=({path:e,regex:t,silent:n,keyMatching:o,transform:u,nestingSeparator:c})=>({name:b,read:()=>{try{let r=g(e,"utf-8"),a=y(r)||{};return p(a,{regex:t})}catch(r){throw new Error(`Failed to parse / read .env file at ${e}: ${r instanceof Error?r.message:r}`)}},silent:n,keyMatching:o,transform:u,nestingSeparator:c});export{Q as dotEnvAdapter};