@pitininja/envious-typebox
v6.1.5
Published
[](https://badge.fury.io/js/@pitininja%2Fenvious-typebox)
Readme
Envious Typebox resolver
Only Typebox v1 or superior is supported
Install
npm i @pitininja/envious-typeboxUsage
See the official Typebox documentation for how to write the schema.
import { envious } from '@pitininja/envious';
import { typeboxResolver } from '@pitininja/envious-typebox';
import { Type } from '@sinclair/typebox';
const env = envious({
resolver: typeboxResolver({
schema: Type.Object({
STRING_VAR: Type.String(),
NUMBER_VAR: Type.Integer(),
BOOLEAN_VAR_WITH_DEFAULT: Type.Boolean({ default: false }),
OPTIONAL_VAR: Type.Optional(Type.String())
})
})
});Formats
String formats can be loaded in the formats property of the Typebox resolver options, as an object with the format name as key and a regex or a validation function as value.
import { envious } from '@pitininja/envious';
import { typeboxResolver } from '@pitininja/envious-typebox';
import { Type } from '@sinclair/typebox';
import dayjs from 'dayjs';
const env = envious({
resolver: typeboxResolver({
schema: Type.Object({
EXAMPLE_URI: Type.String({ format: 'uri' }),
EXAMPLE_DATE: Type.String({ format: 'date' })
}),
formats: {
uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
date: (val) => dayjs(val).isValid()
}
})
});