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

@parkour-ops/application-configuration

v1.0.1

Published

Define and initialise Typescript-friendly global read-only application configuration in runtime.

Downloads

11

Readme

Application Configuration

  • Define and initialise Typescript-friendly global read-only application configuration in runtime.

  • Populate each config value using either a value (or source of value, e.g. function) (fromVal), an inline function (fromFunc), or the environment variable parser (fromEnv).

  • Validate config values using Zod schema validation library, optionally using built-in base schemas: String, Number, Int, BigInt, and Boolean.

How to Use

  1. Create a config.ts file:

    This file will define and export your app configuration.

    Import and use createConfig({...}) to define the configuration.

    import { Boolean, Integer, String, configVar, createConfig, fromEnv, fromFunc, fromVal } from "../src";
    
    const config = createConfig({
        // config can be sourced from env vars using `fromEnv`
        // "REQUIRED" will ensure error is thrown if env var has not been set
        hostUrl: configVar("Host URL", "REQUIRED", String.url())(fromEnv("HOST")),
        // config can be sourced from (in-line) functions using `fromFunc`
        timeout: configVar("Timeout (in seconds)", "REQUIRED", Int)(fromFunc(()=>{
            const minCeiled = Math.ceil(5);
            const maxFloored = Math.floor(10);
            return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive
        })
        ),
        // config can be sourced from pre-defined values or existing functions using `fromVal`
        // this example uses a custom schema
        protocol: configVar("Protocol", "REQUIRED", AvailableProtocol)(fromVal("HTTP")),
        // configs can be nested
        a: {
            b: {
                c: {
                    portNumber: configVar("Port Number", "REQUIRED", Int)(fromEnv("PORT"))
                },
            }
        },
        // env vars can be parsed as boolean, the following (case-insensitive) evaluate to TRUE: "true", "yes", "t", "y"
        // "OPTIONAL" means error will NOT be thrown if env var has not been set, will instead evaluate to FALSE (for boolean schema) or UNDEFINED (for non-boolean schema).
        forceTLS: configVar("Force Transport Layer Security (TLS)", "OPTIONAL", Boolean)(fromEnv("FORCE_TLS"))
    });
  2. Access your configuration from other source files:

    import config from "config.ts"
    
    console.log(config.a.b.c.portNumber);
    // 8080
    
    console.log(typeof config.a.b.c.portNumber);
    // number