diff --git a/types/cfenv/cfenv-tests.ts b/types/cfenv/cfenv-tests.ts new file mode 100644 index 0000000000..6cbaf06408 --- /dev/null +++ b/types/cfenv/cfenv-tests.ts @@ -0,0 +1,34 @@ +import * as cfenv from 'cfenv'; + +const appEnv = cfenv.getAppEnv(); // $ExpectType AppEnv + +cfenv.getAppEnv({}); // $ExpectType AppEnv +cfenv.getAppEnv({ name: 'foo' }); // $ExpectType AppEnv +cfenv.getAppEnv({ protocol: 'foo' }); // $ExpectType AppEnv +cfenv.getAppEnv({ vcap: {} }); // $ExpectType AppEnv +cfenv.getAppEnv({ vcap: { application: 'foo' } }); // $ExpectType AppEnv +cfenv.getAppEnv({ vcap: { services: 'foo' } }); // $ExpectType AppEnv +cfenv.getAppEnv({ vcapFile: 'foo' }); // $ExpectType AppEnv + +appEnv.app; // $ExpectType object +appEnv.isLocal; // $ExpectType boolean +appEnv.name; // $ExpectType string +appEnv.port; // $ExpectType number +appEnv.bind; // $ExpectType string +appEnv.urls; // $ExpectType string[] +appEnv.url; // $ExpectType string +appEnv.services; // $ExpectType object + +appEnv.toJSON(); // $ExpectType string + +appEnv.getServices(); // $ExpectType { [key: string]: Service; } + +appEnv.getService('foo'); // $ExpectType Service | null +appEnv.getService(/foo/); // $ExpectType Service | null + +appEnv.getServiceURL('foo'); // $ExpectType string | null +appEnv.getServiceURL(/foo/); // $ExpectType string | null +appEnv.getServiceURL('foo', { a: 'b' }); // $ExpectType string | null + +appEnv.getServiceCreds('foo'); // $ExpectType object | null +appEnv.getServiceCreds(/foo/); // $ExpectType object | null diff --git a/types/cfenv/index.d.ts b/types/cfenv/index.d.ts new file mode 100644 index 0000000000..2858a69de2 --- /dev/null +++ b/types/cfenv/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for cfenv 1.2 +// Project: https://github.com/cloudfoundry-community/node-cfenv +// Definitions by: Jordan Adams +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Service { + label: string; + name: string; + plan: string; + tags: string[]; + credentials: object; +} + +export interface AppEnv { + app: object; + isLocal: boolean; + name: string; + port: number; + bind: string; + urls: string[]; + url: string; + services: object; + + toJSON: () => string; + getServices: () => { [key: string]: Service }; + getService: (spec: string | RegExp) => Service | null; + getServiceURL: (spec: string | RegExp, replacements?: object) => string | null; + getServiceCreds: (spec: string | RegExp) => object | null; +} + +export interface GetAppEnvOptions { + name?: string; + protocol?: string; + vcap?: { + application?: string; + services?: string; + }; + vcapFile?: string; +} + +export function getAppEnv(options?: GetAppEnvOptions): AppEnv; diff --git a/types/cfenv/tsconfig.json b/types/cfenv/tsconfig.json new file mode 100644 index 0000000000..89446f5b44 --- /dev/null +++ b/types/cfenv/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cfenv-tests.ts" + ] +} diff --git a/types/cfenv/tslint.json b/types/cfenv/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cfenv/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }