Skip to content

Commit

Permalink
Auto-fixing code
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Aug 6, 2019
1 parent aa36937 commit a46113f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
8 changes: 0 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[npm]: https://www.npmjs.com/package/universal-dotenv
[travis]: https://travis-ci.org/sebastian-software/universal-dotenv
[appveyor]: https://ci.appveyor.com/project/swernerx/universal-dotenv/branch/master

[sponsor-img]: https://badgen.net/badge/Sponsored%20by/Sebastian%20Software/692446
[deps-img]: https://badgen.net/david/dep/sebastian-software/universal-dotenv
[npm-downloads-img]: https://badgen.net/npm/dm/universal-dotenv
Expand All @@ -26,20 +25,17 @@ This solution is heavily inspired by the approach chosen by [Create React App](h
- Supports variable expansion between different settings.
- Allows local overrides using files which use a ".local" postfix.


## All Strings

It is important to remember that all environment variables are always stored as strings. Even numbers and booleans. The casting to other types must therefore take place in the application code. See also: https://github.com/motdotla/dotenv/issues/51


## Variables

- `NODE_ENV`: Typically either `production`, `development` or `test`
- `ENV_CONTEXT`: Often used for e.g. `client` or `server`. Can be also something totally custom e.g. `docker`, `staging`, etc.
- `APP_ROOT`: Points to the root folder of the application (absolute filesystem path)
- `APP_SOURCE`: Points to the source folder. If `src` exists this is being used. Otherwise the assumption is that it's identical to the `APP_ROOT`.


## File Priority

Files are being loaded in this order. Values which are already set are never overwritten. Command line environment settings e.g. via [cross-env](https://www.npmjs.com/package/cross-env) always win.
Expand All @@ -55,7 +51,6 @@ Files are being loaded in this order. Values which are already set are never ove

Note: `local` files without `NODE_ENV` are not respected when running in `NODE_ENV=test`.


## Basic Usage

All loading features are enabled by importing the core module itself:
Expand All @@ -70,7 +65,6 @@ After this you can access all environment settings you have defined in one of yo
console.log(process.env.APP_MY_ENV)
```


## Serialization

The module offers access to all app specific environment settings which should be prefixed with `APP_` e.g. `APP_TITLE = "My App"`.
Expand Down Expand Up @@ -112,12 +106,10 @@ const { raw, stringified, webpack } = getEnvironment({

By default the `getEnvironment()` method translates strings which look like numbers or booleans into their native type representation. To disable this behavior pass over `false` for `enableTranslation` like:


```js
const { raw, stringified, webpack } = getEnvironment({ translate: false })
```


## License

[Apache License Version 2.0, January 2004](license)
Expand Down
16 changes: 7 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ export function init(): void {
type EnvValue = string | boolean | number | undefined

export interface EnvMap {
[s: string]: EnvValue;
[s: string]: EnvValue
}

export interface Environment {
raw: EnvMap;
stringified: EnvMap;
raw: EnvMap
stringified: EnvMap
webpack: {
"process.env": EnvMap;
};
"process.env": EnvMap
}
}

function defaultFilterEnv(key: string): boolean {
Expand All @@ -90,11 +90,9 @@ function defaultFilterEnv(key: string): boolean {
const truthy = new Set([ "y", "yes", "true", true ])
const falsy = new Set([ "n", "no", "false", false ])



export interface GetEnvironmentOptions {
filter?: (key: string) => {};
translate?: boolean;
filter?: (key: string) => {}
translate?: boolean
}

export function getEnvironment({
Expand Down
1 change: 0 additions & 1 deletion src/noenv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ test("Defaults to development for NODE_ENV", () => {
expect(stringified).toMatchSnapshot(snapshotOpts)
expect(webpack).toBeDefined()
})

2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module 'cross-env';
declare module "cross-env"

0 comments on commit a46113f

Please sign in to comment.