mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add typings for convict
This commit is contained in:
parent
0d595e843d
commit
7ebce403e5
58
convict/convict-tests.ts
Normal file
58
convict/convict-tests.ts
Normal file
@ -0,0 +1,58 @@
|
||||
/// <reference path='convict.d.ts' />
|
||||
/// <reference path='../validator/validator.d.ts' />
|
||||
|
||||
import convict = require('convict');
|
||||
import validator = require('validator');
|
||||
|
||||
// define a schema
|
||||
|
||||
var conf = convict({
|
||||
env: {
|
||||
doc: 'The applicaton environment.',
|
||||
format: ['production', 'development', 'test'],
|
||||
default: 'development',
|
||||
env: 'NODE_ENV',
|
||||
arg: 'node-env',
|
||||
},
|
||||
ip: {
|
||||
doc: 'The IP address to bind.',
|
||||
format: 'ipaddress',
|
||||
default: '127.0.0.1',
|
||||
env: 'IP_ADDRESS',
|
||||
},
|
||||
port: {
|
||||
doc: 'The port to bind.',
|
||||
format: 'port',
|
||||
default: 0,
|
||||
env: 'PORT',
|
||||
arg: 'port',
|
||||
},
|
||||
key: {
|
||||
doc: "API key",
|
||||
format: (val: string) => validator.isUUID(val),
|
||||
default: '01527E56-8431-11E4-AF91-47B661C210CA'
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// load environment dependent configuration
|
||||
|
||||
var env = conf.get('env');
|
||||
conf.loadFile('./config/' + env + '.json');
|
||||
conf.loadFile(['./configs/always.json', './configs/sometimes.json']);
|
||||
|
||||
// perform validation
|
||||
|
||||
conf.validate();
|
||||
|
||||
var port: number = conf.default('port');
|
||||
|
||||
if (conf.has('key')) {
|
||||
conf.set('the.awesome', true);
|
||||
conf.load({
|
||||
thing: {
|
||||
a: 'b'
|
||||
}
|
||||
});
|
||||
}
|
||||
// vim:et:sw=2:ts=2
|
||||
33
convict/convict.d.ts
vendored
Normal file
33
convict/convict.d.ts
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
// Type definitions for node-convict v0.6.0
|
||||
// Project: https://github.com/mozilla/node-convict
|
||||
// Definitions by: Wim Looman <https://github.com/Nemo157>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "convict" {
|
||||
function convict(schema: convict.Schema): convict.Config;
|
||||
|
||||
module convict {
|
||||
interface Schema {
|
||||
[name: string]: {
|
||||
default: any;
|
||||
doc?: string;
|
||||
format?: any;
|
||||
env?: string;
|
||||
arg?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface Config {
|
||||
get(name: string): any;
|
||||
default(name: string): any;
|
||||
has(name: string): boolean;
|
||||
set(name: string, value: any): void;
|
||||
load(conf: Object): void;
|
||||
loadFile(file: string): void;
|
||||
loadFile(files: string[]): void;
|
||||
validate(): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = convict;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user