UNPKG

zod-config

Version:

Load configuration variables from multiple sources with flexible adapters, ensuring type safety with Zod.

2 lines (1 loc) 998 B
import{readFileSync as l}from"fs";function f(e){return!e||typeof e!="object"?!1:Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null}function u(e,t){let{regex:n}=t;return n?a(e,n):e}var a=(e,t)=>{if(e==null)return{};if(!f(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,i)=>(n[i]=e[i],n),{})};import{ZodDefault as x,ZodObject as z,ZodOptional as T}from"zod/v3";import*as o from"zod/v4/core";var k={strict:p(e=>e),lenient:p(d)};function d(e){return e.replace(/[^a-z0-9]/gi,"").toLowerCase()}function p(e){return(t,n)=>e(t)===e(n)}import y from"json5";var g="json5 adapter",G=({path:e,regex:t,silent:n,keyMatching:i,transform:s})=>({name:g,read:()=>{try{let r=l(e,"utf-8"),c=y.parse(r)||{};return u(c,{regex:t})}catch(r){throw new Error(`Failed to parse / read JSON5 file at ${e}: ${r instanceof Error?r.message:r}`)}},silent:n,keyMatching:i,transform:s});export{G as json5Adapter};