An open API service indexing awesome lists of open source software.

https://github.com/artdecocode/africa

A library to interactively create and read configuration files.
https://github.com/artdecocode/africa

Last synced: 11 months ago
JSON representation

A library to interactively create and read configuration files.

Awesome Lists containing this project

README

          

# africa

[![npm version](https://badge.fury.io/js/africa.svg)](https://npmjs.org/package/africa)


Africa

`africa` is a _Node.JS_ package which simplifies reading from and writing to persistent configuration files in user's home directory. If a configuration exists, it will be read, and if not, the user will be presented with questions, after which the answers will be stored in the `.rc` file.

```sh
yarn add africa
```

## Table Of Contents

- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`async africa(packageName: string, questions: object, config?: AfricaConfig): Object`](#async-africapackagename-stringquestions-objectconfig-force-booleanhomedir-stringquestionstimeout-numberlocal-booleanrcnamefunction-function-object)
* [`_africa.Config`](#type-_africaconfig)



## API

The package is available by importing its default function:

```js
import africa from 'africa'
```



## `async africa(`
  `packageName: string,`
  `questions: object,`
  `config?: {`
    `force?: boolean,`
    `homedir?: string,`
    `questionsTimeout?: number,`
    `local?: boolean,`
    `rcNameFunction?: function,`
  `},`
`): Object`

Call `africa` asynchronously to read or create a new configuration. Questions should adhere to the [`reloquent`][2]'s interface.

| Argument | Description |
| ------------- | --------------------------------------------------------------------------------------------------- |
| `packageName` | Name of the package which uses `africa`. It will be used when generating a name for the `.rc` file. |
| `questions` | An object with questions answers to which will be saved into the `.rc` file. |
| `config` | Additional configuration parameters, see [`AfricaConfig` Type](#africaconfig-type). |

```javascript
import africa from 'africa'
import { userInfo } from 'os'

(async () => {
try {
const config = await africa('africa', {
name: {
defaultValue: userInfo().username,
text: 'user',
},
}, { force: true })
console.log(config)
} catch ({ stack }) {
console.log(stack)
}
})()
```

```sh
user: [zavr]
{ name: 'zavr' }
```

`_africa.Config`: The configuration object to configure additional functionality.


Name
Type & Description
Default


force
boolean
false



Ask questions and update the configuration file even if it already exists.


homedir
string
os.homedir()



In which directory to save and search for configuration file.


questionsTimeout
number
-



How log to wait in ms before timing out. Will wait forever by default.


local
boolean
false



Whether to read a local config file in the current working directory rather than in the HOMEDIR. When initialising, the default values will be taken from the home config if it exists so that it is easy to extend .rc files.


rcNameFunction
function(string): string
-



Function used to generate the .rc name. Default: packageName => .${packageName}rc.



Photo [Diana Robinson][3], 2017




Art Deco


© Art Deco 2019


Tech Nation Visa


Tech Nation Visa Sucks

[2]: https://www.npmjs.com/package/reloquent
[3]: https://www.flickr.com/photos/dianasch/31316774424/in/photolist-PHmDYC-moFj48-Q4Aya5-63Gpiw-mLTkJi-VNKhAn-Rz3Mrh-62BZoA-5q9HuM-6cnt7G-5Jv17M-zn5DFn-5QA73Q-6xjraT-aqGVsL-odrGp-azaw9g-wJQZ9M-4nGawg-4rHcYe-atRxbW-5JYiwy-eki9WF-ahdLm5-aTm2jZ-bp9exn-9xL37X-NBPkZ9-38Exqu-69Wv9G-7yxhvg-8GsnfW-agEC2n-svkzJf-k1ihc6-pPd9Aj-5SuyNP-aAg4Gf-DAMWZ1-DHceLL-oCxZ7U-pQe8E4-y875RB-c21GHN-dNZXJ3-NJ5yVx-e663y6-e6bFDq-jYo6Sm-cem5Xu