Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@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
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.