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

fastconf

v0.3.2

Published

super simple environment-based configuration utility

Downloads

16

Readme

fastconf

npm npm

Requires at least partial ES6 support (node v4 or higher)

npm install fastconf

fast example

console.log(process.env) /* {
  'FOO_BAR': '123',
  'NOPE': 'true',
  'XBPF_ZIG_ZAG': '2929'
} */

const config = fastconf([
  // All keys are required unless a default value is provided
  ['FOO_BAR', {type: Number}],
  ['NOPE', {type: Boolean, defaultValue: false}],
  ['MORE_THINGS', {defaultValue: 'apples'}]
], {
  xbpf: { // You can also pass an object (with the keys prop) if you want to
          // further configure fastconf
    prefix: 'XBPF_',
    keys: [
      'ZIG_ZAG' // You can also just provide strings in keys array (options are defaults)
    ]
  }
})

console.log(config) /* {
  fooBar: 123,
  nope: true,
  moreThings: 'apples',
  xbpf: {
    zigZag: '2929'
  }
} */

slow example

import fastconf from 'fastconf'

// Fastconf is a convenience utility to quickly generate a
// configuration object based on the provided lookup object.
//
// It expects that all keys you give it are unique (will
// never map to the same key in the returned object), and that
// all keys are required unless specified optional.
const config = fastconf({
  // (Since 0.2.0) You can now just pass an array in place of the first object,
  // which is equivalent to passing {keys: [the array]}

  // Prefix, useful for not having to repeat yourself.
  // If you have a prefix of 'NICE_', and have a required key 'FOO_BAR',
  // then fastconf will expect there to be an environment variable
  // with the key 'NICE_FOO_BAR', and will add it to the object
  // with the key fooBar.
  prefix: 'NICE_',

  // Whether to normalize names of the environment variables or not.
  // If true, keys like FOO_BAR will be named fooBar in the returned
  // configuration object.
  //
  // Defaults to true.
  normalizeNames: true,

  // Whether to consider a required key as existing only if it's undefined.
  // Otherwise, the following rule applies:
  // * The key does not exist if the environment variable is an empty string
  //
  // Defaults to false.
  strictExistence: false,

  // (Since 0.3.0) Whether to wrap the returned object in a proxy
  // that throws an error when getting keys that have undefined values.
  //
  // If true, and Proxy is not a function then this will
  // throw an error.
  // Defaults to false.
  useProxy: false,

  // An array of [key, options] values.
  //
  // (Since 0.1.0) The elements could also just be strings, which is the same
  // as doing ['KEY'] (default options)
  keys: [
    ['FOO_BAR', {
      // Key type. Can be either String, Number, or Boolean.
      //
      // The String type returns values as-is.
      //
      // The Number type parses the string as a number. If the
      // parsed number is NaN, then fastconf will throw an error.
      //
      // The Boolean type tried to parse the string as a boolean.
      // It must be one of the following values:
      //  false: '0', 'false' (case insensitive), 'no' (case insensitive)
      //  true: '1', 'true' (case insensitive), 'yes' (case insensitive)
      //
      // Defaults to String.
      type: Number,

      // Whether to normalize the name for this individual key.
      // See normalizeNames's documentation for more info.
      //
      // Defaults to normalizeNames's value.
      normalizeName: false,

      // Whether to use strict existence checking for this individual
      // key. See strictExistence's documentation for more info.
      strictExistence: true,

      // Default value, which can be any value. If a default value
      // is provided (not undefined), then the key is no longer required, and
      // fastconf will not throw an error if the value does not
      // exist.
      defaultValue: 0
    }],
    ['MORE_THINGS', {type: String, defaultValue: null}]
  ]
}, {
  // The optional second object provided are any "namespaces"
  // that you want to provide. These can be nested.
  // For example, if you have the 'xbpf' namespace, with its
  // own set of keys and values, the returned
  // object will look like this:
  //
  // {
  //   FOO_BAR: 123,
  //   moreThings: null,
  //   xbpf: {
  //     zigZag: 2929
  //   }
  // }
  //
  // This is useful for separate prefixes, and general organization.
  // Note that the object gets run through another call to fastconf(),
  // with the difference of it reusing the already determined environment
  // object.
  xbpf: {
    prefix: 'XBPF_',
    keys: [
      ['ZIG_ZAG', {type: Number}]
    ]
  }
}, {
  // If you wish to, you can provide your own key-value environment map.
  // Requires that all values for the keys are strings.
  //
  // Otherwise, fastconf will use process.env
  'NICE_FOO_BAR': '123',
  'XBPF_ZIG_ZAG': '2929'
})