loony-dotenv 0.1.1 → 0.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/lib/index.cjs ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_fs = __toESM(require("fs"), 1);
37
+ var import_path = __toESM(require("path"), 1);
38
+ function parseEnvLine(line) {
39
+ const trimmed = line.trim();
40
+ if (!trimmed || trimmed.startsWith("#")) return null;
41
+ let separatorIndex = -1;
42
+ for (let i = 0; i < trimmed.length; i++) {
43
+ if (trimmed[i] === "=" && trimmed[i - 1] !== "\\") {
44
+ separatorIndex = i;
45
+ break;
46
+ }
47
+ }
48
+ if (separatorIndex === -1) {
49
+ console.warn(`[loony-dotenv] Skipping malformed line: ${trimmed}`);
50
+ return null;
51
+ }
52
+ const key = trimmed.slice(0, separatorIndex).trim();
53
+ let value = trimmed.slice(separatorIndex + 1).trim();
54
+ const commentIndex = value.indexOf(" #");
55
+ if (commentIndex !== -1) {
56
+ value = value.slice(0, commentIndex).trim();
57
+ }
58
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
59
+ value = value.slice(1, -1);
60
+ }
61
+ value = value.replace(/\\=/g, "=");
62
+ return { key, value };
63
+ }
64
+ function loadEnv(envPath = ".env") {
65
+ const absolutePath = import_path.default.resolve(envPath);
66
+ if (!import_fs.default.existsSync(absolutePath)) {
67
+ console.error(`[loony-dotenv] .env file not found at: ${absolutePath}`);
68
+ return;
69
+ }
70
+ const fileContents = import_fs.default.readFileSync(absolutePath, "utf8");
71
+ const lines = fileContents.split(/\r?\n/);
72
+ for (const line of lines) {
73
+ const parsed = parseEnvLine(line);
74
+ if (!parsed) continue;
75
+ const { key, value } = parsed;
76
+ if (!(key in process.env)) {
77
+ process.env[key] = value;
78
+ }
79
+ }
80
+ }
81
+ var index_default = loadEnv;
82
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\n/**\n * Safely parse a single line of KEY=VALUE format.\n * Supports quoted values and inline comments.\n * @param {string} line\n * @returns {{ key: string, value: string } | null}\n */\nfunction parseEnvLine(line: any) {\n const trimmed = line.trim();\n\n // Skip blank lines and comment lines\n if (!trimmed || trimmed.startsWith(\"#\")) return null;\n\n // Find first '=' that isn't escaped\n let separatorIndex = -1;\n for (let i = 0; i < trimmed.length; i++) {\n if (trimmed[i] === \"=\" && trimmed[i - 1] !== \"\\\\\") {\n separatorIndex = i;\n break;\n }\n }\n\n if (separatorIndex === -1) {\n console.warn(`[loony-dotenv] Skipping malformed line: ${trimmed}`);\n return null;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n let value = trimmed.slice(separatorIndex + 1).trim();\n\n // Remove inline comments: KEY=value # comment\n const commentIndex = value.indexOf(\" #\");\n if (commentIndex !== -1) {\n value = value.slice(0, commentIndex).trim();\n }\n\n // Remove surrounding quotes\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n\n // Unescape escaped '=' (i.e., KEY=va\\=lue)\n value = value.replace(/\\\\=/g, \"=\");\n\n return { key, value };\n}\n\n/**\n * Loads variables from a .env file into process.env.\n * @param {string} envPath - Path to .env file (default: \".env\")\n */\nfunction loadEnv(envPath = \".env\") {\n const absolutePath = path.resolve(envPath);\n\n if (!fs.existsSync(absolutePath)) {\n console.error(`[loony-dotenv] .env file not found at: ${absolutePath}`);\n return;\n }\n\n const fileContents = fs.readFileSync(absolutePath, \"utf8\");\n const lines = fileContents.split(/\\r?\\n/);\n\n for (const line of lines) {\n const parsed = parseEnvLine(line);\n if (!parsed) continue;\n\n const { key, value } = parsed;\n\n // Do not override existing environment variables\n if (!(key in process.env)) {\n process.env[key] = value;\n }\n }\n}\n\nexport default loadEnv;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAQjB,SAAS,aAAa,MAAW;AAC/B,QAAM,UAAU,KAAK,KAAK;AAG1B,MAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,EAAG,QAAO;AAGhD,MAAI,iBAAiB;AACrB,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,QAAI,QAAQ,CAAC,MAAM,OAAO,QAAQ,IAAI,CAAC,MAAM,MA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are function loadEnv(envPath?: string): void;
6
+
7
+ export { loadEnv as default };
package/lib/index.d.ts CHANGED
@@ -3,4 +3,5 @@
3
3
  * @param {string} envPath - Path to .env file (default: ".env")
4
4
  */
5
5
  declare function loadEnv(envPath?: string): void;
6
- export default loadEnv;
6
+
7
+ export { loadEnv as default };
package/lib/index.js CHANGED
@@ -1,70 +1,51 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const path_1 = __importDefault(require("path"));
8
- /**
9
- * Safely parse a single line of KEY=VALUE format.
10
- * Supports quoted values and inline comments.
11
- * @param {string} line
12
- * @returns {{ key: string, value: string } | null}
13
- */
1
+ // index.ts
2
+ import fs from "fs";
3
+ import path from "path";
14
4
  function parseEnvLine(line) {
15
- const trimmed = line.trim();
16
- // Skip blank lines and comment lines
17
- if (!trimmed || trimmed.startsWith("#"))
18
- return null;
19
- // Find first '=' that isn't escaped
20
- let separatorIndex = -1;
21
- for (let i = 0; i < trimmed.length; i++) {
22
- if (trimmed[i] === "=" && trimmed[i - 1] !== "\\") {
23
- separatorIndex = i;
24
- break;
25
- }
26
- }
27
- if (separatorIndex === -1) {
28
- console.warn(`[loony-dotenv] Skipping malformed line: ${trimmed}`);
29
- return null;
30
- }
31
- const key = trimmed.slice(0, separatorIndex).trim();
32
- let value = trimmed.slice(separatorIndex + 1).trim();
33
- // Remove inline comments: KEY=value # comment
34
- const commentIndex = value.indexOf(" #");
35
- if (commentIndex !== -1) {
36
- value = value.slice(0, commentIndex).trim();
5
+ const trimmed = line.trim();
6
+ if (!trimmed || trimmed.startsWith("#")) return null;
7
+ let separatorIndex = -1;
8
+ for (let i = 0; i < trimmed.length; i++) {
9
+ if (trimmed[i] === "=" && trimmed[i - 1] !== "\\") {
10
+ separatorIndex = i;
11
+ break;
37
12
  }
38
- // Remove surrounding quotes
39
- if ((value.startsWith('"') && value.endsWith('"')) ||
40
- (value.startsWith("'") && value.endsWith("'"))) {
41
- value = value.slice(1, -1);
42
- }
43
- // Unescape escaped '=' (i.e., KEY=va\=lue)
44
- value = value.replace(/\\=/g, "=");
45
- return { key, value };
13
+ }
14
+ if (separatorIndex === -1) {
15
+ console.warn(`[loony-dotenv] Skipping malformed line: ${trimmed}`);
16
+ return null;
17
+ }
18
+ const key = trimmed.slice(0, separatorIndex).trim();
19
+ let value = trimmed.slice(separatorIndex + 1).trim();
20
+ const commentIndex = value.indexOf(" #");
21
+ if (commentIndex !== -1) {
22
+ value = value.slice(0, commentIndex).trim();
23
+ }
24
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
25
+ value = value.slice(1, -1);
26
+ }
27
+ value = value.replace(/\\=/g, "=");
28
+ return { key, value };
46
29
  }
47
- /**
48
- * Loads variables from a .env file into process.env.
49
- * @param {string} envPath - Path to .env file (default: ".env")
50
- */
51
30
  function loadEnv(envPath = ".env") {
52
- const absolutePath = path_1.default.resolve(envPath);
53
- if (!fs_1.default.existsSync(absolutePath)) {
54
- console.error(`[loony-dotenv] .env file not found at: ${absolutePath}`);
55
- return;
56
- }
57
- const fileContents = fs_1.default.readFileSync(absolutePath, "utf8");
58
- const lines = fileContents.split(/\r?\n/);
59
- for (const line of lines) {
60
- const parsed = parseEnvLine(line);
61
- if (!parsed)
62
- continue;
63
- const { key, value } = parsed;
64
- // Do not override existing environment variables
65
- if (!(key in process.env)) {
66
- process.env[key] = value;
67
- }
31
+ const absolutePath = path.resolve(envPath);
32
+ if (!fs.existsSync(absolutePath)) {
33
+ console.error(`[loony-dotenv] .env file not found at: ${absolutePath}`);
34
+ return;
35
+ }
36
+ const fileContents = fs.readFileSync(absolutePath, "utf8");
37
+ const lines = fileContents.split(/\r?\n/);
38
+ for (const line of lines) {
39
+ const parsed = parseEnvLine(line);
40
+ if (!parsed) continue;
41
+ const { key, value } = parsed;
42
+ if (!(key in process.env)) {
43
+ process.env[key] = value;
68
44
  }
45
+ }
69
46
  }
70
- exports.default = loadEnv;
47
+ var index_default = loadEnv;
48
+ export {
49
+ index_default as default
50
+ };
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\n/**\n * Safely parse a single line of KEY=VALUE format.\n * Supports quoted values and inline comments.\n * @param {string} line\n * @returns {{ key: string, value: string } | null}\n */\nfunction parseEnvLine(line: any) {\n const trimmed = line.trim();\n\n // Skip blank lines and comment lines\n if (!trimmed || trimmed.startsWith(\"#\")) return null;\n\n // Find first '=' that isn't escaped\n let separatorIndex = -1;\n for (let i = 0; i < trimmed.length; i++) {\n if (trimmed[i] === \"=\" && trimmed[i - 1] !== \"\\\\\") {\n separatorIndex = i;\n break;\n }\n }\n\n if (separatorIndex === -1) {\n console.warn(`[loony-dotenv] Skipping malformed line: ${trimmed}`);\n return null;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n let value = trimmed.slice(separatorIndex + 1).trim();\n\n // Remove inline comments: KEY=value # comment\n const commentIndex = value.indexOf(\" #\");\n if (commentIndex !== -1) {\n value = value.slice(0, commentIndex).trim();\n }\n\n // Remove surrounding quotes\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n\n // Unescape escaped '=' (i.e., KEY=va\\=lue)\n value = value.replace(/\\\\=/g, \"=\");\n\n return { key, value };\n}\n\n/**\n * Loads variables from a .env file into process.env.\n * @param {string} envPath - Path to .env file (default: \".env\")\n */\nfunction loadEnv(envPath = \".env\") {\n const absolutePath = path.resolve(envPath);\n\n if (!fs.existsSync(absolutePath)) {\n console.error(`[loony-dotenv] .env file not found at: ${absolutePath}`);\n return;\n }\n\n const fileContents = fs.readFileSync(absolutePath, \"utf8\");\n const lines = fileContents.split(/\\r?\\n/);\n\n for (const line of lines) {\n const parsed = parseEnvLine(line);\n if (!parsed) continue;\n\n const { key, value } = parsed;\n\n // Do not override existing environment variables\n if (!(key in process.env)) {\n process.env[key] = value;\n }\n }\n}\n\nexport default loadEnv;\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAQjB,SAAS,aAAa,MAAW;AAC/B,QAAM,UAAU,KAAK,KAAK;AAG1B,MAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,EAAG,QAAO;AAGhD,MAAI,iBAAiB;AACrB,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,QAAI,QAAQ,CAAC,MAAM,OAAO,QAAQ,IAAI,CAAC,MAAM,MAAM;AACjD,uBAAiB;AACjB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,mBAAmB,IAAI;AACzB,YAAQ,KAAK,2CAA2C,OAAO,EAAE;AACjE,WAAO;AAAA,EACT;AAEA,QAAM,MAAM,QAAQ,MAAM,GAAG,cAAc,EAAE,KAAK;AAClD,MAAI,QAAQ,QAAQ,MAAM,iBAAiB,CAAC,EAAE,KAAK;AAGnD,QAAM,eAAe,MAAM,QAAQ,IAAI;AACvC,MAAI,iBAAiB,IAAI;AACvB,YAAQ,MAAM,MAAM,GAAG,YAAY,EAAE,KAAK;AAAA,EAC5C;AAGA,MACG,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,KAC3C,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAC5C;AACA,YAAQ,MAAM,MAAM,GAAG,EAAE;AAAA,EAC3B;AAGA,UAAQ,MAAM,QAAQ,QAAQ,GAAG;AAEjC,SAAO,EAAE,KAAK,MAAM;AACtB;AAMA,SAAS,QAAQ,UAAU,QAAQ;AACjC,QAAM,eAAe,KAAK,QAAQ,OAAO;AAEzC,MAAI,CAAC,GAAG,WAAW,YAAY,GAAG;AAChC,YAAQ,MAAM,0CAA0C,YAAY,EAAE;AACtE;AAAA,EACF;AAEA,QAAM,eAAe,GAAG,aAAa,cAAc,MAAM;AACzD,QAAM,QAAQ,aAAa,MAAM,OAAO;AAExC,aAAW,QAAQ,OAAO;AACxB,UAAM,SAAS,aAAa,IAAI;AAChC,QAAI,CAAC,OAAQ;AAEb,UAAM,EAAE,KAAK,MAAM,IAAI;AAGvB,QAAI,EAAE,OAAO,QAAQ,MAAM;AACzB,cAAQ,IAAI,GAAG,IAAI;AAAA,IACrB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "loony-dotenv",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Simple environment loader that reads .env files and automatically populates process.env for Node.js applications.",
5
5
  "type": "module",
6
6
  "private": false,
7
- "main": "./lib/index.js",
7
+ "main": "./lib/index.cjs",
8
+ "module": "./lib/index.js",
8
9
  "types": "./lib/index.d.ts",
9
10
  "exports": {
10
11
  ".": {
11
12
  "types": "./lib/index.d.ts",
12
- "import": "./lib/index.js"
13
+ "import": "./lib/index.js",
14
+ "require": "./lib/index.cjs"
13
15
  }
14
16
  },
15
17
  "files": [
@@ -28,14 +30,14 @@
28
30
  "url": "https://github.com/loony-js/loony-dotenv.git"
29
31
  },
30
32
  "scripts": {
31
- "build": "npm run clean && tsc",
32
- "clean": "rm -rf lib",
33
- "dev": "ts-node index.ts",
34
- "prepublishOnly": "npm run clean && npm run build"
33
+ "clean": "rm -rf lib dist",
34
+ "build": "npm run clean && tsup ./index.ts --format cjs,esm --dts --out-dir lib",
35
+ "prepublishOnly": "npm run build"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "^25.0.3",
38
39
  "ts-node": "^10.9.2",
40
+ "tsup": "^8.5.1",
39
41
  "typescript": "^5.9.3"
40
42
  },
41
43
  "engines": {