Files: dbfe7b74a3adb5a6f94f01cd9a3f8fd4d696bd93 / schema / pollTypes / chooseOne.js
671 bytesRaw
1 | const Validate = require('is-my-json-valid') |
2 | |
3 | const typeString = 'chooseOne' |
4 | const typeStringPattern =`^${typeString}$` |
5 | const typeStringRegex = new RegExp(typeStringPattern) |
6 | |
7 | function isValidTypeString(string) { |
8 | return typeStringRegex.test(string) |
9 | } |
10 | |
11 | function create({choices}) { |
12 | return { |
13 | choices, |
14 | type: typeString, |
15 | } |
16 | } |
17 | |
18 | var schema = { |
19 | type: 'object', |
20 | required: ['type', 'choices'], |
21 | properties: { |
22 | type: { |
23 | type: 'string', |
24 | pattern: typeStringPattern |
25 | }, |
26 | choices: { |
27 | type: 'array', |
28 | } |
29 | } |
30 | } |
31 | |
32 | const validate = Validate(schema, { verbose: true }) |
33 | |
34 | module.exports = { |
35 | isValidTypeString, |
36 | schema, |
37 | validate, |
38 | create |
39 | } |
40 |
Built with git-ssb-web