safe-env-getter 0.1.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/.devcontainer/devcontainer.json +26 -0
- package/LICENSE +202 -0
- package/README.md +85 -0
- package/lib/index.d.ts +92 -0
- package/lib/index.js +67 -0
- package/package.json +106 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dev-safe-env-getter",
|
|
3
|
+
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
|
|
4
|
+
"features": {
|
|
5
|
+
"ghcr.io/devcontainers/features/common-utils:2": {
|
|
6
|
+
"username": "developer",
|
|
7
|
+
"upgradePackages": true
|
|
8
|
+
},
|
|
9
|
+
"ghcr.io/devcontainers/features/git:1": {},
|
|
10
|
+
"ghcr.io/devcontainers/features/node:1": {
|
|
11
|
+
"version": "24"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
|
|
15
|
+
"workspaceFolder": "/workspace",
|
|
16
|
+
"mounts": [
|
|
17
|
+
"target=/workspace/node_modules"
|
|
18
|
+
],
|
|
19
|
+
"remoteUser": "developer",
|
|
20
|
+
"remoteEnv": {
|
|
21
|
+
"npm_config_loglevel": "error"
|
|
22
|
+
},
|
|
23
|
+
"postCreateCommand": {
|
|
24
|
+
"fixVolumePerms": "sudo chown -R $(whoami): /workspace"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Safe Env Getter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/safe-env-getter)
|
|
4
|
+
[](https://www.npmjs.com/package/safe-env-getter)
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
|
|
7
|
+
Type-safe environment variable getter for Node.js. Reads and parses `process.env` with a spec (string, number, boolean, enum), optional defaults, and clear errors when required variables are missing or invalid.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Typed specs**: `string`, `number`, `boolean`, and `enum` with TypeScript inference
|
|
12
|
+
- **Optional defaults**: Fallback values when the variable is unset or empty
|
|
13
|
+
- **Strict validation**: Throws with clear messages for missing or invalid values
|
|
14
|
+
- **Boolean parsing**: Accepts `1`, `true`, `yes`, `on` (case-insensitive) as `true`
|
|
15
|
+
- **Enum constraint**: Restricts values to a fixed set of choices
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
**npm**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install safe-env-getter
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**yarn**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn add safe-env-getter
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { SafeEnvGetter, SafeEnvType } from 'safe-env-getter';
|
|
35
|
+
|
|
36
|
+
// String (spec omitted → defaults to SafeEnvType.String; throws if missing)
|
|
37
|
+
const nodeEnv = SafeEnvGetter.getEnv('NODE_ENV');
|
|
38
|
+
|
|
39
|
+
// String with default (3rd arg: options)
|
|
40
|
+
const logLevel = SafeEnvGetter.getEnv('LOG_LEVEL', SafeEnvType.String, { default: 'info' });
|
|
41
|
+
|
|
42
|
+
// Number with default
|
|
43
|
+
const port = SafeEnvGetter.getEnv('PORT', SafeEnvType.Number, { default: 3000 });
|
|
44
|
+
|
|
45
|
+
// Boolean (parses 1/true/yes/on as true)
|
|
46
|
+
const debug = SafeEnvGetter.getEnv('DEBUG', SafeEnvType.Boolean, { default: false });
|
|
47
|
+
|
|
48
|
+
// Enum (required)
|
|
49
|
+
const mode = SafeEnvGetter.getEnv('MODE', SafeEnvType.Enum(['read', 'write']));
|
|
50
|
+
// Enum with default
|
|
51
|
+
const modeWithDefault = SafeEnvGetter.getEnv('MODE', SafeEnvType.Enum(['read', 'write']), { default: 'read' });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
`SafeEnvGetter.getEnv(key, spec?, options?)` takes:
|
|
57
|
+
|
|
58
|
+
| Argument | Required | Description |
|
|
59
|
+
|----------|----------|-------------|
|
|
60
|
+
| **key** | Yes | Environment variable name (e.g. `"PORT"`, `"NODE_ENV"`). |
|
|
61
|
+
| **spec** | No | Type spec; defaults to `SafeEnvType.String` when omitted. Use `SafeEnvType.String`, `SafeEnvType.Number`, `SafeEnvType.Boolean`, or `SafeEnvType.Enum(choices)`. |
|
|
62
|
+
| **options** | No | Optional object. Use `{ default: value }` to provide a fallback when the variable is missing or empty. |
|
|
63
|
+
|
|
64
|
+
**Spec types:**
|
|
65
|
+
|
|
66
|
+
| Spec | Shape | Description |
|
|
67
|
+
|------|--------|-------------|
|
|
68
|
+
| `string` | `{ type: 'string' }` | Raw string value. |
|
|
69
|
+
| `number` | `{ type: 'number' }` | Parsed with `Number()`; throws if NaN. |
|
|
70
|
+
| `boolean` | `{ type: 'boolean' }` | `1`/`true`/`yes`/`on` (case-insensitive) → `true`, else `false`. |
|
|
71
|
+
| `enum` | `{ type: 'enum', choices: readonly T[] }` | Value must be in `choices`; throws otherwise. |
|
|
72
|
+
|
|
73
|
+
**Errors:**
|
|
74
|
+
|
|
75
|
+
- If the variable is missing or empty and `options.default` is not set: `Missing required environment variable: <key>`.
|
|
76
|
+
- For `number`, invalid values: `Env <key>: expected number, got "<raw>"`.
|
|
77
|
+
- For `enum`, invalid values: `Env <key>: must be one of [choice1, choice2, ...]`.
|
|
78
|
+
|
|
79
|
+
## Requirements
|
|
80
|
+
|
|
81
|
+
- **Node.js** >= 20.0.0
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
This project is licensed under the Apache-2.0 License.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec for a string environment variable.
|
|
3
|
+
* The default value is passed via the third argument of `getEnv`, not in the spec.
|
|
4
|
+
*/
|
|
5
|
+
export type SafeEnvTypeString = {
|
|
6
|
+
type: 'string';
|
|
7
|
+
default?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Spec for a numeric environment variable.
|
|
11
|
+
* Values are parsed with `Number()`; invalid values throw.
|
|
12
|
+
* The default value is passed via the third argument of `getEnv`, not in the spec.
|
|
13
|
+
*/
|
|
14
|
+
export type SafeEnvTypeNumber = {
|
|
15
|
+
type: 'number';
|
|
16
|
+
default?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Spec for a boolean environment variable.
|
|
20
|
+
* Parses `1`, `true`, `yes`, `on` (case-insensitive) as `true`; anything else as `false`.
|
|
21
|
+
* The default value is passed via the third argument of `getEnv`, not in the spec.
|
|
22
|
+
*/
|
|
23
|
+
export type SafeEnvTypeBoolean = {
|
|
24
|
+
type: 'boolean';
|
|
25
|
+
default?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Spec for an enum environment variable with a fixed set of choices.
|
|
29
|
+
* The value must be one of `choices`; otherwise an error is thrown.
|
|
30
|
+
* The default value is passed via the third argument of `getEnv`, not in the spec.
|
|
31
|
+
*
|
|
32
|
+
* @template T - Literal string union of allowed values.
|
|
33
|
+
*/
|
|
34
|
+
export type SafeEnvTypeEnum<T extends string = string> = {
|
|
35
|
+
type: 'enum';
|
|
36
|
+
choices: readonly T[];
|
|
37
|
+
default?: T;
|
|
38
|
+
};
|
|
39
|
+
/** Union of all environment variable spec types. */
|
|
40
|
+
export type SafeEnvSpec = SafeEnvTypeString | SafeEnvTypeNumber | SafeEnvTypeBoolean | SafeEnvTypeEnum;
|
|
41
|
+
/**
|
|
42
|
+
* Predefined spec constants for use as the second argument to `getEnv`.
|
|
43
|
+
* Use the third argument `options: { default: value }` to provide a fallback when the variable is missing.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SafeEnvType: {
|
|
46
|
+
/** Spec for a string value. */
|
|
47
|
+
readonly String: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
};
|
|
50
|
+
/** Spec for a numeric value. */
|
|
51
|
+
readonly Number: {
|
|
52
|
+
readonly type: "number";
|
|
53
|
+
};
|
|
54
|
+
/** Spec for a boolean value (1/true/yes/on → true). */
|
|
55
|
+
readonly Boolean: {
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Returns a spec that restricts the value to one of the given choices.
|
|
60
|
+
* @param choices - Allowed string literals.
|
|
61
|
+
* @returns Enum spec for use with `getEnv`.
|
|
62
|
+
*/
|
|
63
|
+
readonly Enum: <T extends string>(choices: readonly T[]) => SafeEnvTypeEnum<T>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Infers the return type from the given spec.
|
|
67
|
+
* @template S - A `SafeEnvSpec` variant.
|
|
68
|
+
*/
|
|
69
|
+
export type SafeEnvSpecToType<S> = S extends SafeEnvTypeString ? string : S extends SafeEnvTypeNumber ? number : S extends SafeEnvTypeBoolean ? boolean : S extends SafeEnvTypeEnum<infer T> ? T : never;
|
|
70
|
+
/**
|
|
71
|
+
* Reads and parses an environment variable according to the given spec.
|
|
72
|
+
* If the variable is missing or empty and no default is provided in `options`, throws an error.
|
|
73
|
+
*
|
|
74
|
+
* @param key - Environment variable name (e.g. `"PORT"`, `"NODE_ENV"`).
|
|
75
|
+
* @param spec - Type spec; defaults to `SafeEnvType.String` when omitted.
|
|
76
|
+
* @param options - Optional. Use `{ default: value }` to provide a fallback when the variable is missing.
|
|
77
|
+
* @returns Parsed value with type inferred from `spec`.
|
|
78
|
+
* @throws {Error} When the variable is missing and `options.default` is not set.
|
|
79
|
+
* @throws {Error} When `spec.type` is `"number"` and the value is not a valid number.
|
|
80
|
+
* @throws {Error} When `spec.type` is `"enum"` and the value is not in `spec.choices`.
|
|
81
|
+
*/
|
|
82
|
+
declare function getEnv<K extends string, S extends SafeEnvSpec = SafeEnvTypeString>(key: K, spec?: S, options?: {
|
|
83
|
+
default?: SafeEnvSpecToType<S>;
|
|
84
|
+
}): SafeEnvSpecToType<S>;
|
|
85
|
+
/**
|
|
86
|
+
* Safe environment variable getter.
|
|
87
|
+
* Use `SafeEnvGetter.getEnv(key, spec?, options?)` to read and parse environment variables with type safety.
|
|
88
|
+
*/
|
|
89
|
+
export declare const SafeEnvGetter: {
|
|
90
|
+
readonly getEnv: typeof getEnv;
|
|
91
|
+
};
|
|
92
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SafeEnvGetter = exports.SafeEnvType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Predefined spec constants for use as the second argument to `getEnv`.
|
|
6
|
+
* Use the third argument `options: { default: value }` to provide a fallback when the variable is missing.
|
|
7
|
+
*/
|
|
8
|
+
exports.SafeEnvType = {
|
|
9
|
+
/** Spec for a string value. */
|
|
10
|
+
String: { type: 'string' },
|
|
11
|
+
/** Spec for a numeric value. */
|
|
12
|
+
Number: { type: 'number' },
|
|
13
|
+
/** Spec for a boolean value (1/true/yes/on → true). */
|
|
14
|
+
Boolean: { type: 'boolean' },
|
|
15
|
+
/**
|
|
16
|
+
* Returns a spec that restricts the value to one of the given choices.
|
|
17
|
+
* @param choices - Allowed string literals.
|
|
18
|
+
* @returns Enum spec for use with `getEnv`.
|
|
19
|
+
*/
|
|
20
|
+
Enum: (choices) => ({ type: 'enum', choices }),
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Reads and parses an environment variable according to the given spec.
|
|
24
|
+
* If the variable is missing or empty and no default is provided in `options`, throws an error.
|
|
25
|
+
*
|
|
26
|
+
* @param key - Environment variable name (e.g. `"PORT"`, `"NODE_ENV"`).
|
|
27
|
+
* @param spec - Type spec; defaults to `SafeEnvType.String` when omitted.
|
|
28
|
+
* @param options - Optional. Use `{ default: value }` to provide a fallback when the variable is missing.
|
|
29
|
+
* @returns Parsed value with type inferred from `spec`.
|
|
30
|
+
* @throws {Error} When the variable is missing and `options.default` is not set.
|
|
31
|
+
* @throws {Error} When `spec.type` is `"number"` and the value is not a valid number.
|
|
32
|
+
* @throws {Error} When `spec.type` is `"enum"` and the value is not in `spec.choices`.
|
|
33
|
+
*/
|
|
34
|
+
function getEnv(key, spec = exports.SafeEnvType.String, options) {
|
|
35
|
+
const raw = process.env[key];
|
|
36
|
+
const defaultValue = options?.default;
|
|
37
|
+
const hasDefault = defaultValue !== undefined;
|
|
38
|
+
if (raw == null || raw === '') {
|
|
39
|
+
if (!hasDefault)
|
|
40
|
+
throw new Error(`Missing required environment variable: ${key}`);
|
|
41
|
+
return defaultValue;
|
|
42
|
+
}
|
|
43
|
+
switch (spec.type) {
|
|
44
|
+
case 'number': {
|
|
45
|
+
const n = Number(raw);
|
|
46
|
+
if (Number.isNaN(n))
|
|
47
|
+
throw new Error(`Env ${key}: expected number, got "${raw}"`);
|
|
48
|
+
return n;
|
|
49
|
+
}
|
|
50
|
+
case 'boolean':
|
|
51
|
+
return (/^(1|true|yes|on)$/i.test(raw) ? true : false);
|
|
52
|
+
case 'enum':
|
|
53
|
+
if (!spec.choices.includes(raw))
|
|
54
|
+
throw new Error(`Env ${key}: must be one of [${spec.choices.join(', ')}]`);
|
|
55
|
+
return raw;
|
|
56
|
+
default:
|
|
57
|
+
return raw;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Safe environment variable getter.
|
|
62
|
+
* Use `SafeEnvGetter.getEnv(key, spec?, options?)` to read and parse environment variables with type safety.
|
|
63
|
+
*/
|
|
64
|
+
exports.SafeEnvGetter = {
|
|
65
|
+
getEnv,
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBb0NBOzs7R0FHRztBQUNVLFFBQUEsV0FBVyxHQUFHO0lBQ3pCLCtCQUErQjtJQUMvQixNQUFNLEVBQUUsRUFBRSxJQUFJLEVBQUUsUUFBUSxFQUF1QztJQUMvRCxnQ0FBZ0M7SUFDaEMsTUFBTSxFQUFFLEVBQUUsSUFBSSxFQUFFLFFBQVEsRUFBdUM7SUFDL0QsdURBQXVEO0lBQ3ZELE9BQU8sRUFBRSxFQUFFLElBQUksRUFBRSxTQUFTLEVBQXdDO0lBQ2xFOzs7O09BSUc7SUFDSCxJQUFJLEVBQUUsQ0FBbUIsT0FBcUIsRUFBRSxFQUFFLENBQUMsQ0FBQyxFQUFFLElBQUksRUFBRSxNQUFNLEVBQUUsT0FBTyxFQUFFLENBQXVCO0NBQzVGLENBQUM7QUFhWDs7Ozs7Ozs7Ozs7R0FXRztBQUNILFNBQVMsTUFBTSxDQUNiLEdBQU0sRUFDTixPQUFVLG1CQUFXLENBQUMsTUFBVyxFQUNqQyxPQUE0QztJQUU1QyxNQUFNLEdBQUcsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQzdCLE1BQU0sWUFBWSxHQUFHLE9BQU8sRUFBRSxPQUFPLENBQUM7SUFDdEMsTUFBTSxVQUFVLEdBQU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XG4gICAgICBjb25zdCBuID0gTnVtYmVyKHJhdyk7XG4gICAgICBpZiAoTnVtYmVyLmlzTmFOKG4pKSB0aHJvdyBuZXcgRXJyb3IoYEVudiAke2tleX06IGV4cGVjdGVkIG51bWJlciwgZ290IFwiJHtyYXd9XCJgKTtcbiAgICAgIHJldHVybiBuIGFzIFNhZmVFbnZTcGVjVG9UeXBlPFM+O1xuICAgIH1cbiAgICBjYXNlICdib29sZWFuJzpcbiAgICAgIHJldHVybiAoL14oMXx0cnVlfHllc3xvbikkL2kudGVzdChyYXcpID8gdHJ1ZSA6IGZhbHNlKSBhcyBTYWZlRW52U3BlY1RvVHlwZTxTPjtcbiAgICBjYXNlICdlbnVtJzpcbiAgICAgIGlmICghc3BlYy5jaG9pY2VzLmluY2x1ZGVzKHJhdykpIHRocm93IG5ldyBFcnJvcihgRW52ICR7a2V5fTogbXVzdCBiZSBvbmUgb2YgWyR7c3BlYy5jaG9pY2VzLmpvaW4oJywgJyl9XWApO1xuICAgICAgcmV0dXJuIHJhdyBhcyBTYWZlRW52U3BlY1RvVHlwZTxTPjtcbiAgICBkZWZhdWx0OlxuICAgICAgcmV0dXJuIHJhdyBhcyBTYWZlRW52U3BlY1RvVHlwZTxTPjtcbiAgfVxufVxuXG4vKipcbiAqIFNhZmUgZW52aXJvbm1lbnQgdmFyaWFibGUgZ2V0dGVyLlxuICogVXNlIGBTYWZlRW52R2V0dGVyLmdldEVudihrZXksIHNwZWM/LCBvcHRpb25zPylgIHRvIHJlYWQgYW5kIHBhcnNlIGVudmlyb25tZW50IHZhcmlhYmxlcyB3aXRoIHR5cGUgc2FmZXR5LlxuICovXG5leHBvcnQgY29uc3QgU2FmZUVudkdldHRlciA9IHtcbiAgZ2V0RW52LFxufSBhcyBjb25zdDsiXX0=
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "safe-env-getter",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/gammarers-labs/safe-env-getter.git"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npx projen build",
|
|
9
|
+
"bump": "npx projen bump",
|
|
10
|
+
"clobber": "npx projen clobber",
|
|
11
|
+
"compile": "npx projen compile",
|
|
12
|
+
"default": "npx projen default",
|
|
13
|
+
"eject": "npx projen eject",
|
|
14
|
+
"eslint": "npx projen eslint",
|
|
15
|
+
"package": "npx projen package",
|
|
16
|
+
"post-compile": "npx projen post-compile",
|
|
17
|
+
"post-upgrade": "npx projen post-upgrade",
|
|
18
|
+
"pre-compile": "npx projen pre-compile",
|
|
19
|
+
"release": "npx projen release",
|
|
20
|
+
"test": "npx projen test",
|
|
21
|
+
"test:watch": "npx projen test:watch",
|
|
22
|
+
"unbump": "npx projen unbump",
|
|
23
|
+
"upgrade": "npx projen upgrade",
|
|
24
|
+
"watch": "npx projen watch",
|
|
25
|
+
"projen": "npx projen"
|
|
26
|
+
},
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "yicr",
|
|
29
|
+
"email": "yicr@users.noreply.github.com",
|
|
30
|
+
"organization": false
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@stylistic/eslint-plugin": "^2",
|
|
34
|
+
"@types/jest": "^30.0.0",
|
|
35
|
+
"@types/node": "^20",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^8",
|
|
37
|
+
"@typescript-eslint/parser": "^8",
|
|
38
|
+
"commit-and-tag-version": "^12",
|
|
39
|
+
"constructs": "^10.0.0",
|
|
40
|
+
"eslint": "^9",
|
|
41
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
42
|
+
"eslint-plugin-import": "^2.32.0",
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
|
+
"jest-junit": "^16",
|
|
45
|
+
"projen": "^0.99.15",
|
|
46
|
+
"ts-jest": "^29.4.6",
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
|
+
"typescript": "5.9.x"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">= 20.0.0"
|
|
52
|
+
},
|
|
53
|
+
"main": "lib/index.js",
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"version": "0.1.0",
|
|
59
|
+
"jest": {
|
|
60
|
+
"coverageProvider": "v8",
|
|
61
|
+
"testMatch": [
|
|
62
|
+
"<rootDir>/@(src|test)/**/*(*.)@(spec|test).ts?(x)",
|
|
63
|
+
"<rootDir>/@(src|test)/**/__tests__/**/*.ts?(x)",
|
|
64
|
+
"<rootDir>/@(projenrc)/**/*(*.)@(spec|test).ts?(x)",
|
|
65
|
+
"<rootDir>/@(projenrc)/**/__tests__/**/*.ts?(x)"
|
|
66
|
+
],
|
|
67
|
+
"clearMocks": true,
|
|
68
|
+
"collectCoverage": true,
|
|
69
|
+
"coverageReporters": [
|
|
70
|
+
"json",
|
|
71
|
+
"lcov",
|
|
72
|
+
"clover",
|
|
73
|
+
"cobertura",
|
|
74
|
+
"text"
|
|
75
|
+
],
|
|
76
|
+
"coverageDirectory": "coverage",
|
|
77
|
+
"coveragePathIgnorePatterns": [
|
|
78
|
+
"/node_modules/"
|
|
79
|
+
],
|
|
80
|
+
"testPathIgnorePatterns": [
|
|
81
|
+
"/node_modules/"
|
|
82
|
+
],
|
|
83
|
+
"watchPathIgnorePatterns": [
|
|
84
|
+
"/node_modules/"
|
|
85
|
+
],
|
|
86
|
+
"reporters": [
|
|
87
|
+
"default",
|
|
88
|
+
[
|
|
89
|
+
"jest-junit",
|
|
90
|
+
{
|
|
91
|
+
"outputDirectory": "test-reports"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
],
|
|
95
|
+
"transform": {
|
|
96
|
+
"^.+\\.[t]sx?$": [
|
|
97
|
+
"ts-jest",
|
|
98
|
+
{
|
|
99
|
+
"tsconfig": "tsconfig.dev.json"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"types": "lib/index.d.ts",
|
|
105
|
+
"//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
|
|
106
|
+
}
|