ngx-envconfig
Advanced tools
Comparing version 1.2.2 to 1.2.3
{ | ||
"name": "ngx-envconfig", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Configuration utility for Angular app based on the environment variables ", | ||
@@ -5,0 +5,0 @@ "repository": { |
115
README.md
@@ -7,2 +7,11 @@ # ngx-envconfig | ||
## Using JSON files configure your app like a boss | ||
Specify a list of API endpoints in the JSON and use the values from your code. | ||
![](demo1.gif) | ||
Look how beautiful is your code :blush: | ||
![](demo2.gif) | ||
## Table of contents: | ||
@@ -42,55 +51,2 @@ 1. [ Features ](#features) | ||
<a name="api"></a> | ||
# API Reference | ||
<a name="module"></a> | ||
### ConfigModule | ||
- *.forRoot(envConfig: EnvConfig)* Based on the provided `envConfig.state` value, it will load the approprate `*.json` config file. It assumes that configuration json files are located under `./src/assets/config` folder. Angular will bootstrap the app, only after the configuration `*.json` file is loaded. | ||
### EnvConfig | ||
- *.state: string* Specifies the environment. For instane if it's equalt to `'development'` then will load `development.json` file from `./src/assets/config` folder | ||
- *.fallbackDev: boolean = false* Indicates whether to get the value from `development.json` configuration if there is no match in the specified environment. For instance if `"SOME_KEY"` does not exist in `production.json` then it will return the value of `"SOME_KEY"` from `development.json`, if `"SOME_KEY"` value does exist `development.json` file. | ||
<a name="service"></a> | ||
### ConfigService | ||
- *.get(propertyName: string): any*. Returns the corresponding value of the provided property `propertyName` config file. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.get('HOST_API')) | ||
// prints: 'http://development.server.com' in development mode | ||
} | ||
``` | ||
- *.getEnv(): string*. Returns the current environment | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.getEnv()) | ||
// prints: 'development' in development mode | ||
} | ||
``` | ||
- *.isDevMode(): boolean*. Returns `true` if environment is development, otherwhise `false` | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.isDevMode()) | ||
// prints: true in development mode | ||
} | ||
``` | ||
- *.getApi(endpoint: string): string*. This function will only work if you have provided `"API_ENDPOINTS"` object in cofig file, which provides the list of available API endpoints and `"HOST_API"` which is the API's host URL. Returns API endpoint from `"API_ENDPOINTS"` by concatenating it with `"HOST_API"`. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.getApi('USER')) | ||
// prints: 'http://development.server.com/api/v1/user' in development mode | ||
} | ||
``` | ||
- *.onLoad: AsyncSubject<boolean> boolean*. Async subject to be subscribed. Emits when the config file is already loaded. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
this.config.onLoad.subscribe(()=>{ | ||
console.log('Config file is loaded'); | ||
}) | ||
} | ||
``` | ||
<a name="started"></a> | ||
@@ -292,1 +248,54 @@ # Getting Started | ||
<a name="api"></a> | ||
# API Reference | ||
<a name="module"></a> | ||
### ConfigModule | ||
- *.forRoot(envConfig: EnvConfig)* Based on the provided `envConfig.state` value, it will load the approprate `*.json` config file. It assumes that configuration json files are located under `./src/assets/config` folder. Angular will bootstrap the app, only after the configuration `*.json` file is loaded. | ||
### EnvConfig | ||
- *.state: string* Specifies the environment. For instane if it's equalt to `'development'` then will load `development.json` file from `./src/assets/config` folder | ||
- *.fallbackDev: boolean = false* Indicates whether to get the value from `development.json` configuration if there is no match in the specified environment. For instance if `"SOME_KEY"` does not exist in `production.json` then it will return the value of `"SOME_KEY"` from `development.json`, if `"SOME_KEY"` value does exist `development.json` file. | ||
<a name="service"></a> | ||
### ConfigService | ||
- *.get(propertyName: string): any*. Returns the corresponding value of the provided property `propertyName` config file. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.get('HOST_API')) | ||
// prints: 'http://development.server.com' in development mode | ||
} | ||
``` | ||
- *.getEnv(): string*. Returns the current environment | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.getEnv()) | ||
// prints: 'development' in development mode | ||
} | ||
``` | ||
- *.isDevMode(): boolean*. Returns `true` if environment is development, otherwhise `false` | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.isDevMode()) | ||
// prints: true in development mode | ||
} | ||
``` | ||
- *.getApi(endpoint: string): string*. This function will only work if you have provided `"API_ENDPOINTS"` object in cofig file, which provides the list of available API endpoints and `"HOST_API"` which is the API's host URL. Returns API endpoint from `"API_ENDPOINTS"` by concatenating it with `"HOST_API"`. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
console.log(this.config.getApi('USER')) | ||
// prints: 'http://development.server.com/api/v1/user' in development mode | ||
} | ||
``` | ||
- *.onLoad: AsyncSubject<boolean> boolean*. Async subject to be subscribed. Emits when the config file is already loaded. | ||
```javascript | ||
constructor(private config: ConfigService){ | ||
this.config.onLoad.subscribe(()=>{ | ||
console.log('Config file is loaded'); | ||
}) | ||
} | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
299
0
57854
27