0.1.2 • Published 1 year ago

convict-template-format v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

convict-template-type

Allows for template strings inside of node-convict configurations with one additional line of code allowing you to define configuration values in terms of other configuration values.

Install

npm install convict-template-format

Usage

TypeScript

The template type can be added to a convict schema as shown in the example and the value will be replaced when calling the replaceTemplateValues function.

Example:

import convict from "convict";
import templateFormat, { replaceTemplateValues } from "convict-template-format";

convict.addFormats(templateFormat);

const config = convict({
  deployment: {
    format: String,
    default: "staging"
  },
  appName: {
    format: "template",
    default: "app.${deployment}"
  }
});

replaceTemplateValues(config);

config.validate();

Templates can reference nested values as well as other template values:

const config = convict({
  deployment: {
    format: String,
    default: "staging"
  },
  serverA : {
    host: {
      format: "template",
      default: "https://servera.${deployment}.test.com"
    },
    health: {
      format: "template",
      default: "${serverA.host}/health"
    }
  }
});

Circular dependenancies will throw an Error,

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago