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

fconf

v1.0.1

Published

Hierarchical configuration loader with support for javascript functions as configuration options.

Downloads

15

Readme

fconf

npm version install size downloads

This is a hierarchical configuration loader for node.js, meant to be used in a CLI.

This one is quite small, it handles javascript functions as configuration options, with an alias system to eventually choose which function to use from command line arguments.

Hierarchy system

  • default configuration you hard-code it
  • user configuration file
  • user ENV
  • user command line arguments

The latter overrides the preceding one, etc.

Install

// with yarn
yarn add fconf

// with npm
npm install fconf

Usage

The CLI tool :

#! /usr/bin/env node

const fconf = require('fconf');

const configuration = fconf({
  filename: 'clitoolname.conf.js',
  defaults: {
    inputQty: 1,
    outputFile: 'out.json',
    transformQty: qty => qty *  2
  }
});

console.log(configuration);
console.log(configuration.transformQty(configuration.inputQty));

This makes each options to be configurable by configuration file, environment variables and command line arguments.

$ cliToolName
{
  inputQty: 1,
  outputFile: 'out.json',
  transformQty: [Function: transformQty],
  '$0': 'cliToolName'
}
2

$ OUTPUT_FILE='data.json' cliToolName --input-qty=3
{
  inputQty: 3,
  outputFile: 'data.json',
  transformQty: [Function: transformQty],
  '$0': 'cliToolName'
}
6

Also environment variables have an impact on the result only if a matching key is present in the configuration. This is done to avoid other environment variables 'polluting' the result.

Let's say the user have a file clitoolname.conf.js now in his/her project directory :

// clitoolname.conf.js
module.exports = {
  inputQty: 2,
  transformQty: qty => qty * 4
}

$ cliToolName
{
  inputQty: 2,
  outputFile: 'out.json',
  transformQty: [Function: transformQty], // this will multiply by 4 now
  '$0': 'cliToolName'
}
8

Shortcut system

The only way the user can provide functions in through the configuration file. We can't provide javascript functions through environment or command line arguments.

To make functions arguments still flexible we made a simple shortcut system. You can hard-code it the CLI:

#! /usr/bin/env node

const fconf = require('fconf');

const configuration = fconf({
  filename: 'clitoolname.conf.js',
  defaults: {
    inputQty: 1,
    outputFile: 'out.json',
    transformQty: 'double' // it will be replaced by the matching shortcut
  },
  shortcuts: {
    double: qty => qty *  2,
    triple: qty => qty *  3,
    quadruple: qty => qty * 4
  }
});

console.log(configuration);
console.log(configuration.transformQty(configuration.inputQty));

The user can also use it :

$ cliToolName --transform-qty=triple
{
  inputQty: 1,
  outputFile: 'out.json',
  transformQty: [Function: transformQty], // this will multiply by 3
  '$0': 'cliToolName'
}
3

The user can make his own shortcuts in the configuration file :

// clitoolname.conf.js
module.exports = {
  inputQty: 2,
  transformQty: 'quintuple'
}
module.exports.shortcuts = {
  quintuple: qty => qty * 5
}

$ cliToolName
{
  inputQty: 2,
  outputFile: 'out.json',
  transformQty: [Function: transformQty], // this will multiply by 5
  '$0': 'cliToolName'
}
10

Todo

Generate help display.