-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should environment variable values be normalized? #17
Comments
Hi. Sharing some experience for doing this. For Nuxt users, we had been doing env value deserialization for couple of years using unjs/destr and it gave both positive and negative feedbacks. I think for boolean type Re numbers we had several user issues where tokens (intended to be string) looking like a number are wongly parsed. For example should an env with value |
From my experience maintaining npmjs.com/qs, as well as working with jquery's |
Just spent one hour trying to figure out why some code was working locally, and failing on our CI -- it turns out that something was setting an env var to When it comes to booleans, it's incredibly annoying because there is no easy conversion from a string to boolean: If we want to avoid implicit deserialization, it could be explicit with an API like const str = env("FOO");
const str2 = env("FOO", "string");
const bool = env("FOO", "boolean");
const num = env("FOO", "number");
const int = env("FOO", "bigint"); where the type definition would be function env(name: string): string | undefined;
function env(name: string, type: "string"): string | undefined;
function env(name: string, type: "boolean"): boolean | undefined;
function env(name: string, type: "number"): number | undefined;
function env(name: string, type: "bigint"): bigint | undefined;
function env(name: string, type: unknown): string | boolean | number | bigint | undefined; |
Small suggestion re future compatibility if env(name, { type: "boolean" }) |
Fwiw to note for future, I don't think we should worry about the API having an argument for a default value, instead allowing the user to do |
Eg:
'0'
->0
,'false'
->false
. Suggested by @nicolo-ribaudoThe text was updated successfully, but these errors were encountered: