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

configeur

v5.0.0

Published

Extensible parsing of environment variables into config.

Downloads

9

Readme

configeur

This module is inspired by and borrows much of its behaviour from the excellent Konfiga module. This module removes the commandline parsing abilities of its ancestor, adds required variables, and simplifies some internal logic around custom parsers by slightly altering that part of the options API.

configeur reads in the environment and uses a spec to parse and the values found to appropriate types. It supports:

  • Type casting, with some types parsers included and API to add or replace parsers.
  • Default values when environment variables should be optional.
  • Required values when environment variables are not optional.

Usage

Configeur accepts an object which defines config variables names and how to derive them from the environment (or a default). Import as an ES module.

For example:

// Module config.js

import configeur from 'configeur';

export default configeur({
  PORT: {
    defaultValue: '8000',
    type: 'number'
  }
});

The above, assuming no values are read from the environment, will assign to config.js as a default export:

{
  PORT: 8000
}

Fields used to configure a config variable are:

| field | required | description | | ------------------- | -------- | ----------- | | 'defaultValue' | false | The value used when the variable is not found in the environment. Must always be a string, as if it has come from the environment. | | 'required' | false | Defaults to false. When true, a corresponding environment variable is required. A default will be ignored and an error thrown when the environment variable is not found. | 'type' | false | The type to cast to. Defaults to 'string'.

Default types are:

  • 'string'
  • 'number'
  • 'boolean'

Additional types can be specified as parsers.

Options

configeur accepts a second parameter consisting of an options object.

parsers

configeur comes with default parsers. To add more parsers, or override existing parsers, this array can be used. For example, to add an 'integer' type:

const config = configeur(schema, {
  parsers: [
    ['integer', value => parseInt(value, 10)]
  ]
});

mutable

By default, the object returned by configuer is frozen. Since it is also flat, the object is completely immutable. The mutable option makes configeur return an unfrozen object. This is not recommended in general, but may be useful for testing purposes.