siko 0.1.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/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "siko",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": "./src/index.js",
6
+ "main": "./src/index.js",
7
+ "files": ["src"],
8
+ "keywords": ["config", "env", "utility"],
9
+ "license": "MIT"
10
+ }
package/src/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # siko
2
+
3
+ Tiny, safe config loader.
4
+
5
+ ## Install
6
+ ```bash
7
+ npm install siko
8
+ ```
9
+
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ import { siko } from "siko";
15
+
16
+ const config = siko({
17
+ PORT: {
18
+ default: 3000,
19
+ parse: Number
20
+ },
21
+ NODE_ENV: {
22
+ default: "development"
23
+ }
24
+ });
25
+
26
+ console.log(config.PORT);
27
+ ```
package/src/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export function siko(schema, env = process.env) {
2
+ const result = {};
3
+
4
+ for (const key in schema) {
5
+ const value = env[key] ?? schema[key].default;
6
+
7
+ if (value === undefined) {
8
+ throw new Error(`Missing required config: ${key}`);
9
+ }
10
+
11
+ result[key] = schema[key].parse
12
+ ? schema[key].parse(value)
13
+ : value;
14
+ }
15
+
16
+ return Object.freeze(result);
17
+ }