scenv 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +65 -0
  2. package/package.json +10 -17
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # scenv
2
+
3
+ Environment and context variables with runtime-configurable resolution.
4
+
5
+ Define variables once with `scenv()`, then resolve values from **set overrides** (e.g. CLI `--set`), **environment**, **context files**, or **defaults**. Control behavior via config (file, env, or `configure()`)—same code, different config per run.
6
+
7
+ **Requires Node 18+.**
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add scenv
13
+ # or
14
+ npm install scenv
15
+ ```
16
+
17
+ ## Quick start
18
+
19
+ ```ts
20
+ import { configure, parseScenvArgs, scenv } from "scenv";
21
+
22
+ // Optional: apply CLI flags (--set, --context, --prompt, etc.)
23
+ configure(parseScenvArgs(process.argv.slice(2)));
24
+
25
+ const apiUrl = scenv("API URL", {
26
+ key: "api_url",
27
+ env: "API_URL",
28
+ default: "http://localhost:4000",
29
+ });
30
+
31
+ const url = await apiUrl.get(); // throws if missing or invalid
32
+ const result = await apiUrl.safeGet(); // { success, value? } | { success: false, error? }
33
+ await apiUrl.save(); // write current value to a context file
34
+ ```
35
+
36
+ ## Resolution order
37
+
38
+ 1. **Set overrides** – e.g. `--set key=value`
39
+ 2. **Environment** – `process.env[envKey]`
40
+ 3. **Context** – merged JSON context files
41
+ 4. **Default** – variable’s `default` option
42
+
43
+ Prompting (when to ask the user) is controlled by config `prompt`: `always` | `never` | `fallback` | `no-env`.
44
+
45
+ ## Optional integrations
46
+
47
+ | Package | Purpose |
48
+ |--------|--------|
49
+ | [scenv-zod](https://www.npmjs.com/package/scenv-zod) | `validator(zodSchema)` for type-safe validation and coercion. |
50
+ | [scenv-inquirer](https://www.npmjs.com/package/scenv-inquirer) | `prompt()` and callbacks for interactive prompts. |
51
+
52
+ ## Documentation
53
+
54
+ Full docs (config, contexts, resolution, saving, API) live in the [monorepo](https://github.com/PKWadsy/senv):
55
+
56
+ - [Configuration](https://github.com/PKWadsy/senv/blob/main/docs/CONFIGURATION.md)
57
+ - [Contexts](https://github.com/PKWadsy/senv/blob/main/docs/CONTEXTS.md)
58
+ - [Resolution](https://github.com/PKWadsy/senv/blob/main/docs/RESOLUTION.md)
59
+ - [Saving](https://github.com/PKWadsy/senv/blob/main/docs/SAVING.md)
60
+ - [API reference](https://github.com/PKWadsy/senv/blob/main/docs/API.md)
61
+ - [Integration (scenv-zod, scenv-inquirer)](https://github.com/PKWadsy/senv/blob/main/docs/INTEGRATION.md)
62
+
63
+ ## License
64
+
65
+ MIT
package/package.json CHANGED
@@ -1,17 +1,10 @@
1
1
  {
2
2
  "name": "scenv",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Environment and context variables with runtime-configurable resolution",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/PKWadsy/senv.git"
8
- },
9
- "keywords": [
10
- "env",
11
- "config",
12
- "context",
13
- "variables"
14
- ],
5
+ "repository": { "type": "git", "url": "https://github.com/PKWadsy/scenv" },
6
+ "publishConfig": { "access": "public", "provenance": true },
7
+ "keywords": ["env", "config", "context", "variables"],
15
8
  "type": "module",
16
9
  "main": "dist/index.cjs",
17
10
  "module": "dist/index.js",
@@ -26,6 +19,11 @@
26
19
  "files": [
27
20
  "dist"
28
21
  ],
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest"
26
+ },
29
27
  "devDependencies": {
30
28
  "@types/node": "^20.0.0",
31
29
  "@vitest/coverage-v8": "^2.1.9",
@@ -35,10 +33,5 @@
35
33
  },
36
34
  "engines": {
37
35
  "node": ">=18"
38
- },
39
- "scripts": {
40
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
41
- "test": "vitest run",
42
- "test:watch": "vitest"
43
36
  }
44
- }
37
+ }