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

2.2.1 • Public • Published

confconf-purify

Integrates @confconf/confconf with purify-ts.

Install

npm i --save @confconf/confconf-purify purify-ts

Usage

import { confconf, envConfig } from "@confconf/confconf-purify";
import { Codec, number, string, GetType } from "purify-ts/Codec";

// Define a schema
const configSchema = Codec.interface({
  port: number,
  db: Codec.interface({
    host: string,
    name: string,
  }),
});

type Config = GetType<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-purify

Weekly Downloads

1

Version

2.2.1

License

MIT

Unpacked Size

5.03 kB

Total Files

6

Last publish

Collaborators

  • tomiturtiainen