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

hyper-config

v0.1.20

Published

Config wrapper with merge, references, string macros, tagging, yml and json file loading, environment support

Downloads

23

Readme

Hyper config

Config wrapper with merging, references, string macros, tagging, etc.

var HyperConfig = require('hyper-config');

Api

  • HyperConfig(object):

    • refLabel: string, '~' - reference label to config parts
    • annotationLabel: string, '@' - annotation label, mark control config parts
    • macroBegin: string, '{' - used in macro string replacement
    • macroEnd: string, '}' - used in macro string replacement
  • addConfig(object): deep merge js object to config

  • build(): build config and return config session object:

    • get(string): get config part by dot-separated path string or undefined if wrong path
    • getByTag(string): return array with config parts, marked by tag

Overview

  • ~ - link to parts of config
  • ~{path} - replacement macro string
  • ~disable - command to delete this config object branch
  • @tag - array of tag names, group by provided tag names
"section": {
  "subsection": {
    "value": "test"
  },
  "name1": {
    "value": 123,
    "param": "~{section.subsection.value}/qweqwe",
    "param2": "~~test/~~{section.subsection.value}",
    "@tag": ["tag1", "tag2"]
  },
  "name2": {
    "ref": "~section.name1"
  },
  "name3": {
    "val": "test"
  }
},

"section2.subsection2.name1": {
  "value": "example"
}
//init.js
var Config = HyperConfig().addConfig(require('./config.json'));

Config.addConfig({
  section: {
    name3: '~disable'
  }
});

var config = Config.build();

console.log(config.get('section.subsection')); //{value: 'test'}
console.log(config.get('section.subsection.qweiweruhwitur')); // undefined
console.log(config.get('section2.subsection2.name1.value')); // example
console.log(config.get('section.name1.param')); // test/qweqwe
console.log(config.get('section.name1.param2')); // ~test/~{section.subsection.value}
console.log(config.get('section.name2.ref')); // {value: 123, param: 'test/qweqwe'}
console.log(config.get('section.name3')); // undefined
console.log(config.getByTag('tag1')); // [{value: 123, param: 'test/qweqwe'}]

Merge configs

var HyperConfig = require('hyper-config');

var defaultConfig = {
  logger: {
    transports: {
      console: {
        proc: 'console.log'
      },
      file: {
        fileName: 'test'
      }
    }
  }
};
var envConfig = {};
if (process.env.NODE_ENV === 'development') {
  envConfig = {
    logger: {
      file: {
        fileName: 'test-dev'
      }
    }
  };
}

var someConfig = {
  'logger.transports.file.fileName': 'test-some'
};
// expands to {logger: {transports: { file: {fileName: 'test'}}}}

var config = HyperConfig()
  .addConfig(defaultConfig);
  .addConfig(envConfig)
  .addConfig(someConfig)
  .build();

console.log(config.get('logger.transports.file.fileName')); // test-some in development, test in other
console.log(config.get('wrongpath')); // undefined

References and macros

var HyperConfig = require('hyper-config');

var defaultConfig = {
  console: {
    proc: 'console.log',
    name: '~common.name',
    obj: '~common.data',
    email: '~common.name@-name@@mail.test'
  },
  common: {
    name: 'test',
    data: {
      name: 'test data'
    }
  }
};

var config = HyperConfig()
  .addConfig(defaultConfig);
  .build();

console.log(config.get('console.name')); // test
console.log(config.get('console.obj.data')); // test data
config.get('common.data').name = 'test 2 data';
console.log(config.get('console.obj.data')); // test 2 data
console.log(config.get('console.email')); // [email protected]

Tagging

var HyperConfig = require('hyper-config');

var defaultConfig = {
  console: {
    proc: 'console.log',
    '@tags': ['t2', 't1']
  },
  file: {
    name: 'testfile',
    '@tags': ['t1']
  },
  some: {
    name: 'testsome'
  }
};

var config = HyperConfig()
  .addConfig(defaultConfig);
  .build();

console.log(config.getByTag('t1')); // [{proc: 'console.log'}, {name: 'testfile'}]
console.log(config.getByTag('t2')); // [{proc: 'console.log'}]
console.log(config.getByTag('someTag')); // []