arkenv 0.3.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 CHANGED
@@ -1,7 +1,106 @@
1
- # `arkenv`
2
-
3
- Hello, developers! Welcome to the `arkenv` package codebase. This directory contains the core implementation of ArkEnv, providing typesafe environment variable parsing and validation for Node.js.
4
-
5
- For more information, please refer to the [README](../../README.md) in the monorepo root.
6
-
7
- Happy coding!
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
+ <a href="https://arkenv.js.org">
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">
6
+ </a>
7
+ <br />
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>
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>
16
+ </p>
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
+
23
+ ## Installation
24
+
25
+ <details open>
26
+ <summary>npm</summary>
27
+
28
+ ```sh
29
+ npm install arkenv arktype
30
+ ```
31
+ </details>
32
+
33
+ <details>
34
+ <summary>pnpm</summary>
35
+
36
+ ```sh
37
+ pnpm add arkenv arktype
38
+ ```
39
+ </details>
40
+
41
+ <details>
42
+ <summary>Yarn</summary>
43
+
44
+ ```sh
45
+ yarn add arkenv arktype
46
+ ```
47
+ </details>
48
+
49
+ <details>
50
+ <summary>Bun</summary>
51
+
52
+ ```sh
53
+ bun add arkenv arktype
54
+ ```
55
+ </details>
56
+
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
+ });
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.
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
+ > ![ArkType syntax highlighting in VS Code](https://raw.githubusercontent.com/yamcodes/arkenv/main/assets/dx.png)
81
+
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**: Only a single dependency ([see size](https://bundlephobia.com/package/arkenv))
88
+ - ⚡ **Fast**: Optimized for performance with minimal overhead
89
+
90
+ ## Documentation
91
+
92
+ For detailed documentation and examples, please visit our [documentation site](https://arkenv.js.org/docs).
93
+
94
+ ## Plugins
95
+
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
97
+
98
+ ## Supporting ArkEnv
99
+
100
+ If you love ArkEnv, you can support the project by starring it on GitHub!
101
+
102
+ You are also welcome to directly [contribute to the project's development](https://github.com/yamcodes/arkenv/blob/main/CONTRIBUTING.md).
103
+
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 🙏
package/dist/index.cjs CHANGED
@@ -31,18 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  createEnv: () => createEnv,
34
- default: () => index_default,
35
- host: () => host,
36
- port: () => port
34
+ default: () => createEnv
37
35
  });
38
36
  module.exports = __toCommonJS(index_exports);
39
37
 
40
- // src/define-env.ts
41
- var define_env_exports = {};
42
- __export(define_env_exports, {
43
- createEnv: () => createEnv
44
- });
45
- var import_arktype = require("arktype");
38
+ // src/create-env.ts
39
+ var import_arktype3 = require("arktype");
46
40
 
47
41
  // src/errors.ts
48
42
  var import_chalk = __toESM(require("chalk"), 1);
@@ -75,31 +69,13 @@ ${indent(formatErrors(errors))}
75
69
  }
76
70
  };
77
71
 
78
- // src/define-env.ts
79
- var createEnv = (def, env = process.env) => {
80
- const schema = (0, import_arktype.type)(def);
81
- const requiredEnvKeys = Object.keys(
82
- def
83
- );
84
- const filteredEnvVars = Object.fromEntries(
85
- Object.entries(env).filter(([key]) => requiredEnvKeys.includes(key))
86
- );
87
- const validatedEnv = schema(filteredEnvVars);
88
- if (validatedEnv instanceof import_arktype.type.errors) {
89
- throw new ArkEnvError(validatedEnv);
90
- }
91
- return validatedEnv;
92
- };
72
+ // src/scope.ts
73
+ var import_arktype2 = require("arktype");
93
74
 
94
75
  // src/types.ts
95
- var types_exports = {};
96
- __export(types_exports, {
97
- host: () => host,
98
- port: () => port
99
- });
100
- var import_arktype2 = require("arktype");
101
- var port = (0, import_arktype2.type)("string", "=>", (data, ctx) => {
102
- const asNumber = Number.parseInt(data);
76
+ var import_arktype = require("arktype");
77
+ var port = (0, import_arktype.type)("string", "=>", (data, ctx) => {
78
+ const asNumber = Number.parseInt(data, 10);
103
79
  const isInteger = Number.isInteger(asNumber);
104
80
  const isBetween = 0 <= asNumber && asNumber <= 65535;
105
81
  if (!isInteger || !isBetween) {
@@ -107,13 +83,30 @@ var port = (0, import_arktype2.type)("string", "=>", (data, ctx) => {
107
83
  }
108
84
  return asNumber;
109
85
  });
110
- var host = (0, import_arktype2.type)("string.ip | 'localhost'");
86
+ var host = (0, import_arktype.type)("string.ip | 'localhost'");
111
87
 
112
- // src/index.ts
113
- var index_default = { ...define_env_exports, ...types_exports };
88
+ // src/scope.ts
89
+ var $ = (0, import_arktype2.scope)({
90
+ string: import_arktype2.type.module({
91
+ ...import_arktype2.type.keywords.string,
92
+ host
93
+ }),
94
+ number: import_arktype2.type.module({
95
+ ...import_arktype2.type.keywords.number,
96
+ port
97
+ })
98
+ });
99
+
100
+ // src/create-env.ts
101
+ function createEnv(def, env = process.env) {
102
+ const schema = $.type.raw(def);
103
+ const validatedEnv = schema(env);
104
+ if (validatedEnv instanceof import_arktype3.type.errors) {
105
+ throw new ArkEnvError(validatedEnv);
106
+ }
107
+ return validatedEnv;
108
+ }
114
109
  // Annotate the CommonJS export names for ESM import in node:
115
110
  0 && (module.exports = {
116
- createEnv,
117
- host,
118
- port
111
+ createEnv
119
112
  });
package/dist/index.d.cts CHANGED
@@ -1,34 +1,93 @@
1
1
  import * as arktype from 'arktype';
2
2
  import { type, distill } from 'arktype';
3
- import * as arktype_internal_methods_string_ts from 'arktype/internal/methods/string.ts';
4
- import * as arktype_internal_methods_morph_ts from 'arktype/internal/methods/morph.ts';
5
3
  import * as arktype_internal_attributes_ts from 'arktype/internal/attributes.ts';
4
+ import * as arktype_internal_keywords_string_ts from 'arktype/internal/keywords/string.ts';
6
5
 
7
- type UserEnvironment = Record<string, string | undefined>;
8
- type EnvSchema<T extends Record<string, string | undefined> = Record<string, string | undefined>> = type.validate<T>;
9
6
  /**
10
- * Define an environment variable schema and validate it against a given environment (defaults to `process.env`)
11
- * @param def - The environment variable schema
12
- * @param env - The environment variables to validate, defaults to `process.env`
13
- * @returns The validated environment variable schema
7
+ * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.
14
8
  */
15
- declare const createEnv: <const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: UserEnvironment) => distill.Out<type.infer<T>>;
9
+ declare const $: arktype.Scope<{
10
+ string: arktype.Submodule<{
11
+ root: string;
12
+ " arkInferred": string;
13
+ trim: arktype.Submodule<arktype_internal_keywords_string_ts.trim.$ & {
14
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
15
+ }>;
16
+ normalize: arktype.Submodule<arktype_internal_keywords_string_ts.normalize.$ & {
17
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
18
+ }>;
19
+ alpha: string;
20
+ alphanumeric: string;
21
+ hex: string;
22
+ base64: arktype.Submodule<{
23
+ root: string;
24
+ url: string;
25
+ } & {
26
+ " arkInferred": string;
27
+ }>;
28
+ capitalize: arktype.Submodule<arktype_internal_keywords_string_ts.capitalize.$ & {
29
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
30
+ }>;
31
+ creditCard: string;
32
+ date: arktype.Submodule<arktype_internal_keywords_string_ts.stringDate.$ & {
33
+ " arkInferred": string;
34
+ }>;
35
+ digits: string;
36
+ email: string;
37
+ integer: arktype.Submodule<arktype_internal_keywords_string_ts.stringInteger.$ & {
38
+ " arkInferred": string;
39
+ }>;
40
+ ip: arktype.Submodule<arktype_internal_keywords_string_ts.ip.$ & {
41
+ " arkInferred": string;
42
+ }>;
43
+ json: arktype.Submodule<arktype_internal_keywords_string_ts.stringJson.$ & {
44
+ " arkInferred": string;
45
+ }>;
46
+ lower: arktype.Submodule<arktype_internal_keywords_string_ts.lower.$ & {
47
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
48
+ }>;
49
+ numeric: arktype.Submodule<arktype_internal_keywords_string_ts.stringNumeric.$ & {
50
+ " arkInferred": string;
51
+ }>;
52
+ regex: string;
53
+ semver: string;
54
+ upper: arktype.Submodule<{
55
+ root: (In: string) => arktype_internal_attributes_ts.To<string>;
56
+ preformatted: string;
57
+ } & {
58
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
59
+ }>;
60
+ url: arktype.Submodule<arktype_internal_keywords_string_ts.url.$ & {
61
+ " arkInferred": string;
62
+ }>;
63
+ uuid: arktype.Submodule<arktype_internal_keywords_string_ts.uuid.$ & {
64
+ " arkInferred": string;
65
+ }>;
66
+ host: string;
67
+ }>;
68
+ number: arktype.Submodule<{
69
+ NaN: number;
70
+ Infinity: number;
71
+ root: number;
72
+ " arkInferred": number;
73
+ integer: number;
74
+ epoch: number;
75
+ safe: number;
76
+ NegativeInfinity: number;
77
+ port: (In: string) => arktype.Out<number>;
78
+ }>;
79
+ }>;
16
80
 
81
+ type RuntimeEnvironment = Record<string, string | undefined>;
82
+ type EnvSchema<def, $ = {}> = type.validate<def, $>;
17
83
  /**
18
- * A `string` that can be parsed into a number between 0 and 65535
19
- */
20
- declare const port: arktype_internal_methods_morph_ts.MorphType<(In: string) => arktype_internal_attributes_ts.Out<number>, {}>;
21
- /**
22
- * An IP address or `"localhost"`
84
+ * Create an environment variables object from a schema and an environment
85
+ * @param def - The environment variable schema
86
+ * @param env - The environment variables to validate, defaults to `process.env`
87
+ * @returns The validated environment variable schema
88
+ * @throws An error if the environment variables are invalid. See {@link ArkEnvError}
23
89
  */
24
- declare const host: arktype_internal_methods_string_ts.StringType<string, {}>;
25
-
26
- declare const _default: {
27
- port: arktype_internal_methods_morph_ts.MorphType<(In: string) => arktype_internal_attributes_ts.Out<number>, {}>;
28
- host: arktype_internal_methods_string_ts.StringType<string, {}>;
29
- createEnv: <const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: {
30
- [x: string]: string | undefined;
31
- }) => arktype.distill.Out<arktype.type.infer<T>>;
32
- };
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
+ declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.infer<T>>;
33
92
 
34
- export { type EnvSchema, createEnv, _default as default, host, port };
93
+ export { type EnvSchema, createEnv, createEnv as default };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,93 @@
1
1
  import * as arktype from 'arktype';
2
2
  import { type, distill } from 'arktype';
3
- import * as arktype_internal_methods_string_ts from 'arktype/internal/methods/string.ts';
4
- import * as arktype_internal_methods_morph_ts from 'arktype/internal/methods/morph.ts';
5
3
  import * as arktype_internal_attributes_ts from 'arktype/internal/attributes.ts';
4
+ import * as arktype_internal_keywords_string_ts from 'arktype/internal/keywords/string.ts';
6
5
 
7
- type UserEnvironment = Record<string, string | undefined>;
8
- type EnvSchema<T extends Record<string, string | undefined> = Record<string, string | undefined>> = type.validate<T>;
9
6
  /**
10
- * Define an environment variable schema and validate it against a given environment (defaults to `process.env`)
11
- * @param def - The environment variable schema
12
- * @param env - The environment variables to validate, defaults to `process.env`
13
- * @returns The validated environment variable schema
7
+ * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.
14
8
  */
15
- declare const createEnv: <const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: UserEnvironment) => distill.Out<type.infer<T>>;
9
+ declare const $: arktype.Scope<{
10
+ string: arktype.Submodule<{
11
+ root: string;
12
+ " arkInferred": string;
13
+ trim: arktype.Submodule<arktype_internal_keywords_string_ts.trim.$ & {
14
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
15
+ }>;
16
+ normalize: arktype.Submodule<arktype_internal_keywords_string_ts.normalize.$ & {
17
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
18
+ }>;
19
+ alpha: string;
20
+ alphanumeric: string;
21
+ hex: string;
22
+ base64: arktype.Submodule<{
23
+ root: string;
24
+ url: string;
25
+ } & {
26
+ " arkInferred": string;
27
+ }>;
28
+ capitalize: arktype.Submodule<arktype_internal_keywords_string_ts.capitalize.$ & {
29
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
30
+ }>;
31
+ creditCard: string;
32
+ date: arktype.Submodule<arktype_internal_keywords_string_ts.stringDate.$ & {
33
+ " arkInferred": string;
34
+ }>;
35
+ digits: string;
36
+ email: string;
37
+ integer: arktype.Submodule<arktype_internal_keywords_string_ts.stringInteger.$ & {
38
+ " arkInferred": string;
39
+ }>;
40
+ ip: arktype.Submodule<arktype_internal_keywords_string_ts.ip.$ & {
41
+ " arkInferred": string;
42
+ }>;
43
+ json: arktype.Submodule<arktype_internal_keywords_string_ts.stringJson.$ & {
44
+ " arkInferred": string;
45
+ }>;
46
+ lower: arktype.Submodule<arktype_internal_keywords_string_ts.lower.$ & {
47
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
48
+ }>;
49
+ numeric: arktype.Submodule<arktype_internal_keywords_string_ts.stringNumeric.$ & {
50
+ " arkInferred": string;
51
+ }>;
52
+ regex: string;
53
+ semver: string;
54
+ upper: arktype.Submodule<{
55
+ root: (In: string) => arktype_internal_attributes_ts.To<string>;
56
+ preformatted: string;
57
+ } & {
58
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
59
+ }>;
60
+ url: arktype.Submodule<arktype_internal_keywords_string_ts.url.$ & {
61
+ " arkInferred": string;
62
+ }>;
63
+ uuid: arktype.Submodule<arktype_internal_keywords_string_ts.uuid.$ & {
64
+ " arkInferred": string;
65
+ }>;
66
+ host: string;
67
+ }>;
68
+ number: arktype.Submodule<{
69
+ NaN: number;
70
+ Infinity: number;
71
+ root: number;
72
+ " arkInferred": number;
73
+ integer: number;
74
+ epoch: number;
75
+ safe: number;
76
+ NegativeInfinity: number;
77
+ port: (In: string) => arktype.Out<number>;
78
+ }>;
79
+ }>;
16
80
 
81
+ type RuntimeEnvironment = Record<string, string | undefined>;
82
+ type EnvSchema<def, $ = {}> = type.validate<def, $>;
17
83
  /**
18
- * A `string` that can be parsed into a number between 0 and 65535
19
- */
20
- declare const port: arktype_internal_methods_morph_ts.MorphType<(In: string) => arktype_internal_attributes_ts.Out<number>, {}>;
21
- /**
22
- * An IP address or `"localhost"`
84
+ * Create an environment variables object from a schema and an environment
85
+ * @param def - The environment variable schema
86
+ * @param env - The environment variables to validate, defaults to `process.env`
87
+ * @returns The validated environment variable schema
88
+ * @throws An error if the environment variables are invalid. See {@link ArkEnvError}
23
89
  */
24
- declare const host: arktype_internal_methods_string_ts.StringType<string, {}>;
25
-
26
- declare const _default: {
27
- port: arktype_internal_methods_morph_ts.MorphType<(In: string) => arktype_internal_attributes_ts.Out<number>, {}>;
28
- host: arktype_internal_methods_string_ts.StringType<string, {}>;
29
- createEnv: <const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: {
30
- [x: string]: string | undefined;
31
- }) => arktype.distill.Out<arktype.type.infer<T>>;
32
- };
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
+ declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.infer<T>>;
33
92
 
34
- export { type EnvSchema, createEnv, _default as default, host, port };
93
+ export { type EnvSchema, createEnv, createEnv as default };
package/dist/index.js CHANGED
@@ -1,15 +1,5 @@
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
- // src/define-env.ts
8
- var define_env_exports = {};
9
- __export(define_env_exports, {
10
- createEnv: () => createEnv
11
- });
12
- import { type } from "arktype";
1
+ // src/create-env.ts
2
+ import { type as type3 } from "arktype";
13
3
 
14
4
  // src/errors.ts
15
5
  import chalk from "chalk";
@@ -42,31 +32,13 @@ ${indent(formatErrors(errors))}
42
32
  }
