Skip to main content

Class: BooleanType

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'

Hierarchy

Constructors

constructor

new BooleanType(name, options?)

Parameters

NameType
namestring
options?CoreTypeOptions

Overrides

CoreType.constructor

Defined in

schema/types/boolean-type.ts:39

Properties

name

name: string

Inherited from

CoreType.name

Defined in

schema/interfaces/schema.types.ts:51


options

Optional options: CoreTypeOptions

Inherited from

CoreType.options

Defined in

schema/types/core-type.ts:23


typeName

typeName: string

Inherited from

CoreType.typeName

Defined in

schema/interfaces/schema.types.ts:51


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

Overrides

CoreType.sName

Defined in

schema/types/boolean-type.ts:42

Accessors

default

get default(): unknown

Returns

unknown

Inherited from

CoreType.default

Defined in

schema/types/core-type.ts:39


required

get required(): boolean | RequiredOption | RequiredFunction

Returns

boolean | RequiredOption | RequiredFunction

Inherited from

CoreType.required

Defined in

schema/types/core-type.ts:31


validator

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

Returns

undefined | string | ValidatorFunction | ValidatorOption

Inherited from

CoreType.validator

Defined in

schema/types/core-type.ts:35

Methods

buildDefault

buildDefault(): unknown

Returns

unknown

Inherited from

CoreType.buildDefault

Defined in

schema/types/core-type.ts:43


cast

cast(value, strategy?): any

Parameters

NameTypeDefault value
valueanyundefined
strategyCAST_STRATEGYCAST_STRATEGY.DEFAULT_OR_DROP

Returns

any

Overrides

CoreType.cast

Defined in

schema/types/boolean-type.ts:47


checkRequired

checkRequired(): string | void

Returns

string | void

Inherited from

CoreType.checkRequired

Defined in

schema/types/core-type.ts:62


checkValidator

checkValidator(value): void

Parameters

NameType
valueunknown

Returns

void

Inherited from

CoreType.checkValidator

Defined in

schema/types/core-type.ts:71


isEmpty

isEmpty(value): boolean

Parameters

NameType
valueboolean

Returns

boolean

Overrides

CoreType.isEmpty

Defined in

schema/types/boolean-type.ts:65


isStrictStrategy

isStrictStrategy(strategy): boolean

Parameters

NameType
strategyVALIDATION_STRATEGY

Returns

boolean

Inherited from

CoreType.isStrictStrategy

Defined in

schema/types/core-type.ts:79


validate

validate(value, strategy): any

Parameters

NameType
valueany
strategyany

Returns

any

Overrides

CoreType.validate

Defined in

schema/types/boolean-type.ts:57