-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathNullSchema.js
More file actions
43 lines (38 loc) · 1.04 KB
/
NullSchema.js
File metadata and controls
43 lines (38 loc) · 1.04 KB
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
'use strict'
const { BaseSchema } = require('./BaseSchema')
const { setAttribute, FLUENT_SCHEMA } = require('./utils')
const initialState = {
type: 'null'
}
/**
* Represents a NullSchema.
* @param {Object} [options] - Options
* @param {StringSchema} [options.schema] - Default schema
* @param {boolean} [options.generateIds = false] - generate the id automatically e.g. #properties.foo
* @returns {StringSchema}
*/
const NullSchema = ({ schema = initialState, ...options } = {}) => {
options = {
generateIds: false,
factory: NullSchema,
...options
}
const { valueOf, raw } = BaseSchema({ ...options, schema })
return {
valueOf,
raw,
[FLUENT_SCHEMA]: true,
isFluentSchema: true,
/**
* Set a property to type null
*
* {@link https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.6.1.1|reference}
* @returns {FluentSchema}
*/
null: () => setAttribute({ schema, ...options }, ['type', 'null'])
}
}
module.exports = {
NullSchema,
default: NullSchema
}