Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-envconfig

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-envconfig - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

2

package.json
{
"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": {

@@ -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');
})
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc