API

Schemas#

To make sure your configuration is exactly the shape you want, you will need to add a schema. This is entirely optional but highly recommended.

By using a schema, all loaded configuration keys will be inserted in the naming conventation that your schema definition uses. It will stop using the configured naming convention and instead use the schema's, See formatting for more information on naming conventions.

.addZodSchema(schema)#

This schema parser takes a Zod schema. It will validate the configuration using the schema before returning the config. It will also run any transformations the schema definition has.

import { createConfigLoader } from '@neato/config';
import { z } from 'zod';
 
const schema = z.object({
  username: z.string(),
});
 
export const config = createConfigLoader()
  .addZodSchema(schema)
  .load();
 
// the config variable now has type { username: string }

.addJOISchema(schema)#

This schema parser takes a JOI schema. It will validate the configuration using the schema before returning the config. It will also run any transformations the schema definition has. You should use the generic argument in Joi.object<T>() to give your schema a type.

We recommend using Zod schemas instead, as types are fully infered from the schema. No need to create both the schema and type definition.

import { createConfigLoader } from '@neato/config';
import Joi from 'joi';
 
interface ConfigDef {
  username: string;
}
 
const schema = Joi.object<ConfigDef>({
  username: Joi.string().required(),
});
 
export const config = createConfigLoader()
  .addJOISchema(schema)
  .load();