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

africa

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

africa

A library to interactively create and read configuration files.

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

africa

npm version Build status Pipeline Badge

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.

yarn add africa

Table Of Contents

API

The package is available by importing its default function:

import africa from 'africa'

async africa(
  packageName: string,
  questions=: !_reloquent.Questions,
  config=: !Config,
): !Object

Read package configuration from the home directory, or ask questions with readline interface to create a new configuration in ~/.${packageName}rc.

  • packageName* string: The name of the package.
  • questions !_reloquent.Questions (optional): An object with questions to ask when config wasn't found.
  • config !Config (optional): Configuration object.

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

Config: The configuration object to configure additional functionality.

NameTypeDescriptionDefault
forcebooleanAsk questions and update the configuration file even if it already exists.false
homedirstringIn which directory to save and search for configuration file.os.homedir()
questionsTimeoutnumberHow log to wait in ms before timing out. Will wait forever by default.-
localbooleanWhether 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.false
recursivebooleanpaid Read all configurations up to the root one from the home directory, and merge them together.false
skipExistingbooleanpaid When creating nested configs, skip writing values that are taken from parent RCs.true
rcNameFunction(packageName: string) => stringFunction used to generate the .rc name. Default: packageName => .${packageName}rc.-
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)
  }
})()
user: [zavr]
{ name: 'zavr' }

Groups

It's possible to ask questions in groups, such that answers will be received in a nested object. Only 1 level of nesting is supported at the moment. To group questions, import the Group type and pass questions to it.

import africa, { Group } from 'africa'

africa('test', {
  group: new Group({
    test: {
      text: 'hello',
    },
  }),
  nongroup: {
    text: 'your-name',
  },
}, { force: true, homedir: __dirname })
your-name: [name-doc] name-doc
hello: [world-doc] world-doc
{
  "nongroup": "name-doc",
  "group": {
    "test": "world-doc"
  }
}

Photo Diana Robinson, 2017

GNU Affero General Public License v3.0

Art Deco © Art Deco™ 2020AGPL-3.0

Keywords

FAQs

Package last updated on 02 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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