Class: Field
Abstract class representing a subset of any primitive value type, herein referred to as a fieldtype. For example, a hypothetical class Email extends Field
would represent a subset of string
(i.e. strings that are valid email addresses). A class which extends Field
should define the requirements of its fieldtype by overriding Field.prototype.parse
. Instances of Field
are used to validate values and compose Schemas
.
Hierarchy
- Field
↳ Text
↳ Number
Index
Constructors
Properties
Methods
Object literals
Constructors
constructor
+ new Field(defaultVal
: any, flags
: number): Field
Defined in lib/Field.ts:19
Parameters:
Name | Type | Default | Description |
---|---|---|---|
defaultVal |
any | undefined | A default value. |
flags |
number | null | A bit field. |
Returns: Field
Properties
default
• default: any
Defined in lib/Field.ts:13
The value to be returned from Field.prototype.parse
when invoked with undefined
or null
. Note that providing a defualt value effectively renders the field optional.
flags
• flags: number
Defined in lib/Field.ts:16
A bit field representing a set of boolean flags
.
lastError
• lastError: string
Defined in lib/Field.ts:19
The error message produced by the last call to Field.prototype.parse
, if it was unsuccessful.
Methods
clone
▸ clone(): Field
Defined in lib/Field.ts:39
Returns a copy of the Field
instance.
Returns: Field
hasFlag
▸ hasFlag(flag
: number): boolean
Defined in lib/Field.ts:34
Checks if the specified flag is set on Field.prototype.flags
.
Parameters:
Name | Type | Description |
---|---|---|
flag |
number | A bit mask. |
Returns: boolean
A boolean determining whether or not the flag is present.
parse
▸ parse(value
: any): Promise‹any›
Defined in lib/Field.ts:48
(async) Checks if the input value
is, or can be converted to, a valid case of the instance's fieldtype. If the input is null
or undefined
, uses the default
value in its place.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | The value to be parsed. |
Returns: Promise‹any›
The parsed value, or undefined
if the input
was invalid.
Object literals
Static
Flags
▪ Flags: object
Defined in lib/Field.ts:5
OPT
• OPT: number = 1
Defined in lib/Field.ts:7
OPTIONAL denotes that a field should have a default value of null.
PRV
• PRV: number = 2
Defined in lib/Field.ts:9
PRIVATE denotes that a field should not be exposed.