Skip to content

Latest commit

 

History

History
87 lines (62 loc) · 1.72 KB

File metadata and controls

87 lines (62 loc) · 1.72 KB

SchemaValue

A schema value is the individual property of the schema.

Arguments

new SchemaValue(type, required, defaultValue)

type

A supported value Javascript type

Type: SchemaValueConstructorType | Schema<T>

Required: TRUE

required

Whether the value is required

Type: boolean

Required: FALSE

Default Value: false

defaultValue

Type: SchemaValueType | SchemaJSON

Required: FALSE

Default Value: undefined

Properties

None

Methods

Name Description Async Arguments Return
toJSON Get a JSON representation os the value no None JSONValue
toString Get a string representation os the value no None string

Errors

Invalid SchemaValue type provided

Error thrown when the type specified is not a supported type.

// function is not a valid type
new SchemaValue(Function)

Default value does not match type

Error thrown when the default value does not match the type.

// type is String but defaultValue is number
new SchemaValue(String, false, 12)

Examples

new SchemaValue(Schema, false, {})
new SchemaValue(SchemaId, true)
new SchemaValue(ArrayOf(OneOf([String, Number], "")), false, [0, 1, 2])
new SchemaValue(Array, true)
new SchemaValue(Int32Array)
new SchemaValue(Date)
const todoSchema = new Schema<ToDo>("todo");

new SchemaValue(todoSchema, true)