From edd6ca755a05f6098f9308d33d39cd5b2a6dce44 Mon Sep 17 00:00:00 2001 From: Stan Goldmann Date: Fri, 14 Jul 2017 13:45:57 +0200 Subject: [PATCH] Add typings for dotenv-safe --- types/dotenv-safe/dotenv-safe-tests.ts | 7 +++++ types/dotenv-safe/index.d.ts | 40 ++++++++++++++++++++++++++ types/dotenv-safe/tsconfig.json | 23 +++++++++++++++ types/dotenv-safe/tslint.json | 13 +++++++++ 4 files changed, 83 insertions(+) create mode 100644 types/dotenv-safe/dotenv-safe-tests.ts create mode 100644 types/dotenv-safe/index.d.ts create mode 100644 types/dotenv-safe/tsconfig.json create mode 100644 types/dotenv-safe/tslint.json diff --git a/types/dotenv-safe/dotenv-safe-tests.ts b/types/dotenv-safe/dotenv-safe-tests.ts new file mode 100644 index 0000000000..eca6c0937a --- /dev/null +++ b/types/dotenv-safe/dotenv-safe-tests.ts @@ -0,0 +1,7 @@ +import env = require("dotenv-safe") + +env.load({ + allowEmptyValues: true, + path: "/foo/bar/baz.env", + sample: "/foo/bar/qux.env" +}) diff --git a/types/dotenv-safe/index.d.ts b/types/dotenv-safe/index.d.ts new file mode 100644 index 0000000000..a435f36fe7 --- /dev/null +++ b/types/dotenv-safe/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for dotenv-safe 4.0 +// Project: https://github.com/rolodato/dotenv-safe +// Definitions by: Stan Goldmann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import env = require("dotenv") + +export interface MissingEnvVarsError extends Error { + /** + * Path to example environment file. + */ + sample: string + + /** + * Variables which existing in the sample file, but not in the loaded file. + */ + missing: string[] +} + +/** + * Loads environment variables file into 'process.env'. + * + * @param {object} options + * @param {string} [options.sample=".env.example"] Path to example environment file. + * @param {string} [options.path=".env"] Path to environment file. + * @param {string} [options.encoding="utf8"] Encoding of your file containing environment variables. + * @param {boolean} [options.allowEmptyValues=false] Enabling this option will not throw an error after loading. + * + * @throws MissingEnvVarsError + * + * @return env.DotenvResult + */ +export function load(options?: { + path?: string, + sample?: string, + silent?: boolean, + encoding?: string, + allowEmptyValues?: boolean, +}): env.DotenvResult diff --git a/types/dotenv-safe/tsconfig.json b/types/dotenv-safe/tsconfig.json new file mode 100644 index 0000000000..a3c86013c6 --- /dev/null +++ b/types/dotenv-safe/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dotenv-safe-tests.ts" + ] +} diff --git a/types/dotenv-safe/tslint.json b/types/dotenv-safe/tslint.json new file mode 100644 index 0000000000..e84284df26 --- /dev/null +++ b/types/dotenv-safe/tslint.json @@ -0,0 +1,13 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "member-access": true, + "semicolon": false, + "one-line": { + "options": [ + "check-open-brace", + "check-whitespace" + ] + } + } +}