@impargo/configurator

Loads all yaml files under config directory in the root folder, validates them against a schema, and then returns them if they're valid. Otherwise logs an error and exits the process with error code 1.

Usage no npm install needed!

<script type="module">
  import impargoConfigurator from 'https://cdn.skypack.dev/@impargo/configurator';
</script>

README

Configurator

Loads all yaml files under config directory in the root folder, validates them against a schema, and then returns them if they're valid. Otherwise logs an error and exits the process with error code 1.

Schema

Schema validation currently supports the following values:

  • Objects
  • Arrays
  • Numbers
  • Strings
  • Booleans

Example

import { parse, schema } from 'configurator'

const parsed = parse(schema.object({
  config: schema.object({
    PORT: schema.number(),
  }),
  secrets: schema.object({
    MONGO_URL: schema.string(),
  }),
}))

console.log(parsed)
// {
//   config: {
//     port: 123
//   },
//   secrets: {
//     MONGO_URL: "mongodb://server.mongodb.net/db"
//   }
// }