diginext-utils 3.11.2 → 3.11.3
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/README.md +162 -162
- package/dist/file/detectPrivateKeyByFilePath.js +20 -9
- package/dist/file/detectPrivateKeyByFilePath.js.map +1 -1
- package/dist/file/parseEnvFile.d.ts +8 -0
- package/dist/file/parseEnvFile.js +45 -0
- package/dist/file/parseEnvFile.js.map +1 -0
- package/esm/file/detectPrivateKeyByFilePath.js +20 -9
- package/esm/file/detectPrivateKeyByFilePath.js.map +1 -1
- package/esm/file/parseEnvFile.d.ts +8 -0
- package/esm/file/parseEnvFile.js +38 -0
- package/esm/file/parseEnvFile.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
# The library of utility plugins
|
|
2
|
-
|
|
3
|
-
## Exports
|
|
4
|
-
|
|
5
|
-
- "diginext-utils/dist": ES6 modules / NodeJS
|
|
6
|
-
- "diginext-utils/esm": Node modules / JavaScript modules
|
|
7
|
-
|
|
8
|
-
## Imports
|
|
9
|
-
|
|
10
|
-
### ES5 module import:
|
|
11
|
-
|
|
12
|
-
```javascript
|
|
13
|
-
import utils from "diginext-utils";
|
|
14
|
-
console.log(utils.xname.NameEN.generateName()); // output some random name in English
|
|
15
|
-
|
|
16
|
-
// or
|
|
17
|
-
|
|
18
|
-
import { NameEN } from "diginext-utils/dist/name";
|
|
19
|
-
console.log(NameEN.generateName()); // output some random name in English
|
|
20
|
-
|
|
21
|
-
// or just
|
|
22
|
-
import { generateName } from "diginext-utils/dist/name/en";
|
|
23
|
-
console.log(generateName()); // output some random name in English
|
|
24
|
-
|
|
25
|
-
// or with require(...)
|
|
26
|
-
const xurl = require("../dist/string/url");
|
|
27
|
-
xurl.isLink("abc"); // FALSE
|
|
28
|
-
xurl.isLink("https://www.google.com"); // TRUE
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Node module import:
|
|
32
|
-
|
|
33
|
-
**IMPORTANT**: Set "type" as "module" your `package.json`
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
// NodeJS moduies
|
|
37
|
-
import utils from "diginext-utils";
|
|
38
|
-
console.log(utils.xname.NameEN.generateName()); // output some random name in English
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
```html
|
|
42
|
-
// browser
|
|
43
|
-
<script type="module">
|
|
44
|
-
import { NameEN } from "diginext-utils/esm/name/index.js"; // ".js" file extension is required !
|
|
45
|
-
console.log(NameEN.generateName()); // output some random name in English
|
|
46
|
-
</script>
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Features
|
|
50
|
-
|
|
51
|
-
- xconsole
|
|
52
|
-
- xarray
|
|
53
|
-
- sumArray
|
|
54
|
-
- averageArray
|
|
55
|
-
- minArray
|
|
56
|
-
- maxArray
|
|
57
|
-
- sortElementByString
|
|
58
|
-
- sortElementByNumber
|
|
59
|
-
- firstElement
|
|
60
|
-
- lastElement
|
|
61
|
-
- randomIndex
|
|
62
|
-
- randomElement
|
|
63
|
-
- mergeAndMakeUniqueElement
|
|
64
|
-
- allMatchInArray
|
|
65
|
-
- removeItem
|
|
66
|
-
- removeItemByKey
|
|
67
|
-
- getRandom
|
|
68
|
-
- getHalfRandom
|
|
69
|
-
- shuffle
|
|
70
|
-
- moveIndex
|
|
71
|
-
- moveArray
|
|
72
|
-
- xmath
|
|
73
|
-
- rand
|
|
74
|
-
- randRound
|
|
75
|
-
- randHalt
|
|
76
|
-
- randInt
|
|
77
|
-
- randFloat
|
|
78
|
-
- degToRad
|
|
79
|
-
- radToDeg
|
|
80
|
-
- angleBetweenPoints
|
|
81
|
-
- diffDate
|
|
82
|
-
- positiveNumber
|
|
83
|
-
- xname
|
|
84
|
-
- NameEN.generateName()
|
|
85
|
-
- NameVI.generateName()
|
|
86
|
-
- xobject
|
|
87
|
-
- isNull
|
|
88
|
-
- toBool
|
|
89
|
-
- toInt
|
|
90
|
-
- toFloat
|
|
91
|
-
- toArray
|
|
92
|
-
- objectToArray
|
|
93
|
-
- xjson
|
|
94
|
-
- isValid
|
|
95
|
-
- xfile
|
|
96
|
-
- createDir
|
|
97
|
-
- fileMove
|
|
98
|
-
- findFileByExt
|
|
99
|
-
- xstring
|
|
100
|
-
- getBetween
|
|
101
|
-
- makeString
|
|
102
|
-
- toUpperCase
|
|
103
|
-
- toLowerCase
|
|
104
|
-
- titleize
|
|
105
|
-
- capitalize
|
|
106
|
-
- capitalizeName
|
|
107
|
-
- clearUnicodeCharacters
|
|
108
|
-
- generateUUID
|
|
109
|
-
- randAllCharacterByLength
|
|
110
|
-
- randomStringByLength
|
|
111
|
-
- formatNumber
|
|
112
|
-
- generatePassword
|
|
113
|
-
- trimNull
|
|
114
|
-
- addQueryParam
|
|
115
|
-
- getUrlParams
|
|
116
|
-
- isLink
|
|
117
|
-
- getFileNameWithoutExtension
|
|
118
|
-
- getFileNameWithExtension
|
|
119
|
-
- getFileExtension
|
|
120
|
-
- isImage
|
|
121
|
-
- xurl
|
|
122
|
-
- addQueryParam
|
|
123
|
-
- getUrlParams
|
|
124
|
-
- isLink
|
|
125
|
-
- getFileNameWithoutExtension
|
|
126
|
-
- getFileNameWithExtension
|
|
127
|
-
- getFileExtension
|
|
128
|
-
- isImage
|
|
129
|
-
- slug
|
|
130
|
-
- makeSlug
|
|
131
|
-
- color
|
|
132
|
-
- random
|
|
133
|
-
- pSBC
|
|
134
|
-
- hexToRgb
|
|
135
|
-
- hexDarken
|
|
136
|
-
- hexLighten
|
|
137
|
-
- RGBToHex
|
|
138
|
-
- device
|
|
139
|
-
- camera
|
|
140
|
-
- requestCamera
|
|
141
|
-
- requestDeviceOrientationControl
|
|
142
|
-
- browser
|
|
143
|
-
- isPotrait
|
|
144
|
-
- isLandscape
|
|
145
|
-
- ua
|
|
146
|
-
- isFacebookWebview
|
|
147
|
-
- isInAppWebview
|
|
148
|
-
- Timer
|
|
149
|
-
- wait
|
|
150
|
-
- Validation
|
|
151
|
-
- imageValidate
|
|
152
|
-
- videoValidate
|
|
153
|
-
|
|
154
|
-
## Dev
|
|
155
|
-
|
|
156
|
-
```
|
|
157
|
-
yarn dev
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Support
|
|
161
|
-
|
|
162
|
-
Liên hệ [TOP GROUP Developers](mailto:dev@wearetopgroup.com) nếu cần hỗ trợ.
|
|
1
|
+
# The library of utility plugins
|
|
2
|
+
|
|
3
|
+
## Exports
|
|
4
|
+
|
|
5
|
+
- "diginext-utils/dist": ES6 modules / NodeJS
|
|
6
|
+
- "diginext-utils/esm": Node modules / JavaScript modules
|
|
7
|
+
|
|
8
|
+
## Imports
|
|
9
|
+
|
|
10
|
+
### ES5 module import:
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
import utils from "diginext-utils";
|
|
14
|
+
console.log(utils.xname.NameEN.generateName()); // output some random name in English
|
|
15
|
+
|
|
16
|
+
// or
|
|
17
|
+
|
|
18
|
+
import { NameEN } from "diginext-utils/dist/name";
|
|
19
|
+
console.log(NameEN.generateName()); // output some random name in English
|
|
20
|
+
|
|
21
|
+
// or just
|
|
22
|
+
import { generateName } from "diginext-utils/dist/name/en";
|
|
23
|
+
console.log(generateName()); // output some random name in English
|
|
24
|
+
|
|
25
|
+
// or with require(...)
|
|
26
|
+
const xurl = require("../dist/string/url");
|
|
27
|
+
xurl.isLink("abc"); // FALSE
|
|
28
|
+
xurl.isLink("https://www.google.com"); // TRUE
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Node module import:
|
|
32
|
+
|
|
33
|
+
**IMPORTANT**: Set "type" as "module" your `package.json`
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
// NodeJS moduies
|
|
37
|
+
import utils from "diginext-utils";
|
|
38
|
+
console.log(utils.xname.NameEN.generateName()); // output some random name in English
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
// browser
|
|
43
|
+
<script type="module">
|
|
44
|
+
import { NameEN } from "diginext-utils/esm/name/index.js"; // ".js" file extension is required !
|
|
45
|
+
console.log(NameEN.generateName()); // output some random name in English
|
|
46
|
+
</script>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- xconsole
|
|
52
|
+
- xarray
|
|
53
|
+
- sumArray
|
|
54
|
+
- averageArray
|
|
55
|
+
- minArray
|
|
56
|
+
- maxArray
|
|
57
|
+
- sortElementByString
|
|
58
|
+
- sortElementByNumber
|
|
59
|
+
- firstElement
|
|
60
|
+
- lastElement
|
|
61
|
+
- randomIndex
|
|
62
|
+
- randomElement
|
|
63
|
+
- mergeAndMakeUniqueElement
|
|
64
|
+
- allMatchInArray
|
|
65
|
+
- removeItem
|
|
66
|
+
- removeItemByKey
|
|
67
|
+
- getRandom
|
|
68
|
+
- getHalfRandom
|
|
69
|
+
- shuffle
|
|
70
|
+
- moveIndex
|
|
71
|
+
- moveArray
|
|
72
|
+
- xmath
|
|
73
|
+
- rand
|
|
74
|
+
- randRound
|
|
75
|
+
- randHalt
|
|
76
|
+
- randInt
|
|
77
|
+
- randFloat
|
|
78
|
+
- degToRad
|
|
79
|
+
- radToDeg
|
|
80
|
+
- angleBetweenPoints
|
|
81
|
+
- diffDate
|
|
82
|
+
- positiveNumber
|
|
83
|
+
- xname
|
|
84
|
+
- NameEN.generateName()
|
|
85
|
+
- NameVI.generateName()
|
|
86
|
+
- xobject
|
|
87
|
+
- isNull
|
|
88
|
+
- toBool
|
|
89
|
+
- toInt
|
|
90
|
+
- toFloat
|
|
91
|
+
- toArray
|
|
92
|
+
- objectToArray
|
|
93
|
+
- xjson
|
|
94
|
+
- isValid
|
|
95
|
+
- xfile
|
|
96
|
+
- createDir
|
|
97
|
+
- fileMove
|
|
98
|
+
- findFileByExt
|
|
99
|
+
- xstring
|
|
100
|
+
- getBetween
|
|
101
|
+
- makeString
|
|
102
|
+
- toUpperCase
|
|
103
|
+
- toLowerCase
|
|
104
|
+
- titleize
|
|
105
|
+
- capitalize
|
|
106
|
+
- capitalizeName
|
|
107
|
+
- clearUnicodeCharacters
|
|
108
|
+
- generateUUID
|
|
109
|
+
- randAllCharacterByLength
|
|
110
|
+
- randomStringByLength
|
|
111
|
+
- formatNumber
|
|
112
|
+
- generatePassword
|
|
113
|
+
- trimNull
|
|
114
|
+
- addQueryParam
|
|
115
|
+
- getUrlParams
|
|
116
|
+
- isLink
|
|
117
|
+
- getFileNameWithoutExtension
|
|
118
|
+
- getFileNameWithExtension
|
|
119
|
+
- getFileExtension
|
|
120
|
+
- isImage
|
|
121
|
+
- xurl
|
|
122
|
+
- addQueryParam
|
|
123
|
+
- getUrlParams
|
|
124
|
+
- isLink
|
|
125
|
+
- getFileNameWithoutExtension
|
|
126
|
+
- getFileNameWithExtension
|
|
127
|
+
- getFileExtension
|
|
128
|
+
- isImage
|
|
129
|
+
- slug
|
|
130
|
+
- makeSlug
|
|
131
|
+
- color
|
|
132
|
+
- random
|
|
133
|
+
- pSBC
|
|
134
|
+
- hexToRgb
|
|
135
|
+
- hexDarken
|
|
136
|
+
- hexLighten
|
|
137
|
+
- RGBToHex
|
|
138
|
+
- device
|
|
139
|
+
- camera
|
|
140
|
+
- requestCamera
|
|
141
|
+
- requestDeviceOrientationControl
|
|
142
|
+
- browser
|
|
143
|
+
- isPotrait
|
|
144
|
+
- isLandscape
|
|
145
|
+
- ua
|
|
146
|
+
- isFacebookWebview
|
|
147
|
+
- isInAppWebview
|
|
148
|
+
- Timer
|
|
149
|
+
- wait
|
|
150
|
+
- Validation
|
|
151
|
+
- imageValidate
|
|
152
|
+
- videoValidate
|
|
153
|
+
|
|
154
|
+
## Dev
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
yarn dev
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Support
|
|
161
|
+
|
|
162
|
+
Liên hệ [TOP GROUP Developers](mailto:dev@wearetopgroup.com) nếu cần hỗ trợ.
|
|
@@ -5,20 +5,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.detectPrivateKeyByFilePath = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const
|
|
8
|
+
const parseEnvFile_1 = __importDefault(require("./parseEnvFile"));
|
|
9
9
|
function detectPrivateKeyByFilePath(_path) {
|
|
10
10
|
//
|
|
11
11
|
if (!fs_1.default.existsSync(_path))
|
|
12
12
|
return true;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (_path.includes(".env")) {
|
|
14
|
+
const env = (0, parseEnvFile_1.default)(_path);
|
|
15
|
+
const secretPattern = /(SECRET|TOKEN|PRIVATE)/g;
|
|
16
|
+
let success = true;
|
|
17
|
+
for (let i = 0; i < Object.keys(env).length; i++) {
|
|
18
|
+
const key = Object.keys(env)[i];
|
|
19
|
+
const value = env[key];
|
|
20
|
+
if (key.match(secretPattern)) {
|
|
21
|
+
if (!!value) {
|
|
22
|
+
console.error(key, value);
|
|
23
|
+
success = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return success;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const fileContents = fs_1.default.readFileSync(_path, "utf8");
|
|
31
|
+
if (fileContents.includes(`${`-----`}BEGIN `))
|
|
19
32
|
return false;
|
|
20
|
-
default:
|
|
21
|
-
break;
|
|
22
33
|
}
|
|
23
34
|
return true;
|
|
24
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,
|
|
1
|
+
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"m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
|
5
|
+
* @return {Object} - An object with keys and values based on the .env file.
|
|
6
|
+
*/
|
|
7
|
+
export default function parseEnvFile(path: string): any;
|
|
8
|
+
export { parseEnvFile };
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
exports.parseEnvFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
/**
|
|
9
|
+
* Reads an .env file and converts it into a JavaScript object.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} path - The path to the .env file.
|
|
12
|
+
* @return {Object} - An object with keys and values based on the .env file.
|
|
13
|
+
*/
|
|
14
|
+
function parseEnvFile(path) {
|
|
15
|
+
const env = {};
|
|
16
|
+
// Check if the file exists
|
|
17
|
+
if (!fs_1.default.existsSync(path)) {
|
|
18
|
+
console.error("File not found");
|
|
19
|
+
return env;
|
|
20
|
+
}
|
|
21
|
+
// Read file contents
|
|
22
|
+
const fileContents = fs_1.default.readFileSync(path, "utf8");
|
|
23
|
+
// Split the file content by new lines and iterate over each line
|
|
24
|
+
fileContents.split("\n").forEach((line) => {
|
|
25
|
+
// Trim whitespace and ignore comments or empty lines
|
|
26
|
+
const trimmedLine = line.trim();
|
|
27
|
+
if (trimmedLine.startsWith("#") || trimmedLine === "")
|
|
28
|
+
return;
|
|
29
|
+
// Split each line into key and value at the first '='
|
|
30
|
+
const [key, ...rest] = trimmedLine.split("=");
|
|
31
|
+
let value = rest.join("=").trim();
|
|
32
|
+
// Remove surrounding quotes if they wrap the entire value
|
|
33
|
+
if ((value.startsWith(`"`) && value.endsWith(`"`)) || (value.startsWith(`'`) && value.endsWith(`'`))) {
|
|
34
|
+
// Extract the value within the quotes, preserving any quotes that are part of the value
|
|
35
|
+
value = value.substring(1, value.length - 1);
|
|
36
|
+
}
|
|
37
|
+
// Add to env object
|
|
38
|
+
if (key)
|
|
39
|
+
env[key] = value;
|
|
40
|
+
});
|
|
41
|
+
return env;
|
|
42
|
+
}
|
|
43
|
+
exports.default = parseEnvFile;
|
|
44
|
+
exports.parseEnvFile = parseEnvFile;
|
|
45
|
+
//# sourceMappingURL=parseEnvFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnvFile.js","sourceRoot":"","sources":["../../src/file/parseEnvFile.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAEpB;;;;;GAKG;AACH,SAAwB,YAAY,CAAC,IAAY;IAChD,MAAM,GAAG,GAAG,EAAS,CAAC;IAEtB,2BAA2B;IAC3B,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,OAAO,GAAG,CAAC;KACX;IAED,qBAAqB;IACrB,MAAM,YAAY,GAAG,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEnD,iEAAiE;IACjE,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACzC,qDAAqD;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,KAAK,EAAE;YAAE,OAAO;QAE9D,sDAAsD;QACtD,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAElC,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;YACrG,wFAAwF;YACxF,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAC7C;QAED,oBAAoB;QACpB,IAAI,GAAG;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACZ,CAAC;AAhCD,+BAgCC;AAEQ,oCAAY"}
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import
|
|
2
|
+
import parseEnvFile from "./parseEnvFile";
|
|
3
3
|
export default function detectPrivateKeyByFilePath(_path) {
|
|
4
4
|
//
|
|
5
5
|
if (!fs.existsSync(_path))
|
|
6
6
|
return true;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
if (_path.includes(".env")) {
|
|
8
|
+
const env = parseEnvFile(_path);
|
|
9
|
+
const secretPattern = /(SECRET|TOKEN|PRIVATE)/g;
|
|
10
|
+
let success = true;
|
|
11
|
+
for (let i = 0; i < Object.keys(env).length; i++) {
|
|
12
|
+
const key = Object.keys(env)[i];
|
|
13
|
+
const value = env[key];
|
|
14
|
+
if (key.match(secretPattern)) {
|
|
15
|
+
if (!!value) {
|
|
16
|
+
console.error(key, value);
|
|
17
|
+
success = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return success;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const fileContents = fs.readFileSync(_path, "utf8");
|
|
25
|
+
if (fileContents.includes(`${`-----`}BEGIN `))
|
|
13
26
|
return false;
|
|
14
|
-
default:
|
|
15
|
-
break;
|
|
16
27
|
}
|
|
17
28
|
return true;
|
|
18
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"detectPrivateKeyByFilePath.js","sourceRoot":"","sources":["../../src/file/detectPrivateKeyByFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,KAAa;IAC/D,EAAE;IACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEvC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC3B,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAEhC,MAAM,aAAa,GAAG,yBAAyB,CAAC;QAEhD,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACjD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YAEvB,IAAI,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;gBAC7B,IAAI,CAAC,CAAC,KAAK,EAAE;oBACZ,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBAC1B,OAAO,GAAG,KAAK,CAAC;iBAChB;aACD;SACD;QAED,OAAO,OAAO,CAAC;KACf;SAAM;QACN,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAW,CAAC;QAC9D,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,OAAO,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;KAC5D;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads an .env file and converts it into a JavaScript object.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} path - The path to the .env file.
|
|
5
|
+
* @return {Object} - An object with keys and values based on the .env file.
|
|
6
|
+
*/
|
|
7
|
+
export default function parseEnvFile(path: string): any;
|
|
8
|
+
export { parseEnvFile };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
/**
|
|
3
|
+
* Reads an .env file and converts it into a JavaScript object.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} path - The path to the .env file.
|
|
6
|
+
* @return {Object} - An object with keys and values based on the .env file.
|
|
7
|
+
*/
|
|
8
|
+
export default function parseEnvFile(path) {
|
|
9
|
+
const env = {};
|
|
10
|
+
// Check if the file exists
|
|
11
|
+
if (!fs.existsSync(path)) {
|
|
12
|
+
console.error("File not found");
|
|
13
|
+
return env;
|
|
14
|
+
}
|
|
15
|
+
// Read file contents
|
|
16
|
+
const fileContents = fs.readFileSync(path, "utf8");
|
|
17
|
+
// Split the file content by new lines and iterate over each line
|
|
18
|
+
fileContents.split("\n").forEach((line) => {
|
|
19
|
+
// Trim whitespace and ignore comments or empty lines
|
|
20
|
+
const trimmedLine = line.trim();
|
|
21
|
+
if (trimmedLine.startsWith("#") || trimmedLine === "")
|
|
22
|
+
return;
|
|
23
|
+
// Split each line into key and value at the first '='
|
|
24
|
+
const [key, ...rest] = trimmedLine.split("=");
|
|
25
|
+
let value = rest.join("=").trim();
|
|
26
|
+
// Remove surrounding quotes if they wrap the entire value
|
|
27
|
+
if ((value.startsWith(`"`) && value.endsWith(`"`)) || (value.startsWith(`'`) && value.endsWith(`'`))) {
|
|
28
|
+
// Extract the value within the quotes, preserving any quotes that are part of the value
|
|
29
|
+
value = value.substring(1, value.length - 1);
|
|
30
|
+
}
|
|
31
|
+
// Add to env object
|
|
32
|
+
if (key)
|
|
33
|
+
env[key] = value;
|
|
34
|
+
});
|
|
35
|
+
return env;
|
|
36
|
+
}
|
|
37
|
+
export { parseEnvFile };
|
|
38
|
+
//# sourceMappingURL=parseEnvFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnvFile.js","sourceRoot":"","sources":["../../src/file/parseEnvFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAY;IAChD,MAAM,GAAG,GAAG,EAAS,CAAC;IAEtB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,OAAO,GAAG,CAAC;KACX;IAED,qBAAqB;IACrB,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEnD,iEAAiE;IACjE,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACzC,qDAAqD;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,KAAK,EAAE;YAAE,OAAO;QAE9D,sDAAsD;QACtD,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,KAAK,GAAG,IAAI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