-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from Coder-Spirit/fix-nominal-inputs-version
feat: port safe-env package
- Loading branch information
Showing
13 changed files
with
698 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# @coderspirit/safe-env | ||
|
||
[![NPM version](https://img.shields.io/npm/v/@coderspirit/safe-env.svg?style=flat)](https://www.npmjs.com/package/@coderspirit/safe-env) | ||
[![TypeScript](https://badgen.net/npm/types/@coderspirit/safe-env)](http://www.typescriptlang.org/) | ||
[![License](https://badgen.net/npm/license/@coderspirit/safe-env)](https://opensource.org/licenses/MIT) | ||
[![npm downloads](https://img.shields.io/npm/dm/@coderspirit/safe-env.svg?style=flat)](https://www.npmjs.com/package/@coderspirit/safe-env) | ||
[![Known Vulnerabilities](https://snyk.io//test/github/Coder-Spirit/safe-env/badge.svg?targetFile=package.json)](https://snyk.io//test/github/Coder-Spirit/safe-env?targetFile=package.json) | ||
[![Security Score](https://snyk-widget.herokuapp.com/badge/npm/@coderspirit%2Fsafe-env/badge.svg)](https://snyk.io/advisor/npm-package/@coderspirit/safe-env) | ||
|
||
> Small library to load strongly typed values from environment variables | ||
## Install instructions | ||
|
||
### Node | ||
|
||
``` | ||
# With PNPM | ||
pnpm add @coderspirit/safe-env | ||
# With NPM | ||
npm install @coderspirit/safe-env | ||
# Or with Yarn: | ||
yarn add @coderspirit/safe-env | ||
``` | ||
|
||
## Example | ||
|
||
```ts | ||
import { getSafeEnv } from '@coderspirit/safe-env' | ||
|
||
// It validates the specified constraints at construction time | ||
const safeEnv = getSafeEnv(process.env, { | ||
host: { type: 'string', default: 'localhost' }, | ||
port: { type: 'uint16', default: 4321 }, | ||
|
||
githubToken: { type: 'string', optional: true }, | ||
secretToken: { type: 'string' }, | ||
}) | ||
|
||
// It leverages the powerful TypeScript's type system to tell you at | ||
// compile time if you made a mistake. | ||
const host = safeEnv.get('hostt') // Type Error | ||
|
||
const host = safeEnv.get('host') // All good | ||
|
||
// The return type tells you not only that you have a number, but also | ||
// that it is an integer and positive. | ||
const port = safeEnv.get('port') | ||
|
||
// It will return undefined if the variable does not exist | ||
const githubToken = safeEnv.get('githubToken') | ||
|
||
// It fill fail if the variable does not exist | ||
const secretToken = safeEnv.get('secretToken') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "@coderspirit/safe-env", | ||
"version": "1.0.0", | ||
"description": "Safe & strongly typed environment variables accessor", | ||
"main": "./dist/main.cjs", | ||
"module": "./dist/main.mjs", | ||
"types": "./dist/main.d.cts", | ||
"files": ["dist"], | ||
"exports": { | ||
"import": { | ||
"types": "./dist/main.d.mts", | ||
"default": "./dist/main.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/main.d.cts", | ||
"default": "./dist/main.cjs" | ||
} | ||
}, | ||
"keywords": ["typescript", "nominal", "environment"], | ||
"author": "Andres Correa Casablanca <castarco@coderspirit.xyz>", | ||
"private": false, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rm -rf dist && rollup --config rollup.config.prod.mjs", | ||
"lint:_all": "pnpm run lint:tsc && pnpm run lint:biome && pnpm run lint:publint", | ||
"lint:biome": "biome lint .", | ||
"lint:publint": "publint", | ||
"lint:tsc": "tsc", | ||
"test": "vitest run", | ||
"prepublishOnly": "pnpm run build" | ||
}, | ||
"dependencies": { | ||
"@coderspirit/nominal": "workspace:^", | ||
"@coderspirit/nominal-inputs": "workspace:^", | ||
"ajv": "^8.12.0" | ||
}, | ||
"devDependencies": { | ||
"@coderspirit/eslint-config": "^2.0.0", | ||
"@types/node": "^20.12.5", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.4.4", | ||
"vitest": "^0.34.6" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Coder-Spirit/nominal.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Coder-Spirit/nominal/issues" | ||
}, | ||
"homepage": "https://github.com/Coder-Spirit/nominal#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pluginTs from '@rollup/plugin-typescript' | ||
import { defineConfig } from 'rollup' | ||
import dts from 'rollup-plugin-dts' | ||
|
||
const input = 'src/main.ts' | ||
|
||
export default defineConfig([ | ||
{ | ||
input, | ||
output: [ | ||
{ format: 'cjs', file: 'dist/main.cjs' }, | ||
{ format: 'esm', file: 'dist/main.mjs' }, | ||
], | ||
plugins: [pluginTs()], | ||
}, | ||
{ | ||
input, | ||
output: [ | ||
{ format: 'cjs', file: 'dist/main.d.cts' }, | ||
{ format: 'esm', file: 'dist/main.d.mts' }, | ||
], | ||
plugins: [dts()], | ||
}, | ||
]) |
Oops, something went wrong.