Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This directory contains a collection of example projects that demonstrate variou
## Examples

> [!NOTE]
> The examples listed below are written in TypeScript out of convention.
> ArkEnv does _not_ require TypeScript. If you prefer plain JavaScript, see [basic-js](https://github.com/yamcodes/arkenv/tree/main/examples/basic-js) for a basic example.
> The examples listed below are written in TypeScript.
> While ArkEnv works with plain JavaScript, TypeScript is recommended. See [Requirements](https://github.com/yamcodes/arkenv/blob/main/packages/arkenv/README.md#typescript-setup) for details. If you're still interested in working with ArkEnv in plain JavaScript, see the [`basic-js`](https://github.com/yamcodes/arkenv/tree/main/examples/basic-js) example.

| Name | Description |
| ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
Expand Down
17 changes: 17 additions & 0 deletions examples/basic-js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import arkenv from "arkenv";

const env = arkenv({
HOST: "string.host",
PORT: "number.port",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
});

// Automatically validate and parse process.env
// Runtime validation still works without TypeScript!
const host = env.HOST;
const port = env.PORT;
const nodeEnv = env.NODE_ENV;

console.log({ host, port, nodeEnv });

export default env;
14 changes: 11 additions & 3 deletions packages/arkenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,19 @@ bun add arkenv arktype

## Requirements

- **TypeScript >= 5.1** and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
ArkEnv is tested on [**Node.js LTS** and **Current**](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [**Bun 1.3.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.

### TypeScript setup

While ArkEnv works with plain JavaScript, *TypeScript is highly recommended* to get the full typesafety benefits. To get ArkEnv to work with TypeScript, we require:

- [**Modern TypeScript module resolution**](https://www.typescriptlang.org/tsconfig/#moduleResolution). One of the following is required in your `tsconfig.json`:
- `"moduleResolution": "bundler"` - Recommended for modern bundlers (Vite, Next.js, etc.). Supplied by default when using `"module": "Preserve"`.
- `"moduleResolution": "bundler"` - Recommended for modern bundlers (Vite, Next.js, etc.). Supplied by default when using `"module": "Preserve"` (Introduced in TypeScript v5.4).
- `"moduleResolution": "node16"` or `"nodenext"` - For Node.js projects. Supplied by default when using a matching `"module"` value.
- Tested on [**Node.js LTS** and **Current**](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [**Bun 1.3.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
- **TypeScript >= 5.1** and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)

> [!NOTE]
> Without TypeScript, runtime validation still works, but you lose build-time type checking and, in some cases, editor autocomplete. Try our [examples](https://arkenv.js.org/docs/examples) to see this in action!

## Plugins

Expand Down
Loading