Socket
Socket
Sign inDemoInstall

node-confmanager

Package Overview
Dependencies
5
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-confmanager

A configuration manager


Version published
Weekly downloads
3
decreased by-94.34%
Maintainers
1
Install size
164 kB
Created
Weekly downloads
 

Readme

Source

node-confmanager

A configuration manager

Build status Coverage status Dependency status Dev dependency status Issues Pull requests

Installation

$ npm install node-confmanager

Features

  • All the features of the node-containerpattern package
  • clone data in "get" action to avoid unwanted changes
  • Saving the data in a JSON file
  • Load the data from this JSON file and/or commandline
  • access to the data with shortcuts in commandline

Doc

see the node-containerpattern documentation to see extended methods & attribues

node-confmanager

-- Attributes --

  • filePath: string conf file
  • spaces: string formate file
  • shortcuts: string for container

-- Constructor --

  • constructor(confPath?: string, spaces?: boolean, recursionSeparator?: string)

-- Methods --

  • deleteFile() : return Promise instance delete the conf file
  • fileExists() : return Promise instance => then((exists) => {}) check if the conf file exists
  • clearShortcuts() : return this forget all the shortcuts
  • clear() : return this node-containerpattern.clear & clearShortcuts
  • load() : return Promise instance load data from conf file then commandline (commandline takeover)
  • save() : return Promise instance save data into conf file
  • shortcut(string key, string shortkey) : return this bind a shortcut for commandline

Examples

Native

const ConfManager = require("node-confmanager");

const conf = new ConfManager(require("path").join(__dirname, "conf.json"));

conf
  .skeleton("debug", "boolean") // add skeleton (based on [node-containerpattern](https://www.npmjs.com/package/node-containerpattern)) to check datatype
  .shortcut("debug", "d") // add shortcut to simply use comandline params, can add "-d true" to commandline to activate debug
  .shortcut("usr.login", "ul")
  .shortcut("usr.password", "up");

conf.fileExists().then((exists) => {
  
  return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" })
      .set("debug", false)
      .set("prod", "n") // = false
      .save();

}).then(() => {

  // can add "--usr.login login2" or "-ul login2" to commandline to force login change
  return conf.load();

}).then(() => {

    console.log(conf.get("debug"));
    console.log(conf.get("usr.login"));

}).catch((err) => {
  console.log(err);
});

Typescript

import ConfManager = require("node-confmanager");
import { join } from "path";

const Conf = new ConfManager(join(__dirname, "conf.json"));

Conf
  .skeleton("debug", "boolean").shortcut("debug", "d")
  .shortcut("usr.login", "ul")
  .shortcut("usr.password", "up");

Conf.fileExists().then((exists: boolean) => {

  return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" })
      .set("debug", false)
      .set("prod", "n") // = false
      .save();

}).then(() => {

  return Conf.load();

}).then(() => {

    console.log(Conf.get("debug"));
    console.log(Conf.get("usr.login"));

}).catch((err: Error) => {
  console.log(err);
});

Run

node mysoft.js -d
node mysoft.js --debug
node mysoft.js --debug "true"
node mysoft.js --debug "yes"
node mysoft.js --debug "y"

Tests

$ npm run-script tests

License

ISC

Keywords

FAQs

Last updated on 23 May 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc