# 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
})
2
3
4
# 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
↳ CoreType
↳ BooleanType
# Constructors
# constructor
+ new BooleanType(name
: string, options?
: CoreTypeOptions): BooleanType
Overrides CoreType.constructor
Parameters:
Name | Type |
---|---|
name | string |
options? | CoreTypeOptions |
Returns: BooleanType
# Properties
# name
• name: string
Inherited from IOttomanType.name
# Optional
options
• options? : CoreTypeOptions
Inherited from CoreType.options
# typeName
• typeName: string
Inherited from IOttomanType.typeName
# Static
convertToFalse
▪ convertToFalse: Set‹string | number | false | true› = new Set([false, 'false', 0, '0', 'no'])
# Static
convertToTrue
▪ convertToTrue: Set‹string | number | false | true› = new Set([true, 'true', 1, '1', 'yes'])
# Static
sName
▪ sName: string = Boolean.name
# Accessors
# default
• get default(): unknown
Inherited from CoreType.default
Returns: unknown
# required
• get required(): boolean | RequiredOption | RequiredFunction
Inherited from CoreType.required
Returns: boolean | RequiredOption | RequiredFunction
# validator
• get validator(): ValidatorOption | ValidatorFunction | string | undefined
Inherited from CoreType.validator
Returns: ValidatorOption | ValidatorFunction | string | undefined
# Methods
# buildDefault
▸ buildDefault(): unknown
Inherited from CoreType.buildDefault
Returns: unknown
# cast
▸ cast(value
: any, strategy
: CAST_STRATEGY): any
Overrides IOttomanType.cast
Parameters:
Name | Type | Default |
---|---|---|
value | any | - |
strategy | CAST_STRATEGY | CAST_STRATEGY.DEFAULT_OR_DROP |
Returns: any
# checkRequired
▸ checkRequired(): string | void
Inherited from CoreType.checkRequired
Returns: string | void
# checkValidator
▸ checkValidator(value
: unknown): void
Inherited from CoreType.checkValidator
Parameters:
Name | Type |
---|---|
value | unknown |
Returns: void
# isEmpty
▸ isEmpty(value
: boolean): boolean
Parameters:
Name | Type |
---|---|
value | boolean |
Returns: boolean
# isStrictStrategy
▸ isStrictStrategy(strategy
: VALIDATION_STRATEGY): boolean
Inherited from CoreType.isStrictStrategy
Parameters:
Name | Type |
---|---|
strategy | VALIDATION_STRATEGY |
Returns: boolean
# validate
▸ validate(value
: any, strategy
: any): any
Parameters:
Name | Type |
---|---|
value | any |
strategy | any |
Returns: any