19 lines
432 B
TypeScript
19 lines
432 B
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Configuration } from './config.interfaces';
|
|
|
|
@Injectable()
|
|
export class ConfigurationService {
|
|
constructor(
|
|
@Inject('CONFIGURATION')
|
|
public config: Configuration,
|
|
) {}
|
|
|
|
public get<T>(key: string): T {
|
|
return key
|
|
.replace(/\[|\]\.?/g, '.')
|
|
.split('.')
|
|
.filter((s) => s)
|
|
.reduce((acc, val) => acc && acc[val], this.config);
|
|
}
|
|
}
|