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

confene

v1.1.0

Published

Goal of Confene is to give an easy way to create a configuration for yours nodes projects.

Downloads

8

Readme

Confene

Why this package

Goal of Confene is to give an easy way to create a configuration for yours nodes projects. You can give easily configuration by:

  • Environement variable
  • Configration file
  • Arguments

How to use it

  1. Create an interface of your configuration
export interface IMyConf {
    key1: string;
    key2: number;
    key3: boolean[];
    key4: IMyObject;
}
  1. Create a factory for this configuration
export class MyConfFactory implements IConfigurationFactory<IMyConf> {
    public instance: Promise<IMyConf>;
    public description: IConfigurationParameters<IMyConf> = {
        confFileName: ".myproject.conf.json";
        description: {
            key1: {
                name: "key1",
                type: "string",
                description: "Key 1 for example"
            },
            key2: {
                name: "key2",
                type: "number"
            },
            key3: {
                name: "key3",
                type: "boolean[]"
            },
            key4: {
                name: "key4",
                type: "json"
            }
        };
    }
}
  1. Use it
ConfigurationFactory.get(new MyConfFactory()).then((conf) => {
    //Read conf
    conf.key1...
})

Ho does it works

When you call ConfigurationFactory.get(), Confene will try to get your conf from

  1. Arguments
  2. Environment variables
  3. Configuration file from home dir

Options

export interface IConfigurationParameters<T> {
    homeDir?: string; //Specify homedir. Default is os.homedir()
    confFileName: string; //Name of configuration file
    loaders?: Array<ILoader>; //Loaders to read conf. Default is [new ArgsLoader(), new EnvLoader(), new ConfLoader()]
    saverConf?: ISaver; //Class to use to save configuration
    description: TConfigurationParameters<T>; //Description of your configuration object
    helpsParams?: {longNames: string[], shortNames: string[] }; //Parameters to show help. By default : --help, -h
    savesParams?: {longNames: string[], shortNames: string[] }; //Parameters to save conf. By default : --save
    helpFinally?: (help: string) => Promise<void>; //Callback when help is shown. By default : console.log(help) && process.exit(0);
}
export interface IConfigurationDescriptor<T, U> {
    name: T; //Property name
    from?: {
        [key: string]: string[] // Loader name with names into this loader. With it, you can (for example) choose differents keys for conf from arguments and from file
        // By default keys are: "conf", "env", "args"
    };
    type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]' | 'boolean[]' | 'json'; //Type of property
    isMandatory?: boolean; //Specify is Confene must throw an error is value isn't specified
    default?: U; //Default value
    isNullable?: boolean; //Value can be null
    isUndefinedable?: boolean; //Value can be undefined
    shortAlias?: string[]; // Short alias of this property
    longAlias?: string[]; // Long alias of this property
    description?: string; // Description of this field. Used for help generation
    onBadValue?: <V>(value: any, index?: number) => Promise<U> | Promise<V> | U | V; //Callback on a bad value
    onValue?: <V>(value: V, index?: number) => Promise<V> | V; //Callback on a good value
}