UNPKG

1.25 kBJavaScriptView Raw
1'use strict';
2
3const Joi = require('joi');
4
5/**
6 * Validator for a "file" String
7 * Regex: https://regexper.com/#%5E%5Ba-zA-Z0-9._-%5D%2B%5C.(js|css)%24
8 */
9
10const file = Joi.string()
11 .label('entrypoint filename')
12 .regex(/^[a-zA-Z0-9/._-]+\.(js|css)$/)
13 .lowercase()
14 .trim()
15 .required();
16
17/**
18 * Validator for an array of "file" strings
19 */
20
21const files = Joi.array()
22 .label('entrypoint filenames')
23 .items(file);
24
25/**
26 * Validator for a "tag" String
27 */
28const tag = Joi.string()
29 .label('tag')
30 .regex(/^[a-zA-Z0-9_-]+$/)
31 .required();
32
33/**
34 * Validator for a "type" String
35 */
36const type = Joi.any()
37 .label('file type')
38 .required()
39 .valid('js', 'css');
40
41/**
42 * Validator for a "bundle instruction" object
43 */
44const bundleInstruction = Joi.array()
45 .label('bundle instruction')
46 .items(Joi.string())
47 .required();
48
49const options = Joi.object()
50 .label('options object')
51 .optional();
52
53const hash = Joi.string()
54 .label('hash')
55 .regex(/^[0-9A-Fa-f]+$/)
56 .required();
57
58const hashArray = Joi.array()
59 .label('hash array')
60 .items(hash)
61 .required();
62
63module.exports = {
64 file,
65 files,
66 tag,
67 type,
68 bundleInstruction,
69 options,
70 hash,
71 hashArray,
72};