Files: e602c7f5b93b901ece225fec5f2fc495eeaed73d / schema / positionTypes / chooseOne.js
685 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 ({choice, reason}) { |
12 | return { |
13 | choice, |
14 | type: typeString, |
15 | reason |
16 | } |
17 | } |
18 | |
19 | var schema = { |
20 | type: 'object', |
21 | required: ['type', 'choice'], |
22 | properties: { |
23 | type: { |
24 | type: 'string', |
25 | pattern: typeStringPattern |
26 | }, |
27 | choice: { |
28 | type: 'string' |
29 | } |
30 | } |
31 | } |
32 | |
33 | const validate = Validate(schema, { verbose: true }) |
34 | |
35 | module.exports = { |
36 | isValidTypeString, |
37 | schema, |
38 | validate, |
39 | create |
40 | } |
41 |
Built with git-ssb-web