Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yunreal/enya
An ergonomic env parsing library
https://github.com/yunreal/enya
bun env enviroment inference typescript validation
Last synced: 17 days ago
JSON representation
An ergonomic env parsing library
- Host: GitHub
- URL: https://github.com/yunreal/enya
- Owner: yUnreal
- Created: 2024-10-17T18:41:33.000Z (19 days ago)
- Default Branch: main
- Last Pushed: 2024-10-19T14:53:33.000Z (17 days ago)
- Last Synced: 2024-10-20T04:26:36.805Z (17 days ago)
- Topics: bun, env, enviroment, inference, typescript, validation
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Enya
An ergonomic env parsing library
```bash
bun add enya
```## Quick Start
Enya is an ergonomic env parsing library supercharged by Bun. Designed to be fast and with an extensive support for TypeScript.
Parsing your env from process.env.
```ts
import { e } from 'enya';const env = e
.env({
DATABASE_URL: e.url(),
PORT: e.port().default(() => 8080),
})
.parse();
```Now we can infer the type of the enviroment easily.
```ts
/**
* type Env = {
* DATABASE_URL: URL;
* PORT: number;
* }
*/
type Env = typeof env;
```## Installing
Enya was created with [Bun](https://bun.sh/), so you need to install it.
Install Bun with the command below:
### Linux & macOS
```bash
curl -fsSL https://bun.sh/install | bash
```### Windows
```bash
powershell -c "irm bun.sh/install.ps1 | iex"
```Then you can easily install Enya as a package.
```bash
bun add enya
bun add -d @types/bun
```## Using dotenv or any env var loader
Enya lets you load your environment variables however you want, even though Bun already loads them automatically. For this, you can look at the example below:
```ts
import { e } from 'enya';
import { config } from 'dotenv';/**
* {
* USER_EMAIL: string;
* PORT: number;
* }
*/
const env = e
.env({
USER_EMAIL: e.email(),
PORT: e.for({
production: e.never(),
development: e.number(),
}),
})
.parse(config());console.log(env);
```## Enya API
Enya has a **great** API for customizing each property of your environment variables which were not shown in the examples above, but you can find them in the [documentation](https://github.com/yUnreal/enya/blob/main/docs/API.md).
In a short period Enya will provide more support for customizations and more schemes.
## Why not envalid or env-var?
Enya is supercharged by Bun and end-to-end type safety, being 80x faster than env-var and 7x faster than envalid. With an ergonomic and modern API.