4.0.0 • Published 1 year ago
@ltv/env v4.0.0
env
NodeJS safe environment parser. Compatible with TypeScript.
In this version,
- I have removed dotenv support. If you want to use dotenv, please use the previous version. Otherwise, you should install the dotenv package yourself.
- I have removed the lodash.has and lodash.trim dependencies, and the package size has been reduced. There is no dependency anymore.
Features
- Safe environment parser
- Compatible with TypeScript
With typescript, if you're using are not mentioning the default value, the return type will be T | undefined.
Otherwise, the return type will be T.
e.g.
const foo = env.string('FOO') // foo: string | undefined
const bar = env.string('BAR', 'bar') // bar: stringInstallation
npm install @ltv/envUsage
const env = require('@ltv/env')import env from '@ltv/env'env.string
env.string(key: string, defaultValue?: string): stringenv.number
env.number(key: string, defaultValue?: number): numberenv.int
env.int(key: string, defaultValue?: number): numberenv.float
env.float(key: string, defaultValue?: number): numberenv.bool
env.bool(key: string, defaultValue?: boolean): booleanenv.array
env.array(key: string, defaultValue?: string[]): string[]env.json
env.json(key: string, defaultValue?: object): objectenv.date
env.date(key: string, defaultValue?: Date): Date