@alwatr/env 5.5.29 → 6.0.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/main.js ADDED
@@ -0,0 +1,5 @@
1
+ /* 📦 @alwatr/env v6.0.0 */
2
+ import{platformInfo as k}from"@alwatr/platform-info";function x(j){let h=process.env[j.name];if(h==="")h=void 0;if(k.development===!0)h??=j.developmentValue??j.defaultValue;else h??=j.defaultValue;if(h===void 0)throw Error(`Environment variable "${j.name}" is required.`);return h}export{x as getEnv};
3
+
4
+ //# debugId=9C51324E9F77C0E464756E2164756E21
5
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": [
5
+ "import {platformInfo} from '@alwatr/platform-info';\n\n/**\n * Parameters for retrieving an environment variable value.\n */\nexport type GetEnvOption = {\n /**\n * The name of the environment variable.\n */\n name: string;\n\n /**\n * The default value to use if the environment variable is not set.\n * If not provided, the environment variable is required and an error will be thrown if it is not set.\n * Except in development mode, where the development value will be used instead if provided.\n */\n defaultValue?: string;\n\n /**\n * The value to use in a development environment.\n * It will be overwrite the default value in development mode and completely ignored in production mode.\n */\n developmentValue?: string;\n};\n\nexport function getEnv(option: GetEnvOption): string {\n let value = process.env[option.name];\n if (value === '') value = undefined; // empty string is considered as undefined in environment variables\n\n if (platformInfo.development === true) {\n value ??= option.developmentValue ?? option.defaultValue;\n }\n else {\n value ??= option.defaultValue;\n }\n\n if (value === undefined) {\n throw new Error(`Environment variable \"${option.name}\" is required.`);\n }\n\n return value;\n}\n"
6
+ ],
7
+ "mappings": ";AAAA,uBAAQ,8BAyBD,SAAS,CAAM,CAAC,EAA8B,CACnD,IAAI,EAAQ,QAAQ,IAAI,EAAO,MAC/B,GAAI,IAAU,GAAI,EAAQ,OAE1B,GAAI,EAAa,cAAgB,GAC/B,IAAU,EAAO,kBAAoB,EAAO,aAG5C,SAAU,EAAO,aAGnB,GAAI,IAAU,OACZ,MAAU,MAAM,yBAAyB,EAAO,oBAAoB,EAGtE,OAAO",
8
+ "debugId": "9C51324E9F77C0E464756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
2
  "name": "@alwatr/env",
3
3
  "description": "A tiny and tree-shakable TypeScript library to get environment variables with type-safe and fallback value for development and production.",
4
- "version": "5.5.29",
4
+ "version": "6.0.0",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "dependencies": {
8
- "@alwatr/platform-info": "5.5.29"
8
+ "@alwatr/platform-info": "6.0.0"
9
9
  },
10
10
  "devDependencies": {
11
- "@alwatr/nano-build": "6.4.2",
12
- "@alwatr/prettier-config": "6.0.2",
13
- "@alwatr/tsconfig-base": "6.0.4",
14
- "@alwatr/type-helper": "7.0.2",
11
+ "@alwatr/nano-build": "7.0.0",
12
+ "@alwatr/prettier-config": "7.0.0",
13
+ "@alwatr/tsconfig-base": "7.0.0",
14
+ "@alwatr/type-helper": "8.0.0",
15
15
  "@types/node": "^24.12.0",
16
16
  "typescript": "^5.9.3"
17
17
  },
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./dist/main.d.ts",
21
- "import": "./dist/main.mjs",
22
- "require": "./dist/main.cjs"
21
+ "default": "./dist/main.js"
23
22
  }
24
23
  },
25
24
  "files": [
26
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
25
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
26
+ "README.md",
27
27
  "LICENSE",
28
28
  "!demo/**/*",
29
29
  "!**/*.test.js"
@@ -47,8 +47,6 @@
47
47
  "utils"
48
48
  ],
49
49
  "license": "MPL-2.0",
50
- "main": "./dist/main.cjs",
51
- "module": "./dist/main.mjs",
52
50
  "prettier": "@alwatr/prettier-config",
