Skip to content

Commit 29b4761

Browse files
committed
Adding custom schema format for comma separated emails
1 parent 40d8a6c commit 29b4761

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/helpers/configValidator.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const configSchema = require('./schemas/config.schema.json');
55

66
const ajv = new Ajv({ logger: false, allErrors: true });
77
ajv.addMetaSchema(metaSchema);
8+
9+
ajv.addFormat('comma-separated-emails', {
10+
type: 'string',
11+
validate: (emails) => {
12+
const emailRegex = new RegExp(/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i);
13+
return emails.split(',').every((email) => emailRegex.test(email.trim()));
14+
},
15+
});
16+
817
const validator = ajv.addSchema(configSchema, 'config');
918

1019
function validateConfig(config) {

src/helpers/schemas/config.schema.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@
4949
"to": {
5050
"anyOf": [
5151
{
52-
"type": "string"
52+
"type": "string",
53+
"format": "comma-separated-emails"
5354
},
5455
{
5556
"type": "array",
5657
"items": {
57-
"type": "string"
58+
"type": "string",
59+
"format": "email"
5860
}
5961
}
6062
]

0 commit comments

Comments
 (0)