本文整理汇总了TypeScript中convict.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: convict
let config = convict({
env: {
doc: 'Application environment',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV',
arg: 'node-env'
},
server: {
ip: {
doc: 'IP address to bind',
format: 'ipaddress',
default: '0.0.0.0'
},
port: {
doc: 'port to bind',
env: 'PORT',
format: 'port',
default: 9000
}
},
database: {
host: {
doc: 'Database host name/IP',
format: String,
env: 'MONGODB_URI',
default: 'testing'
},
name: {
doc: 'Database name',
format: String,
default: 'users'
}
}
});
示例2: require
'use strict';
const convict = require('convict');
export const config = convict({
ENV: {
doc: 'The application environment.',
format: ['prd', 'dev', 'test'],
default: 'dev',
env: 'ENV',
arg: 'env'
},
PORT: {
doc: 'Applicatoin port',
format: 'Number',
default: '4000',
env: 'PORT',
arg: 'port'
},
DB_HOST: {
doc: 'The application environment.',
format: 'String',
default: 'mongodb://localhost:4082'
},
DB_NAME: {
doc: 'Application database name',
format: 'String',
default: 'portfolio'
}
});
示例3: Error
export function validateJobConfig<T>(inputSchema: convict.Schema<any>, inputConfig: any) {
const config = convict(inputSchema as convict.Schema<ValidatedJobConfig & T>);
try {
config.load(inputConfig);
config.validate(validateOptions);
} catch (err) {
throw new Error(`Validation failed for jobConfig: ${inputConfig.name} - ${err.stack}`);
}
return config.getProperties();
}
示例4: require
const convict = require('convict'),
path = require('path'),
fs = require('fs');
const customConfigPath = path.resolve(process.cwd(), 'sln.json');
const schema = require('./schema.js');
const config = convict(schema);
config.set('path.root', process.cwd());
try {
var customConfigFile = fs.readFileSync(customConfigPath);
config.loadFile(customConfigFile);
} catch(e) {
console.log('No custom config loaded from', customConfigPath)
}
config.validate({strict: true});
export = config.getProperties();