53
51
  "publishConfig": {
54
52
  "access": "public"
@@ -61,14 +59,14 @@
61
59
  "scripts": {
62
60
  "b": "bun run build",
63
61
  "build": "bun run build:ts && bun run build:es",
64
- "build:es": "nano-build --preset=module",
62
+ "build:es": "nano-build --preset=module src/main.ts",
65
63
  "build:ts": "tsc --build",
66
64
  "c": "bun run clean",
67
65
  "cb": "bun run clean && bun run build",
68
66
  "clean": "rm -rfv dist *.tsbuildinfo",
69
- "d": "bun run build:es && bun --enable-source-maps --trace-warnings",
67
+ "d": "bun run build:es && bun",
70
68
  "t": "bun run test",
71
- "test": "echo test-skipped",
69
+ "test": "bun test",
72
70
  "w": "bun run watch",
73
71
  "watch": "bun run watch:ts & bun run watch:es",
74
72
  "watch:es": "bun run build:es --watch",
@@ -77,5 +75,5 @@
77
75
  "sideEffects": false,
78
76
  "type": "module",
79
77
  "types": "./dist/main.d.ts",
80
- "gitHead": "c3889e3756b0a0f9b935a1b702a1373ac52cb379"
78
+ "gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
81
79
  }
package/src/main.ts ADDED
@@ -0,0 +1,42 @@
1
+ import {platformInfo} from '@alwatr/platform-info';
2
+
3
+ /**
4
+ * Parameters for retrieving an environment variable value.
5
+ */
6
+ export type GetEnvOption = {
7
+ /**
8
+ * The name of the environment variable.
9
+ */
10
+ name: string;
11
+
12
+ /**
13
+ * The default value to use if the environment variable is not set.
14
+ * If not provided, the environment variable is required and an error will be thrown if it is not set.
15
+ * Except in development mode, where the development value will be used instead if provided.
16
+ */
17
+ defaultValue?: string;
18
+
19
+ /**
20
+ * The value to use in a development environment.
21
+ * It will be overwrite the default value in development mode and completely ignored in production mode.
22
+ */
23
+ developmentValue?: string;
24
+ };
25
+
26
+ export function getEnv(option: GetEnvOption): string {
27
+ let value = process.env[option.name];
28
+ if (value === '') value = undefined; // empty string is considered as undefined in environment variables
29
+
30
+ if (platformInfo.development === true) {
31
+ value ??= option.developmentValue ?? option.defaultValue;
32
+ }
33
+ else {
34
+ value ??= option.defaultValue;
35
+ }
36
+
37
+ if (value === undefined) {
38
+ throw new Error(`Environment variable "${option.name}" is required.`);
39
+ }
40
+
41
+ return value;
42
+ }
package/CHANGELOG.md DELETED
@@ -1,272 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [5.5.29](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.28...@alwatr/env@5.5.29) (2026-03-16)
7
-
8
- ### 🔨 Code Refactoring
9
-
10
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
11
-
12
- ### 🔗 Dependencies update
13
-
14
- * bump the npm-dependencies group with 10 updates ([c48d9ba](https://github.com/Alwatr/nanolib/commit/c48d9baa1cd7c2dc144b3e01e0fda60bf87c074c))
15
-
16
- ## [5.5.28](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.27...@alwatr/env@5.5.28) (2026-02-18)
17
-
18
- ### 🔗 Dependencies update
19
-
20
- * update @types/node to version 24.10.13 across multiple packages ([4c6d2a3](https://github.com/Alwatr/nanolib/commit/4c6d2a37ab26b1c86812b2aa38b2eca4ee097cb6))
21
-
22
- ## [5.5.27](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.26...@alwatr/env@5.5.27) (2025-12-23)
23
-
24
- ### 🔗 Dependencies update
25
-
26
- * upgrade @types/node to version 24.10.4 and update related dependencies ([acf04df](https://github.com/Alwatr/nanolib/commit/acf04df71647f5a401ef5e6bbfffcc478e4326d2))
27
-
28
- ## [5.5.26](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.25...@alwatr/env@5.5.26) (2025-12-13)
29
-
30
- ### 🔗 Dependencies update
31
-
32
- * update `@types/node` and `[@lerna-lite](https://github.com/lerna-lite)` dependencies. ([8daa8fd](https://github.com/Alwatr/nanolib/commit/8daa8fd023d5414c9f95feb4319353c6ea34be31))
33
-
34
- ## [5.5.25](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.24...@alwatr/env@5.5.25) (2025-12-10)
35
-
36
- ### 🔗 Dependencies update
37
-
38
- * Upgrade lerna-lite, prettier, types/node, and yarn dependencies. ([42a7fca](https://github.com/Alwatr/nanolib/commit/42a7fca15430aca2ac1eaa19496c2a2ebfc8c470))
39
-
40
- ## [5.5.24](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.23...@alwatr/env@5.5.24) (2025-11-18)
41
-
42
- ### 🔨 Code Refactoring
43
-
44
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
45
-
46
- ## [5.5.23](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.22...@alwatr/env@5.5.23) (2025-11-15)
47
-
48
- ### 🔗 Dependencies update
49
-
50
- * bump the npm-dependencies group with 2 updates ([a80b84d](https://github.com/Alwatr/nanolib/commit/a80b84dada6c09b5e5621e7487c8ec13fff3c23a))
51
-
52
- ## [5.5.22](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.21...@alwatr/env@5.5.22) (2025-11-15)
53
-
54
- **Note:** Version bump only for package @alwatr/env
55
-
56
- ## [5.5.21](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.20...@alwatr/env@5.5.21) (2025-11-04)
57
-
58
- ### 🔗 Dependencies update
59
-
60
- * bump the npm-dependencies group across 1 directory with 9 updates ([fdf29d5](https://github.com/Alwatr/nanolib/commit/fdf29d5aa89983cb06f79d42650a364521f5c4b9))
61
- * update @types/node from ^22.18.12 to ^24.10.0 across multiple packages ([1169a86](https://github.com/Alwatr/nanolib/commit/1169a86001da2abfbe99a7da33c8e92183f553f6))
62
-
63
- ## [5.5.20](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.19...@alwatr/env@5.5.20) (2025-10-06)
64
-
65
- ### 🔗 Dependencies update
66
-
67
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
68
-
69
- ## [5.5.19](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.18...@alwatr/env@5.5.19) (2025-09-27)
70
-
71
- ### 🧹 Miscellaneous Chores
72
-
73
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
74
-
75
- ## [5.5.18](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.17...@alwatr/env@5.5.18) (2025-09-22)
76
-
77
- **Note:** Version bump only for package @alwatr/env
78
-
79
- ## [5.5.17](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.16...@alwatr/env@5.5.17) (2025-09-22)
80
-
81
- **Note:** Version bump only for package @alwatr/env
82
-
83
- ## [5.5.16](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.15...@alwatr/env@5.5.16) (2025-09-21)
84
-
85
- **Note:** Version bump only for package @alwatr/env
86
-
87
- ## [5.5.15](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.14...@alwatr/env@5.5.15) (2025-09-20)
88
-
89
- ### 🐛 Bug Fixes
90
-
91
- * add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
92
- * add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
93
-
94
- ### 🧹 Miscellaneous Chores
95
-
96
- * remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
97
-
98
- ## [5.5.14](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.13...@alwatr/env@5.5.14) (2025-09-19)
99
-
100
- **Note:** Version bump only for package @alwatr/env
101
-
102
- ## [5.5.13](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.12...@alwatr/env@5.5.13) (2025-09-15)
103
-
104
- **Note:** Version bump only for package @alwatr/env
105
-
106
- ## [5.5.12](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.11...@alwatr/env@5.5.12) (2025-09-13)
107
-
108
- ### 🔗 Dependencies update
109
-
110
- * update @types/node version to ^22.18.3 in multiple package.json files ([13db6fc](https://github.com/Alwatr/nanolib/commit/13db6fc176bc6cdcefedc50d77ac550bd5052c9a))
111
-
112
- ## [5.5.11](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.10...@alwatr/env@5.5.11) (2025-09-13)
113
-
114
- ### 🧹 Miscellaneous Chores
115
-
116
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
117
-
118
- ## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.9...@alwatr/env@5.5.10) (2025-09-09)
119
-
120
- ### 🧹 Miscellaneous Chores
121
-
122
- * remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
123
-
124
- ## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.8...@alwatr/env@5.5.9) (2025-09-06)
125
-
126
- **Note:** Version bump only for package @alwatr/env
127
-
128
- ## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.7...@alwatr/env@5.5.8) (2025-09-05)
129
-
130
- ### 🔗 Dependencies update
131
-
132
- * update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
133
-
134
- ## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.6...@alwatr/env@5.5.7) (2025-09-01)
135
-
136
- ### 🔗 Dependencies update
137
-
138
- * update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
139
-
140
- ## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.5...@alwatr/env@5.5.6) (2025-08-23)
141
-
142
- **Note:** Version bump only for package @alwatr/env
143
-
144
- ## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.3...@alwatr/env@5.5.5) (2025-08-23)
145
-
146
- ### 🐛 Bug Fixes
147
-
148
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
149
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
150
-
151
- ### 🔨 Code Refactoring
152
-
153
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
154
-
155
- ### 🧹 Miscellaneous Chores
156
-
157
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
158
-
159
- ### 🔗 Dependencies update
160
-
161
- * revert @types/node version to ^22.17.2 (LTS) ([49f8101](https://github.com/Alwatr/nanolib/commit/49f8101eac5c41aa7684112f4308254dbfab9787))
162
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
163
-
164
- ## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.3...@alwatr/env@5.5.4) (2025-08-23)
165
-
166
- ### Code Refactoring
167
-
168
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
169
-
170
- ## <small>5.5.3 (2025-04-15)</small>
171
-
172
- **Note:** Version bump only for package @alwatr/env
173
-
174
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.1...@alwatr/env@5.5.2) (2025-04-01)
175
-
176
- ### Dependencies update
177
-
178
- * bump the development-dependencies group across 1 directory with 2 updates ([c1320b4](https://github.com/Alwatr/nanolib/commit/c1320b447a492c5e720e25ad71e9df81eeea3670)) by @dependabot[bot]
179
-
180
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.5.0...@alwatr/env@5.5.1) (2025-03-18)
181
-
182
- ### Dependencies update
183
-
184
- * bump the development-dependencies group with 9 updates ([7290aa3](https://github.com/Alwatr/nanolib/commit/7290aa3b52ce66ca237d2a12d28a7687b113f83d)) by @dependabot[bot]
185
-
186
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/env@5.4.0...@alwatr/env@5.5.0) (2025-03-06)
187
-
188
- ### Miscellaneous Chores
189
-
190
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
191
-
192
- ### Dependencies update
193
-
194
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
195
-
196
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/env@1.0.1...@alwatr/env@5.4.0) (2025-02-18)
197
-
198
- ### Dependencies update
199
-
200
- * bump @types/node from ^22.13.0 to ^22.13.4 and prettier from 3.4.2 to 3.5.1; update eslint-import-resolver-typescript to 3.8.2 ([b9a8399](https://github.com/Alwatr/nanolib/commit/b9a8399add39509e90bfdc589fb5e2321718029d)) by @
201
-
202
- ## 5.3.0 (2025-02-03)
203
-
204
- ### Miscellaneous Chores
205
-
206
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
207
-
208
- ### Dependencies update
209
-
210
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
211
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
212
-
213
- ## 5.0.0 (2024-11-02)
214
-
215
- ### ⚠ BREAKING CHANGES
216
-
217
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
218
-
219
- ### Code Refactoring
220
-
221
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
222
-
223
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
224
-
225
- ### Miscellaneous Chores
226
-
227
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
228
-
229
- ### Dependencies update
230
-
231
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
232
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
233
-
234
- ## 5.0.0 (2024-11-02)
235
-
236
- ### ⚠ BREAKING CHANGES
237
-
238
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
239
-
240
- ### Bug Fixes
241
-
242
- * **env:** package.json path ([fff643d](https://github.com/Alwatr/nanolib/commit/fff643d949340e84509502e62b2587d03a47e034)) by @
243
-
244
- ### Code Refactoring
245
-
246
- * **env:** rename package and function ([6d72576](https://github.com/Alwatr/nanolib/commit/6d72576576964ba4bf3bdc5767e14d9293f941c9)) by @
247
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
248
-
249
- ### Dependencies update
250
-
251
- * bump the development-dependencies group across 1 directory with 2 updates ([2dfda9e](https://github.com/Alwatr/nanolib/commit/2dfda9ec38a595f1fd961490d1a2fbf060f20a66)) by @
252
- * update ([4434ba6](https://github.com/Alwatr/nanolib/commit/4434ba67c3f576bb1a0c307fbdb263c43cd9733a)) by @
253
-
254
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/env@1.0.0...@alwatr/env@1.0.1) (2024-11-02)
255
-
256
- ### Dependencies update
257
-
258
- * update ([4434ba6](https://github.com/Alwatr/nanolib/commit/4434ba67c3f576bb1a0c307fbdb263c43cd9733a)) by @alimd
259
-
260
- ## 1.0.0 (2024-10-25)
261
-
262
- ### Bug Fixes
263
-
264
- * **env:** package.json path ([fff643d](https://github.com/Alwatr/nanolib/commit/fff643d949340e84509502e62b2587d03a47e034)) by @alimd
265
-
266
- ### Code Refactoring
267
-
268
- * **env:** rename package and function ([6d72576](https://github.com/Alwatr/nanolib/commit/6d72576576964ba4bf3bdc5767e14d9293f941c9)) by @alimd
269
-
270
- ### Dependencies update
271
-
272
- * bump the development-dependencies group across 1 directory with 2 updates ([2dfda9e](https://github.com/Alwatr/nanolib/commit/2dfda9ec38a595f1fd961490d1a2fbf060f20a66)) by @dependabot[bot]
package/dist/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/env v5.5.29 */
2
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{getEnv:()=>getEnv});module.exports=__toCommonJS(main_exports);var import_platform_info=require("@alwatr/platform-info");function getEnv(option){let value=process.env[option.name];if(value==="")value=void 0;if(import_platform_info.platformInfo.development===true){value??=option.developmentValue??option.defaultValue}else{value??=option.defaultValue}if(value===void 0){throw new Error(`Environment variable "${option.name}" is required.`)}return value}0&&(module.exports={getEnv});
3
- //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {platformInfo} from '@alwatr/platform-info';\n\n/**\n * Parameters for retrieving an environment variable value.\n */\nexport type GetEnvOption = {\n /**\n * The name of the environment variable.\n */\n name: string;\n\n /**\n * The default value to use if the environment variable is not set.\n * If not provided, the environment variable is required and an error will be thrown if it is not set.\n * Except in development mode, where the development value will be used instead if provided.\n */\n defaultValue?: string;\n\n /**\n * The value to use in a development environment.\n * It will be overwrite the default value in development mode and completely ignored in production mode.\n */\n developmentValue?: string;\n};\n\nexport function getEnv(option: GetEnvOption): string {\n let value = process.env[option.name];\n if (value === '') value = undefined; // empty string is considered as undefined in environment variables\n\n if (platformInfo.development === true) {\n value ??= option.developmentValue ?? option.defaultValue;\n }\n else {\n value ??= option.defaultValue;\n }\n\n if (value === undefined) {\n throw new Error(`Environment variable \"${option.name}\" is required.`);\n }\n\n return value;\n}\n"],
5
- "mappings": ";qqBAAA,kIAA2B,iCAyBpB,SAAS,OAAO,OAA8B,CACnD,IAAI,MAAQ,QAAQ,IAAI,OAAO,IAAI,EACnC,GAAI,QAAU,GAAI,MAAQ,OAE1B,GAAI,kCAAa,cAAgB,KAAM,CACrC,QAAU,OAAO,kBAAoB,OAAO,YAC9C,KACK,CACH,QAAU,OAAO,YACnB,CAEA,GAAI,QAAU,OAAW,CACvB,MAAM,IAAI,MAAM,yBAAyB,OAAO,IAAI,gBAAgB,CACtE,CAEA,OAAO,KACT",
6
- "names": []
7
- }
package/dist/main.mjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/env v5.5.29 */
2
- import{platformInfo}from"@alwatr/platform-info";function getEnv(option){let value=process.env[option.name];if(value==="")value=void 0;if(platformInfo.development===true){value??=option.developmentValue??option.defaultValue}else{value??=option.defaultValue}if(value===void 0){throw new Error(`Environment variable "${option.name}" is required.`)}return value}export{getEnv};
3
- //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {platformInfo} from '@alwatr/platform-info';\n\n/**\n * Parameters for retrieving an environment variable value.\n */\nexport type GetEnvOption = {\n /**\n * The name of the environment variable.\n */\n name: string;\n\n /**\n * The default value to use if the environment variable is not set.\n * If not provided, the environment variable is required and an error will be thrown if it is not set.\n * Except in development mode, where the development value will be used instead if provided.\n */\n defaultValue?: string;\n\n /**\n * The value to use in a development environment.\n * It will be overwrite the default value in development mode and completely ignored in production mode.\n */\n developmentValue?: string;\n};\n\nexport function getEnv(option: GetEnvOption): string {\n let value = process.env[option.name];\n if (value === '') value = undefined; // empty string is considered as undefined in environment variables\n\n if (platformInfo.development === true) {\n value ??= option.developmentValue ?? option.defaultValue;\n }\n else {\n value ??= option.defaultValue;\n }\n\n if (value === undefined) {\n throw new Error(`Environment variable \"${option.name}\" is required.`);\n }\n\n return value;\n}\n"],
5
- "mappings": ";AAAA,OAAQ,iBAAmB,wBAyBpB,SAAS,OAAO,OAA8B,CACnD,IAAI,MAAQ,QAAQ,IAAI,OAAO,IAAI,EACnC,GAAI,QAAU,GAAI,MAAQ,OAE1B,GAAI,aAAa,cAAgB,KAAM,CACrC,QAAU,OAAO,kBAAoB,OAAO,YAC9C,KACK,CACH,QAAU,OAAO,YACnB,CAEA,GAAI,QAAU,OAAW,CACvB,MAAM,IAAI,MAAM,yBAAyB,OAAO,IAAI,gBAAgB,CACtE,CAEA,OAAO,KACT",
6
- "names": []
7
- }