arkenv 0.4.0 → 0.5.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 +28 -12
- package/dist/index.cjs +2 -9
- package/dist/index.d.cts +1 -10
- package/dist/index.d.ts +1 -10
- package/dist/index.js +2 -15
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
+
<sup><b>We are now featured on <a href="https://arktype.io/docs/ecosystem#arkenv">arktype.io</a>!</b></sup>
|
|
3
|
+
<br />
|
|
2
4
|
<a href="https://arkenv.js.org">
|
|
3
5
|
<img alt="arkenv - Typesafe Environment Variables" src="https://og.tailgraph.com/og?titleFontFamily=JetBrains+Mono&textFontFamily=Inter&title=ArkEnv&titleTailwind=text-[%23e9eef9]%20font-bold%20relative%20decoration-%5Brgb(180,215,255)%5D%20decoration-wavy%20decoration-[5px]%20underline%20underline-offset-[16px]%20text-5xl%20mb-8&text=Typesafe%20environment%20variables%20powered%20by%20ArkType&textTailwind=text-[%238b9dc1]%20text-3xl&bgTailwind=bg-gradient-to-b%20from-[%23061a3a]%20to-black" width="645px">
|
|
4
6
|
</a>
|
|
5
7
|
<br />
|
|
6
8
|
<a href="https://github.com/yamcodes/arkenv/actions/workflows/tests.yml?query=branch%3Amain"><img alt="Tests Status" src="https://github.com/yamcodes/arkenv/actions/workflows/tests.yml/badge.svg?event=push&branch=main"></a>
|
|
7
|
-
<a href="https://
|
|
8
|
-
<a href="https://www.
|
|
9
|
-
<a href="https://
|
|
10
|
-
<a href="https://
|
|
9
|
+
<a href="https://www.npmjs.com/package/arkenv?activeTab=versions"><img alt="Total Downloads" src="https://img.shields.io/npm/dt/arkenv?logo=npm&color=blue&label=downloads"></a>
|
|
10
|
+
<a href="https://www.typescriptlang.org/"><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white"></a>
|
|
11
|
+
<a href="https://arktype.io/"><img alt="Powered By ArkType" src="https://custom-icon-badges.demolab.com/badge/ArkType-0d1526?logo=arktype2&logoColor=e9eef9"></a>
|
|
12
|
+
<a href="https://nodejs.org/en"><img alt="Node.js" src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=node.js&logoColor=white"></a>
|
|
13
|
+
<a href="https://bun.com/"><img alt="Bun" src="https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df"></a>
|
|
14
|
+
<a href="https://vite.dev/"><img alt="Vite" src="https://custom-icon-badges.demolab.com/badge/Vite-2e2742?logo=vite2&logoColor=dfdfd6"></a>
|
|
15
|
+
<a href="https://github.com/yamcodes/arkenv"><img alt="GitHub Repo stars" src="https://custom-icon-badges.demolab.com/github/stars/yamcodes/arkenv?logo=star&logoColor=373737&label=Star%20us!"></a>
|
|
11
16
|
</p>
|
|
12
17
|
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- TypeScript >= 5.1 and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
|
|
21
|
+
- We support Node.js ([example](examples/basic/README.md)), Bun ([example](examples/with-bun/README.md)), and Vite ([example](examples/with-vite-react-ts/README.md))
|
|
22
|
+
|
|
13
23
|
## Installation
|
|
14
24
|
|
|
15
25
|
<details open>
|
|
@@ -46,18 +56,16 @@ bun add arkenv arktype
|
|
|
46
56
|
|
|
47
57
|
## Quickstart
|
|
48
58
|
|
|
49
|
-
> [!TIP]
|
|
50
|
-
> Find more examples in the [examples](https://github.com/yamcodes/arkenv/tree/main/examples) directory.
|
|
51
|
-
|
|
52
59
|
```ts
|
|
53
|
-
import
|
|
60
|
+
import arkenv from 'arkenv';
|
|
54
61
|
|
|
55
|
-
const env =
|
|
62
|
+
const env = arkenv({
|
|
56
63
|
HOST: "string.host", // valid IP address or localhost
|
|
57
64
|
PORT: "number.port", // valid port number (0-65535)
|
|
58
65
|
NODE_ENV: "'development' | 'production' | 'test'",
|
|
59
66
|
});
|
|
60
67
|
|
|
68
|
+
|
|
61
69
|
// Automatically validate and parse process.env
|
|
62
70
|
// TypeScript knows the ✨exact✨ types!
|
|
63
71
|
console.log(env.HOST); // (property) HOST: string
|
|
@@ -65,12 +73,18 @@ console.log(env.PORT); // (property) PORT: number
|
|
|
65
73
|
console.log(env.NODE_ENV); // (property) NODE_ENV: "development" | "production" | "test"
|
|
66
74
|
```
|
|
67
75
|
|
|
76
|
+
You can find more examples in the [examples](https://github.com/yamcodes/arkenv/tree/main/examples) directory.
|
|
77
|
+
|
|
78
|
+
> [!TIP]
|
|
79
|
+
> **VS Code Users:** Get syntax highlighting and inline error summaries for the ArkType ecosystem with the [ArkType VS Code extension](https://marketplace.visualstudio.com/items?itemName=arktypeio.arkdark). For even better TypeScript highlighting, try [ArkThemes](https://marketplace.cursorapi.com/items/?itemName=arktypeio.arkthemes).
|
|
80
|
+
> 
|
|
81
|
+
|
|
68
82
|
## Features
|
|
69
83
|
|
|
70
84
|
- 🔒 **Typesafe**: Full TypeScript support with inferred types
|
|
71
85
|
- 🚀 **Runtime validation**: Catch missing or invalid environment variables early
|
|
72
86
|
- 💪 **Powered by ArkType**: Leverage ArkType's powerful type system
|
|
73
|
-
- 🪶 **Lightweight**: Only a single dependency ([
|
|
87
|
+
- 🪶 **Lightweight**: Only a single dependency ([see size](https://bundlephobia.com/package/arkenv))
|
|
74
88
|
- ⚡ **Fast**: Optimized for performance with minimal overhead
|
|
75
89
|
|
|
76
90
|
## Documentation
|
|
@@ -81,9 +95,11 @@ For detailed documentation and examples, please visit our [documentation site](h
|
|
|
81
95
|
|
|
82
96
|
- [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin): [Vite](https://vite.dev/) plugin to validate environment variables at build time
|
|
83
97
|
|
|
84
|
-
##
|
|
98
|
+
## Supporting ArkEnv
|
|
99
|
+
|
|
100
|
+
If you love ArkEnv, you can support the project by starring it on GitHub!
|
|
85
101
|
|
|
86
|
-
|
|
102
|
+
You are also welcome to directly [contribute to the project's development](https://github.com/yamcodes/arkenv/blob/main/CONTRIBUTING.md).
|
|
87
103
|
|
|
88
104
|
## Thanks / Inspiration
|
|
89
105
|
|
package/dist/index.cjs
CHANGED
|
@@ -31,15 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
createEnv: () => createEnv,
|
|
34
|
-
default: () =>
|
|
34
|
+
default: () => createEnv
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
38
|
// src/create-env.ts
|
|
39
|
-
var create_env_exports = {};
|
|
40
|
-
__export(create_env_exports, {
|
|
41
|
-
createEnv: () => createEnv
|
|
42
|
-
});
|
|
43
39
|
var import_arktype3 = require("arktype");
|
|
44
40
|
|
|
45
41
|
// src/errors.ts
|
|
@@ -79,7 +75,7 @@ var import_arktype2 = require("arktype");
|
|
|
79
75
|
// src/types.ts
|
|
80
76
|
var import_arktype = require("arktype");
|
|
81
77
|
var port = (0, import_arktype.type)("string", "=>", (data, ctx) => {
|
|
82
|
-
const asNumber = Number.parseInt(data);
|
|
78
|
+
const asNumber = Number.parseInt(data, 10);
|
|
83
79
|
const isInteger = Number.isInteger(asNumber);
|
|
84
80
|
const isBetween = 0 <= asNumber && asNumber <= 65535;
|
|
85
81
|
if (!isInteger || !isBetween) {
|
|
@@ -110,9 +106,6 @@ function createEnv(def, env = process.env) {
|
|
|
110
106
|
}
|
|
111
107
|
return validatedEnv;
|
|
112
108
|
}
|
|
113
|
-
|
|
114
|
-
// src/index.ts
|
|
115
|
-
var index_default = { ...create_env_exports };
|
|
116
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
117
110
|
0 && (module.exports = {
|
|
118
111
|
createEnv
|
package/dist/index.d.cts
CHANGED
|
@@ -90,13 +90,4 @@ type EnvSchema<def, $ = {}> = type.validate<def, $>;
|
|
|
90
90
|
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T, (typeof $)["t"]>, env?: RuntimeEnvironment): distill.Out<type.infer<T, (typeof $)["t"]>>;
|
|
91
91
|
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.infer<T>>;
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T, typeof $["t"]>, env?: {
|
|
95
|
-
[x: string]: string | undefined;
|
|
96
|
-
}): arktype.distill.Out<arktype.type.infer<T, typeof $["t"]>>;
|
|
97
|
-
createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: {
|
|
98
|
-
[x: string]: string | undefined;
|
|
99
|
-
}): arktype.distill.Out<arktype.type.infer<T>>;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { type EnvSchema, createEnv, _default as default };
|
|
93
|
+
export { type EnvSchema, createEnv, createEnv as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -90,13 +90,4 @@ type EnvSchema<def, $ = {}> = type.validate<def, $>;
|
|
|
90
90
|
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T, (typeof $)["t"]>, env?: RuntimeEnvironment): distill.Out<type.infer<T, (typeof $)["t"]>>;
|
|
91
91
|
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.infer<T>>;
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T, typeof $["t"]>, env?: {
|
|
95
|
-
[x: string]: string | undefined;
|
|
96
|
-
}): arktype.distill.Out<arktype.type.infer<T, typeof $["t"]>>;
|
|
97
|
-
createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: {
|
|
98
|
-
[x: string]: string | undefined;
|
|
99
|
-
}): arktype.distill.Out<arktype.type.infer<T>>;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { type EnvSchema, createEnv, _default as default };
|
|
93
|
+
export { type EnvSchema, createEnv, createEnv as default };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/create-env.ts
|
|
8
|
-
var create_env_exports = {};
|
|
9
|
-
__export(create_env_exports, {
|
|
10
|
-
createEnv: () => createEnv
|
|
11
|
-
});
|
|
12
2
|
import { type as type3 } from "arktype";
|
|
13
3
|
|
|
14
4
|
// src/errors.ts
|
|
@@ -48,7 +38,7 @@ import { scope, type as type2 } from "arktype";
|
|
|
48
38
|
// src/types.ts
|
|
49
39
|
import { type } from "arktype";
|
|
50
40
|
var port = type("string", "=>", (data, ctx) => {
|
|
51
|
-
const asNumber = Number.parseInt(data);
|
|
41
|
+
const asNumber = Number.parseInt(data, 10);
|
|
52
42
|
const isInteger = Number.isInteger(asNumber);
|
|
53
43
|
const isBetween = 0 <= asNumber && asNumber <= 65535;
|
|
54
44
|
if (!isInteger || !isBetween) {
|
|
@@ -79,10 +69,7 @@ function createEnv(def, env = process.env) {
|
|
|
79
69
|
}
|
|
80
70
|
return validatedEnv;
|
|
81
71
|
}
|
|
82
|
-
|
|
83
|
-
// src/index.ts
|
|
84
|
-
var index_default = { ...create_env_exports };
|
|
85
72
|
export {
|
|
86
73
|
createEnv,
|
|
87
|
-
|
|
74
|
+
createEnv as default
|
|
88
75
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkenv",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"bugs": "https://github.com/yamcodes/arkenv/labels/arkenv",
|
|
32
32
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@ark/schema": "^0.
|
|
35
|
-
"@types/node": "
|
|
34
|
+
"@ark/schema": "^0.49.0",
|
|
35
|
+
"@types/node": "24.3.1",
|
|
36
36
|
"tsup": "^8.5.0",
|
|
37
37
|
"typescript": "^5.9.2"
|
|
38
38
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"arktype": "^2.1.22"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"chalk": "^5.6.
|
|
43
|
+
"chalk": "^5.6.2"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rimraf dist && tsup",
|