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

blacktea.configmanager

v0.1.0

Published

A configuration manager that manages configuration inside json files

Downloads

2

Readme

#blacktea.configManager A configuration manager able to manage configurations inside json files. ##Overview

##Installation Install it via the npm command: npm install blacktea.configManager --save ##Usage For the library to work, you need to add a configuration path to your package.json file: "configurationDirectory":"Config" In the above example we set /Config as the configuration directory. Now load the library: var configuration = require("blacktea.configManager"); Suppose you have a json file called ./Config/subdir/test.json with the following content:

{
    "path":{
        "to":{
            "value":"testingValue"
        }
    }
}

reading a configuration is as simple as: var someValue = configuration.get("subdir/test","/path/to/value"); In the above example you read the value "testingValue". Setting a value is just as simple: configuration.set("subdir/test","path/to/new/value",{new:"value"}) Now you have a json file which looks like this:

{
    "path":{
        "to":{
            "value":"testingValue",
            "new":{
                "value":{
                    "new":"value"
                }
            }
        }
    }
}

If you want to delete a value: configuration.delete("subdir/test","/path/to/value"); The resulting json file looks like this:

{
    "path":{
        "to":{
            "new":{
                "value":{
                    "new":"value"
                }
            }
        }
    }
}

You can also merge values: configuration.merge("subdir/test","path/to/new/value",{another:["a","b","c"]}); And you get:

{
    "path":{
        "to":{
            "new":{
                "value":{
                    "new":"value",
                    "another":["a","b","c"]
                }
            }
        }
    }
}

Accessing array values is also possible: var arrayValue = configuration.get("subdir/test","/path/to/new/value/another[1]"); will get you the value "b" The library also supports some useful methods like push/pop or append/shift. All are described in detail in dhe documentation section. The library supports a simple forEach method, which goes through all elements of a configuration json value and executes a callback. The value can be either an object or array. If it is neither, the callback will execute only once on the json value itself:

configuration.forEach("subdir/test","path/to/new/value/another",function(value,key,configurationPath){
    console.log("the value is: "+value);
    console.log("the key is: "+key);
    console.log("the configuration path is: "+configurationPath);
});

This module uses the json-templating library blacktea.jsonTemplates, which means it supports basic template strings. It injects a helper with its own functions into the jsonTemplates library and thus you can make a few very nice things. Assuming our test.json file would have the following content:

{
    "key1":"{{config.get('subdir/test','key3')}}",
    "key2":10,
    "key3":"{{config.get('subdir/test','key2')}}"
}

##Documentation -get(configPath, jsonPath) gets a configuration value. Throws an exception if the value doesn't exist. configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file -getOrDefault(configPath, jsonPath, defaultValue) gets a configuration value. If the value doesn't exist, it returns the default value. configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file defaultValue - the default value to return, if the actual value doesn't exist -set(configPath, jsonPath, value) sets a configuration value. configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file value - the value to set -delete(configPath, jsonPath) deletes a configuration value. configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file -merge(configPath, jsonPath, value) merges a value into an existing configuration. configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file value - the value to merge -forEach(configPath, jsonPath, callbask) goes through all values and calls a callback with the value, key and the json path of the current iteration. If value is an array or object, it calls the callback on each member, else it calls the callback on the actual value configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file callback - the callback with the arguments value, key, jsonPath. -append(configPath, jsonPath, value) appends a value to a configuration array configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file value - the value to append -push(configPath, jsonPath, value) prepends a value to a configuration array configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file value - the value to prepend -shift(configPath, jsonPath) removes the first value of a configuration array and returns it configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file -pop(configPath, jsonPath) removes the last value of a configuration array and returns it configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file -clear(configPath, jsonPath) empties a configuration array configPath - the path of the configuration file jsonPath - the path to the value inside of the configuration file -packageJson(configPath, defaultValue) an attempt to read the package.json file. The module searches for the file in the root directory jsonPath - the configuration path to the value inside the package.json defaultValue - the default value to return if the configuration wasn't found ##Licence blacktea.configManager is released under the MIT License.