@confconf/confconf-typebox
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

confconf-typebox

Integrates @confconf/confconf with @sinclair/typebox.

Install

npm i --save @confconf/confconf-typebox @sinclair/typebox

Usage

import { confconf, envConfig } from "@confconf/confconf-typebox";
import { Static, Type } from "@sinclair/typebox";

// Define a schema
const configSchema = Type.Object({
  port: Type.Number(),
  db: Type.Object({
    host: Type.String(),
    name: Type.String(),
  }),
});

type Config = Static<typeof configSchema>;

// Create the configuration loader and load configuration and validate
// it against the schema
const config = await confconf({
  schema: configSchema,
  providers: [
    // Load from env variables
    envConfig({
      // Map the specifc env variables into a specific structure
      structure: {
        port: "PORT",
        db: {
          host: "DB_HOST",
          name: "DB_NAME",
        },
      },
    }),
  ],
}).loadAndValidate();

Package Sidebar

Install

npm i @confconf/confconf-typebox

Weekly Downloads

41

Version

2.2.1

License

MIT

Unpacked Size

4.84 kB

Total Files

6

Last publish

Collaborators

  • tomiturtiainen