baher-dotenv 1.1.2

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/LICENSE ADDED
@@ -0,0 +1,35 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Baher Hamed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ # رخصة MIT
26
+
27
+ حقوق النشر © 2026 Baher Hamed
28
+
29
+ يُمنح الإذن، مجانًا، لأي شخص يحصل على نسخة من هذا البرنامج والملفات التوثيقية المرتبطة به، بالتعامل مع البرنامج دون قيود، بما في ذلك على سبيل المثال لا الحصر حقوق الاستخدام، والنسخ، والتعديل، والدمج، والنشر، والتوزيع، والترخيص من الباطن، و/أو بيع نسخ من البرنامج، والسماح للأشخاص الذين يتم تزويدهم بالبرنامج بالقيام بذلك، وذلك وفقًا للشروط التالية:
30
+
31
+ يجب تضمين إشعار حقوق النشر أعلاه وإشعار الإذن هذا في جميع النسخ أو الأجزاء الجوهرية من البرنامج.
32
+
33
+ يتم توفير البرنامج “كما هو” دون أي ضمان من أي نوع، صريحًا كان أو ضمنيًا، بما في ذلك على سبيل المثال لا الحصر ضمانات القابلية للتسويق، والملاءمة لغرض معين، وعدم الانتهاك. ولا يتحمل المؤلفون أو أصحاب حقوق النشر في أي حال من الأحوال المسؤولية عن أي مطالبة أو أضرار أو أي مسؤولية أخرى، سواء في دعوى تعاقدية أو تقصيرية أو غير ذلك، تنشأ عن البرنامج أو ترتبط به أو باستخدامه أو أي تعاملات أخرى فيه.
34
+
35
+ > هذه ترجمة عربية غير رسمية لرخصة MIT. النسخة الإنجليزية أعلاه هي النسخة الأساسية المعتمدة.
package/README.md ADDED
@@ -0,0 +1,368 @@
1
+ <div align="center">
2
+
3
+ <img src="./docs/images/logo.png" width="420" alt="Baher Hamed Enterprise Software Engineering Logo"/>
4
+
5
+ # baher-dotenv
6
+
7
+ Type-safe environment configuration loader for Node.js.
8
+
9
+ <p dir="rtl" align="center">
10
+ مكتبة لإدارة وتحميل متغيرات البيئة في تطبيقات Node.js بطريقة آمنة باستخدام TypeScript
11
+ </p>
12
+
13
+ ![Node.js](https://img.shields.io/badge/Node.js-20%2B-green)
14
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)
15
+ ![NX](https://img.shields.io/badge/NX-Monorepo-purple)
16
+ ![Backend](https://img.shields.io/badge/Backend-Node.js-success)
17
+ ![Package](https://img.shields.io/badge/Package-Public-success)
18
+ ![License](https://img.shields.io/badge/License-MIT-lightgrey)
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ ## 🇺🇸 English
25
+
26
+ ## Overview
27
+
28
+ `baher-dotenv` is a TypeScript library for Node.js backend applications.
29
+
30
+ It allows you to define environment variables using a typed configuration object, then load these values into `process.env`.
31
+
32
+ The main goal is to make environment configuration more structured, centralized, and type-safe.
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ npm install baher-dotenv
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ ```ts
47
+ import { baherEnvConfig, baherLoadEnv, ENV_TYPE } from 'baher-dotenv';
48
+
49
+ const envConfig = baherEnvConfig({
50
+ APP_NAME: {
51
+ type: ENV_TYPE.String,
52
+ value: 'orders-api',
53
+ },
54
+
55
+ APP_PORT: {
56
+ type: ENV_TYPE.Number,
57
+ value: 3000,
58
+ },
59
+
60
+ ENABLE_ELK: {
61
+ type: ENV_TYPE.Boolean,
62
+ value: true,
63
+ },
64
+ });
65
+
66
+ baherLoadEnv(envConfig);
67
+ ```
68
+
69
+ After calling `baherLoadEnv`, the values will be available inside `process.env`:
70
+
71
+ ```ts
72
+ process.env.APP_NAME; // "orders-api"
73
+ process.env.APP_PORT; // "3000"
74
+ process.env.ENABLE_ELK; // "true"
75
+ ```
76
+
77
+ ---
78
+
79
+ ## API
80
+
81
+ ### `ENV_TYPE`
82
+
83
+ A constant object used to define the type of each environment variable.
84
+
85
+ ```ts
86
+ ENV_TYPE.String
87
+ ENV_TYPE.Number
88
+ ENV_TYPE.Boolean
89
+ ```
90
+
91
+ ---
92
+
93
+ ### `baherEnvConfig(config)`
94
+
95
+ Defines a typed environment configuration.
96
+
97
+ ```ts
98
+ const envConfig = baherEnvConfig({
99
+ APP_PORT: {
100
+ type: ENV_TYPE.Number,
101
+ value: 3000,
102
+ },
103
+ });
104
+ ```
105
+
106
+ If the value does not match the selected type, TypeScript will show an error.
107
+
108
+ Example:
109
+
110
+ ```ts
111
+ const envConfig = baherEnvConfig({
112
+ APP_PORT: {
113
+ type: ENV_TYPE.Number,
114
+ value: '3000', // TypeScript error
115
+ },
116
+ });
117
+ ```
118
+
119
+ ---
120
+
121
+ ### `baherLoadEnv(config, options?)`
122
+
123
+ Loads the provided configuration into `process.env`.
124
+
125
+ ```ts
126
+ baherLoadEnv(envConfig);
127
+ ```
128
+
129
+ By default, existing values inside `process.env` are not overwritten.
130
+
131
+ To allow overriding existing values:
132
+
133
+ ```ts
134
+ baherLoadEnv(envConfig, {
135
+ override: true,
136
+ });
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Supported Types
142
+
143
+ Currently supported types:
144
+
145
+ ```ts
146
+ string
147
+ number
148
+ boolean
149
+ ```
150
+
151
+ All values are converted to strings before being added to `process.env`, because Node.js environment variables are string-based.
152
+
153
+ ---
154
+
155
+ ## Build
156
+
157
+ ```bash
158
+ npx nx build baher-dotenv
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Release
164
+
165
+ From the workspace root:
166
+
167
+ ```bash
168
+ npm run release
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Project Structure
174
+
175
+ ```text
176
+ dotenv/
177
+ src/
178
+ index.ts
179
+ lib/
180
+ core/
181
+ constants/
182
+ functions/
183
+ types/
184
+ README.md
185
+ package.json
186
+ ```
187
+
188
+ ---
189
+
190
+ ## License
191
+
192
+ MIT License.
193
+
194
+ See [LICENSE](../../LICENSE).
195
+
196
+ ---
197
+
198
+ ## 🇪🇬 العربية
199
+
200
+ ## نظرة عامة
201
+
202
+ `baher-dotenv` هي مكتبة موجهة لتطبيقات Node.js.
203
+
204
+ تساعدك المكتبة على تعريف متغيرات البيئة باستخدام TypeScript بشكل منظم وآمن من ناحية الأنواع، ثم تحميل هذه القيم داخل `process.env`.
205
+
206
+ الهدف الأساسي من المكتبة هو جعل إعدادات البيئة أكثر تنظيمًا ومركزية وتقليل الأخطاء الناتجة عن التعامل مع القيم كنصوص غير واضحة.
207
+
208
+ ---
209
+
210
+ ## التثبيت
211
+
212
+ ```bash
213
+ npm install baher-dotenv
214
+ ```
215
+
216
+ ---
217
+
218
+ ## طريقة الاستخدام
219
+
220
+ ```ts
221
+ import { baherEnvConfig, baherLoadEnv, ENV_TYPE } from 'baher-dotenv';
222
+
223
+ const envConfig = baherEnvConfig({
224
+ APP_NAME: {
225
+ type: ENV_TYPE.String,
226
+ value: 'orders-api',
227
+ },
228
+
229
+ APP_PORT: {
230
+ type: ENV_TYPE.Number,
231
+ value: 3000,
232
+ },
233
+
234
+ ENABLE_ELK: {
235
+ type: ENV_TYPE.Boolean,
236
+ value: true,
237
+ },
238
+ });
239
+
240
+ baherLoadEnv(envConfig);
241
+ ```
242
+
243
+ بعد تنفيذ `baherLoadEnv` سيتم إضافة القيم داخل `process.env`:
244
+
245
+ ```ts
246
+ process.env.APP_NAME; // "orders-api"
247
+ process.env.APP_PORT; // "3000"
248
+ process.env.ENABLE_ELK; // "true"
249
+ ```
250
+
251
+ ---
252
+
253
+ ## الواجهة البرمجية
254
+
255
+ ### `ENV_TYPE`
256
+
257
+ ثابت يستخدم لتحديد نوع كل متغير بيئة.
258
+
259
+ ```ts
260
+ ENV_TYPE.String
261
+ ENV_TYPE.Number
262
+ ENV_TYPE.Boolean
263
+ ```
264
+
265
+ ---
266
+
267
+ ### `baherEnvConfig(config)`
268
+
269
+ تستخدم لتعريف إعدادات البيئة بطريقة typed.
270
+
271
+ ```ts
272
+ const envConfig = baherEnvConfig({
273
+ APP_PORT: {
274
+ type: ENV_TYPE.Number,
275
+ value: 3000,
276
+ },
277
+ });
278
+ ```
279
+
280
+ إذا كانت قيمة `value` لا تطابق النوع المحدد في `type`، سيظهر خطأ من TypeScript.
281
+
282
+ مثال غير صحيح:
283
+
284
+ ```ts
285
+ const envConfig = baherEnvConfig({
286
+ APP_PORT: {
287
+ type: ENV_TYPE.Number,
288
+ value: '3000', // TypeScript error
289
+ },
290
+ });
291
+ ```
292
+
293
+ ---
294
+
295
+ ### `baherLoadEnv(config, options?)`
296
+
297
+ تستخدم لتحميل القيم داخل `process.env`.
298
+
299
+ ```ts
300
+ baherLoadEnv(envConfig);
301
+ ```
302
+
303
+ بشكل افتراضي، إذا كانت القيمة موجودة مسبقًا داخل `process.env` فلن يتم استبدالها.
304
+
305
+ للسماح باستبدال القيم الموجودة:
306
+
307
+ ```ts
308
+ baherLoadEnv(envConfig, {
309
+ override: true,
310
+ });
311
+ ```
312
+
313
+ ---
314
+
315
+ ## الأنواع المدعومة
316
+
317
+ الأنواع المدعومة حاليًا:
318
+
319
+ ```ts
320
+ string
321
+ number
322
+ boolean
323
+ ```
324
+
325
+ يتم تحويل كل القيم إلى `string` قبل إضافتها إلى `process.env`، لأن متغيرات البيئة في Node.js تعتمد على النصوص.
326
+
327
+ ---
328
+
329
+ ## بناء المكتبة
330
+
331
+ ```bash
332
+ npx nx build baher-dotenv
333
+ ```
334
+
335
+ ---
336
+
337
+ ## إصدار المكتبة
338
+
339
+ من جذر المشروع:
340
+
341
+ ```bash
342
+ npm run release
343
+ ```
344
+
345
+ ---
346
+
347
+ ## هيكل المشروع
348
+
349
+ ```text
350
+ dotenv/
351
+ src/
352
+ index.ts
353
+ lib/
354
+ core/
355
+ constants/
356
+ functions/
357
+ types/
358
+ README.md
359
+ package.json
360
+ ```
361
+
362
+ ---
363
+
364
+ ## الترخيص
365
+
366
+ رخصة MIT.
367
+
368
+ راجع ملف [LICENSE](../../LICENSE).
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../dotenv/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/index.js';
@@ -0,0 +1,6 @@
1
+ export declare const ENV_TYPE: {
2
+ readonly String: "string";
3
+ readonly Number: "number";
4
+ readonly Boolean: "boolean";
5
+ };
6
+ //# sourceMappingURL=constant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/constants/constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;CAIX,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const ENV_TYPE = {
2
+ String: 'string',
3
+ Number: 'number',
4
+ Boolean: 'boolean',
5
+ };
@@ -0,0 +1,2 @@
1
+ export * from './constant.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './constant.js';
@@ -0,0 +1,3 @@
1
+ import type { EnvConfig } from '../types/index.js';
2
+ export declare function baherEnvConfig<const T extends EnvConfig>(config: T): T;
3
+ //# sourceMappingURL=baher-env-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baher-env-config.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/functions/baher-env-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAEtE"}
@@ -0,0 +1,3 @@
1
+ export function baherEnvConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,6 @@
1
+ import type { EnvConfig } from '../types/index.js';
2
+ export interface LoadEnvOptions {
3
+ override?: boolean;
4
+ }
5
+ export declare function baherLoadEnv(config: EnvConfig, options?: LoadEnvOptions): void;
6
+ //# sourceMappingURL=baher-load-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baher-load-env.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/functions/baher-load-env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,YAAY,CACxB,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,cAAmB,GAC7B,IAAI,CAUN"}
@@ -0,0 +1,9 @@
1
+ export function baherLoadEnv(config, options = {}) {
2
+ const { override = false } = options;
3
+ for (const [key, variable] of Object.entries(config)) {
4
+ if (!override && process.env[key] !== undefined) {
5
+ continue;
6
+ }
7
+ process.env[key] = String(variable.value);
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ export * from './baher-env-config.js';
2
+ export * from './baher-load-env.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './baher-env-config.js';
2
+ export * from './baher-load-env.js';
@@ -0,0 +1,4 @@
1
+ export * from './constants/index.js';
2
+ export * from './types/index.js';
3
+ export * from './functions/index.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../dotenv/src/lib/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './constants/index.js';
2
+ export * from './types/index.js';
3
+ export * from './functions/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './types.js';
@@ -0,0 +1,14 @@
1
+ import { ENV_TYPE } from "../constants/index.js";
2
+ export type EnvType = typeof ENV_TYPE[keyof typeof ENV_TYPE];
3
+ export type EnvVariable = {
4
+ type: typeof ENV_TYPE.String;
5
+ value: string;
6
+ } | {
7
+ type: typeof ENV_TYPE.Number;
8
+ value: number;
9
+ } | {
10
+ type: typeof ENV_TYPE.Boolean;
11
+ value: boolean;
12
+ };
13
+ export type EnvConfig = Record<string, EnvVariable>;
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../dotenv/src/lib/core/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE7D,MAAM,MAAM,WAAW,GACnB;IACA,IAAI,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,GACC;IACA,IAAI,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,GACC;IACA,IAAI,EAAE,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC9B,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEJ,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function dotenv(): string;
2
+ //# sourceMappingURL=dotenv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotenv.d.ts","sourceRoot":"","sources":["../../../dotenv/src/lib/dotenv.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,IAAI,MAAM,CAE/B"}
package/lib/dotenv.js ADDED
@@ -0,0 +1,3 @@
1
+ export function dotenv() {
2
+ return 'dotenv';
3
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './core/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../dotenv/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './core/index.js';
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "baher-dotenv",
3
+ "version": "1.1.2",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./index.d.ts",
13
+ "import": "./index.js",
14
+ "default": "./index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "**/*.js",
19
+ "**/*.d.ts",
20
+ "**/*.d.ts.map",
21
+ "README.md",
22
+ "LICENSE",
23
+ "docs"
24
+ ],
25
+ "dependencies": {
26
+ "tslib": "^2.3.0"
27
+ },
28
+ "description": "A lightweight TypeScript library for type-safe Node.js environment configuration.",
29
+ "author": "Baher Hamed",
30
+ "keywords": [
31
+ "dotenv",
32
+ "env",
33
+ "environment",
34
+ "environment-variables",
35
+ "nodejs",
36
+ "typescript",
37
+ "type-safe",
38
+ "configuration",
39
+ "config",
40
+ "process-env"
41
+ ],
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/baherhamed/baher-dotenv.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/baherhamed/baher-dotenv/issues"
48
+ },
49
+ "homepage": "https://github.com/baherhamed/baher-dotenv#readme"
50
+ }