arkenv 0.7.0 → 0.7.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.
- package/README.md +63 -44
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,24 +1,72 @@
|
|
|
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 />
|
|
4
2
|
<a href="https://arkenv.js.org">
|
|
5
3
|
<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">
|
|
6
4
|
</a>
|
|
7
5
|
<br />
|
|
8
6
|
<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>
|
|
9
|
-
<
|
|
7
|
+
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/arkenv">
|
|
10
8
|
<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
9
|
<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
10
|
<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
11
|
<a href="https://bun.com/"><img alt="Bun" src="https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df"></a>
|
|
14
12
|
<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://
|
|
13
|
+
<a href="https://discord.com/channels/957797212103016458/1415373591394127894"><img alt="Chat on Discord" src="https://img.shields.io/discord/957797212103016458?label=Chat&color=5865f4&logo=discord&labelColor=121214"></a>
|
|
16
14
|
</p>
|
|
15
|
+
<h3 align="center">Proud member of the <a href="https://arktype.io/docs/ecosystem#arkenv">ArkType ecosystem</a></h3>
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img alt="ArkEnv Demo" src="https://arkenv.js.org/assets/demo.gif" />
|
|
19
|
+
</p>
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
<br/>
|
|
22
|
+
<br/>
|
|
23
|
+
<br/>
|
|
24
|
+
|
|
25
|
+
### [Read the docs →](https://arkenv.js.org/docs)
|
|
26
|
+
|
|
27
|
+
<br/>
|
|
28
|
+
<br/>
|
|
29
|
+
|
|
30
|
+
## Introduction
|
|
31
|
+
|
|
32
|
+
> [!TIP]
|
|
33
|
+
> 📖 **Reading this on GitHub?** Check out [this page in our docs](https://arkenv.js.org/docs) to hover over code blocks and get type hints!
|
|
34
|
+
|
|
35
|
+
ArkEnv is an environment variable parser powered by [ArkType](https://arktype.io/), TypeScript's 1:1 validator. ArkEnv lets you use familiar TypeScript-like syntax to create a ready to use, typesafe environment variable object:
|
|
36
|
+
|
|
37
|
+
```ts twoslash
|
|
38
|
+
import arkenv from 'arkenv';
|
|
39
|
+
|
|
40
|
+
const env = arkenv({
|
|
41
|
+
HOST: "string.host", // valid IP address or localhost
|
|
42
|
+
PORT: "number.port", // valid port number (0-65535)
|
|
43
|
+
NODE_ENV: "'development' | 'production' | 'test'",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Hover to see ✨exact✨ types
|
|
47
|
+
const host = env.HOST;
|
|
48
|
+
const port = env.PORT;
|
|
49
|
+
const nodeEnv = env.NODE_ENV;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
With ArkEnv, your environment variables are **guaranteed to match your schema**. If any variable is incorrect or missing, the app won't start and a clear error will be thrown:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
ArkEnvError: Errors found while validating environment variables
|
|
56
|
+
HOST must be a string or "localhost" (was missing)
|
|
57
|
+
PORT must be an integer between 0 and 65535 (was "hello")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
- Zero external dependencies
|
|
63
|
+
- Works in Node.js, Bun, and Vite
|
|
64
|
+
- Tiny: <1kB gzipped
|
|
65
|
+
- Build-time and runtime validation
|
|
66
|
+
- Single import, zero config for most projects
|
|
67
|
+
- Validated, defaultable, typesafe environment variables
|
|
68
|
+
- Powered by ArkType, TypeScript's 1:1 validator
|
|
69
|
+
- Optimized from editor to runtime
|
|
22
70
|
|
|
23
71
|
## Installation
|
|
24
72
|
|
|
@@ -54,53 +102,24 @@ bun add arkenv arktype
|
|
|
54
102
|
```
|
|
55
103
|
</details>
|
|
56
104
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import arkenv from 'arkenv';
|
|
61
|
-
|
|
62
|
-
const env = arkenv({
|
|
63
|
-
HOST: "string.host", // valid IP address or localhost
|
|
64
|
-
PORT: "number.port", // valid port number (0-65535)
|
|
65
|
-
NODE_ENV: "'development' | 'production' | 'test'",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Automatically validate and parse process.env
|
|
70
|
-
// TypeScript knows the ✨exact✨ types!
|
|
71
|
-
console.log(env.HOST); // (property) HOST: string
|
|
72
|
-
console.log(env.PORT); // (property) PORT: number
|
|
73
|
-
console.log(env.NODE_ENV); // (property) NODE_ENV: "development" | "production" | "test"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
You can find more examples in the [examples](https://github.com/yamcodes/arkenv/tree/main/examples) directory.
|
|
105
|
+
:rocket: **Let's get started!** Read the [2-minute setup guide](https://arkenv.js.org/docs/quickstart) or [start with an example](https://arkenv.js.org/docs/examples).
|
|
77
106
|
|
|
78
107
|
> [!TIP]
|
|
79
|
-
>
|
|
80
|
-
> 
|
|
108
|
+
> Improve your DX with *syntax highlighting* in [VS Code & Cursor](https://arkenv.js.org/docs/integrations/vscode) or [JetBrains IDEs](https://arkenv.js.org/docs/integrations/jetbrains).
|
|
81
109
|
|
|
82
|
-
##
|
|
83
|
-
|
|
84
|
-
- 🔒 **Typesafe**: Full TypeScript support with inferred types
|
|
85
|
-
- 🚀 **Runtime validation**: Catch missing or invalid environment variables early
|
|
86
|
-
- 💪 **Powered by ArkType**: Leverage ArkType's powerful type system
|
|
87
|
-
- 🪶 **Lightweight**: Zero dependencies, [tiny bundle size](https://bundlephobia.com/package/arkenv)
|
|
88
|
-
- ⚡ **Fast**: Optimized for performance with minimal overhead
|
|
89
|
-
|
|
90
|
-
## Documentation
|
|
110
|
+
## Requirements
|
|
91
111
|
|
|
92
|
-
|
|
112
|
+
- TypeScript >= 5.1 and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
|
|
113
|
+
- [Node.js 22 LTS](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [Bun 1.2](https://github.com/yamcodes/arkenv/tree/main/examples/with-bun), and [Vite 7](https://github.com/yamcodes/arkenv/tree/main/examples/with-vite-react-ts) are tested. Older versions may work but aren't officially supported
|
|
93
114
|
|
|
94
115
|
## Plugins
|
|
95
116
|
|
|
96
|
-
- [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin)
|
|
117
|
+
- [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin)
|
|
97
118
|
|
|
98
119
|
## Supporting ArkEnv
|
|
99
120
|
|
|
100
|
-
If you love ArkEnv, you can support the project by starring it on GitHub
|
|
121
|
+
If you love ArkEnv, you can support the project by **starring it on GitHub**!
|
|
101
122
|
|
|
102
123
|
You are also welcome to directly [contribute to the project's development](https://github.com/yamcodes/arkenv/blob/main/CONTRIBUTING.md).
|
|
103
124
|
|
|
104
|
-
## Thanks / Inspiration
|
|
105
|
-
|
|
106
|
-
Find projects and people who helped or inspired the creation of ArkEnv in [THANKS.md](https://github.com/yamcodes/arkenv/blob/main/THANKS.md). Thank you 🙏
|
|
125
|
+
## [Thanks / Inspiration](https://github.com/yamcodes/arkenv/blob/main/THANKS.md)
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ArkEnvError: () => ArkEnvError,
|
|
23
24
|
createEnv: () => createEnv,
|
|
24
25
|
default: () => index_default,
|
|
25
26
|
type: () => type4
|
|
@@ -106,6 +107,7 @@ var arkenv = createEnv;
|
|
|
106
107
|
var index_default = arkenv;
|
|
107
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
109
|
0 && (module.exports = {
|
|
110
|
+
ArkEnvError,
|
|
109
111
|
createEnv,
|
|
110
112
|
type
|
|
111
113
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as arktype from 'arktype';
|
|
2
|
-
import { type as type$1, distill } from 'arktype';
|
|
2
|
+
import { type as type$1, distill, ArkErrors } from 'arktype';
|
|
3
3
|
import * as arktype_internal_attributes_ts from 'arktype/internal/attributes.ts';
|
|
4
4
|
import * as arktype_internal_keywords_string_ts from 'arktype/internal/keywords/string.ts';
|
|
5
5
|
import * as arktype_internal_type_ts from 'arktype/internal/type.ts';
|
|
@@ -81,14 +81,18 @@ declare const $: arktype.Scope<{
|
|
|
81
81
|
|
|
82
82
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
83
83
|
type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
|
|
84
|
+
/**
|
|
85
|
+
* TODO: If possible, find a better type than "const T extends Record<string, unknown>",
|
|
86
|
+
* and be as close as possible to the type accepted by ArkType's `type`.
|
|
87
|
+
*/
|
|
84
88
|
/**
|
|
85
89
|
* Create an environment variables object from a schema and an environment
|
|
86
90
|
* @param def - The environment variable schema
|
|
87
91
|
* @param env - The environment variables to validate, defaults to `process.env`
|
|
88
92
|
* @returns The validated environment variable schema
|
|
89
|
-
* @throws An error if the environment variables are invalid.
|
|
93
|
+
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
94
|
*/
|
|
91
|
-
declare function createEnv<const T extends Record<string,
|
|
95
|
+
declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
|
|
92
96
|
|
|
93
97
|
declare const type: arktype_internal_type_ts.TypeParser<{
|
|
94
98
|
string: arktype.Submodule<{
|
|
@@ -162,6 +166,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
|
|
|
162
166
|
}>;
|
|
163
167
|
}>;
|
|
164
168
|
|
|
169
|
+
declare class ArkEnvError extends Error {
|
|
170
|
+
constructor(errors: ArkErrors, message?: string);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
175
|
+
*
|
|
176
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.
|
|
177
|
+
*/
|
|
165
178
|
declare const arkenv: typeof createEnv;
|
|
166
179
|
|
|
167
|
-
export { type EnvSchema, createEnv, arkenv as default, type };
|
|
180
|
+
export { ArkEnvError, type EnvSchema, createEnv, arkenv as default, type };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as arktype from 'arktype';
|
|
2
|
-
import { type as type$1, distill } from 'arktype';
|
|
2
|
+
import { type as type$1, distill, ArkErrors } from 'arktype';
|
|
3
3
|
import * as arktype_internal_attributes_ts from 'arktype/internal/attributes.ts';
|
|
4
4
|
import * as arktype_internal_keywords_string_ts from 'arktype/internal/keywords/string.ts';
|
|
5
5
|
import * as arktype_internal_type_ts from 'arktype/internal/type.ts';
|
|
@@ -81,14 +81,18 @@ declare const $: arktype.Scope<{
|
|
|
81
81
|
|
|
82
82
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
83
83
|
type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
|
|
84
|
+
/**
|
|
85
|
+
* TODO: If possible, find a better type than "const T extends Record<string, unknown>",
|
|
86
|
+
* and be as close as possible to the type accepted by ArkType's `type`.
|
|
87
|
+
*/
|
|
84
88
|
/**
|
|
85
89
|
* Create an environment variables object from a schema and an environment
|
|
86
90
|
* @param def - The environment variable schema
|
|
87
91
|
* @param env - The environment variables to validate, defaults to `process.env`
|
|
88
92
|
* @returns The validated environment variable schema
|
|
89
|
-
* @throws An error if the environment variables are invalid.
|
|
93
|
+
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
94
|
*/
|
|
91
|
-
declare function createEnv<const T extends Record<string,
|
|
95
|
+
declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
|
|
92
96
|
|
|
93
97
|
declare const type: arktype_internal_type_ts.TypeParser<{
|
|
94
98
|
string: arktype.Submodule<{
|
|
@@ -162,6 +166,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
|
|
|
162
166
|
}>;
|
|
163
167
|
}>;
|
|
164
168
|
|
|
169
|
+
declare class ArkEnvError extends Error {
|
|
170
|
+
constructor(errors: ArkErrors, message?: string);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
175
|
+
*
|
|
176
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.
|
|
177
|
+
*/
|
|
165
178
|
declare const arkenv: typeof createEnv;
|
|
166
179
|
|
|
167
|
-
export { type EnvSchema, createEnv, arkenv as default, type };
|
|
180
|
+
export { ArkEnvError, type EnvSchema, createEnv, arkenv as default, type };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkenv",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@ark/schema": "^0.49.0",
|
|
35
|
-
"@types/node": "24.
|
|
35
|
+
"@types/node": "24.6.2",
|
|
36
36
|
"tsup": "^8.5.0",
|
|
37
|
-
"typescript": "^5.9.
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"arktype": "^2.1.22"
|