43
33
  };
44
34
 
45
- // src/define-env.ts
46
- var createEnv = (def, env = process.env) => {
47
- const schema = type(def);
48
- const requiredEnvKeys = Object.keys(
49
- def
50
- );
51
- const filteredEnvVars = Object.fromEntries(
52
- Object.entries(env).filter(([key]) => requiredEnvKeys.includes(key))
53
- );
54
- const validatedEnv = schema(filteredEnvVars);
55
- if (validatedEnv instanceof type.errors) {
56
- throw new ArkEnvError(validatedEnv);
57
- }
58
- return validatedEnv;
59
- };
35
+ // src/scope.ts
36
+ import { scope, type as type2 } from "arktype";
60
37
 
61
38
  // src/types.ts
62
- var types_exports = {};
63
- __export(types_exports, {
64
- host: () => host,
65
- port: () => port
66
- });
67
- import { type as type2 } from "arktype";
68
- var port = type2("string", "=>", (data, ctx) => {
69
- const asNumber = Number.parseInt(data);
39
+ import { type } from "arktype";
40
+ var port = type("string", "=>", (data, ctx) => {
41
+ const asNumber = Number.parseInt(data, 10);
70
42
  const isInteger = Number.isInteger(asNumber);
71
43
  const isBetween = 0 <= asNumber && asNumber <= 65535;
72
44
  if (!isInteger || !isBetween) {
@@ -74,13 +46,30 @@ var port = type2("string", "=>", (data, ctx) => {
74
46
  }
75
47
  return asNumber;
76
48
  });
77
- var host = type2("string.ip | 'localhost'");
49
+ var host = type("string.ip | 'localhost'");
50
+
51
+ // src/scope.ts
52
+ var $ = scope({
53
+ string: type2.module({
54
+ ...type2.keywords.string,
55
+ host
56
+ }),
57
+ number: type2.module({
58
+ ...type2.keywords.number,
59
+ port
60
+ })
61
+ });
78
62
 
79
- // src/index.ts
80
- var index_default = { ...define_env_exports, ...types_exports };
63
+ // src/create-env.ts
64
+ function createEnv(def, env = process.env) {
65
+ const schema = $.type.raw(def);
66
+ const validatedEnv = schema(env);
67
+ if (validatedEnv instanceof type3.errors) {
68
+ throw new ArkEnvError(validatedEnv);
69
+ }
70
+ return validatedEnv;
71
+ }
81
72
  export {
82
73
  createEnv,
83
- index_default as default,
84
- host,
85
- port
74
+ createEnv as default
86
75
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arkenv",
3
3
  "type": "module",
4
- "version": "0.3.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,22 +31,23 @@
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.46.0",
35
- "@types/node": "22.14.0",
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
  },
39
39
  "peerDependencies": {
40
- "arktype": "^2.0.2"
40
+ "arktype": "^2.1.22"
41
41
  },
42
42
  "dependencies": {
43
- "chalk": "^5.6.0"
43
+ "chalk": "^5.6.2"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && tsup",
47
47
  "test:once": "pnpm test",
48
48
  "typecheck": "tsc --noEmit",
49
49
  "clean": "rimraf dist node_modules",
50
- "test": "pnpm -w test --project arkenv"
50
+ "test": "pnpm -w test --project arkenv",
51
+ "fix": "pnpm -w run fix"
51
52
  }
52
53
  }