Skip to main content

Class: BooleanType

Defined in: schema/types/boolean-type.ts:38

Boolean are plain JavaScript Boolean.

Options​

  • required flag to define if the field is mandatory
  • validator that will be applied to the field a validation function, validation object or string with the name of the custom validator
  • default that will define the initial value of the field, this option allows a value or a function
  • immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict

Example​

const userSchema =  new Schema({
isActive: Boolean,
isSomething: Schema.Types.Boolean
})

Ottoman will cast the following values to true:​

  • true
  • 'true'
  • 1
  • '1'
  • 'yes'

Ottoman will cast the following values to false:​

  • false
  • 'false'
  • 0
  • '0'
  • 'no'

Extends​

Constructors​

Constructor​

new BooleanType(name, options?): BooleanType

Defined in: schema/types/boolean-type.ts:39

Parameters​

name​

string

options?​

CoreTypeOptions

Returns​

BooleanType

Overrides​

CoreType.constructor

Properties​

name​

name: string

Defined in: schema/interfaces/schema.types.ts:51

Inherited from​

CoreType.name


options?​

optional options: CoreTypeOptions

Defined in: schema/types/core-type.ts:23

Inherited from​

CoreType.options


typeName​

typeName: string

Defined in: schema/interfaces/schema.types.ts:51

Inherited from​

CoreType.typeName


convertToFalse​

static convertToFalse: Set<string | number | boolean>

Defined in: schema/types/boolean-type.ts:45


convertToTrue​

static convertToTrue: Set<string | number | boolean>

Defined in: schema/types/boolean-type.ts:44


sName​

static sName: string = Boolean.name

Defined in: schema/types/boolean-type.ts:42

Overrides​

CoreType.sName

Accessors​

default​

Get Signature​

get default(): unknown

Defined in: schema/types/core-type.ts:39

Returns​

unknown

Inherited from​

CoreType.default


required​

Get Signature​

get required(): boolean | RequiredOption | RequiredFunction

Defined in: schema/types/core-type.ts:31

Returns​

boolean | RequiredOption | RequiredFunction

Inherited from​

CoreType.required


validator​

Get Signature​

get validator(): undefined | string | ValidatorFunction | ValidatorOption

Defined in: schema/types/core-type.ts:35

Returns​

undefined | string | ValidatorFunction | ValidatorOption

Inherited from​

CoreType.validator

Methods​

buildDefault()​

buildDefault(): unknown

Defined in: schema/types/core-type.ts:43

Returns​

unknown

Inherited from​

CoreType.buildDefault


cast()​

cast(value, strategy): any

Defined in: schema/types/boolean-type.ts:47

Parameters​

value​

any

strategy​

CAST_STRATEGY = CAST_STRATEGY.DEFAULT_OR_DROP

Returns​

any

Overrides​

CoreType.cast


checkRequired()​

checkRequired(): string | void

Defined in: schema/types/core-type.ts:62

Returns​

string | void

Inherited from​

CoreType.checkRequired


checkValidator()​

checkValidator(value): void

Defined in: schema/types/core-type.ts:71

Parameters​

value​

unknown

Returns​

void

Inherited from​

CoreType.checkValidator


isEmpty()​

isEmpty(value): boolean

Defined in: schema/types/boolean-type.ts:65

Parameters​

value​

boolean

Returns​

boolean

Overrides​

CoreType.isEmpty


isStrictStrategy()​

isStrictStrategy(strategy): boolean

Defined in: schema/types/core-type.ts:79

Parameters​

strategy​

VALIDATION_STRATEGY

Returns​

boolean

Inherited from​

CoreType.isStrictStrategy


validate()​

validate(value, strategy): any

Defined in: schema/types/boolean-type.ts:57

Parameters​

value​

any

strategy​

any

Returns​

any

Overrides​

CoreType.validate