@o3co/ts.hocon 1.9.0 → 1.11.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.
@@ -0,0 +1,56 @@
1
+ import { C as Config } from '../config-Dlq6rF3w.cjs';
2
+
3
+ type EnvOptions = {
4
+ /**
5
+ * Selects which variables to mount, and is stripped from the resulting path.
6
+ * Required by {@link loadEnv}: mounting the whole environment would pull in
7
+ * PATH, HOME and whatever secrets happen to be set (spec F1.1).
8
+ * {@link parseDotEnv} allows it to be empty, a `.env` file being a closed set
9
+ * the caller chose deliberately.
10
+ */
11
+ prefix?: string;
12
+ /** Source name for error messages. */
13
+ originDescription?: string;
14
+ };
15
+ /**
16
+ * Mount a prefixed slice of the environment as config.
17
+ *
18
+ * ```ts
19
+ * const base = loadEnv({ prefix: 'APP_' }) // APP_DB__HOST -> db.host
20
+ * ```
21
+ *
22
+ * Reading a single variable needs nothing from here — HOCON's own `${?VAR}`
23
+ * already does that. This is for mounting a whole namespace as a subtree.
24
+ *
25
+ * `__` is the only path separator: a single `_` stays part of its segment
26
+ * (`APP_DB__MAX_CONN` → `db.max_conn`), and a literal `.` in a variable name is
27
+ * key text rather than a boundary, so `APP_FOO.BAR` becomes the single
28
+ * top-level key `foo.bar` — addressable as the quoted path `"foo.bar"` — and
29
+ * coexists with `APP_FOO__BAR` instead of colliding with it (F1.2).
30
+ *
31
+ * Two names that do map to one path are an error, the environment having no
32
+ * order to break the tie with (F1.6). Keys named `__proto__`, `constructor` or
33
+ * `prototype` are kept like any other (F2.9).
34
+ *
35
+ * Values are always strings, and a `${...}` inside one stays literal (F0.2, F1.4).
36
+ */
37
+ declare function loadEnv(opts?: EnvOptions & {
38
+ env?: Record<string, string | undefined>;
39
+ }): Config;
40
+ /**
41
+ * Read `.env` file content.
42
+ *
43
+ * The dialect is deliberately small (spec F1.7): `NAME=value`, an optional
44
+ * `export ` prefix, whole-line `#` comments, single quotes taken literally,
45
+ * double quotes with `\n \r \t \\ \"`. Multi-line values and trailing comments
46
+ * are not supported — an unquoted value containing ` #` is an error rather than
47
+ * a guess about whether a comment was meant. No `${...}` expansion.
48
+ *
49
+ * Names map to paths exactly as in {@link loadEnv}: `__` is the only separator,
50
+ * so a literal `.` stays key text (`FOO.BAR` → the single key `foo.bar`). A
51
+ * file has a definite line order, so a repeated name is last-wins (F0.7)
52
+ * rather than the collision error the process environment gets.
53
+ */
54
+ declare function parseDotEnv(input: string, opts?: EnvOptions): Config;
55
+
56
+ export { type EnvOptions, loadEnv, parseDotEnv };
@@ -0,0 +1,56 @@
1
+ import { C as Config } from '../config-Dlq6rF3w.js';
2
+
3
+ type EnvOptions = {
4
+ /**
5
+ * Selects which variables to mount, and is stripped from the resulting path.
6
+ * Required by {@link loadEnv}: mounting the whole environment would pull in
7
+ * PATH, HOME and whatever secrets happen to be set (spec F1.1).
8
+ * {@link parseDotEnv} allows it to be empty, a `.env` file being a closed set
9
+ * the caller chose deliberately.
10
+ */
11
+ prefix?: string;
12
+ /** Source name for error messages. */
13
+ originDescription?: string;
14
+ };
15
+ /**
16
+ * Mount a prefixed slice of the environment as config.
17
+ *
18
+ * ```ts
19
+ * const base = loadEnv({ prefix: 'APP_' }) // APP_DB__HOST -> db.host
20
+ * ```
21
+ *
22
+ * Reading a single variable needs nothing from here — HOCON's own `${?VAR}`
23
+ * already does that. This is for mounting a whole namespace as a subtree.
24
+ *
25
+ * `__` is the only path separator: a single `_` stays part of its segment
26
+ * (`APP_DB__MAX_CONN` → `db.max_conn`), and a literal `.` in a variable name is
27
+ * key text rather than a boundary, so `APP_FOO.BAR` becomes the single
28
+ * top-level key `foo.bar` — addressable as the quoted path `"foo.bar"` — and
29
+ * coexists with `APP_FOO__BAR` instead of colliding with it (F1.2).
30
+ *
31
+ * Two names that do map to one path are an error, the environment having no
32
+ * order to break the tie with (F1.6). Keys named `__proto__`, `constructor` or
33
+ * `prototype` are kept like any other (F2.9).
34
+ *
35
+ * Values are always strings, and a `${...}` inside one stays literal (F0.2, F1.4).
36
+ */
37
+ declare function loadEnv(opts?: EnvOptions & {
38
+ env?: Record<string, string | undefined>;
39
+ }): Config;
40
+ /**
41
+ * Read `.env` file content.
42
+ *
43
+ * The dialect is deliberately small (spec F1.7): `NAME=value`, an optional
44
+ * `export ` prefix, whole-line `#` comments, single quotes taken literally,
45
+ * double quotes with `\n \r \t \\ \"`. Multi-line values and trailing comments
46
+ * are not supported — an unquoted value containing ` #` is an error rather than
47
+ * a guess about whether a comment was meant. No `${...}` expansion.
48
+ *
49
+ * Names map to paths exactly as in {@link loadEnv}: `__` is the only separator,
50
+ * so a literal `.` stays key text (`FOO.BAR` → the single key `foo.bar`). A
51
+ * file has a definite line order, so a repeated name is last-wins (F0.7)
52
+ * rather than the collision error the process environment gets.
53
+ */
54
+ declare function parseDotEnv(input: string, opts?: EnvOptions): Config;
55
+
56
+ export { type EnvOptions, loadEnv, parseDotEnv };