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
↳
BooleanType
Constructors
constructor
• new BooleanType(name
, options?
)
Parameters
Name | Type |
---|---|
name | string |
options? | CoreTypeOptions |
Overrides
Defined in
schema/types/boolean-type.ts:39
Properties
name
• name: string
Inherited from
Defined in
schema/interfaces/schema.types.ts:51
options
• Optional
options: CoreTypeOptions
Inherited from
Defined in
typeName
• typeName: string
Inherited from
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
Defined in
schema/types/boolean-type.ts:42
Accessors
default
• get
default(): unknown
Returns
unknown
Inherited from
CoreType.default
Defined in
required
• get
required(): boolean
| RequiredOption
| RequiredFunction
Returns
boolean
| RequiredOption
| RequiredFunction
Inherited from
CoreType.required
Defined in
validator
• get
validator(): undefined
| string
| ValidatorFunction
| ValidatorOption
Returns
undefined
| string
| ValidatorFunction
| ValidatorOption
Inherited from
CoreType.validator
Defined in
Methods
buildDefault
▸ buildDefault(): unknown
Returns
unknown
Inherited from
Defined in
cast
▸ cast(value
, strategy?
): any
Parameters
Name | Type | Default value |
---|---|---|
value | any | undefined |
strategy | CAST_STRATEGY | CAST_STRATEGY.DEFAULT_OR_DROP |
Returns
any
Overrides
Defined in
schema/types/boolean-type.ts:47
checkRequired
▸ checkRequired(): string
| void
Returns
string
| void
Inherited from
Defined in
checkValidator
▸ checkValidator(value
): void
Parameters
Name | Type |
---|---|
value | unknown |
Returns
void
Inherited from
Defined in
isEmpty
▸ isEmpty(value
): boolean
Parameters
Name | Type |
---|---|
value | boolean |
Returns
boolean
Overrides
Defined in
schema/types/boolean-type.ts:65
isStrictStrategy
▸ isStrictStrategy(strategy
): boolean
Parameters
Name | Type |
---|---|
strategy | VALIDATION_STRATEGY |
Returns
boolean
Inherited from
Defined in
validate
▸ validate(value
, strategy
): any
Parameters
Name | Type |
---|---|
value | any |
strategy | any |
Returns
any