
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@lurenjs/config
Advanced tools
This a TypeScript library is to help you create a configuration class that values are injected from environment variables or files.
experimentalDecorators, emitDecoratorMetadata compilation options should be enabled in your tsconfig.json file.
{
"compilerOptions": {
//...
"experimentalDecorators": true,
"emitDecoratorMetadata": true
//...
}
}
$ yarn add @lurenjs/config reflect-metadata
$ npm i -S @lurenjs/config reflect-metadata
The configuration class should be decorator with Configuration, each property that you want to inject should be decorated with InjectEnv.
Values will be injected when instance is created.
@Configuration()
class Foo {
@InjectEnv('HOST', { default: 'localhost' })
public host: string;
@InjectEnv('PORT', {
transform: (val) => Number.parseInt(val, 10),
})
public port: number;
@InjectEnv('DATABASE', { description: 'database name' })
public database: string;
}
/**
* ENV
*
* PORT=1234
* DATABASE=test
*
**/
const foo = new Foo()
console.log(foo)
/**
* Foo { host: 'localhost', port: 1234, database: 'test' }
** /
Notice:For env variable injection, Configuration decorator is not required, but then value will be set on the prototype, that means fields won't be listed in Object.keys() or Object.getOwnProperites().
import { InjectEnv } from './inject-env';
class Foo {
@InjectEnv('HOST', { default: 'localhost' })
host: string;
@InjectEnv('PORT', {
transform: (val) => Number(val),
})
port: number;
@InjectEnv('DATABASE', { description: 'database name' })
database: string;
}
const foo = new Foo();
console.log(foo);
/* Foo {} */
console.log(foo.host, foo.port, foo.database);
/* localhost 1234 db_name */
static fields can be injected too.
import { InjectEnv } from './inject-env';
class Foo {
@InjectEnv('HOST', { default: 'localhost' })
static host: string;
@InjectEnv('PORT', {
transform: (val) => Number(val),
})
static port: number;
@InjectEnv('DATABASE', { description: 'database name' })
static database: string;
}
/**
* ENV
*
* HOST=localhost
* PORT=1234
* DATABASE= db_name
*
**/
console.log(Foo)
/**
* [class Foo] { host: 'localhost', port: 1234, database: 'db_name' }
** /
Config source can be an file, json and yaml format is supported, yaml is the default format. Then base filepath cwd(current work directory).
@Configuration({ filepath: './test/config.yml' })
class Bar {
@InjectProp()
zee: number;
@InjectProp()
foo: string;
@InjectProp({ transform: (val) => Number(val) })
ordinal: number;
}
const bar = new Bar();
/**
* ./test/config.yml
*
* foo: bar
* ordinal: "1"
* zee: 1
*
**/
const bar = new Bar()
/**
* Bar { zee: 1, foo: 'bar', ordinal: 1 }
** /
FAQs
load environment variable for class
The npm package @lurenjs/config receives a total of 854 weekly downloads. As such, @lurenjs/config popularity was classified as not popular.
We found that @lurenjs/config 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
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.