Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@beesley/ts-env
Advanced tools
An environment variable reader for TypeScript. Simple and minimal. ✨
This is basically the package created by @lpgera, but since that package doesn't play well at all with typescript when you're using es modules I've forked it and rebuilt is as a universal package to work with either es modules or common js.
This package requires typescript
to be installed.
# with npm
npm install @beesley/ts-env
# or with Yarn
yarn add @beesley/ts-env
Reading different types of environment variables without ts-env
:
if (!process.env.PORT) {
throw new Error('process.env.PORT is missing')
}
if (!process.env.DATABASE) {
throw new Error('process.env.DATABASE is missing')
}
const port: number = parseInt(process.env.PORT)
const database: string = process.env.DATABASE
const debug: boolean | undefined = process.env.DEBUG === 'true'
Doing the same with ts-env
:
import tsEnv from '@beesley/ts-env'
const port: number = tsEnv.numberOrThrow('PORT')
const database: string = tsEnv.stringOrThrow('DATABASE')
const debug: boolean | undefined = tsEnv.boolean('DEBUG')
Reads a string value from process.env[key]
.
Reads a string value from process.env[key]
.
Throws an error if it's undefined
.
Reads a boolean value from process.env[key]
.
"0" and "false" are considered false
, "1" and "true" are considered true
.
Everything else will be read as undefined
.
Reads a boolean value from process.env[key]
.
"0" and "false" are considered false
, "1" and "true" are considered true
.
Everything else will result in an error thrown.
Reads a number value from process.env[key]
.
If a number cannot be parsed, it will return undefined
.
Reads a number value from process.env[key]
.
If a number cannot be parsed, an error will be thrown.
Reads a string array from process.env[key]
.
Reads a string array from process.env[key]
.
Throws an error if it's undefined
.
Reads a number array from process.env[key]
.
If any item cannot be parsed, it will return undefined
.
Reads a number array from process.env[key]
.
If any item cannot be parsed, an error will be thrown.
FAQs
An environment variable reader for TypeScript
The npm package @beesley/ts-env receives a total of 0 weekly downloads. As such, @beesley/ts-env popularity was classified as not popular.
We found that @beesley/ts-env demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.