/
optionsSchema.js
70 lines (64 loc) · 1.67 KB
/
optionsSchema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import joi from "joi";
const hastNodeTypeRegex = joi
.string()
.regex(/^(element|comment|text)$/, "hast node type");
const html5TagNameRegex = joi
.string()
// eslint-disable-next-line no-control-regex
.regex(/^[a-z]([^A-Z\s/\u0000>])*$/, "html5 element tag name");
const hastPropertyNameRegex = /^[^\t />"'=-]+$/;
const hastSchema = joi
.array()
.items(
joi.object({
type: hastNodeTypeRegex,
tagName: html5TagNameRegex.when("type", {
is: "element",
then: joi.required()
}),
value: joi
.string()
.when("type", {
is: "comment",
then: joi.required()
})
.when("type", {
is: "text",
then: joi.required()
}),
properties: joi
.object({
class: joi.any().forbidden(),
for: joi.any().forbidden()
})
.pattern(hastPropertyNameRegex, joi.any()),
children: joi.lazy(() => hastSchema)
})
)
.description("hast schema");
const schema = joi.object({
debug: joi.boolean(),
placeholderAffix: joi.string(),
elements: joi.object(undefined).pattern(
/\w/,
joi
.object({
propsDefaultValues: joi
.object(undefined)
.pattern(hastPropertyNameRegex, joi.any()),
html: joi.object({
tagName: html5TagNameRegex,
properties: joi
.object({
class: joi.any().forbidden(),
for: joi.any().forbidden()
})
.pattern(hastPropertyNameRegex, joi.any()),
children: hastSchema
}),
replace: joi.func()
})
.without("html", "replace")
)
});
export default schema;