# @frenchex/config-api

> Configuration API

Latest version **0.3.2** (published 2020-12-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @frenchex/config-api
pnpm add @frenchex/config-api
yarn add @frenchex/config-api
bun add @frenchex/config-api
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2020-12-11 |
| First published | 2020-01-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Stéphane Erard |
| Maintainers | serard, s.erard |
| Keywords | configuration, api |

## Links

- npm: https://www.npmjs.com/package/@frenchex/config-api
- Repository: https://github.com/French-Exception/node-config-api
- Homepage: https://github.com/French-Exception/node-config-api#readme
- Issues: https://github.com/French-Exception/node-config-api/issues
- npm.io page: https://npm.io/package/@frenchex/config-api

## Dependencies (1)

- [@frenchex/config-lib](https://npm.io/package/@frenchex/config-lib.md) ^0.3.5

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2020-12-11
- 0.3.1 — 2020-11-03
- 0.0.12 — 2020-04-10
- 0.0.11 — 2020-01-29
- 0.0.10 — 2020-01-29
- 0.0.9 — 2020-01-21
- 0.0.8 — 2020-01-20
- 0.0.7 — 2020-01-20
- 0.0.6 — 2020-01-20
- 0.0.5 — 2020-01-20
- 0.0.4 — 2020-01-20
- 0.0.3 — 2020-01-20
- 0.0.2 — 2020-01-19

## README

# About

Configuration API let you use Configuration Lib with your own code.

It helps create and load User-scoped, Global-scoped and Directory-scoped Configuration files.

Configuration files can be ```.json``` or ```.js``` files returning plain JSON or 

# Installation

```bash
npm i --save @frenchex/config-api
```

# Usage 
## From File
Example loading from file (from tests) :
```typescript
import * as api from "@frenchex/config-api"

const config = await api.fromFile({
    env: {env: 'dev'},
    file: path.join(testResourcesRootPath, 'js.js'),
    root: testResourcesRootPath
})

const foobar = await config.get<string>('foo.bar');
const foobar2 = await config.get<string>('foo.foobar');
const foo = await config.get<{ bar: string, foobar: string }>('foo');
const promise = await config.get<string>('promise');

expect(foobar).to.be.equal('foobar');
expect(foobar2).to.be.equal('foobarfoobar');
expect(foo).to.be.deep.equal({bar: 'foobar', foobar: 'foobarfoobar'});
expect(promise).to.be.deep.equal('resolved');
```

## From JS object
Example loading config from object (from tests):
```typescript

const config = await api.fromDeclaration({
    $: {
        foo: {
            bar: 'foobar'
        }
    }
})

const bar = await config.get<string>('foo.bar');
expect(bar).to.be.equal('foobar');
```


## From File & JS object

You can also do both

````typescript
const config = await api.fromFile({
    env: {env: 'dev'},
    file: path.join(testResourcesRootPath, 'js.js'),
    root: testResourcesRootPath,
    $: {
        "imports": ['my_file_%env%.json'],  
    }
})
````

---
_Source: https://npm.io/package/@frenchex/config-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
