Skip to content

Commit

Permalink
Change typings, add to package.json (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeyBurkman authored and evanshortiss committed Dec 15, 2016
1 parent 102615c commit 21d2ecc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ describe('concat.js', function () {

```

## TypeScript
To use with TypeScript, just import it like this:
```ts
import env from 'get-env';

const stringVar = env('STRING').required().asString();
```

## Contributors
* @MikeyBurkman
* @itavy
45 changes: 28 additions & 17 deletions env-var.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@

declare function E (varName: string, defaultValue?: string): E.IVariable;

declare namespace E {

interface IVariable {
required: () => IVariable,
asInt: () => number,
asFloat: () => number,
asPositiveInt: () => number,
asNegativeInt: () => number,
asString: () => string,
asJson: () => Object|Array<any>,
asBool: () => boolean,
asStrictBool: () => boolean,
}
export interface IPresentVariable {
asFloat: () => number;
asInt: () => number;
asPositiveInt: () => number;
asNegativeInt: () => number;
asString: () => string;
asJson: () => Object|Array<any>;
asBool: () => boolean;
asStrictBool: () => boolean;
}

function mock (mockValues: Object): (varName: string, defaultValue?: string) => E.IVariable;
export interface IOptionalVariable {
required: () => IPresentVariable;
asFloat: () => number|undefined;
asInt: () => number|undefined;
asPositiveInt: () => number|undefined;
asNegativeInt: () => number|undefined;
asString: () => string|undefined;
asJson: () => Object|Array<any>|undefined;
asBool: () => boolean|undefined;
asStrictBool: () => boolean|undefined;
}

export interface IEnv {
(): Object,
(varName: string): IOptionalVariable;
(varName: string, defaultValue: string): IPresentVariable;
mock(mockVars: Object): IEnv;
}

export = E;
export const env: IEnv;
export default env;
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "env-var",
"version": "2.3.1",
"version": "2.3.2",
"description": "programmatic wrapper for process.env with support for defaults",
"main": "lib/index.js",
"scripts": {
Expand All @@ -25,7 +25,10 @@
],
"author": "Evan Shortiss",
"license": "MIT",
"files": ["lib/"],
"files": [
"lib/",
"env-var.d.ts"
],
"bugs": {
"url": "https://github.com/evanshortiss/env-var/issues"
},
Expand Down

0 comments on commit 21d2ecc

Please sign in to comment.