How to use the convict.addFormat function in convict

To help you get started, we’ve selected a few convict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coralproject / talk / src / core / common / config.ts View on Github external
import convict from "convict";
import Joi from "joi";

// Add custom format for the mongo uri scheme.
convict.addFormat({
  name: "mongo-uri",
  validate: (url: string) => {
    Joi.assert(
      url,
      Joi.string().uri({
        scheme: ["mongodb"],
      })
    );
  },
});

// Add custom format for the redis uri scheme.
convict.addFormat({
  name: "redis-uri",
  validate: (url: string) => {
    Joi.assert(
github coralproject / talk / src / core / server / config.ts View on Github external
// Add custom format for the redis uri scheme.
convict.addFormat({
  name: "redis-uri",
  validate: (url: string) => {
    Joi.assert(
      url,
      Joi.string().uri({
        scheme: ["redis"],
      })
    );
  },
});

// Add a custom format for the optional-url that includes a trailing slash.
convict.addFormat({
  name: "optional-url",
  validate: (url: string) => {
    if (url) {
      Joi.assert(url, Joi.string().uri());
    }
  },
  // Ensure that there is an ending slash.
  coerce: (url: string) => (url ? ensureEndSlash(url) : url),
});

// Add a custom format that is a duration parsed with `ms` to used instead of
// the default format which will use `moment`.
convict.addFormat({
  name: "ms",
  validate: (val: number) => {
    Joi.assert(val, Joi.number().min(0));
github terascope / teraslice / packages / teraslice / lib / config / validators / job.js View on Github external
convictFormats.forEach((format) => {
            convict.addFormat(format);
        });
github terascope / teraslice / packages / teraslice / lib / config / validators / config.js View on Github external
convictFormats.forEach((format) => {
    convict.addFormat(format);
});
github terascope / teraslice / packages / terafoundation / src / validate-configs.ts View on Github external
config.schema_formats.forEach((format) => {
            convict.addFormat(format);
        });
    }
github terascope / teraslice / spec / config / validators / job-spec.js View on Github external
convictFormats.forEach(function(obj) {
    convict.addFormat(obj)
});
github marmelab / web-myna / src / config.js View on Github external
import signale from 'signale';
import convict from 'convict';
import rc from 'rc';

import { MODE_PLAYER } from './modes.js';

const processEnv = process.env;
const isPlayerMode = processEnv['WEB_MYNA_MODE'] === MODE_PLAYER || !processEnv['WEB_MYNA_MODE'];

const globalConfiguration = rc('webmyna', { apis: [], recordingsPath: null });

convict.addFormat({
    name: 'apis',
    validate: (apis, schema) => {
        if (!Array.isArray(apis)) {
            throw new Error('must be of type Array');
        }

        apis.map((api, index) => {
            const tokenName = api.name ? `${api.name.toUpperCase().replace(/-/g, '_')}_TOKEN` : null;
            signale.debug(tokenName);
            if (tokenName || isPlayerMode) {
                const apiToken = processEnv[tokenName];
                apis[index].token = isPlayerMode ? 'webMynaPlayerToken' : apiToken;
            }
        });

        for (const api of apis) {

convict

Featureful configuration management library for Node.js (nested structure, schema validation, etc.)

Apache-2.0
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis