@theholocron/env-utils 1.5.2 → 1.6.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/dist/index.d.mts +24 -1
- package/dist/index.mjs +25 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
+
//#region src/create-env-lookup.d.ts
|
|
3
|
+
interface EnvLookup {
|
|
4
|
+
/** Return the string value for `key`, or `undefined` if absent or empty. */
|
|
5
|
+
get(key: string): string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a lightweight env lookup backed by a fixed source dict or, when
|
|
9
|
+
* called with no arguments, by a lazy read of `process.env` on every call.
|
|
10
|
+
*
|
|
11
|
+
* Use the no-arg form for the application singleton — it always reflects the
|
|
12
|
+
* current state of `process.env` so tests can mutate it freely:
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // singleton — reads process.env lazily
|
|
16
|
+
* export const env = createEnvLookup();
|
|
17
|
+
*
|
|
18
|
+
* // injectable — tests pass a fake dict
|
|
19
|
+
* export function makeEnv(source?: Record<string, string | undefined>) {
|
|
20
|
+
* return createEnvLookup(source);
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
declare function createEnvLookup(source?: Record<string, string | undefined>): EnvLookup;
|
|
24
|
+
//#endregion
|
|
2
25
|
//#region src/types.d.ts
|
|
3
26
|
type Primitive = string | number | boolean;
|
|
4
27
|
type EnvObject = {
|
|
@@ -195,4 +218,4 @@ declare function filterByNamespace(raw: Record<string, string | undefined>, name
|
|
|
195
218
|
*/
|
|
196
219
|
declare function mergeNamespaces(raw: Record<string, string | undefined>, namespaces: string[]): Record<string, string | undefined>;
|
|
197
220
|
//#endregion
|
|
198
|
-
export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, type EnvLoader, type EnvObject, type EnvParser, type EnvParserOptions, type Environment, type Primitive, createEnvParser, environment, filterByNamespace, mergeNamespaces };
|
|
221
|
+
export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, type EnvLoader, type EnvLookup, type EnvObject, type EnvParser, type EnvParserOptions, type Environment, type Primitive, createEnvLookup, createEnvParser, environment, filterByNamespace, mergeNamespaces };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
+
//#region src/create-env-lookup.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a lightweight env lookup backed by a fixed source dict or, when
|
|
5
|
+
* called with no arguments, by a lazy read of `process.env` on every call.
|
|
6
|
+
*
|
|
7
|
+
* Use the no-arg form for the application singleton — it always reflects the
|
|
8
|
+
* current state of `process.env` so tests can mutate it freely:
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // singleton — reads process.env lazily
|
|
12
|
+
* export const env = createEnvLookup();
|
|
13
|
+
*
|
|
14
|
+
* // injectable — tests pass a fake dict
|
|
15
|
+
* export function makeEnv(source?: Record<string, string | undefined>) {
|
|
16
|
+
* return createEnvLookup(source);
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
function createEnvLookup(source) {
|
|
20
|
+
return { get(key) {
|
|
21
|
+
const val = (source ?? process.env)[key];
|
|
22
|
+
return typeof val === "string" && val ? val : void 0;
|
|
23
|
+
} };
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
2
26
|
//#region src/environment.ts
|
|
3
27
|
const ENVIRONMENTS = [
|
|
4
28
|
"local",
|
|
@@ -286,4 +310,4 @@ function createEnvParser(options) {
|
|
|
286
310
|
};
|
|
287
311
|
}
|
|
288
312
|
//#endregion
|
|
289
|
-
export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, createEnvParser, environment, filterByNamespace, mergeNamespaces };
|
|
313
|
+
export { DEFAULT_ENVIRONMENT, DEPLOYED_ENVIRONMENTS, DotenvLoader, ENVIRONMENTS, createEnvLookup, createEnvParser, environment, filterByNamespace, mergeNamespaces };
|