@theholocron/env-utils 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,6 +38,17 @@ export const config = map((get) => ({
38
38
  }));
39
39
  ```
40
40
 
41
+ ### Precedence chains
42
+
43
+ `firstEnv(env, names, fallback?)` returns the first variable in `names` that is set and non-empty, else `fallback`:
44
+
45
+ ```typescript
46
+ import { createEnvLookup, firstEnv } from "@theholocron/env-utils";
47
+
48
+ const env = createEnvLookup();
49
+ const dsn = firstEnv(env, ["MYAPP_SENTRY_DSN", "SENTRY_DSN"], DEFAULT_DSN);
50
+ ```
51
+
41
52
  ### Logging
42
53
 
43
54
  Debug output (key-loaded counts, missing-key warnings, deprecation notices) goes to `console.info`/`console.warn` by default. Pass an `EnvLogger` (any object shaped `{ info(message, meta?), warn(message, meta?) }`) to route it elsewhere:
package/dist/index.d.mts CHANGED
@@ -195,6 +195,18 @@ export declare const environment: {
195
195
  };
196
196
  type Environment = (typeof ENVIRONMENTS)[number];
197
197
  //#endregion
198
+ //#region src/first-env.d.ts
199
+ /**
200
+ * Return the value of the first variable in `names` that is set and
201
+ * non-empty, or `fallback` when none is. Use it for a precedence chain such
202
+ * as a product-specific name, then the vendor-native name, then a default.
203
+ *
204
+ * @example
205
+ * const dsn = firstEnv(env, ["HOLOCRON_SENTRY_DSN", "SENTRY_DSN"], DEFAULT_DSN);
206
+ */
207
+ export declare function firstEnv(env: EnvLookup, names: readonly string[], fallback: string): string;
208
+ export declare function firstEnv(env: EnvLookup, names: readonly string[], fallback?: string): string | undefined;
209
+ //#endregion
198
210
  //#region src/loader.d.ts
199
211
  /**
200
212
  * Default loader — calls dotenv/config so the .env file is
package/dist/index.mjs CHANGED
@@ -315,4 +315,13 @@ function createEnvParser(options) {
315
315
  };
316
316
  }
317
317
  //#endregion
318
- export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, createEnvLookup, createEnvParser, environment, filterByNamespace, mergeNamespaces };
318
+ //#region src/first-env.ts
319
+ function firstEnv(env, names, fallback) {
320
+ for (const name of names) {
321
+ const value = env.get(name);
322
+ if (value !== void 0) return value;
323
+ }
324
+ return fallback;
325
+ }
326
+ //#endregion
327
+ export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, createEnvLookup, createEnvParser, environment, filterByNamespace, firstEnv, mergeNamespaces };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/env-utils",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "Runtime environment detection and typed env-var parsing.",
5
5
  "keywords": [
6
6
  "env",