This module is used to validate CNDI Template prompt responses.
# CNDI Template prompt specs can specify validators for prompts:
prompts:
- type: Input
name: lets_encrypt_email
message: "Enter your email address for Let's Encrypt"
validators:
- email
- min_length: 3Each validator needs to be implemented in this module, otherwise the prompt will be assumed valid.
import { CNDIValidators } from "@cndi/validators";
const emailErrorMessage: string | null = CNDIValidators.email({
value: "foo.bar",
type: "Input",
});
console.log(emailErrorMessage); // 'Invalid email address'
const passwordErrorMessage: string | null = CNDIValidators.min_length({
value: "foo",
type: "Input",
arg: 3,
});
// because the value has a length of atleast 3:
console.log(passwordErrorMessage); // null