Giter Site home page Giter Site logo

perry-mitchell / user-config Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 5 KB

Easy user application configuration management

License: MIT License

JavaScript 100.00%
config configuration configuration-file settings settings-storage user-profile nodejs

user-config's Introduction

user-config

Easy user application configuration management

Build Status npm version

Usage

When requiring the library, user-config returns a function which is used to instantiate a config object that allows getting and setting of config values:

const createConfig = require("user-config");

const config = createConfig("my-app");

// items in config are stored in objects and must be serialisable
config.set("some.config.item", 123);

Configuration changes should be saved after being changed:

const config = require("user-config")("my-app");

config.set("port", 443);
config.save();

Values can easily be retrieved from the store, including entire objects:

const config = require("user-config")("my-app");

console.log(`Application running on interface ${config.get("listen.ip")}`);

Templating

Outdated configurations can be updated using a templating system. By passing a template to the creation of the config store, old configurations can be merged with the template to ensure the presence of keys and structures:

const createConfig = require("user-config");

const TEMPLATE = {
    ip: "0.0.0.0",
    encryption: {
        mode: "aes-gcm"
    }
}
const config = createConfig("my-app", TEMPLATE);
config.get("encryption.mode"); // "aes-gcm"

Browser usage

When being used in the context of a browser, user-config knows to use localStorage instead of the filesystem. Storage switching is transparent.

user-config's People

Contributors

perry-mitchell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.