npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

setup-manager

v1.3.0

Published

The interface to create JSON configurations within code

Downloads

30

Readme

Setup Manager — The interface to create JSON configurations within code

NPM version Build Status Join the chat at https://gitter.im/termosa/setup-manager

Simple API to extend and generate deep nested hash objects in JavaScript.

Installation

To install Setup Manager, simply:

$ npm install --save setup-manager

API

constructor(/* object */ source)

Constructor can receive an optional object to clone it and use as a base.

var constructor = require("setup-manager");
var manager = constructor(source);

It returns an object with the list of functions

manager.set(/* string | object */ name, value)

It sets the dot-separated property with passed value to the result object.

It has several uncommon features:

  • Extends exists object in specified property with value's properties if value is an object.
  • Concatenates exists array in specified property if value is an array.
  • Uses name to extend core object if name is an object.
  • Returns setter-function if value is not defined. This function can be called with value to set the property defined in set method.
constructor().set("name", "value").setup();
// Returns: { "name": "value" }

constructor().set("name", { prop: "value" }).setup();
// Returns: { "name": { "prop": "value" }}

constructor().set("name.prop", "value").setup();
// Returns: { "name": { "prop": "value" }}

constructor()
  .set("name.prop1", "value1")
  .set("name.prop2", "value2")
  .setup();
// Returns: { "name": { "prop1": "value1", "prop2": "value2" }}

var config = constructor();
var builder = config.set("list");
builder([ 7, 13 ])([ 42 ]);
config.setup();
// Returns: { list: [ 7, 13, 42 ] }
manager.get(/* string */ name)

It returns the value of specified property

constructor().set("user.name", "John").get("user.name");
// Returns: "John"
manager.setup()

It returns the object with all sets applied to it

constructor()
  .set("user.name", "Alice")
  .set("user.email", "[email protected]")
  .setup(); 
// Returns: { "user": { "name": "Alice", "email": "[email protected]" }}

Usage

To create the plain list:

var session = require("setup-manager")();

session.set("username", "John Mora");
session.set("email", "[email protected]");

module.exports = session.setup();

/* Will return:
 * {
 *   "username": "John Mora",
 *   "email":    "[email protected]"
 * }
 */

To create the nested object:

var server = require("setup-manager");

server.set("name", "slave-01");
server.set("host.domain", "localhost");
server.set("host.port", 7364);

module.exports = server.setup();

/* Will return:
 * {
 *   "name": "slave-01",
 *   "host": {
 *     "domain": "setup-manager.npm",
 *     "port":   7364
 *   }
 * }
 */

To extend the object:

// default.config.js
var config = require("setup-manager");

config.set("env", "production");
config.set("host", {
  protocol: "https",
  domain:   "setup-manager.npm",
  port:     7364
});

module.exports = config.setup();
// local.config.js
var base_configuration = require("./default.config.js");
var config = require("setup-manager")(base_configuration);

config.set("env", "development");
config.set("host", {
  domain: "localhost",
  port:   3080
});

module.exports = config.setup();

/* Will return:
 * {
 *   "env": "development",
 *   "host": {
 *     "protocol": "https",
 *     "host":     "localhost",
 *     "port":     3080
 *   }
 * }
 */

To create the complex configuration:

var SuperPlugin = require("SuperPlugin");
var base_configuration = require("./default.config.js");
var config = require("setup-manager")(base_configuration);

var setAlias = config.set("resolve.alias");
var setPlugins = config.set("plugins");

function addAlias(name, source) {
  var alias = {};
  alias[name] = source;
  setAlias(alias);
}

function addPlugin(plugin) {
  setPlugins([plugin]);
}

// set vendor aliases
addAlias("module", "./modules");
addAlias("style", "./styles");

// setup an extra plugin
addPlugin(new SuperPlugin({ mode: "unsafe" }));
addAlias("super", "./node_modules/SuperPlugin/vendors");

module.exports = config.setup();

/* Will return:
 * {
 *   "plugins": [ SuperPlugin { mode: "unsafe" } ],
 *   "resolve": {
 *     "alias": {
 *       "modue": "./modules",
 *       "style": "./styles",
 *       "super": "./node_modules/SuperPlugin/vendors"
 *     }
 *   }
 */