@wild-framework/config 0.1.0 → 0.2.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/env.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Parse the contents of a `.env` file into a flat key/value record.
3
+ *
4
+ * Supports:
5
+ * - `KEY=value`
6
+ * - `KEY="value with spaces"` and `KEY='value'`
7
+ * - optional `export KEY=value` prefix (dotenv-compatible)
8
+ * - full-line `#` comments and blank lines
9
+ *
10
+ * Later keys override earlier ones. Values are NOT coerced to primitives —
11
+ * env vars are always strings (matching `process.env`).
12
+ */
13
+ export declare function parseEnv(content: string): Record<string, string>;
14
+ /**
15
+ * Load a `.env` file into `process.env`.
16
+ *
17
+ * - Does NOT override variables already present in `process.env`
18
+ * (the real environment always wins).
19
+ * - Defaults to `.env` in `process.cwd()`; pass an explicit path to override.
20
+ *
21
+ * @returns the parsed key/value pairs that were applied (excluding overrides)
22
+ */
23
+ export declare function loadEnv(path?: string): Record<string, string>;
24
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsChE;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,IAAI,SAAiC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcrF"}
package/dist/env.js ADDED
@@ -0,0 +1,71 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ /**
4
+ * Parse the contents of a `.env` file into a flat key/value record.
5
+ *
6
+ * Supports:
7
+ * - `KEY=value`
8
+ * - `KEY="value with spaces"` and `KEY='value'`
9
+ * - optional `export KEY=value` prefix (dotenv-compatible)
10
+ * - full-line `#` comments and blank lines
11
+ *
12
+ * Later keys override earlier ones. Values are NOT coerced to primitives —
13
+ * env vars are always strings (matching `process.env`).
14
+ */
15
+ export function parseEnv(content) {
16
+ const result = {};
17
+ for (const rawLine of content.split(/\r?\n/)) {
18
+ const line = rawLine.trim();
19
+ if (!line || line.startsWith("#"))
20
+ continue;
21
+ // Strip an optional `export ` prefix (dotenv style).
22
+ const withoutExport = line.replace(/^export\s+/, "");
23
+ const eq = withoutExport.indexOf("=");
24
+ if (eq === -1)
25
+ continue;
26
+ const key = withoutExport.slice(0, eq).trim();
27
+ if (!key)
28
+ continue;
29
+ let value = withoutExport.slice(eq + 1).trim();
30
+ // Strip surrounding quotes (single or double), and unescape basic pairs.
31
+ if (value.length >= 2) {
32
+ const first = value[0];
33
+ const last = value[value.length - 1];
34
+ if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
35
+ value = value.slice(1, -1);
36
+ if (first === '"') {
37
+ value = value.replace(/\\n/g, "\n").replace(/\\"/g, '"');
38
+ }
39
+ }
40
+ }
41
+ // Strip a trailing inline comment (space-prefixed #), outside quotes.
42
+ const hash = value.indexOf(" #");
43
+ if (hash !== -1)
44
+ value = value.slice(0, hash).trimEnd();
45
+ result[key] = value;
46
+ }
47
+ return result;
48
+ }
49
+ /**
50
+ * Load a `.env` file into `process.env`.
51
+ *
52
+ * - Does NOT override variables already present in `process.env`
53
+ * (the real environment always wins).
54
+ * - Defaults to `.env` in `process.cwd()`; pass an explicit path to override.
55
+ *
56
+ * @returns the parsed key/value pairs that were applied (excluding overrides)
57
+ */
58
+ export function loadEnv(path = resolve(process.cwd(), ".env")) {
59
+ if (!existsSync(path))
60
+ return {};
61
+ const parsed = parseEnv(readFileSync(path, "utf8"));
62
+ const applied = {};
63
+ for (const [key, value] of Object.entries(parsed)) {
64
+ if (process.env[key] === undefined) {
65
+ process.env[key] = value;
66
+ applied[key] = value;
67
+ }
68
+ }
69
+ return applied;
70
+ }
71
+ //# sourceMappingURL=env.js.map
@@ -0,0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AAO,OAAO,CAAC;AACnB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Config } from "./config.js";
2
2
  export { ConfigProvider } from "./provider.js";
3
+ export { loadEnv, parseEnv } from "./env.js";
3
4
  export { ConfigAlreadyRegisteredError, ConfigNotRegisteredError, ConfigNotValidatedError, ConfigValidationError, } from "./errors.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACH,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACxB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACH,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACxB,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Config } from "./config.js";
2
2
  export { ConfigProvider } from "./provider.js";
3
+ export { loadEnv, parseEnv } from "./env.js";
3
4
  export { ConfigAlreadyRegisteredError, ConfigNotRegisteredError, ConfigNotValidatedError, ConfigValidationError, } from "./errors.js";
4
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACH,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACxB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACH,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACxB,MAAM,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wild-framework/config",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "zod": "^3.24.0",
35
- "@wild-framework/core": "0.1.0",
36
- "@wild-framework/container": "0.1.0"
35
+ "@wild-framework/core": "0.2.0",
36
+ "@wild-framework/container": "0.2.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsc",