[dotenv] Update types for v6.1.0

This commit is contained in:
Max Beatty
2018-11-01 15:44:38 -07:00
parent 81c1b73511
commit dac8f708b0
2 changed files with 64 additions and 47 deletions
+12 -14
View File
@@ -1,20 +1,18 @@
import dotenv = require('dotenv');
import dotenv = require("dotenv");
const env = dotenv.config();
const dbUrl: string | null = env.error || !env.parsed ? null : env.parsed['DATABASE_URL'];
const dbUrl: string | null = env.error || !env.parsed ? null : env.parsed["BASIC"];
dotenv.config({
path: '.env'
dotenv.load({
path: ".env-example",
encoding: "utf8",
debug: true
});
dotenv.config({
encoding: 'utf8'
const parsed = dotenv.parse("NODE_ENV=production\nDB_HOST=a.b.c");
const dbHost: string = parsed["DB_HOST"];
const parsedFromBuffer = dotenv.parse(new Buffer("JUSTICE=league\n"), {
debug: true
});
dotenv.load();
const parsed = dotenv.parse("ENVIRONMENT=production\nDEBUG=no\n");
const debug: string = parsed['DEBUG'];
const parsedFromBuffer = dotenv.parse(new Buffer("JUSTICE=league\n"));
const justice: string = parsedFromBuffer['JUSTICE'];
const justice: string = parsedFromBuffer["JUSTICE"];
+52 -33
View File
@@ -1,46 +1,65 @@
// Type definitions for dotenv 4.0
// Type definitions for dotenv 6.1
// Project: https://github.com/motdotla/dotenv
// Definitions by: Jussi Kinnula <https://github.com/jussikinnula>, Borek Bernard <https://github.com/borekb>, Eric Naeseth <https://github.com/enaeseth>
// Definitions by: Jussi Kinnula <https://github.com/jussikinnula>
// Borek Bernard <https://github.com/borekb>
// Eric Naeseth <https://github.com/enaeseth>
// Max Beatty <https://github.com/maxbeatty>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export interface DotenvParseOptions {
/**
* You may turn on logging to help debug why certain keys or values are not being set as you expect.
*/
debug?: boolean;
}
export interface DotenvParseOutput {
[name: string]: string;
}
/**
* Parses a string or buffer in the .env file format into an object.
*
* @param src - contents to be parsed
* @param options - additional options
* @returns an object with keys and values based on `src`
*/
export function parse(src: string | Buffer): {[name: string]: string};
export function parse(
src: string | Buffer,
options?: DotenvParseOptions
): DotenvParseOutput;
export interface DotenvConfigOptions {
/**
* You may specify a custom path if your file containing environment variables is located elsewhere.
*/
path?: string;
/**
* You may specify the encoding of your file containing environment variables.
*/
encoding?: string;
/**
* You may turn on logging to help debug why certain keys or values are not being set as you expect.
*/
debug?: boolean;
}
export interface DotenvConfigOutput {
error?: Error;
parsed?: DotenvParseOutput;
}
/**
* Loads `.env` into `process.env`.
*
* @return Object Object with either
* - "parsed" containing the parsed keys and values or
* - "error" containing an Error object
*
* Loads `.env` file contents into {@link https://nodejs.org/api/process.html#process_process_env | `process.env`}.
* Example: 'KEY=value' becomes { parsed: { KEY: 'value' } }
*
* @param options - controls behavior
* @returns an object with a `parsed` key if successful or `error` key if an error occurred
*
*/
export function config(options?: DotenvOptions): DotenvResult;
export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
export const load: typeof config;
export interface DotenvOptions {
/**
* You can specify a custom path if your file containing environment variables is named or located differently.
*
* @default '.env'
*/
path?: string;
/**
* You may specify the encoding of your file containing environment variables using this option.
*
* @default 'utf8'
*/
encoding?: string;
}
export interface DotenvResult {
error?: Error;
parsed?: {
[name: string]: string;
};
}