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

pico-conf

v3.0.3

Published

A tiny config manager for node and browser

Downloads

8

Readme

🎛️ pico-conf

A tiny config manager for javascript. Inspired by nconf.

NPM

Features

  • No dependacies
  • Under 60 lines of easy-to-follow code
  • Utils for reading in commandline arguments, environment variables, and requiring in files
  • Fallbacks when it can't find values you are looking for
  • Agnostic to storage method; Just takes JS objects
  • Can be transpiled to work on the browser
  • Always forces lowercase tp prevent casing issues
const config = require('pico-conf')
  .set({
    auth : {
      type : 'basic'
      token : 'defaultdefaultdefault'
    }
  })
  .env()
  .file('./local.js', {})
  .argv();

config.get('auth:token');
const config = require('pico-conf')
  .set({ // Set up some basic defaults
    some_setting : true
    also : {
      nesting : {
        is : {
          Supported : true
        }
      }
    }
  })
  // try to load a local config with an empty fallback
  .file('./local.config.json', {})
  .env() //Load in environment variables
  .argv() //And any commandline arguments last


---

config.get('some_setting'); // true

config.get('also__nesting.IS:supported'); // nesting is supported through ':', '.', or '__'

config.get('I__dont.exist', [1,2,3,4]) // Provides fallback

config.get('important__value', ()=>{ // Fallbacks can be functions too
  console.warn('⚠ You should really set this up before doing anything serious ⚠')
  return 'foo'
})

Install

I suggest just coping and pasting the pico-conf.js file into your project. It's a single 60 line file with no dependacies, so you can review and easily modify the source as you see fit.

However it is hosted on npm if that tickles your fancy: npm install pico-conf

API

.get(path, [fallback])

Lowercases and splits the path, then searches through the .cache to find the config value and return it. If it can not find it, it runs/returns the fallback instead. The fallback defaults to throwing an error.

.set(obj)

Parses and adds the obj to the .cache and returns the pico-conf instance. Recursively loops through the object and merges it with whatever was within the existing instance. Lowercases all keys, and overwrites any value with the same path.

config.set({ alpha: 0.25, test : 6 })
  .set({ alpha: 0.8, 'yo__yo' : true });

config.get('alpha'); // 0.8
config.get('yo:yo'); // true

.file(path_to_file, [fallback = throws])

Attempts to require() the provided path_to_file and uses .set() to update and returns the pico-conf instance. Uses the caller's file location for relative file paths.

If it can't find the file, or they was any issue with reading the file, it will call and use the fallback instead. If fallback is a value, that will be added, if it's a function, it will be called first and it's returned value will be used. this is useful if you'd like to print helpful warning or error messages if your system was expecting a config to be loaded.

fallback defaults to throwing an error.

config.file('../package.json');

config.get('name'); // 'pico-conf'

.env()

Loops through and parses then adds each environment variable to the .cache. Lowercases keys and splits into sub-objects based on the separator. Returns the pico-conf instance to allow for chaining.

config.env();
config.get('node_env');

.argv()

Reads in the commandline arguments and splits them by =. Parses and adds each one to the .cache. If no = value was set, it's defaulted to true. Returns the pico-conf instance to allow for chaining.

// node test.js --auth --foo__bar=6

config.argv();
config.get('foo.bar'); //6
config.get('auth'); //true