[cloud-env] Add type declarations (#16772)

This commit is contained in:
Ben Davies
2017-05-31 22:32:50 -07:00
committed by Mohamed Hegazy
parent 1790ce0757
commit 3537f59e0b
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import * as cloudEnv from 'cloud-env';
if (cloudEnv.get('IP', '0.0.0.0') !== '0.0.0.0') {
throw new Error(`cloudEnv.get: expected value 0.0.0.0, but actually received value ${cloudEnv.get('IP', '0.0.0.0')}`);
}
if (!(cloudEnv.defaults instanceof Object)) {
throw new Error(`cloudEnv.defaults: expected value of defaults be an instance of Object, but it was actually an instance of another class: ${typeof cloudEnv.defaults}`);
}

51
types/cloud-env/index.d.ts vendored Normal file
View File

@@ -0,0 +1,51 @@
// Type definitions for cloud-env 0.2.2
// Project: https://github.com/ryanj/cloud-env
// Definitions by: Ben Davies <https://github.com/Morfent>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare interface DefaultSettings {
PORT?: number;
IP?: string;
HOSTNAME?: string;
APP_NAME?: string;
MONGODB_DB_URL?: string;
MONGODB_DB_HOST?: string;
MONGODB_DB_PORT?: number;
MONGODB_DB_USERNAME?: string;
MONGODB_DB_PASSWORD?: string;
POSTGRESQL_DB_URL?: string;
POSTGRESQL_DB_HOST?: string;
POSTGRESQL_DB_PORT?: number;
POSTGRESQL_DB_USERNAME?: string;
POSTGRESQL_DB_PASSWORD?: string;
MYSQL_DB_URL?: string;
MYSQL_DB_HOST?: string;
MYSQL_DB_PORT?: number;
MYSQL_DB_USERNAME?: string;
MYSQL_DB_PASSWORD?: string;
}
declare type MaybeNum = number | void;
declare type MaybeStr = string | void;
export const get: (key: string, default_key?: string) => MaybeStr;
export const defaults: { [key: string]: DefaultSettings; };
export const PORT: MaybeNum;
export const IP: MaybeStr;
export const HOSTNAME: MaybeStr;
export const APP_NAME: MaybeStr;
export const MONGODB_DB_URL: MaybeStr;
export const MONGODB_DB_HOST: MaybeStr;
export const MONGODB_DB_PORT: MaybeNum;
export const MONGODB_DB_USERNAME: MaybeStr;
export const MONGODB_DB_PASSWORD: MaybeStr;
export const POSTGRESQL_DB_URL: MaybeStr;
export const POSTGRESQL_DB_HOST: MaybeStr;
export const POSTGRESQL_DB_PORT: MaybeNum;
export const POSTGRESQL_DB_USERNAME: MaybeStr;
export const POSTGRESQL_DB_PASSWORD: MaybeStr;
export const MYSQL_DB_URL: MaybeStr;
export const MYSQL_DB_HOST: MaybeStr;
export const MYSQL_DB_PORT: MaybeNum;
export const MYSQL_DB_USERNAME: MaybeStr;
export const MYSQL_DB_PASSWORD: MaybeStr;

View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"cloud-env-tests.ts"
]
}