@arundo/typed-env
Advanced tools
Comparing version 0.0.7 to 0.0.8
import { z } from 'zod'; | ||
type NamingConvention = 'camelcase' | 'pascalcase' | 'kebabcase' | 'default'; | ||
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${Lowercase<T>}${Capitalize<SnakeToCamelCase<U>>}` : Lowercase<S>; | ||
type RemovePrefix<P extends string | undefined, S extends string> = P extends string ? S extends `${P}_${infer U}` ? U : S : S; | ||
type OutputType<InputType, P extends string | undefined, T extends string> = { | ||
[K in keyof InputType as T extends 'camelcase' ? SnakeToCamelCase<RemovePrefix<P, string & K>> : RemovePrefix<P, string>]: InputType[K]; | ||
} & {}; | ||
type NamingConvention = 'camelcase' | 'default'; | ||
type SnakeToPascalCase<S extends string> = S extends `${infer T}_${infer U}` ? `${Capitalize<Lowercase<T>>}${SnakeToPascalCase<U>}` : Capitalize<Lowercase<S>>; | ||
type SnakeToKebabCase<S extends string> = S extends `${infer T}_${infer U}` ? `${Lowercase<T>}-${Lowercase<SnakeToKebabCase<U>>}` : Lowercase<S>; | ||
type ChangeCase<T extends NamingConvention, S extends string> = 'default' extends T ? S : 'camelcase' extends T ? SnakeToCamelCase<S> : 'pascalcase' extends T ? SnakeToPascalCase<S> : 'kebabcase' extends T ? SnakeToKebabCase<S> : S; | ||
type RemovePrefix<P extends string, S extends string> = P extends '' ? S : P extends `${infer O}_` ? S extends `${O}_${infer U}` ? U : S : S extends `${P}_${infer U}` ? U : S; | ||
type BaseSchema = Record<string, unknown>; | ||
type EnvReturnType<T extends string, P extends string | undefined, S extends BaseSchema> = T extends 'camelcase' ? OutputType<S, P, T> : S; | ||
interface Options<TTransform> { | ||
type Options<TTransform, TPrefixRemoval> = { | ||
transform?: TTransform; | ||
formatErrorFn?: (error: z.ZodError) => string; | ||
excludePrefix?: string; | ||
} | ||
declare const typeEnvironment: <TSchema extends BaseSchema, TTransform extends NamingConvention = "default">(schema: z.ZodType<TSchema, z.ZodTypeDef, TSchema>, options?: Options<TTransform>, overrideEnv?: Record<string, string | undefined>) => EnvReturnType<TTransform & {}, string | undefined, TSchema>; | ||
excludePrefix?: TPrefixRemoval; | ||
}; | ||
declare const typeEnvironment: <TSchema extends BaseSchema, TTransform extends NamingConvention, TPrefixRemoval extends string = "">(schema: z.ZodType<TSchema, z.ZodTypeDef, TSchema>, { transform, formatErrorFn, excludePrefix, }?: Options<TTransform, TPrefixRemoval>, overrideEnv?: Record<string, string | undefined>) => { [K in keyof TSchema as ChangeCase<NonNullable<TTransform>, RemovePrefix<NonNullable<TPrefixRemoval>, string & K>>]: TSchema[K]; }; | ||
export { typeEnvironment }; |
@@ -1,2 +0,2 @@ | ||
"use strict";var o=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var x=(r,e)=>{for(var n in e)o(r,n,{get:e[n],enumerable:!0})},g=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!S.call(r,t)&&t!==n&&o(r,t,{get:()=>e[t],enumerable:!(a=T(e,t))||a.enumerable});return r};var h=r=>g(o({},"__esModule",{value:!0}),r);var C={};x(C,{typeEnvironment:()=>E});module.exports=h(C);var c=require("zod"),m={},u=r=>r.toLowerCase().replace(/_([a-z])/g,(e,n)=>n.toUpperCase()),l=r=>e=>Object.fromEntries(Object.entries(e).map(([n,a])=>[r(n),a])),i=r=>`Environment variable validation failed:${r.issues.map(e=>` | ||
'${e.path.join(",")}': ${e.message}`).join(",")}`,y=()=>{if(m?.env!==void 0)return m.env;if(process.env!==void 0)return process.env;throw new Error("Failed to get environment object")},v=r=>e=>e.replace(r,""),P=r=>e=>n=>e(v(r)(n)),E=(r,e={transform:"default",formatErrorFn:i,excludePrefix:""},n=y())=>{let{transform:a="default",formatErrorFn:t=i}=e??{},f=e?.excludePrefix??"",d=P(f);try{return r.transform(s=>a==="camelcase"?l(d(u))(s):s).parse(n)}catch(s){throw s instanceof c.z.ZodError?new Error(t(s)):new Error("Environment variable validation failed")}};0&&(module.exports={typeEnvironment}); | ||
"use strict";var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(e,r)=>{for(var n in r)o(e,n,{get:r[n],enumerable:!0})},g=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of S(r))!T.call(e,a)&&a!==n&&o(e,a,{get:()=>r[a],enumerable:!(t=h(r,a))||t.enumerable});return e};var p=e=>g(o({},"__esModule",{value:!0}),e);var _={};d(_,{typeEnvironment:()=>k});module.exports=p(_);var i=require("zod"),m={},x=e=>e.toLowerCase().replace(/_([a-z])/g,(r,n)=>n.toUpperCase()),l=e=>e.toLowerCase().replace(/(^[a-z]|_[a-z])/g,(r,n)=>n.startsWith("_")?n.replace("_","").toUpperCase():n.toUpperCase()),v=e=>e.toLowerCase().replace(/_/g,"-"),u=e=>{switch(e){case"camelcase":return x;case"pascalcase":return l;case"kebabcase":return v;default:return r=>r}},y=e=>r=>Object.fromEntries(Object.entries(r).map(([n,t])=>[e(n),t])),C=e=>`Environment variable validation failed:${e.issues.map(r=>` | ||
'${r.path.join(",")}': ${r.message}`).join(",")}`,P=()=>{if(m?.env!==void 0)return m.env;if(process.env!==void 0)return process.env;throw new Error("Failed to get environment object")},E=e=>r=>e?e.endsWith("_")?r.replace(e,""):r.replace(`${e}_`,""):r,b=e=>r=>n=>r(E(e)(n)),k=(e,{transform:r="default",formatErrorFn:n=C,excludePrefix:t=""}={},a=P())=>{let c=b(t);try{return e.transform(f=>y(c(u(r)))(f)).parse(a)}catch(s){throw s instanceof i.z.ZodError?new Error(n(s)):new Error("Environment variable validation failed")}};0&&(module.exports={typeEnvironment}); |
{ | ||
"name": "@arundo/typed-env", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Typed environment variables made easy 🚀", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9624
28