arkenv 0.7.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 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
- <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>
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://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>
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
- ## Requirements
17
+ <br/>
18
+ <br/>
19
+ <br/>
19
20
 
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))
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
- ## Quickstart
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
- > **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).
104
+ > Improve your DX with syntax highlighting in [VS Code & Cursor](/docs/integrations/vscode) or [JetBrains IDEs](/docs/integrations/jetbrains).
105
+ >
80
106
  > ![ArkType syntax highlighting in VS Code](https://raw.githubusercontent.com/yamcodes/arkenv/main/assets/dx.png)
81
107
 
82
- ## Features
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
108
+ ## Requirements
91
109
 
92
- For detailed documentation and examples, please visit our [documentation site](https://arkenv.js.org/docs).
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): [Vite](https://vite.dev/) plugin to validate environment variables at build time
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
@@ -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';
@@ -86,7 +86,7 @@ type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
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. See {@link ArkEnvError}
89
+ * @throws An {@link ArkEnvError | error} if the environment variables are invalid.
90
90
  */
91
91
  declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
92
92
 
@@ -162,6 +162,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
162
162
  }>;
163
163
  }>;
164
164
 
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
+ */
165
174
  declare const arkenv: typeof createEnv;
166
175
 
167
- export { type EnvSchema, createEnv, arkenv as default, type };
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';
@@ -86,7 +86,7 @@ type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
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. See {@link ArkEnvError}
89
+ * @throws An {@link ArkEnvError | error} if the environment variables are invalid.
90
90
  */
91
91
  declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
92
92
 
@@ -162,6 +162,15 @@ declare const type: arktype_internal_type_ts.TypeParser<{
162
162
  }>;
163
163
  }>;
164
164
 
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
+ */
165
174
  declare const arkenv: typeof createEnv;
166
175
 
167
- export { type EnvSchema, createEnv, arkenv as default, type };
176
+ export { ArkEnvError, type EnvSchema, createEnv, arkenv as default, type };
package/dist/index.js CHANGED
@@ -77,6 +77,7 @@ var type4 = $.type;
77
77
  var arkenv = createEnv;
78
78
  var index_default = arkenv;
79
79
  export {
80
+ ArkEnvError,
80
81
  createEnv,
81
82
  index_default as default,
82
83
  type4 as type
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arkenv",
3
3
  "type": "module",
4
- "version": "0.7.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",