New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@zcodeapp/configuration

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zcodeapp/configuration

Configuration for load system variables

latest
Source
npmnpm
Version
0.1.9
Version published
Maintainers
0
Created
Source

Configuration

Configuration CI codecov

Overview

The Configuration library is a robust and flexible solution for configuration management in TypeScript applications. It allows for the integration of multiple configuration strategies, facilitating adaptability across different environments and scenarios. With support for asynchronous loading and customizable strategies, this library is ideal for projects requiring an extensible and reliable configuration system.

Features

Customizable Configuration Strategies Integrate different configuration sources using customizable strategies.

Asynchronous Loading Supports asynchronous loading of configuration data.

Extensive Logging Comes with built-in logging capabilities for monitoring the configuration loading and retrieval process.

Scalable and Extendable Easily scalable for complex applications, allowing the addition of new configuration strategies as needed.

Error Handling Robust error handling during the configuration loading process.

Installation

Include the Configuration class in your TypeScript project:

npm install @zcodeapp/configuration @zcodeapp/logger

Usage

To use the Configuration class in your TypeScript project:

import { Di } from "@zcodeapp/di";
import { ExampleStrategy } from "exampleStrategy";
import { Configuration } from "@zcodeapp/configuration";

const di = Di.getInstance();

const config = di.get(Configuration);

const node_env = config.get("NODE_ENV");

API Reference

addStrategy(strategy: IConfigurationStrategy): void Add a new configuration strategy.

load(): Promise<void> Asynchronously load configuration data using the added strategies.

get(key?: string): string Retrieve a specific configuration value by key.

getData(): IConfigurationData[] Get all loaded configuration data.

Example

Using without dependency injection

exampleStrategy.ts

export class ExampleStrategy implements IConfigurationStrategy {
  public async load(): Promise<IConfigurationData[]> {
    // load github, azure, gcp ...
  }
}

main.ts

import { Configuration, EnvironmentStrategy } from "@zcodeapp/configuration";
import { Logger } from "@zcodeapp/logger";

// Get env values
const config = new Configuration(Logger.getInstance(), new EnvironmentStrategy());
const node_env = config.get("NODE_ENV");

Using with dependency injection @zcodeapp/di

exampleStrategy.ts

import { Injectable } from "@zcodeapp/di";

@Injectable()
export class ExampleStrategy implements IConfigurationStrategy {
  public async load(): Promise<IConfigurationData[]> {
    // load github, azure, gcp ...
    // return IConfigurationData[]
  }
}

main.ts

import { Di } from "@zcodeapp/di";
import { ExampleStrategy } from "exampleStrategy";
import { Configuration } from "@zcodeapp/configuration";

const di = Di.getInstance();

const config = di.get(Configuration);
config.addStrategy(di.get(ExampleStrategy));

const custom_value = config.get("CUSTOM_VALUE");

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

configuration

FAQs

Package last updated on 23 Jun 2024

Did you know?

Socket

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.

Install

Related posts