@pitininja/envious 3.1.11 → 3.3.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/README.md +1 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -1
- package/package.json +9 -23
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ import { envious } from '@pitininja/envious';
|
|
|
20
20
|
export const schema = Type.Object({
|
|
21
21
|
STRING_VAR: Type.String(),
|
|
22
22
|
NUMBER_VAR: Type.Integer(),
|
|
23
|
-
|
|
23
|
+
BOOLEAN_VAR_WITH_DEFAULT: Type.Boolean({ default: false }),
|
|
24
24
|
OPTIONAL_VAR: Type.Optional(Type.String())
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -29,14 +29,3 @@ Parse your environment variables.
|
|
|
29
29
|
If the environment variables don't match the schema, an error will be thrown.
|
|
30
30
|
*/
|
|
31
31
|
const env = envious(schema);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
You can provide default values as second parameter of the envious function.
|
|
35
|
-
*/
|
|
36
|
-
const envWithDefaults = envious(schema, {
|
|
37
|
-
STRING_VAR: 'Example',
|
|
38
|
-
NUMBER_VAR: 123,
|
|
39
|
-
BOOLEAN_VAR: true,
|
|
40
|
-
OPTIONAL_VAR: 'Example'
|
|
41
|
-
});
|
|
42
|
-
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import {
|
|
3
|
-
export declare const envious: <T extends TObject>(schema: T
|
|
2
|
+
import type { Static, TObject } from '@sinclair/typebox';
|
|
3
|
+
export declare const envious: <T extends TObject>(schema: T) => Static<T>;
|
package/dist/index.js
CHANGED
|
@@ -5,34 +5,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.envious = void 0;
|
|
7
7
|
require("dotenv/config");
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
8
9
|
const value_1 = require("@sinclair/typebox/value");
|
|
9
|
-
const
|
|
10
|
-
const envious = (schema, defaultValues) => {
|
|
10
|
+
const envious = (schema) => {
|
|
11
11
|
const parsed = value_1.Value.Parse(schema, process.env);
|
|
12
12
|
const errors = [...value_1.Value.Errors(schema, parsed)];
|
|
13
13
|
if (errors.length) {
|
|
14
14
|
const computedErrorMessages = {};
|
|
15
|
-
|
|
15
|
+
for (const { path, message } of errors) {
|
|
16
16
|
const envVarName = path.replace(/^\//, '');
|
|
17
17
|
if (!computedErrorMessages[envVarName]) {
|
|
18
18
|
computedErrorMessages[envVarName] = [];
|
|
19
19
|
}
|
|
20
20
|
computedErrorMessages[envVarName].push(message);
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
const errorTextParts = [
|
|
23
23
|
'Invalid environment variables',
|
|
24
24
|
...Object.entries(computedErrorMessages).map(([varName, messages]) => ` ${varName} : ${messages.join(', ')}`)
|
|
25
25
|
];
|
|
26
|
-
throw new Error(errorTextParts.join(
|
|
26
|
+
throw new Error(errorTextParts.join(node_os_1.default.EOL));
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
return value_1.Value.Cast({
|
|
29
29
|
...schema,
|
|
30
30
|
additionalProperties: false
|
|
31
31
|
}, parsed);
|
|
32
|
-
return {
|
|
33
|
-
...defaultValues,
|
|
34
|
-
...env
|
|
35
|
-
};
|
|
36
32
|
};
|
|
37
33
|
exports.envious = envious;
|
|
38
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAuB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAuB;AACvB,sDAAyB;AAEzB,mDAA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|
2
2
|
"name": "@pitininja/envious",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://github.com/pitininja/envious",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/pitininja/envious"
|
|
9
9
|
},
|
|
10
|
-
"files": [
|
|
11
|
-
"./dist",
|
|
12
|
-
"./LICENSE",
|
|
13
|
-
"./package.json",
|
|
14
|
-
"./README.md"
|
|
15
|
-
],
|
|
10
|
+
"files": ["./dist", "./LICENSE", "./package.json", "./README.md"],
|
|
16
11
|
"main": "./dist/index.js",
|
|
17
12
|
"types": "./dist/index.d.ts",
|
|
18
13
|
"scripts": {
|
|
19
14
|
"prepare": "[ -d '.husky' ] && husky || true",
|
|
20
15
|
"build": "tsc --build --clean tsconfig.build.json && tsc -b ./tsconfig.build.json",
|
|
21
|
-
"
|
|
22
|
-
"lint": "npx
|
|
23
|
-
"format": "npx
|
|
24
|
-
"test": "vitest --run"
|
|
16
|
+
"test": "vitest --run",
|
|
17
|
+
"lint": "npx @biomejs/biome check --error-on-warnings && npx tsc --noEmit",
|
|
18
|
+
"format": "npx @biomejs/biome check --write --error-on-warnings && npx tsc --noEmit"
|
|
25
19
|
},
|
|
26
20
|
"dependencies": {
|
|
27
|
-
"@sinclair/typebox": "^0.33.
|
|
21
|
+
"@sinclair/typebox": "^0.33.9",
|
|
28
22
|
"dotenv": "^16.4.5"
|
|
29
23
|
},
|
|
30
24
|
"devDependencies": {
|
|
25
|
+
"@biomejs/biome": "^1.8.3",
|
|
31
26
|
"@tsconfig/recommended": "^1.0.7",
|
|
32
|
-
"@types/node": "^22.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
34
|
-
"@typescript-eslint/parser": "^7.17.0",
|
|
27
|
+
"@types/node": "^22.5.3",
|
|
35
28
|
"@vitest/coverage-istanbul": "^2.0.5",
|
|
36
|
-
"
|
|
37
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
38
|
-
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
39
|
-
"eslint-config-prettier": "^9.1.0",
|
|
40
|
-
"eslint-plugin-import": "^2.29.1",
|
|
41
|
-
"husky": "^9.1.4",
|
|
42
|
-
"prettier": "^3.3.3",
|
|
43
|
-
"tsup": "^8.2.4",
|
|
29
|
+
"husky": "^9.1.5",
|
|
44
30
|
"typescript": "^5.5.4",
|
|
45
31
|
"vitest": "^2.0.5"
|
|
46
32
|
}
|