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

confound

v0.1.7

Published

A typesafe, functional, configuration library for Typescript

Downloads

3

Readme

Confound

mtranter

A typesafe, functional, configuration library for Typescript

Docs: https://mtranter.github.io/Confound/index.html

Source: https://github.com/mtranter/Confound

Install:

npm install confound

or with Yarn:

yarn add confound

Usage

import { ConfigValueSource, ConfigValueSources } from 'confound'
const { env, envOrDie } = ConfigValueSources

interface AppConfig {
  appName: string,
  commitId?: string,
  environment: string,
  database: {
    host: string,
    port: number
  }
}

const configLoader = ConfigValueSources.obj<AppConfig>({
  appName: "Confounded App", // Use Litral Config Value
  commitId: env("COMMIT_ID"), // Extract optional config value from env variable
  environment: envOrDie("ENVIRONMENT"), // Extract required value from env variable
  database: { 
    host: envOrDie("DATABASE_HOST"),
    port: envOr("DATABASE_PORT", "5432").map(parseInt) // Map extracted config values to required types.
  }
})

const config: AppConfig = await configLoader()

Custom config sources

Confound allows extension by adding custom ConfigValueSources.

For example, using a custom AWS SSM config source:

import * as AWS from 'aws-sdk'

const ssm = new AWS.SSM({ region: "ap-southeast-2" })

const fromSSM = (name: string) => 
  ConfigValueSources
    .of(() => ssm.getParameter({ Name: name, WithDecryption: true })
    .promise()
    .then(v => v.Parameter?.Value))

const fromSSMOrDie = (name: string) => 
  ConfigValueSources
    .orDie(fromSSM(name), `Cannot find SSM Paramter ${name}`)

interface AppConfig {
  environment: string,
  database: {
    host: string,
    port: number,
    username: string,
    password: string
  }
}

const configLoader = ConfigValueSources.obj<AppConfig>({
  environment: envOrDie("ENVIRONMENT"),
  database: {
    host: envOrDie("DATABASE_HOST"),
    port: envOrDie("DATABASE_PORT").map(parseInt),
    username: envOrDie("DATABASE_USENAME_SSM_NAME").flatMap(fromSSMOrDie),
    password: envOrDie("DATABASE_PASSWORD_SSM_NAME").flatMap(fromSSMOrDie)
  }
})

const config: AppConfig = await configLoader()