Skip to content

Commit d8e69ed

Browse files
committed
Initial commit
0 parents  commit d8e69ed

File tree

10 files changed

+1339
-0
lines changed

10 files changed

+1339
-0
lines changed

.github/workflows/deno-ci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deno CI 🦕
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
publish:
13+
name: Run Deno Tests 🧪
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Repository 🛎️
17+
uses: actions/checkout@v4
18+
- name: Setup Deno Environment 🦕
19+
uses: denoland/setup-deno@v2
20+
with:
21+
deno-version: v2.x
22+
- name: Execute Tests 🧪
23+
run: deno task test

.github/workflows/publish-jsr.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish to JSR 🚀
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
name: Publish JSR Package 📦
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write # The OIDC ID token is used for authentication with JSR.
15+
steps:
16+
- name: Checkout Repository 🛎️
17+
uses: actions/checkout@v4
18+
- name: Setup Deno 🦕
19+
uses: denoland/setup-deno@v2
20+
with:
21+
deno-version: v2.x
22+
- name: Run Tests 🧪
23+
run: deno task test
24+
- name: Publish Package 🚀
25+
run: deno publish

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Logs
2+
*.jsonl
3+
*.log
4+
5+
# OS generated files
6+
.DS_Store
7+
.DS_Store?
8+
._*
9+
.Spotlight-V100
10+
.Trashes
11+
ehthumbs.db
12+
Thumbs.db

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 WüSpace e. V.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# @wuespace/envar
2+
3+
[![JSR Scope](https://jsr.io/badges/@wuespace)](https://jsr.io/@wuespace)
4+
[![JSR](https://jsr.io/badges/@wuespace/envar)](https://jsr.io/@wuespace/envar)
5+
[![JSR Score](https://jsr.io/badges/@wuespace/envar/score)](https://jsr.io/@wuespace/envar)
6+
[![Deno CI](https://github.com/wuespace/envar/actions/workflows/deno-ci.yml/badge.svg)](https://github.com/wuespace/envar/actions/workflows/deno-ci.yml)
7+
[![Publish Workflow](https://github.com/wuespace/envar/actions/workflows/publish-jsr.yml/badge.svg)](https://github.com/wuespace/envar/actions/workflows/publish-jsr.yml)
8+
9+
🚀 **Envar** makes it easy to add configurability to your Deno applications.
10+
It supports loading configuration from environment variables as well as
11+
specifying default values.
12+
It even supports configuration values from files specified by environment
13+
variables to provide first-class support for secrets and the like in your
14+
Docker Swarm or Kubernetes deployments.
15+
16+
## 📦 Usage
17+
18+
You can use Envar in your Deno application by importing it from the
19+
`jsr:@wuespace/envar` module.
20+
21+
```tsx
22+
// Import the initVariable function from the module
23+
import { initVariable, EnvNotSetError } from "jsr:@wuespace/envar";
24+
import { z } from "npm:zod";
25+
26+
// Initialize the application variables
27+
await initVariable("PORT", z.string().match(/^[0-9]{1,5}$/), "8080");
28+
await initVariable("SECRET", z.string().min(32));
29+
// At this point, we can rest assured that we have valid values for
30+
// PORT and SECRET. Otherwise, the promises would have been rejected.
31+
32+
// Access the variables like you normally would.
33+
// Everything's synchronous now, so it's quite easy.
34+
console.log(Deno.env.get("PORT"));
35+
console.log(Deno.env.get("SECRET"));
36+
37+
// For type safety, you'll need to check if it's undefined:
38+
const port = Deno.env.get("PORT");
39+
if (port == undefined) {
40+
// Automatically generate a nice error message for the user
41+
throw new EnvNotSetError("PORT");
42+
}
43+
44+
// Alternatively, you can also use process.env in Deno 2.0+
45+
console.log(process.env.PORT);
46+
```
47+
48+
## 👥 Authors
49+
50+
This package was created and is maintained by [WüSpace e. V.](https://github.com/wuespace)
51+
52+
Its primary author is [Zuri Klaschka](https://github.com/pklaschka).
53+
54+
## 📄 License
55+
56+
This package is licensed under the MIT license. See the [LICENSE](LICENSE) file for more information.

deno.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@wuespace/envar",
3+
"version": "0.0.1",
4+
"exports": "./mod.ts",
5+
"license": "MIT",
6+
"scopes": {
7+
},
8+
"publish": {
9+
"include": [
10+
"mod.ts",
11+
"LICENSE",
12+
"README.md"
13+
]
14+
},
15+
"tasks": {
16+
"dev": "deno task test --watch",
17+
"test": "deno test --allow-env --allow-read --allow-write"
18+
},
19+
"imports": {
20+
"@std/assert": "jsr:@std/assert@1",
21+
"@std/log": "jsr:@std/log@^0.224.9"
22+
}
23+
}

0 commit comments

Comments
 (0)