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

confeager

v1.1.0

Published

Strongly typed eager-initialization configuration library for JavaScript

Downloads

3

Readme

ConfEagerJS

ConfEagerJs Build Status at Travis CI

ConfEagerJS is an eager, strongly-typed configuration library for JavaScript, designed to maximize runtime safety, while maintaining lightweight, easy integration and dynamic nature. More on the motivation for this project can be found below.

Quick Start

Installation via NPM:

$ npm install confeager --save

Comparability Note: ConfEagerJS uses Smoke Screen library to define and validate object schemas and types at runtime. This requires usage of EcmaScript decorators. While EcmaScript doesn't officially support decorators yet, the examples below are implemented in TypeScript, but may also be implemented in any other way that compiles decorators.

Consider a YAML configuration file config.yaml:

host: 0.0.0.0           # string
port: 8080              # number
https: false            # boolean
logLevel: INFO          # enum
nestedConfiguration:    # object
  nestedProperty: 1234
arrayConfiguration:     # array
  - 1234
  - 2345

Then a consumer written in TypeScript:

import {exposed, PropertyTypes} from "smoke-screen";
import {ConfEagerSources} from "confeager";

enum LogLevel {
    INFO, WARN, ERROR
}

class NestedConfiguration {

    @exposed({type: PropertyTypes.number})
    readonly nestedProperty: number;

}

class Configuration {

    @exposed({type: PropertyTypes.string})
    readonly host: string;

    @exposed({type: PropertyTypes.number})
    readonly port: number;

    // note the following property, it's called `useHttps` but exposed as `https`:    
    @exposed({as: "https", type: PropertyTypes.number})
    readonly useHttps: boolean;

    // enum property of enum class LogLevel
    // valid values may only be `INFO`, `WARN` or `ERROR`
    @exposed({type: PropertyTypes.enumOf(LogLevel)})
    readonly logLevel: LogLevel;

    @exposed({type: PropertyTypes.objectOf(NestedConfiguration)})
    readonly nestedConfiguration: NestedConfiguration;

    @exposed({type: PropertyTypes.arrayOf(PropertyTypes.number)})
    readonly arrayConfiguration: number[];

    // all other properties are required and their absence
    // from the source will cause an error on init,
    // this property is optional and when absent will be
    // populated with the value "value"
    @exposed({type: PropertyTypes.string, defaultValue: "value"})
    readonly optionalProperty: string;

}

// load config data from a yaml file with a watch interval of
// 10 milliseconds into a conf eager source.
const source = new ConfEagerSources.YamlFile("config.yaml", 10);
// now use the source to instantiate a configuration object
// and bind it to the source, so that when the source data
// updated, the configuration instance immidietaly gets updated too.
const conf = source.create(Configuration);

// that's it, let's use it!
conf.host;                                // => "0.0.0.0"
conf.port;                                // => 8080
conf.useHttps;                            // => false
conf.logLevel;                            // => LogLevel.INFO
conf.nestedConfiguration.nestedProperty;  // => 1234
conf.arrayConfiguration;                  // => [1234, 2345]
conf.optionalProperty;                    // => "value"

Full documentation can be found on the project WIKI on GitHub.

Why?

ConfEagerJS is designed with two main charachteristics: being eager and being strongly-typed. This is a very powerful combination that provides a few main advantages.

As opposed to popular configuration libraries, ConfEagerJS provides you with an interface for declaring your exact expectations from the configuration data. In addition, properties are eagerly loaded and validated. This combination renders a system that validates your entire configuration data source at boot time. The existance and value validity of each property in the source is validated immidiately. This also means no need to check for null and no null pointer errors either. This means no more typos when reading from the configuration, and most importantly, this means that to discover these kind of bugs you do not have to discover the exact control flow that triggers it, but rather let ConfEager find it for you when it loads.

Additionally, ConfEagerJS is aimed to provide simple means to easily implement any data source you like, seamlessly get data updates from it without the need to restart your application, and consume any property type you would like from it.

ConfEagerJS follows a big sister project for Java.

Useful Links

License

ConfEagerJS is registered under MIT license.

Contribution

Really, any kind of contribution will be warmly accepted. (: