@confconf/confconf-purify
v2.2.1
Published
Integrates @confconf/confconf with purify-ts
Downloads
2
Maintainers
Readme
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();