harmony.env 0.0.1

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,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve.
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser: [e.g. Chrome, Safari]
29
+ - Browser Version: [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1, Android 16]
34
+ - Browser: [e.g. stock browser, safari]
35
+ - Browser Version: [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project.
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Example: I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,5 @@
1
+ # Description
2
+ A description of the pull request.
3
+
4
+ # Related issues
5
+ Any related issues, delete if there are none.
@@ -0,0 +1,24 @@
1
+ name: NPM Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ name: publish
10
+ runs-on: codeberg-tiny
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: install node v22
14
+ uses: actions/setup-node@v1
15
+ with:
16
+ node-version: 22
17
+ - name: npm i
18
+ run: npm i
19
+ - name: npm run tsc
20
+ run: npm run tsc
21
+ - name: auth
22
+ run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_CI_TOKEN }}
23
+ - name: publish
24
+ run: npm publish --access public
@@ -0,0 +1,20 @@
1
+ name: TSC check CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ tsc:
9
+ name: tsc
10
+ runs-on: codeberg-tiny
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: install node v22
14
+ uses: actions/setup-node@v1
15
+ with:
16
+ node-version: 22
17
+ - name: npm i
18
+ run: npm i
19
+ - name: npm run tsc
20
+ run: npm run tsc --noEmit
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Harmony.env
2
+ This is an AI free reader of `.env` files, meant to be used within Harmony, though other projects may use it, and add/request features that we've missed.
@@ -0,0 +1,2 @@
1
+ export declare function loadEnv(): void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,wBAAgB,OAAO,SAMtB"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ function parseEnv(env) {
4
+ const obj = {};
5
+ for (let [, name, value] of env.matchAll(/^[ \t]*(?:export)?[ \t]*([a-zA-Z_]+[a-zA-Z0-9_]*)[ \t]*=[ \t]*((?:.*)|)[ \t]*$/gm)) {
6
+ if (!name || !value)
7
+ continue;
8
+ value = value.trim();
9
+ if (value.startsWith("'") && value.endsWith("'")) {
10
+ value = value.match(/^'(.*)'$/)[1];
11
+ obj[name] = value.trim();
12
+ }
13
+ else if (value.startsWith('"') && value.endsWith('"')) {
14
+ try {
15
+ const str = JSON.parse(value);
16
+ if (typeof str === "string") {
17
+ value = str.trim();
18
+ }
19
+ }
20
+ catch { }
21
+ }
22
+ value = value.replaceAll(/\${([a-zA-Z_]+[a-zA-Z0-9_]*)}/gm, (_, str) => {
23
+ return obj[str] ?? process.env[str] ?? "undefined";
24
+ });
25
+ obj[name] = value;
26
+ //console.log(name, value);
27
+ }
28
+ return obj;
29
+ }
30
+ export function loadEnv() {
31
+ try {
32
+ const env = fs.readFileSync(path.join(process.cwd(), ".env"), "utf8");
33
+ const obj = parseEnv(env);
34
+ Object.assign(process.env, obj);
35
+ }
36
+ catch { }
37
+ }
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,SAAS,QAAQ,CAAC,GAAW;IAC5B,MAAM,GAAG,GAAG,EAA4B,CAAC;IACzC,KAAK,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CACvC,kFAAkF,CAClF,EAAE,CAAC;QACH,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK;YAAE,SAAS;QAC9B,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAE,CAAC,CAAC,CAAW,CAAC;YAC9C,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,CAAC;aAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC;gBACJ,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC9B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAC7B,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;gBACpB,CAAC;YACF,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACX,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE,GAAW,EAAE,EAAE;YAC9E,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC;QACpD,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAClB,2BAA2B;IAC5B,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AACD,MAAM,UAAU,OAAO;IACtB,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QACtE,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACX,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "harmony.env",
3
+ "version": "0.0.1",
4
+ "description": "An env loader",
5
+ "keywords": [
6
+ ".env"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "ssh://git@codeberg.org/MelodyChat/harmony-env.git"
11
+ },
12
+ "license": "AGPL-3.0",
13
+ "author": "Mathium05",
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "scripts": {
17
+ "tsc": "tsc"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^25.6.0",
21
+ "prettier": "^3.8.3",
22
+ "typescript": "^6.0.3"
23
+ },
24
+ "prettier": {
25
+ "useTabs": true,
26
+ "printWidth": 100,
27
+ "semi": true,
28
+ "bracketSpacing": false
29
+ },
30
+ "allowScripts": {
31
+ "@yukikaze-bot/erlpack@1.0.1": true
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ function parseEnv(env: string) {
5
+ const obj = {} as Record<string, string>;
6
+ for (let [, name, value] of env.matchAll(
7
+ /^[ \t]*(?:export)?[ \t]*([a-zA-Z_]+[a-zA-Z0-9_]*)[ \t]*=[ \t]*((?:.*)|)[ \t]*$/gm,
8
+ )) {
9
+ if (!name || !value) continue;
10
+ value = value.trim();
11
+ if (value.startsWith("'") && value.endsWith("'")) {
12
+ value = value.match(/^'(.*)'$/)![1] as string;
13
+ obj[name] = value.trim();
14
+ } else if (value.startsWith('"') && value.endsWith('"')) {
15
+ try {
16
+ const str = JSON.parse(value);
17
+ if (typeof str === "string") {
18
+ value = str.trim();
19
+ }
20
+ } catch {}
21
+ }
22
+ value = value.replaceAll(/\${([a-zA-Z_]+[a-zA-Z0-9_]*)}/gm, (_, str: string) => {
23
+ return obj[str] ?? process.env[str] ?? "undefined";
24
+ });
25
+ obj[name] = value;
26
+ //console.log(name, value);
27
+ }
28
+ return obj;
29
+ }
30
+ export function loadEnv() {
31
+ try {
32
+ const env = fs.readFileSync(path.join(process.cwd(), ".env"), "utf8");
33
+ const obj = parseEnv(env);
34
+ Object.assign(process.env, obj);
35
+ } catch {}
36
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "target": "esnext",
5
+ "sourceMap": true,
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "noUncheckedIndexedAccess": true,
9
+ "exactOptionalPropertyTypes": true,
10
+ "strict": true,
11
+ "isolatedModules": false,
12
+ "noUncheckedSideEffectImports": true,
13
+ "moduleDetection": "force",
14
+ "skipLibCheck": true,
15
+ "rootDir":"./src",
16
+ "outDir": "./dist",
17
+ "types":["node"]
18
+ },
19
+ "include": ["src/**/*.ts"],
20
+ "exclude": ["node_modules"]
21
+ }