Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

t-configurator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

t-configurator

Allows to manage configuration files in your project

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

T-Configurator

Allows to create and manage configuration files in your project. You can use gulp-config-parameters plugin to automate how your configuration is created and managed.

Usage

Create your configuration file, lets say ./config.json:

{
  "factoryName": "BMW",
  "showEngineInfo": true,
  "engine": {
    "version": 12,
    "description": "Reactive engine for reactive cars"
  }
}

Then register your configuration file in configurator and use it to get your configuration properties:

import {defaultConfigurator} from "t-configurator/Configurator";

defaultConfigurator.setConfiguration(require('./config.json'));
console.log('factory name: ', configurator.get('factoryName')); // prints: factory name: BMW
console.log('show engine info?: ', configurator.get('showEngineInfo')); // prints: show engine info?: true
console.log('car engine: ', configurator.get('engine')); // prints: car engine: [Object object]

###If you have separate parameters file you can use it this way: Lets say you have created ./parameters.json

{
  "factoryName": "BMW",
  "showEngineInfo": true,
  "engine": {
    "version": 12,
    "description": "Reactive engine for reactive cars"
  }
}

And your ./config.json is like this:

{
  "factoryName": "%factoryName%",
  "showEngineInfo": "%showEngineInfo%",
  "engine": {
    "version": "%engine::version%",
    "name": "Reactive",
    "description": "%engine::description%"
  }
}

Now you can use configuration (with replaced parameters) this way:

import {defaultConfigurator} from "t-configurator/Configurator";

defaultConfigurator.setConfiguration(require('./config.json'));
defaultConfigurator.replaceWithParameters(require('./parameters.json'));
console.log('factory name: ', configurator.get('factoryName')); // prints: factory name: BMW
console.log('show engine info?: ', configurator.get('showEngineInfo')); // prints: show engine info?: true
console.log('car engine: ', configurator.get('engine')); // prints: car engine: [Object object]

This allows you to create a common configuration file for your app, and use different parameters on different platforms. You can use gulp-config-parameters plugin to automate this process.

###If you are using typedi you can inject your configuration in your classes

import {Resolve} from "typedi/Resolve";
import {Config} from "../../src/Annotations";
import {EngineFactory} from "./EngineFactory";

@Resolve()
export class CarFactory {

    private factoryName: string;
    private showEngineInfo: boolean;

    constructor(@Config('factoryName') factoryName: string,
                @Config('showEngineInfo') showEngineInfo: boolean) {

        this.factoryName = factoryName; // gives you "BMW"
        this.showEngineInfo = showEngineInfo; // gives you "true"
    }

}

You can also inject right to the properties:

import {Resolve} from "typedi/Resolve";
import {Config} from "../../src/Annotations";
import {EngineFactory} from "./EngineFactory";

@Resolve()
export class CarFactory {

    @InjectConfig('factoryName')
    factoryName: string;  // value is "BMW"
    
    @InjectConfig('showEngineInfo')
    showEngineInfo: boolean; // value is "true"
    
}

Take a look on samples in ./sample for more examples of usages.

Todos

  • cover with tests
  • more documentation and samples

FAQs

Package last updated on 10 Oct 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc