arkenv 0.5.0 → 0.7.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
@@ -6,13 +6,13 @@
6
6
  </a>
7
7
  <br />
8
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>
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>
10
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
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
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
13
  <a href="https://bun.com/"><img alt="Bun" src="https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df"></a>
14
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>
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
16
  </p>
17
17
 
18
18
  ## Requirements
@@ -84,7 +84,7 @@ You can find more examples in the [examples](https://github.com/yamcodes/arkenv/
84
84
  - 🔒 **Typesafe**: Full TypeScript support with inferred types
85
85
  - 🚀 **Runtime validation**: Catch missing or invalid environment variables early
86
86
  - 💪 **Powered by ArkType**: Leverage ArkType's powerful type system
87
- - 🪶 **Lightweight**: Only a single dependency ([see size](https://bundlephobia.com/package/arkenv))
87
+ - 🪶 **Lightweight**: Zero dependencies, [tiny bundle size](https://bundlephobia.com/package/arkenv)
88
88
  - ⚡ **Fast**: Optimized for performance with minimal overhead
89
89
 
90
90
  ## Documentation
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, {
33
23
  createEnv: () => createEnv,
34
- default: () => createEnv
24
+ default: () => index_default,
25
+ type: () => type4
35
26
  });
36
27
  module.exports = __toCommonJS(index_exports);
37
28
 
@@ -39,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
39
30
  var import_arktype3 = require("arktype");
40
31
 
41
32
  // src/errors.ts
42
- var import_chalk = __toESM(require("chalk"), 1);
33
+ var import_node_util = require("util");
43
34
 
44
35
  // src/utils.ts
45
36
  var indent = (str, amt = 2, { dontDetectNewlines = false } = {}) => {
@@ -56,13 +47,13 @@ var formatErrors = (errors) => Object.entries(errors.byPath).map(([path, error])
56
47
  const valueMatch = messageWithoutPath.match(/\(was "([^"]+)"\)/);
57
48
  const formattedMessage = valueMatch ? messageWithoutPath.replace(
58
49
  `(was "${valueMatch[1]}")`,
59
- `(was ${import_chalk.default.cyan(`"${valueMatch[1]}"`)})`
50
+ `(was ${(0, import_node_util.styleText)("cyan", `"${valueMatch[1]}"`)})`
60
51
  ) : messageWithoutPath;
61
- return `${import_chalk.default.yellow(path)}${formattedMessage}`;
52
+ return `${(0, import_node_util.styleText)("yellow", path)}${formattedMessage}`;
62
53
  }).join("\n");
63
54
  var ArkEnvError = class extends Error {
64
55
  constructor(errors, message = "Errors found while validating environment variables") {
65
- super(`${import_chalk.default.red(message)}
56
+ super(`${(0, import_node_util.styleText)("red", message)}
66
57
  ${indent(formatErrors(errors))}
67
58
  `);
68
59
  this.name = "ArkEnvError";
@@ -106,7 +97,15 @@ function createEnv(def, env = process.env) {
106
97
  }
107
98
  return validatedEnv;
108
99
  }
100
+
101
+ // src/type.ts
102
+ var type4 = $.type;
103
+
104
+ // src/index.ts
105
+ var arkenv = createEnv;
106
+ var index_default = arkenv;
109
107
  // Annotate the CommonJS export names for ESM import in node:
110
108
  0 && (module.exports = {
111
- createEnv
109
+ createEnv,
110
+ type
112
111
  });
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as arktype from 'arktype';
2
- import { type, distill } from 'arktype';
2
+ import { type as type$1, distill } 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
+ import * as arktype_internal_type_ts from 'arktype/internal/type.ts';
5
6
 
6
7
  /**
7
8
  * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.
@@ -79,7 +80,7 @@ declare const $: arktype.Scope<{
79
80
  }>;
80
81
 
81
82
  type RuntimeEnvironment = Record<string, string | undefined>;
82
- type EnvSchema<def, $ = {}> = type.validate<def, $>;
83
+ type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
83
84
  /**
84
85
  * Create an environment variables object from a schema and an environment
85
86
  * @param def - The environment variable schema
@@ -87,7 +88,80 @@ type EnvSchema<def, $ = {}> = type.validate<def, $>;
87
88
  * @returns The validated environment variable schema
88
89
  * @throws An error if the environment variables are invalid. See {@link ArkEnvError}
89
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
- declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.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"]>>;
92
92
 
93
- export { type EnvSchema, createEnv, createEnv as default };
93
+ declare const type: arktype_internal_type_ts.TypeParser<{
94
+ string: arktype.Submodule<{
95
+ root: string;
96
+ " arkInferred": string;
97
+ trim: arktype.Submodule<arktype_internal_keywords_string_ts.trim.$ & {
98
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
99
+ }>;
100
+ normalize: arktype.Submodule<arktype_internal_keywords_string_ts.normalize.$ & {
101
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
102
+ }>;
103
+ alpha: string;
104
+ alphanumeric: string;
105
+ hex: string;
106
+ base64: arktype.Submodule<{
107
+ root: string;
108
+ url: string;
109
+ } & {
110
+ " arkInferred": string;
111
+ }>;
112
+ capitalize: arktype.Submodule<arktype_internal_keywords_string_ts.capitalize.$ & {
113
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
114
+ }>;
115
+ creditCard: string;
116
+ date: arktype.Submodule<arktype_internal_keywords_string_ts.stringDate.$ & {
117
+ " arkInferred": string;
118
+ }>;
119
+ digits: string;
120
+ email: string;
121
+ integer: arktype.Submodule<arktype_internal_keywords_string_ts.stringInteger.$ & {
122
+ " arkInferred": string;
123
+ }>;
124
+ ip: arktype.Submodule<arktype_internal_keywords_string_ts.ip.$ & {
125
+ " arkInferred": string;
126
+ }>;
127
+ json: arktype.Submodule<arktype_internal_keywords_string_ts.stringJson.$ & {
128
+ " arkInferred": string;
129
+ }>;
130
+ lower: arktype.Submodule<arktype_internal_keywords_string_ts.lower.$ & {
131
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
132
+ }>;
133
+ numeric: arktype.Submodule<arktype_internal_keywords_string_ts.stringNumeric.$ & {
134
+ " arkInferred": string;
135
+ }>;
136
+ regex: string;
137
+ semver: string;
138
+ upper: arktype.Submodule<{
139
+ root: (In: string) => arktype_internal_attributes_ts.To<string>;
140
+ preformatted: string;
141
+ } & {
142
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
143
+ }>;
144
+ url: arktype.Submodule<arktype_internal_keywords_string_ts.url.$ & {
145
+ " arkInferred": string;
146
+ }>;
147
+ uuid: arktype.Submodule<arktype_internal_keywords_string_ts.uuid.$ & {
148
+ " arkInferred": string;
149
+ }>;
150
+ host: string;
151
+ }>;
152
+ number: arktype.Submodule<{
153
+ NaN: number;
154
+ Infinity: number;
155
+ root: number;
156
+ " arkInferred": number;
157
+ integer: number;
158
+ epoch: number;
159
+ safe: number;
160
+ NegativeInfinity: number;
161
+ port: (In: string) => arktype.Out<number>;
162
+ }>;
163
+ }>;
164
+
165
+ declare const arkenv: typeof createEnv;
166
+
167
+ export { type EnvSchema, createEnv, arkenv as default, type };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as arktype from 'arktype';
2
- import { type, distill } from 'arktype';
2
+ import { type as type$1, distill } 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
+ import * as arktype_internal_type_ts from 'arktype/internal/type.ts';
5
6
 
6
7
  /**
7
8
  * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.
@@ -79,7 +80,7 @@ declare const $: arktype.Scope<{
79
80
  }>;
80
81
 
81
82
  type RuntimeEnvironment = Record<string, string | undefined>;
82
- type EnvSchema<def, $ = {}> = type.validate<def, $>;
83
+ type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
83
84
  /**
84
85
  * Create an environment variables object from a schema and an environment
85
86
  * @param def - The environment variable schema
@@ -87,7 +88,80 @@ type EnvSchema<def, $ = {}> = type.validate<def, $>;
87
88
  * @returns The validated environment variable schema
88
89
  * @throws An error if the environment variables are invalid. See {@link ArkEnvError}
89
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
- declare function createEnv<const T extends Record<string, string | undefined>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type.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"]>>;
92
92
 
93
- export { type EnvSchema, createEnv, createEnv as default };
93
+ declare const type: arktype_internal_type_ts.TypeParser<{
94
+ string: arktype.Submodule<{
95
+ root: string;
96
+ " arkInferred": string;
97
+ trim: arktype.Submodule<arktype_internal_keywords_string_ts.trim.$ & {
98
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
99
+ }>;
100
+ normalize: arktype.Submodule<arktype_internal_keywords_string_ts.normalize.$ & {
101
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
102
+ }>;
103
+ alpha: string;
104
+ alphanumeric: string;
105
+ hex: string;
106
+ base64: arktype.Submodule<{
107
+ root: string;
108
+ url: string;
109
+ } & {
110
+ " arkInferred": string;
111
+ }>;
112
+ capitalize: arktype.Submodule<arktype_internal_keywords_string_ts.capitalize.$ & {
113
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
114
+ }>;
115
+ creditCard: string;
116
+ date: arktype.Submodule<arktype_internal_keywords_string_ts.stringDate.$ & {
117
+ " arkInferred": string;
118
+ }>;
119
+ digits: string;
120
+ email: string;
121
+ integer: arktype.Submodule<arktype_internal_keywords_string_ts.stringInteger.$ & {
122
+ " arkInferred": string;
123
+ }>;
124
+ ip: arktype.Submodule<arktype_internal_keywords_string_ts.ip.$ & {
125
+ " arkInferred": string;
126
+ }>;
127
+ json: arktype.Submodule<arktype_internal_keywords_string_ts.stringJson.$ & {
128
+ " arkInferred": string;
129
+ }>;
130
+ lower: arktype.Submodule<arktype_internal_keywords_string_ts.lower.$ & {
131
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
132
+ }>;
133
+ numeric: arktype.Submodule<arktype_internal_keywords_string_ts.stringNumeric.$ & {
134
+ " arkInferred": string;
135
+ }>;
136
+ regex: string;
137
+ semver: string;
138
+ upper: arktype.Submodule<{
139
+ root: (In: string) => arktype_internal_attributes_ts.To<string>;
140
+ preformatted: string;
141
+ } & {
142
+ " arkInferred": (In: string) => arktype_internal_attributes_ts.To<string>;
143
+ }>;
144
+ url: arktype.Submodule<arktype_internal_keywords_string_ts.url.$ & {
145
+ " arkInferred": string;
146
+ }>;
147
+ uuid: arktype.Submodule<arktype_internal_keywords_string_ts.uuid.$ & {
148
+ " arkInferred": string;
149
+ }>;
150
+ host: string;
151
+ }>;
152
+ number: arktype.Submodule<{
153
+ NaN: number;
154
+ Infinity: number;
155
+ root: number;
156
+ " arkInferred": number;
157
+ integer: number;
158
+ epoch: number;
159
+ safe: number;
160
+ NegativeInfinity: number;
161
+ port: (In: string) => arktype.Out<number>;
162
+ }>;
163
+ }>;
164
+
165
+ declare const arkenv: typeof createEnv;
166
+
167
+ export { 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 chalk from "chalk";
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 ${chalk.cyan(`"${valueMatch[1]}"`)})`
22
+ `(was ${styleText("cyan", `"${valueMatch[1]}"`)})`
23
23
  ) : messageWithoutPath;
24
- return `${chalk.yellow(path)}${formattedMessage}`;
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(`${chalk.red(message)}
28
+ super(`${styleText("red", message)}
29
29
  ${indent(formatErrors(errors))}
30
30
  `);
31
31
  this.name = "ArkEnvError";
@@ -69,7 +69,15 @@ function createEnv(def, env = process.env) {
69
69
  }
70
70
  return validatedEnv;
71
71
  }
72
+
73
+ // src/type.ts
74
+ var type4 = $.type;
75
+
76
+ // src/index.ts
77
+ var arkenv = createEnv;
78
+ var index_default = arkenv;
72
79
  export {
73
80
  createEnv,
74
- createEnv as default
81
+ index_default as default,
82
+ type4 as type
75
83
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arkenv",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.7.0",
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",