arkenv 0.7.5 → 0.7.6

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
@@ -22,7 +22,7 @@
22
22
  <br/>
23
23
  <br/>
24
24
 
25
- ### [Read the docs →](https://arkenv.js.org/docs)
25
+ ### [Read the docs →](https://arkenv.js.org/docs/arkenv)
26
26
 
27
27
  <br/>
28
28
  <br/>
@@ -30,7 +30,7 @@
30
30
  ## Introduction
31
31
 
32
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!
33
+ > 📖 **Reading this on GitHub?** Check out [this page in our docs](https://arkenv.js.org/docs/arkenv) to hover over code blocks and get type hints!
34
34
 
35
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
36
 
@@ -60,7 +60,7 @@ ArkEnvError: Errors found while validating environment variables
60
60
  ## Features
61
61
 
62
62
  - Zero external dependencies
63
- - Works in Node.js, Bun, and Vite
63
+ - Works in Node.js and Bun
64
64
  - Tiny: <1kB gzipped
65
65
  - Build-time and runtime validation
66
66
  - Single import, zero config for most projects
@@ -110,11 +110,14 @@ bun add arkenv arktype
110
110
  ## Requirements
111
111
 
112
112
  - TypeScript >= 5.1 and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
113
- - Tested on [Node.js **LTS** and **Current**](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [Bun 1.2](https://github.com/yamcodes/arkenv/tree/main/examples/with-bun), and [Vite from **2.9.18** to **7.x**](https://github.com/yamcodes/arkenv/tree/main/examples/with-vite-react-ts). Older versions may work but are not officially supported
113
+ - [Modern TypeScript module resolution](https://www.typescriptlang.org/tsconfig/#moduleResolution). One of the following is required in your `tsconfig.json`:
114
+ - `"moduleResolution": "bundler"` - Recommended for modern bundlers (Vite, Next.js, etc.). Supplied by default when using `"module": "Preserve"`.
115
+ - `"moduleResolution": "node16"` or `"nodenext"` - For Node.js projects. Supplied by default when using a matching `"module"` value.
116
+ - Tested on [Node.js **LTS** and **Current** (22 and 25 at the time of this writing, respectively)](https://github.com/yamcodes/arkenv/tree/main/examples/basic) and [Bun **1.2**](https://github.com/yamcodes/arkenv/tree/main/examples/with-bun). Older versions may work but are not officially supported
114
117
 
115
118
  ## Plugins
116
119
 
117
- - [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin)
120
+ - [@arkenv/vite-plugin](https://github.com/yamcodes/arkenv/tree/main/packages/vite-plugin) (currently under development) - Vite plugin to validate environment variables at build-time. Requires [Vite from **2.9.18** to **7.x**](https://github.com/yamcodes/arkenv/tree/main/apps/playgrounds/vite).
118
121
 
119
122
  ## Supporting ArkEnv
120
123
 
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`arktype`);c=s(c);const l={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},u=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,d=()=>!!(!u()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),f=(e,t)=>u()&&!d()?`${l[e]}${t}${l.reset}`:t,p=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
1
+ Object.defineProperty(exports,`__esModule`,{value:!0});let e=require(`arktype`);const t={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},n=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,r=()=>!!(!n()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),i=(e,i)=>n()&&!r()?`${t[e]}${i}${t.reset}`:i,a=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
2
2
  `).map(e=>`${` `.repeat(t)}${e}`).join(`
3
- `),m=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),i=r?n.replace(`(was "${r[1]}")`,`(was ${f(`cyan`,`"${r[1]}"`)})`):n;return`${f(`yellow`,e)}${i}`}).join(`
4
- `);var h=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${f(`red`,t)}\n${p(m(e))}\n`),this.name=`ArkEnvError`}};const g=(0,c.type)(`string`,`=>`,(e,t)=>{let n=Number.parseInt(e,10);return(!Number.isInteger(n)||!(0<=n&&n<=65535))&&t.mustBe(`an integer between 0 and 65535`),n}),_=(0,c.type)(`string.ip | 'localhost'`),v=(0,c.type)(`'true' | 'false' | true | false`,`=>`,e=>e===`true`||e===!0),y=(0,c.scope)({string:c.type.module({...c.type.keywords.string,host:_}),number:c.type.module({...c.type.keywords.number,port:g}),boolean:v});function b(e,t=process.env){let n=y.type.raw(e)(t);if(n instanceof c.type.errors)throw new h(n);return n}const x=y.type,S=b;var C=S;exports.ArkEnvError=h,exports.createEnv=b,exports.default=C,exports.type=x;
3
+ `),o=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),a=r?n.replace(`(was "${r[1]}")`,`(was ${i(`cyan`,`"${r[1]}"`)})`):n;return`${i(`yellow`,e)}${a}`}).join(`
4
+ `);var s=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${i(`red`,t)}\n${a(o(e))}\n`),this.name=`ArkEnvError`}};const c=(0,e.type)(`string`,`=>`,(e,t)=>{let n=Number.parseInt(e,10);return(!Number.isInteger(n)||!(0<=n&&n<=65535))&&t.mustBe(`an integer between 0 and 65535`),n}),l=(0,e.type)(`string.ip | 'localhost'`),u=(0,e.type)(`'true' | 'false' | true | false`,`=>`,e=>e===`true`||e===!0),d=(0,e.scope)({string:e.type.module({...e.type.keywords.string,host:l}),number:e.type.module({...e.type.keywords.number,port:c}),boolean:u});function f(t,n=process.env){let r=(typeof t==`function`&&`assert`in t?t:d.type.raw(t))(n);if(r instanceof e.type.errors)throw new s(r);return r}const p=d.type,m=f;var h=m;exports.ArkEnvError=s,exports.createEnv=f,exports.default=h,exports.type=p;
package/dist/index.d.cts CHANGED
@@ -83,19 +83,26 @@ declare const $: arktype16.Scope<{
83
83
  //#endregion
84
84
  //#region src/create-env.d.ts
85
85
  type RuntimeEnvironment = Record<string, string | undefined>;
86
- type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
86
+ type EnvSchema<def$1> = type$1.validate<def$1, (typeof $)["t"]>;
87
+ /**
88
+ * Extract the inferred type from an ArkType type definition by checking its call signature
89
+ * When a type definition is called, it returns either the validated value or type.errors
90
+ */
91
+ type InferType<T> = T extends ((value: Record<string, string | undefined>) => infer R) ? R extends type$1.errors ? never : R : T extends type$1.Any<infer U, infer _Scope> ? U : never;
87
92
  /**
88
93
  * TODO: If possible, find a better type than "const T extends Record<string, unknown>",
89
94
  * and be as close as possible to the type accepted by ArkType's `type`.
90
95
  */
91
96
  /**
92
97
  * Create an environment variables object from a schema and an environment
93
- * @param def - The environment variable schema
98
+ * @param def - The environment variable schema (raw object or type definition created with `type()`)
94
99
  * @param env - The environment variables to validate, defaults to `process.env`
95
100
  * @returns The validated environment variable schema
96
101
  * @throws An {@link ArkEnvError | error} if the environment variables are invalid.
97
102
  */
98
103
  declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
104
+ declare function createEnv<T extends type$1.Any>(def: T, env?: RuntimeEnvironment): InferType<T>;
105
+ declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T> | type$1.Any, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>> | InferType<typeof def>;
99
106
  //#endregion
100
107
  //#region src/type.d.ts
101
108
  declare const type: arktype_internal_type_ts0.TypeParser<{
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/scope.ts","../src/create-env.ts","../src/type.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAQa,aAAC;;;;IAUZ,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAVY,qBAAA,yDAAA;MAAA,cAAA,EAAA,MAAA;;;;ICJT,KAAA,qBAAqB,CAAM;MAEpB,IAAS,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;MAAsB,YAAA,EAAA,MAAA;IAAa,CAAA,GAAA;MAAtB,cAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;IAAQ,CAAA,CAAA;IAc1B,GAAA,qBAAS,+CAAA;MAAiB,cAAA,EAAA,MAAA;IAC1B,CAAA,CAAA;IAAV,IAAA,qBAAA,gDAAA;MACA,cAAA,EAAA,MAAA;IACoB,CAAA,CAAA;IAAW,cAAA,EAAA,MAAA;IAAjB,IAAA,EAAA,MAAA;EAAjB,CAAA,CAAA;EAAW,MAAA,qBAAA,CAAA;;;;ICrBD,OAAa,EAAA,MAAA;;;;;;;;;;;KDErB,kBAAA,GAAqB;KAEd,iBAAiB,MAAA,CAAK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,CAAA,GAAA;MAEO,cAAS,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;IAAsB,CAAA,CAAA;IAAa,GAAA,qBAAA,+CAAA;MAAtB,cAAA,EAAA,MAAA;IAAQ,CAAA,CAAA;IAMrC,IAAA,qBAAS,gDAAA;MAAM,cAAA,EAAA,MAAA;IACZ,CAAA,CAAA;IAEL,cAAA,EAAA,MAAA;IAAe,IAAA,EAAA,MAAA;EAEd,CAAA,CAAA;EACD,MAAA,qBAAA,CAAA;IAAe,GAAA,EAAA,MAAA;IACd,QAAA,EAAA,MAAA;IAAC,IAAA,EAAA,MAAA;IAeW,OAAA,EAAS,MAAA;IAAiB,cAAA,EAAA,MAAA;IAC1B,KAAA,EAAA,MAAA;IAAV,IAAA,EAAA,MAAA;IACC,gBAAA,EAAA,MAAA;IACmB,IAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,gBAAA,CAAA,MAAA,CAAA;EAAW,CAAA,CAAA;EAAtB,OAAK,EAAA,CAAA,EAAA,EAAA,OAAA,GAAA,OAAA,GAAA,MAAA,EAAA,gBAAA,CAAA,OAAA,CAAA;CAAjB,CAAA;;;AD7BU,cGqBA,WAAA,SAAoB,KAAA,CHX/B;sBGaQ;;;;;;;;;AHvBV,cICM,MJSJ,EAAA,OITU,SJSV"}
package/dist/index.d.ts CHANGED
@@ -83,19 +83,26 @@ declare const $: arktype16.Scope<{
83
83
  //#endregion
84
84
  //#region src/create-env.d.ts
85
85
  type RuntimeEnvironment = Record<string, string | undefined>;
86
- type EnvSchema<def> = type$1.validate<def, (typeof $)["t"]>;
86
+ type EnvSchema<def$1> = type$1.validate<def$1, (typeof $)["t"]>;
87
+ /**
88
+ * Extract the inferred type from an ArkType type definition by checking its call signature
89
+ * When a type definition is called, it returns either the validated value or type.errors
90
+ */
91
+ type InferType<T> = T extends ((value: Record<string, string | undefined>) => infer R) ? R extends type$1.errors ? never : R : T extends type$1.Any<infer U, infer _Scope> ? U : never;
87
92
  /**
88
93
  * TODO: If possible, find a better type than "const T extends Record<string, unknown>",
89
94
  * and be as close as possible to the type accepted by ArkType's `type`.
90
95
  */
91
96
  /**
92
97
  * Create an environment variables object from a schema and an environment
93
- * @param def - The environment variable schema
98
+ * @param def - The environment variable schema (raw object or type definition created with `type()`)
94
99
  * @param env - The environment variables to validate, defaults to `process.env`
95
100
  * @returns The validated environment variable schema
96
101
  * @throws An {@link ArkEnvError | error} if the environment variables are invalid.
97
102
  */
98
103
  declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T>, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>>;
104
+ declare function createEnv<T extends type$1.Any>(def: T, env?: RuntimeEnvironment): InferType<T>;
105
+ declare function createEnv<const T extends Record<string, unknown>>(def: EnvSchema<T> | type$1.Any, env?: RuntimeEnvironment): distill.Out<type$1.infer<T, (typeof $)["t"]>> | InferType<typeof def>;
99
106
  //#endregion
100
107
  //#region src/type.d.ts
101
108
  declare const type: arktype_internal_type_ts0.TypeParser<{
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/scope.ts","../src/create-env.ts","../src/type.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAQa,aAAC;;;;IAUZ,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAVY,qBAAA,yDAAA;MAAA,cAAA,EAAA,MAAA;;;;ICJT,KAAA,qBAAqB,CAAM;MAEpB,IAAS,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;MAAsB,YAAA,EAAA,MAAA;IAAa,CAAA,GAAA;MAAtB,cAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;IAAQ,CAAA,CAAA;IAc1B,GAAA,qBAAS,+CAAA;MAAiB,cAAA,EAAA,MAAA;IAC1B,CAAA,CAAA;IAAV,IA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process.versions.node!=null,i=()=>!!(!r()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),a=(e,t)=>r()&&!i()?`${n[e]}${t}${n.reset}`:t,o=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
2
2
  `).map(e=>`${` `.repeat(t)}${e}`).join(`
3
3
  `),s=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),i=r?n.replace(`(was "${r[1]}")`,`(was ${a(`cyan`,`"${r[1]}"`)})`):n;return`${a(`yellow`,e)}${i}`}).join(`
4
- `);var c=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${a(`red`,t)}\n${o(s(e))}\n`),this.name=`ArkEnvError`}};const l=t(`string`,`=>`,(e,t)=>{let n=Number.parseInt(e,10);return(!Number.isInteger(n)||!(0<=n&&n<=65535))&&t.mustBe(`an integer between 0 and 65535`),n}),u=t(`string.ip | 'localhost'`),d=t(`'true' | 'false' | true | false`,`=>`,e=>e===`true`||e===!0),f=e({string:t.module({...t.keywords.string,host:u}),number:t.module({...t.keywords.number,port:l}),boolean:d});function p(e,n=process.env){let r=f.type.raw(e)(n);if(r instanceof t.errors)throw new c(r);return r}const m=f.type;var h=p;export{c as ArkEnvError,p as createEnv,h as default,m as type};
4
+ `);var c=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${a(`red`,t)}\n${o(s(e))}\n`),this.name=`ArkEnvError`}};const l=t(`string`,`=>`,(e,t)=>{let n=Number.parseInt(e,10);return(!Number.isInteger(n)||!(0<=n&&n<=65535))&&t.mustBe(`an integer between 0 and 65535`),n}),u=t(`string.ip | 'localhost'`),d=t(`'true' | 'false' | true | false`,`=>`,e=>e===`true`||e===!0),f=e({string:t.module({...t.keywords.string,host:u}),number:t.module({...t.keywords.number,port:l}),boolean:d});function p(e,n=process.env){let r=(typeof e==`function`&&`assert`in e?e:f.type.raw(e))(n);if(r instanceof t.errors)throw new c(r);return r}const m=f.type;var h=p;export{c as ArkEnvError,p as createEnv,h as default,m as type};
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["type","type","type"],"sources":["../src/lib/style-text.ts","../src/utils.ts","../src/errors.ts","../src/types.ts","../src/scope.ts","../src/create-env.ts","../src/type.ts","../src/index.ts"],"sourcesContent":["/**\n * Cross-platform text styling utility\n * Uses ANSI colors in Node environments, plain text in browsers\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\n\n// ANSI color codes for Node environments\nconst colors = {\n\tred: \"\\x1b[31m\",\n\tyellow: \"\\x1b[33m\",\n\tcyan: \"\\x1b[36m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\n/**\n * Check if we're in a Node environment (not browser)\n * Checked dynamically to allow for testing with mocked globals\n */\nconst isNode = (): boolean =>\n\ttypeof process !== \"undefined\" &&\n\tprocess.versions != null &&\n\tprocess.versions.node != null;\n\n/**\n * Check if colors should be disabled based on environment\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\nconst shouldDisableColors = (): boolean => {\n\tif (!isNode()) return true;\n\n\t// Respect NO_COLOR environment variable (https://no-color.org/)\n\tif (process.env.NO_COLOR !== undefined) return true;\n\n\t// Disable colors in CI environments by default\n\tif (process.env.CI !== undefined) return true;\n\n\t// Disable colors if not writing to a TTY\n\tif (process.stdout && !process.stdout.isTTY) return true;\n\n\treturn false;\n};\n\n/**\n * Style text with color. Uses ANSI codes in Node, plain text in browsers.\n * @param color - The color to apply\n * @param text - The text to style\n * @returns Styled text in Node (if colors enabled), plain text otherwise\n */\nexport const styleText = (\n\tcolor: \"red\" | \"yellow\" | \"cyan\",\n\ttext: string,\n): string => {\n\t// Use ANSI colors only in Node environments with colors enabled\n\tif (isNode() && !shouldDisableColors()) {\n\t\treturn `${colors[color]}${text}${colors.reset}`;\n\t}\n\t// Fall back to plain text in browsers or when colors are disabled\n\treturn text;\n};\n","/**\n * Options for the `indent` function\n */\ntype IndentOptions = {\n\t/**\n\t * Whether to detect newlines and indent each line individually, defaults to false (indenting the whole string)\n\t */\n\tdontDetectNewlines?: boolean;\n};\n\n/**\n * Indent a string by a given amount\n * @param str - The string to indent\n * @param amt - The amount to indent by, defaults to 2\n * @param options - {@link IndentOptions}\n * @returns The indented string\n */\nexport const indent = (\n\tstr: string,\n\tamt = 2,\n\t{ dontDetectNewlines = false }: IndentOptions = {},\n) => {\n\tconst detectNewlines = !dontDetectNewlines;\n\tif (detectNewlines) {\n\t\treturn str\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => `${\" \".repeat(amt)}${line}`)\n\t\t\t.join(\"\\n\");\n\t}\n\n\treturn `${\" \".repeat(amt)}${str}`;\n};\n","import type { ArkErrors } from \"arktype\";\nimport { styleText } from \"./lib/style-text\";\nimport { indent } from \"./utils\";\n\n/**\n * Format the errors returned by ArkType to be more readable\n * @param errors - The errors returned by ArkType\n * @returns A string of the formatted errors\n */\nexport const formatErrors = (errors: ArkErrors): string =>\n\tObject.entries(errors.byPath)\n\t\t.map(([path, error]) => {\n\t\t\tconst messageWithoutPath = error.message.startsWith(path)\n\t\t\t\t? error.message.slice(path.length)\n\t\t\t\t: error.message;\n\n\t\t\t// Extract the value in parentheses if it exists\n\t\t\tconst valueMatch = messageWithoutPath.match(/\\(was \"([^\"]+)\"\\)/);\n\t\t\tconst formattedMessage = valueMatch\n\t\t\t\t? messageWithoutPath.replace(\n\t\t\t\t\t\t`(was \"${valueMatch[1]}\")`,\n\t\t\t\t\t\t`(was ${styleText(\"cyan\", `\"${valueMatch[1]}\"`)})`,\n\t\t\t\t\t)\n\t\t\t\t: messageWithoutPath;\n\n\t\t\treturn `${styleText(\"yellow\", path)}${formattedMessage}`;\n\t\t})\n\t\t.join(\"\\n\");\n\nexport class ArkEnvError extends Error {\n\tconstructor(\n\t\terrors: ArkErrors,\n\t\tmessage = \"Errors found while validating environment variables\",\n\t) {\n\t\tsuper(`${styleText(\"red\", message)}\\n${indent(formatErrors(errors))}\\n`);\n\t\tthis.name = \"ArkEnvError\";\n\t}\n}\n","import { type } from \"arktype\";\n\n/**\n * A `string` that can be parsed into a number between 0 and 65535\n */\nexport const port = type(\"string\", \"=>\", (data, ctx) => {\n\tconst asNumber = Number.parseInt(data, 10);\n\tconst isInteger = Number.isInteger(asNumber);\n\tconst isBetween = 0 <= asNumber && asNumber <= 65535;\n\tif (!isInteger || !isBetween) {\n\t\tctx.mustBe(\"an integer between 0 and 65535\");\n\t}\n\treturn asNumber;\n});\n\n/**\n * An IP address or `\"localhost\"`\n */\nexport const host = type(\"string.ip | 'localhost'\");\n\n/**\n * A boolean that accepts string values and converts them to boolean\n * Accepts \"true\" or \"false\" strings and converts them to actual boolean values\n */\nexport const boolean = type(\n\t\"'true' | 'false' | true | false\",\n\t\"=>\",\n\t(str) => str === \"true\" || str === true,\n);\n","import { scope, type } from \"arktype\";\nimport { boolean, host, port } from \"./types\";\n\n// For an explanation of the `$` variable naming convention, see: https://discord.com/channels/957797212103016458/1414659167008063588/1414670282756587581\n\n/**\n * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.\n */\nexport const $ = scope({\n\tstring: type.module({\n\t\t...type.keywords.string,\n\t\thost,\n\t}),\n\tnumber: type.module({\n\t\t...type.keywords.number,\n\t\tport,\n\t}),\n\tboolean,\n});\n","import { type distill, type } from \"arktype\";\nimport { ArkEnvError } from \"./errors\";\nimport { $ } from \"./scope\";\n\ntype RuntimeEnvironment = Record<string, string | undefined>;\n\nexport type EnvSchema<def> = type.validate<def, (typeof $)[\"t\"]>;\n\n/**\n * TODO: If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Create an environment variables object from a schema and an environment\n * @param def - The environment variable schema\n * @param env - The environment variables to validate, defaults to `process.env`\n * @returns The validated environment variable schema\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends Record<string, unknown>>(\n\tdef: EnvSchema<T>,\n\tenv: RuntimeEnvironment = process.env,\n): distill.Out<type.infer<T, (typeof $)[\"t\"]>> {\n\tconst schema = $.type.raw(def);\n\n\tconst validatedEnv = schema(env);\n\n\tif (validatedEnv instanceof type.errors) {\n\t\tthrow new ArkEnvError(validatedEnv);\n\t}\n\n\treturn validatedEnv;\n}\n","import { $ } from \"./scope\";\n\nexport const type = $.type;\n","export type { EnvSchema } from \"./create-env\";\n\nimport { createEnv } from \"./create-env\";\n\n/**\n * `arkenv`'s main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.\n */\nconst arkenv = createEnv;\nexport default arkenv;\nexport { type } from \"./type\";\nexport { createEnv };\nexport { ArkEnvError } from \"./errors\";\n"],"mappings":"0CAOA,MAAM,EAAS,CACd,IAAK,WACL,OAAQ,WACR,KAAM,WACN,MAAO,UACP,CAMK,MACL,OAAO,QAAY,KACnB,QAAQ,UAAY,MACpB,QAAQ,SAAS,MAAQ,KAMpB,MAUL,GATI,CAAC,GAAQ,EAGT,QAAQ,IAAI,WAAa,IAAA,IAGzB,QAAQ,IAAI,KAAO,IAAA,IAGnB,QAAQ,QAAU,CAAC,QAAQ,OAAO,OAW1B,GACZ,EACA,IAGI,GAAQ,EAAI,CAAC,GAAqB,CAC9B,GAAG,EAAO,KAAS,IAAO,EAAO,QAGlC,ECxCK,GACZ,EACA,EAAM,EACN,CAAE,qBAAqB,IAAyB,EAAE,GAE1B,EAQjB,GAAG,IAAI,OAAO,EAAI,GAAG,IANpB,EACL,MAAM;EAAK,CACX,IAAK,GAAS,GAAG,IAAI,OAAO,EAAI,GAAG,IAAO,CAC1C,KAAK;EAAK,CClBD,EAAgB,GAC5B,OAAO,QAAQ,EAAO,OAAO,CAC3B,KAAK,CAAC,EAAM,KAAW,CACvB,IAAM,EAAqB,EAAM,QAAQ,WAAW,EAAK,CACtD,EAAM,QAAQ,MAAM,EAAK,OAAO,CAChC,EAAM,QAGH,EAAa,EAAmB,MAAM,oBAAoB,CAC1D,EAAmB,EACtB,EAAmB,QACnB,SAAS,EAAW,GAAG,IACvB,QAAQ,EAAU,OAAQ,IAAI,EAAW,GAAG,GAAG,CAAC,GAChD,CACA,EAEH,MAAO,GAAG,EAAU,SAAU,EAAK,GAAG,KACrC,CACD,KAAK;EAAK,CAEb,IAAa,EAAb,cAAiC,KAAM,CACtC,YACC,EACA,EAAU,sDACT,CACD,MAAM,GAAG,EAAU,MAAO,EAAQ,CAAC,IAAI,EAAO,EAAa,EAAO,CAAC,CAAC,IAAI,CACxE,KAAK,KAAO,gBC9Bd,MAAa,EAAOA,EAAK,SAAU,MAAO,EAAM,IAAQ,CACvD,IAAM,EAAW,OAAO,SAAS,EAAM,GAAG,CAM1C,OAHI,CAFc,OAAO,UAAU,EAAS,EAE1B,EADA,GAAK,GAAY,GAAY,SAE9C,EAAI,OAAO,iCAAiC,CAEtC,GACN,CAKW,EAAOA,EAAK,0BAA0B,CAMtC,EAAUA,EACtB,kCACA,KACC,GAAQ,IAAQ,QAAU,IAAQ,GACnC,CCpBY,EAAI,EAAM,CACtB,OAAQC,EAAK,OAAO,CACnB,GAAGA,EAAK,SAAS,OACjB,OACA,CAAC,CACF,OAAQA,EAAK,OAAO,CACnB,GAAGA,EAAK,SAAS,OACjB,OACA,CAAC,CACF,UACA,CAAC,CCEF,SAAgB,EACf,EACA,EAA0B,QAAQ,IACY,CAG9C,IAAM,EAFS,EAAE,KAAK,IAAI,EAAI,CAEF,EAAI,CAEhC,GAAI,aAAwBC,EAAK,OAChC,MAAM,IAAI,EAAY,EAAa,CAGpC,OAAO,EC9BR,MAAa,EAAO,EAAE,KCQtB,IAAA,EADe"}
1
+ {"version":3,"file":"index.js","names":["type","type","type"],"sources":["../src/lib/style-text.ts","../src/utils.ts","../src/errors.ts","../src/types.ts","../src/scope.ts","../src/create-env.ts","../src/type.ts","../src/index.ts"],"sourcesContent":["/**\n * Cross-platform text styling utility\n * Uses ANSI colors in Node environments, plain text in browsers\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\n\n// ANSI color codes for Node environments\nconst colors = {\n\tred: \"\\x1b[31m\",\n\tyellow: \"\\x1b[33m\",\n\tcyan: \"\\x1b[36m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\n/**\n * Check if we're in a Node environment (not browser)\n * Checked dynamically to allow for testing with mocked globals\n */\nconst isNode = (): boolean =>\n\ttypeof process !== \"undefined\" &&\n\tprocess.versions != null &&\n\tprocess.versions.node != null;\n\n/**\n * Check if colors should be disabled based on environment\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\nconst shouldDisableColors = (): boolean => {\n\tif (!isNode()) return true;\n\n\t// Respect NO_COLOR environment variable (https://no-color.org/)\n\tif (process.env.NO_COLOR !== undefined) return true;\n\n\t// Disable colors in CI environments by default\n\tif (process.env.CI !== undefined) return true;\n\n\t// Disable colors if not writing to a TTY\n\tif (process.stdout && !process.stdout.isTTY) return true;\n\n\treturn false;\n};\n\n/**\n * Style text with color. Uses ANSI codes in Node, plain text in browsers.\n * @param color - The color to apply\n * @param text - The text to style\n * @returns Styled text in Node (if colors enabled), plain text otherwise\n */\nexport const styleText = (\n\tcolor: \"red\" | \"yellow\" | \"cyan\",\n\ttext: string,\n): string => {\n\t// Use ANSI colors only in Node environments with colors enabled\n\tif (isNode() && !shouldDisableColors()) {\n\t\treturn `${colors[color]}${text}${colors.reset}`;\n\t}\n\t// Fall back to plain text in browsers or when colors are disabled\n\treturn text;\n};\n","/**\n * Options for the `indent` function\n */\ntype IndentOptions = {\n\t/**\n\t * Whether to detect newlines and indent each line individually, defaults to false (indenting the whole string)\n\t */\n\tdontDetectNewlines?: boolean;\n};\n\n/**\n * Indent a string by a given amount\n * @param str - The string to indent\n * @param amt - The amount to indent by, defaults to 2\n * @param options - {@link IndentOptions}\n * @returns The indented string\n */\nexport const indent = (\n\tstr: string,\n\tamt = 2,\n\t{ dontDetectNewlines = false }: IndentOptions = {},\n) => {\n\tconst detectNewlines = !dontDetectNewlines;\n\tif (detectNewlines) {\n\t\treturn str\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => `${\" \".repeat(amt)}${line}`)\n\t\t\t.join(\"\\n\");\n\t}\n\n\treturn `${\" \".repeat(amt)}${str}`;\n};\n","import type { ArkErrors } from \"arktype\";\nimport { styleText } from \"./lib/style-text\";\nimport { indent } from \"./utils\";\n\n/**\n * Format the errors returned by ArkType to be more readable\n * @param errors - The errors returned by ArkType\n * @returns A string of the formatted errors\n */\nexport const formatErrors = (errors: ArkErrors): string =>\n\tObject.entries(errors.byPath)\n\t\t.map(([path, error]) => {\n\t\t\tconst messageWithoutPath = error.message.startsWith(path)\n\t\t\t\t? error.message.slice(path.length)\n\t\t\t\t: error.message;\n\n\t\t\t// Extract the value in parentheses if it exists\n\t\t\tconst valueMatch = messageWithoutPath.match(/\\(was \"([^\"]+)\"\\)/);\n\t\t\tconst formattedMessage = valueMatch\n\t\t\t\t? messageWithoutPath.replace(\n\t\t\t\t\t\t`(was \"${valueMatch[1]}\")`,\n\t\t\t\t\t\t`(was ${styleText(\"cyan\", `\"${valueMatch[1]}\"`)})`,\n\t\t\t\t\t)\n\t\t\t\t: messageWithoutPath;\n\n\t\t\treturn `${styleText(\"yellow\", path)}${formattedMessage}`;\n\t\t})\n\t\t.join(\"\\n\");\n\nexport class ArkEnvError extends Error {\n\tconstructor(\n\t\terrors: ArkErrors,\n\t\tmessage = \"Errors found while validating environment variables\",\n\t) {\n\t\tsuper(`${styleText(\"red\", message)}\\n${indent(formatErrors(errors))}\\n`);\n\t\tthis.name = \"ArkEnvError\";\n\t}\n}\n","import { type } from \"arktype\";\n\n/**\n * A `string` that can be parsed into a number between 0 and 65535\n */\nexport const port = type(\"string\", \"=>\", (data, ctx) => {\n\tconst asNumber = Number.parseInt(data, 10);\n\tconst isInteger = Number.isInteger(asNumber);\n\tconst isBetween = 0 <= asNumber && asNumber <= 65535;\n\tif (!isInteger || !isBetween) {\n\t\tctx.mustBe(\"an integer between 0 and 65535\");\n\t}\n\treturn asNumber;\n});\n\n/**\n * An IP address or `\"localhost\"`\n */\nexport const host = type(\"string.ip | 'localhost'\");\n\n/**\n * A boolean that accepts string values and converts them to boolean\n * Accepts \"true\" or \"false\" strings and converts them to actual boolean values\n */\nexport const boolean = type(\n\t\"'true' | 'false' | true | false\",\n\t\"=>\",\n\t(str) => str === \"true\" || str === true,\n);\n","import { scope, type } from \"arktype\";\nimport { boolean, host, port } from \"./types\";\n\n// For an explanation of the `$` variable naming convention, see: https://discord.com/channels/957797212103016458/1414659167008063588/1414670282756587581\n\n/**\n * The root scope for the ArkEnv library, containing extensions to the ArkType scopes with ArkEnv-specific types like `string.host` and `number.port`.\n */\nexport const $ = scope({\n\tstring: type.module({\n\t\t...type.keywords.string,\n\t\thost,\n\t}),\n\tnumber: type.module({\n\t\t...type.keywords.number,\n\t\tport,\n\t}),\n\tboolean,\n});\n","import { type distill, type } from \"arktype\";\nimport { ArkEnvError } from \"./errors\";\nimport { $ } from \"./scope\";\n\ntype RuntimeEnvironment = Record<string, string | undefined>;\n\nexport type EnvSchema<def> = type.validate<def, (typeof $)[\"t\"]>;\n\n/**\n * Extract the inferred type from an ArkType type definition by checking its call signature\n * When a type definition is called, it returns either the validated value or type.errors\n */\ntype InferType<T> = T extends (\n\tvalue: Record<string, string | undefined>,\n) => infer R\n\t? R extends type.errors\n\t\t? never\n\t\t: R\n\t: T extends type.Any<infer U, infer _Scope>\n\t\t? U\n\t\t: never;\n\n/**\n * TODO: If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Create an environment variables object from a schema and an environment\n * @param def - The environment variable schema (raw object or type definition created with `type()`)\n * @param env - The environment variables to validate, defaults to `process.env`\n * @returns The validated environment variable schema\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends Record<string, unknown>>(\n\tdef: EnvSchema<T>,\n\tenv?: RuntimeEnvironment,\n): distill.Out<type.infer<T, (typeof $)[\"t\"]>>;\nexport function createEnv<T extends type.Any>(\n\tdef: T,\n\tenv?: RuntimeEnvironment,\n): InferType<T>;\nexport function createEnv<const T extends Record<string, unknown>>(\n\tdef: EnvSchema<T> | type.Any,\n\tenv?: RuntimeEnvironment,\n): distill.Out<type.infer<T, (typeof $)[\"t\"]>> | InferType<typeof def>;\nexport function createEnv<const T extends Record<string, unknown>>(\n\tdef: EnvSchema<T> | type.Any,\n\tenv: RuntimeEnvironment = process.env,\n): distill.Out<type.infer<T, (typeof $)[\"t\"]>> | InferType<typeof def> {\n\t// If def is a type definition (has assert method), use it directly\n\t// Otherwise, use raw() to convert the schema definition\n\tconst schema =\n\t\ttypeof def === \"function\" && \"assert\" in def\n\t\t\t? def\n\t\t\t: $.type.raw(def as EnvSchema<T>);\n\n\tconst validatedEnv = schema(env);\n\n\tif (validatedEnv instanceof type.errors) {\n\t\tthrow new ArkEnvError(validatedEnv);\n\t}\n\n\treturn validatedEnv;\n}\n","import { $ } from \"./scope\";\n\nexport const type = $.type;\n","export type { EnvSchema } from \"./create-env\";\n\nimport { createEnv } from \"./create-env\";\n\n/**\n * `arkenv`'s main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.\n */\nconst arkenv = createEnv;\nexport default arkenv;\nexport { type } from \"./type\";\nexport { createEnv };\nexport { ArkEnvError } from \"./errors\";\n"],"mappings":"0CAOA,MAAM,EAAS,CACd,IAAK,WACL,OAAQ,WACR,KAAM,WACN,MAAO,UACP,CAMK,MACL,OAAO,QAAY,KACnB,QAAQ,UAAY,MACpB,QAAQ,SAAS,MAAQ,KAMpB,MAUL,GATI,CAAC,GAAQ,EAGT,QAAQ,IAAI,WAAa,IAAA,IAGzB,QAA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AAK,OAAO,CACnB,GAAGA,EAAK,SAAS,OACjB,OACA,CAAC,CACF,OAAQA,EAAK,OAAO,CACnB,GAAGA,EAAK,SAAS,OACjB,OACA,CAAC,CACF,UACA,CAAC,CC4BF,SAAgB,EACf,EACA,EAA0B,QAAQ,IACoC,CAQtE,IAAM,GAJL,OAAO,GAAQ,YAAc,WAAY,EACtC,EACA,EAAE,KAAK,IAAI,EAAoB,EAEP,EAAI,CAEhC,GAAI,aAAwBC,EAAK,OAChC,MAAM,IAAI,EAAY,EAAa,CAGpC,OAAO,EC7DR,MAAa,EAAO,EAAE,KCQtB,IAAA,EADe"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arkenv",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.6",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -34,12 +34,12 @@
34
34
  "@ark/schema": "0.53.0",
35
35
  "@size-limit/esbuild-why": "11.2.0",
36
36
  "@size-limit/preset-small-lib": "11.2.0",
37
- "@types/node": "24.10.0",
38
- "arktype": "2.1.25",
37
+ "@types/node": "24.10.1",
38
+ "arktype": "2.1.26",
39
39
  "size-limit": "11.2.0",
40
- "tsdown": "0.15.12",
40
+ "tsdown": "0.16.1",
41
41
  "typescript": "5.9.3",
42
- "vitest": "4.0.8"
42
+ "vitest": "4.0.9"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "arktype": "^2.1.22"