Field Types

Primitives

Below is a list of general options supported by all primitive and built-in types.

Options

:zap: Array

The field should be an array. For an array of specified elements, consider using PerfectSchema.ArrayOf(type%)

Options

:zap: Boolean

The field should be a strict boolean value of true or false.

:zap: Date

The field should be an instance of Date and be a valid date value.

Options

:zap: Number

The field should be a strict number, and not NaN.

Options

:zap: Object

The field should be an instanceo of Object.

:zap: String

The field should be a string.

Options

Built-in types

:zap: PerfectSchema.Any

A wildcard type whose value can be anything. This is intended to be an unchecked, blackbox type.

const schema = new PerfectSchema({
  foo: PerfectSchema.Any,
  bar: {
    type: PerfectSchema.Any
  }
});

:zap: PerfectSchema.AnyOf(type%[, type%[, ...]])

Like the Any built-in type, but restricts the actual wildcard types.

const schema = new PerfectSchema({
  foo: PerfectSchema.AnyOf(String, Number, Date),
  bar: {
    type: PerfectSchema.ArrayOf(PerfectSchema.AnyOf(String, Number))
  }
});

:zap: PerfectSchema.ArrayOf(type%)

Like the Array type, but specify element type(s).

const schema = new PerfectSchema({
  foo: PerfectSchema.ArrayOf(String),
  bar: {
    type: PerfectSchema.ArrayOf(PerfectSchema.AnyOf(String, Number))
  }
});
Options

All options from :zap:Array are inherited.

:zap: PerfectSchema.Integer

The field should be a strict integer between, and not be Infinity or NaN.

const schema = new PerfectSchema({
  foo: PerfectSchema.Any,
  bar: {
    type: PerfectSchema.Integer
  }
});
Options

All options from :zap:Number are inherited.