arkenv 0.6.0 → 0.7.1
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 +59 -42
- package/dist/index.cjs +11 -15
- package/dist/index.d.cts +16 -6
- package/dist/index.d.ts +16 -6
- package/dist/index.js +10 -5
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -1,24 +1,67 @@
|
|
|
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
|
+
<br/>
|
|
18
|
+
<br/>
|
|
19
|
+
<br/>
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
### [Read the docs →](https://arkenv.js.org/docs)
|
|
22
|
+
|
|
23
|
+
<br/>
|
|
24
|
+
<br/>
|
|
25
|
+
|
|
26
|
+
## Introduction
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
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:
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
```ts twoslash
|
|
33
|
+
import arkenv from 'arkenv';
|
|
34
|
+
|
|
35
|
+
const env = arkenv({
|
|
36
|
+
HOST: "string.host", // valid IP address or localhost
|
|
37
|
+
PORT: "number.port", // valid port number (0-65535)
|
|
38
|
+
NODE_ENV: "'development' | 'production' | 'test'",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Automatically validate and parse process.env
|
|
43
|
+
// TypeScript knows the ✨exact✨ types!
|
|
44
|
+
console.log(env.HOST); // (property) HOST: string
|
|
45
|
+
console.log(env.PORT); // (property) PORT: number
|
|
46
|
+
console.log(env.NODE_ENV); // (property) NODE_ENV: "development" | "production" | "test"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
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:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
ArkEnvError: Errors found while validating environment variables
|
|
53
|
+
HOST must be a string or "localhost" (was missing)
|
|
54
|
+
PORT must be an integer between 0 and 65535 (was "hello")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Features
|
|
58
|
+
|
|
59
|
+
- Zero external dependencies
|
|
60
|
+
- Works in Node.js, Bun, and Vite
|
|
61
|
+
- Tiny: <1kB gzipped
|
|
62
|
+
- Build-time and runtime validation
|
|
63
|
+
- Single import, zero config for most projects
|
|
64
|
+
- Powered by ArkType, TypeScript's 1:1 validator
|
|
22
65
|
|
|
23
66
|
## Installation
|
|
24
67
|
|
|
@@ -54,53 +97,27 @@ bun add arkenv arktype
|
|
|
54
97
|
```
|
|
55
98
|
</details>
|
|
56
99
|
|
|
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
|
-
});
|
|
100
|
+
: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).
|
|
67
101
|
|
|
68
102
|
|
|
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.
|
|
77
|
-
|
|
78
103
|
> [!TIP]
|
|
79
|
-
>
|
|
104
|
+
> Improve your DX with syntax highlighting in [VS Code & Cursor](/docs/integrations/vscode) or [JetBrains IDEs](/docs/integrations/jetbrains).
|
|
105
|
+
>
|
|
80
106
|
> 
|
|
81
107
|
|
|
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**: Only a single dependency ([see size](https://bundlephobia.com/package/arkenv))
|
|
88
|
-
- ⚡ **Fast**: Optimized for performance with minimal overhead
|
|
89
|
-
|
|
90
|
-
## Documentation
|
|
108
|
+
## Requirements
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
- TypeScript >= 5.1 and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
|
|
111
|
+
- [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
112
|
|
|
94
113
|
## Plugins
|
|
95
114
|
|
|
96
|
-
- [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin)
|
|
115
|
+
- [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin)
|
|
97
116
|
|
|
98
117
|
## Supporting ArkEnv
|
|
99
118
|
|
|
100
|
-
If you love ArkEnv, you can support the project by starring it on GitHub
|
|
119
|
+
If you love ArkEnv, you can support the project by **starring it on GitHub**!
|
|
101
120
|
|
|
102
121
|
You are also welcome to directly [contribute to the project's development](https://github.com/yamcodes/arkenv/blob/main/CONTRIBUTING.md).
|
|
103
122
|
|
|
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 🙏
|
|
123
|
+
## [Thanks / Inspiration](https://github.com/yamcodes/arkenv/blob/main/THANKS.md)
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,21 +15,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var index_exports = {};
|
|
32
22
|
__export(index_exports, {
|
|
23
|
+
ArkEnvError: () => ArkEnvError,
|
|
33
24
|
createEnv: () => createEnv,
|
|
34
|
-
default: () =>
|
|
25
|
+
default: () => index_default,
|
|
35
26
|
type: () => type4
|
|
36
27
|
});
|
|
37
28
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -40,7 +31,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
31
|
var import_arktype3 = require("arktype");
|
|
41
32
|
|
|
42
33
|
// src/errors.ts
|
|
43
|
-
var
|
|
34
|
+
var import_node_util = require("util");
|
|
44
35
|
|
|
45
36
|
// src/utils.ts
|
|
46
37
|
var indent = (str, amt = 2, { dontDetectNewlines = false } = {}) => {
|
|
@@ -57,13 +48,13 @@ var formatErrors = (errors) => Object.entries(errors.byPath).map(([path, error])
|
|
|
57
48
|
const valueMatch = messageWithoutPath.match(/\(was "([^"]+)"\)/);
|
|
58
49
|
const formattedMessage = valueMatch ? messageWithoutPath.replace(
|
|
59
50
|
`(was "${valueMatch[1]}")`,
|
|
60
|
-
`(was ${
|
|
51
|
+
`(was ${(0, import_node_util.styleText)("cyan", `"${valueMatch[1]}"`)})`
|
|
61
52
|
) : messageWithoutPath;
|
|
62
|
-
return `${
|
|
53
|
+
return `${(0, import_node_util.styleText)("yellow", path)}${formattedMessage}`;
|
|
63
54
|
}).join("\n");
|
|
64
55
|
var ArkEnvError = class extends Error {
|
|
65
56
|
constructor(errors, message = "Errors found while validating environment variables") {
|
|
66
|
-
super(`${
|
|
57
|
+
super(`${(0, import_node_util.styleText)("red", message)}
|
|
67
58
|
${indent(formatErrors(errors))}
|
|
68
59
|
`);
|
|
69
60
|
this.name = "ArkEnvError";
|
|
@@ -110,8 +101,13 @@ function createEnv(def, env = process.env) {
|
|
|
110
101
|
|
|
111
102
|
// src/type.ts
|
|
112
103
|
var type4 = $.type;
|
|
104
|
+
|
|
105
|
+
// src/index.ts
|
|
106
|
+
var arkenv = createEnv;
|
|
107
|
+
var index_default = arkenv;
|
|
113
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
109
|
0 && (module.exports = {
|
|
110
|
+
ArkEnvError,
|
|
115
111
|
createEnv,
|
|
116
112
|
type
|
|
117
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';
|
|
@@ -80,16 +80,15 @@ declare const $: arktype.Scope<{
|
|
|
80
80
|
}>;
|
|
81
81
|
|
|
82
82
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
83
|
-
type EnvSchema<def
|
|
83
|
+
type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
|
|
84
84
|
/**
|
|
85
85
|
* Create an environment variables object from a schema and an environment
|
|
86
86
|
* @param def - The environment variable schema
|
|
87
87
|
* @param env - The environment variables to validate, defaults to `process.env`
|
|
88
88
|
* @returns The validated environment variable schema
|
|
89
|
-
* @throws An error if the environment variables are invalid.
|
|
89
|
+
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
90
|
*/
|
|
91
|
-
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T
|
|
92
|
-
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T>>;
|
|
91
|
+
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
|
|
93
92
|
|
|
94
93
|
declare const type: arktype_internal_type_ts.TypeParser<{
|
|
95
94
|
string: arktype.Submodule<{
|
|
@@ -163,4 +162,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
|
|
|
163
162
|
}>;
|
|
164
163
|
}>;
|
|
165
164
|
|
|
166
|
-
|
|
165
|
+
declare class ArkEnvError extends Error {
|
|
166
|
+
constructor(errors: ArkErrors, message?: string);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
171
|
+
*
|
|
172
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.
|
|
173
|
+
*/
|
|
174
|
+
declare const arkenv: typeof createEnv;
|
|
175
|
+
|
|
176
|
+
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';
|
|
@@ -80,16 +80,15 @@ declare const $: arktype.Scope<{
|
|
|
80
80
|
}>;
|
|
81
81
|
|
|
82
82
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
83
|
-
type EnvSchema<def
|
|
83
|
+
type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
|
|
84
84
|
/**
|
|
85
85
|
* Create an environment variables object from a schema and an environment
|
|
86
86
|
* @param def - The environment variable schema
|
|
87
87
|
* @param env - The environment variables to validate, defaults to `process.env`
|
|
88
88
|
* @returns The validated environment variable schema
|
|
89
|
-
* @throws An error if the environment variables are invalid.
|
|
89
|
+
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
90
|
*/
|
|
91
|
-
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T
|
|
92
|
-
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T>>;
|
|
91
|
+
declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
|
|
93
92
|
|
|
94
93
|
declare const type: arktype_internal_type_ts.TypeParser<{
|
|
95
94
|
string: arktype.Submodule<{
|
|
@@ -163,4 +162,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
|
|
|
163
162
|
}>;
|
|
164
163
|
}>;
|
|
165
164
|
|
|
166
|
-
|
|
165
|
+
declare class ArkEnvError extends Error {
|
|
166
|
+
constructor(errors: ArkErrors, message?: string);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
171
|
+
*
|
|
172
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.
|
|
173
|
+
*/
|
|
174
|
+
declare const arkenv: typeof createEnv;
|
|
175
|
+
|
|
176
|
+
export { ArkEnvError, type EnvSchema, createEnv, arkenv as default, type };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type as type3 } from "arktype";
|
|
3
3
|
|
|
4
4
|
// src/errors.ts
|
|
5
|
-
import
|
|
5
|
+
import { styleText } from "util";
|
|
6
6
|
|
|
7
7
|
// src/utils.ts
|
|
8
8
|
var indent = (str, amt = 2, { dontDetectNewlines = false } = {}) => {
|
|
@@ -19,13 +19,13 @@ var formatErrors = (errors) => Object.entries(errors.byPath).map(([path, error])
|
|
|
19
19
|
const valueMatch = messageWithoutPath.match(/\(was "([^"]+)"\)/);
|
|
20
20
|
const formattedMessage = valueMatch ? messageWithoutPath.replace(
|
|
21
21
|
`(was "${valueMatch[1]}")`,
|
|
22
|
-
`(was ${
|
|
22
|
+
`(was ${styleText("cyan", `"${valueMatch[1]}"`)})`
|
|
23
23
|
) : messageWithoutPath;
|
|
24
|
-
return `${
|
|
24
|
+
return `${styleText("yellow", path)}${formattedMessage}`;
|
|
25
25
|
}).join("\n");
|
|
26
26
|
var ArkEnvError = class extends Error {
|
|
27
27
|
constructor(errors, message = "Errors found while validating environment variables") {
|
|
28
|
-
super(`${
|
|
28
|
+
super(`${styleText("red", message)}
|
|
29
29
|
${indent(formatErrors(errors))}
|
|
30
30
|
`);
|
|
31
31
|
this.name = "ArkEnvError";
|
|
@@ -72,8 +72,13 @@ function createEnv(def, env = process.env) {
|
|
|
72
72
|
|
|
73
73
|
// src/type.ts
|
|
74
74
|
var type4 = $.type;
|
|
75
|
+
|
|
76
|
+
// src/index.ts
|
|
77
|
+
var arkenv = createEnv;
|
|
78
|
+
var index_default = arkenv;
|
|
75
79
|
export {
|
|
80
|
+
ArkEnvError,
|
|
76
81
|
createEnv,
|
|
77
|
-
|
|
82
|
+
index_default as default,
|
|
78
83
|
type4 as type
|
|
79
84
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkenv",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -39,9 +39,6 @@
|
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"arktype": "^2.1.22"
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"chalk": "^5.6.2"
|
|
44
|
-
},
|
|
45
42
|
"scripts": {
|
|
46
43
|
"build": "rimraf dist && tsup",
|
|
47
44
|
"test:once": "pnpm test",
|