@class-config/validator-class
v0.6.0
Published
The package of validator config by class-validator
Downloads
2
Maintainers
Readme
@class-config/validator-class
This is a class config validator. This package provides the ability to check the configuration by class-validator
.
Usage
Example
import 'reflect-metadata';
import { BaseConfig, Config, ConfigField, DefaultValue } from '@class-config/core';
import { ClassValidator } from '@class-config/validator-class';
import { IsString, IsNumber } from 'class-validator';
@Config()
class Database extends BaseConfig {
/**
* The server host
*/
@ConfigField()
@DefaultValue('localhost')
@IsString()
public host!: string;
/**
* The server port
*/
@ConfigField()
@DefaultValue('8080')
@IsNumber()
public port!: number;
}
const config = await Database.init<Database>({
validator: new ClassValidator(),
});
More information: class-validator