Skip to content
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

Export envVarToBoolean helper #31198

Open
maorleger opened this issue Sep 24, 2024 · 0 comments
Open

Export envVarToBoolean helper #31198

maorleger opened this issue Sep 24, 2024 · 0 comments
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.

Comments

@maorleger
Copy link
Member

In order to provide a consistent experience integrating with boolean environment variables we should export a envVarToBoolean helper modeled after the one exported in

export function envVarToBoolean(key: KnownEnvironmentKey): boolean {
if (!environmentCache.has(key)) {
loadEnvironmentVariable(key);
}
const value = (environmentCache.get(key) ?? "").toLowerCase();
return value !== "false" && value !== "0" && Boolean(value);
}
function loadEnvironmentVariable(key: KnownEnvironmentKey): void {
if (typeof process !== "undefined" && process.env) {
const rawValue = process.env[key] ?? process.env[key.toLowerCase()];
environmentCache.set(key, rawValue);
}
}

Notes:

  • Ignore the cache section, it's not needed as node will cache the env vars anyway
  • Allow any string, not just the known strings
  • "false" and "0" should translate to boolean false
> Boolean("false")
false
> Boolean("0")
false

Original text from PR:

I am not sure if we export a "envVarToBoolean" helper, but if not I should make an issue to export one from core-util. This is probably fine for now? Up to you (and your team)!

Originally posted by @maorleger in #31160 (comment)

@github-actions github-actions bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 24, 2024
@jeremymeng jeremymeng added Client This issue points to a problem in the data-plane of the library. Azure.Core labels Sep 24, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

No branches or pull requests

2 participants