https://github.com/coursedesign/conev-source-json
conev-source-json is an implementation of conev's source to get configuration from json.
https://github.com/coursedesign/conev-source-json
conev configuration environment npm npm-package
Last synced: about 1 month ago
JSON representation
conev-source-json is an implementation of conev's source to get configuration from json.
- Host: GitHub
- URL: https://github.com/coursedesign/conev-source-json
- Owner: CourseDesign
- Created: 2020-03-18T15:23:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T06:02:16.000Z (over 3 years ago)
- Last Synced: 2025-02-10T08:51:29.051Z (over 1 year ago)
- Topics: conev, configuration, environment, npm, npm-package
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/conev-source-json
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# conev-source-json
conev-source-json is an implementation of conev's source to get configuration from json.

## Install
```shell
# with npm
npm install conev-source-json
# or with Yarn
yarn add conev-source-json
```
## Usage
Get ConfigBuilder from conev and Sources to use.
```typescript
import { ConfigBuilder } from 'conev';
import JsonSource from 'conev-source-json';
```
And create Source and set up.
```typescript
const jsonSource = new JsonSource();
jsonSource
.setConfig('basic', basic) // basic is JSON
.setConfig('dev', dev) // dev is JSON
.setConfig('prd', prd); // prd is JSON
```
Create ConfigBuilder and set Environment, add source. (highest priority is added first).
```typescript
const builder = new ConfigBuilder();
builder
.setEnv('dev', 'basic')
.addSource(jsonSource);
```
Build configuration
```typescript
const config = await builder.build(); // This is the result of combining dev and basic.
```
Use configuration
```typescript
config.get() // The whole configuration created comes out
config.get('a.b.c'); // Is same as config.get().a.b.c
```
## Json Source
```typescript
class JsonSource {
constructor(map?: Map);
setConfig(env: string, ...values: object[]): JsonSource
addConfig(env: string, ...values: object[]): JsonSource;
removeConfig(env: string): JsonSource;
export(): Promise>;
}
```
`JsonSource` defines the source from JSON. Use `setConfig` to add a configuration for a new environment or ` removeConfig` to delete a configuration. Map is returned as the result value of `export`. The key of this map is environment and the value is the configuration when environment.