Giter Club home page Giter Club logo

node-cfg's People

Contributors

dependabot[bot] avatar neezer avatar

Watchers

 avatar

node-cfg's Issues

Fix README

Currently readme is wrong:

- const config = cfg<MyConfig>({ check: assert });
+ const [errors, config] = cfg<MyConfig>({ check: assert });

config.aValue === "whatever";

Generate TS type from schema

Currently you have to pass in the type you want to cast configuration as into cfg. I think TS is powerful enough to do this for you. Need to learn a bit more about advanced types first...

That would change invocation to

import { cfg } from "@neezer/cfg";

// handled internally
- interface MyConfig {
-   aValue: string;
- }

- // use a typeguard to definitely type your config
- const guard = (value: any): value is MyConfig => {
-   return !!value && "aValue" in value;
- };

- // create an assertion function using the typeguard
- const assert = (v: any) => {
-   if (guard(v)) {
-     return v;
-   } else {
-     throw new Error("not a valid configuration!");
-   }
- };

// given `process.env.A_VALUE === 'whatever'`

- const config = cfg<MyConfig>({ check: assert });
+ const config = cfg();

config.aValue === "whatever";

Add flags

Should support configuration by flags.

Add URL parsing when using constituent parts

Sometimes we can't use a connection string as-is because it might contain secrets that are hard to manage in a secure way in operations. Thus, we might have all the parts of a URL spread across multiple environment variables, like so:

Single Multiple
DB_URL DB_NAME
DB_HOST
DB_PORT
DB_USERNAME
DB_PASSWORD
DB_OPTIONS
DB_PROTOCOL

In this case, cfg should be smart enough to "bundle up" the various parts and still expose the final value as a URL.

Perhaps the configuration for such a value might look like this?

{
  "url": {
    "desc": "a connection string in parts",
    "env": "DB_URL",
    "format": "url",
    "stitchFromParts": {
      "port": "DB_PORT",
      "host": "DB_HOST",
      "username": "DB_USERNAME",
      "password": "DB_PASSWORD",
      "protocol": "DB_PROTOCOL",
      "query": "DB_OPTIONS"
    }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.