Class: StringType
Defined in: schema/types/string-type.ts:178
String
are plain JavaScript String and accepts the following options:
Options
- required flag to define if the field is mandatory
- validator that will be applied to the field, allowed function, object or string with the name of the custom validator
- default that will define the initial value of the field, allowed and value or function to generate it
- immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict
- enum defines a list of allowed values
- auto that will generate the initial value of the field. It allows the value 'uuid' or a function. It cannot be used combined with default
Example
const userSchema = new Schema({
name: { type: String, auto: 'uuid', trim: true },
gender: { type: String, enum: ['M', 'F'] }
lastname: Schema.Types.String,
user: { type: String, lowercase: true, minLength: 4, maxLength: 7 }
})
Extends
Constructors
Constructor
new StringType(
name
,options
):StringType
Defined in: schema/types/string-type.ts:179
Parameters
name
string
options
StringTypeOptions
= ...
Returns
StringType
Overrides
Properties
name
name:
string
Defined in: schema/interfaces/schema.types.ts:51
Inherited from
options
options:
StringTypeOptions
Defined in: schema/types/string-type.ts:179
Inherited from
typeName
typeName:
string
Defined in: schema/interfaces/schema.types.ts:51
Inherited from
sName
static
sName:string
=String.name
Defined in: schema/types/string-type.ts:184
Overrides
Accessors
auto
Get Signature
get auto():
undefined
|string
|AutoFunction
Defined in: schema/types/string-type.ts:190
Returns
undefined
| string
| AutoFunction
default
Get Signature
get default():
unknown
Defined in: schema/types/core-type.ts:39
Returns
unknown
Inherited from
enumValues
Get Signature
get enumValues():
unknown
Defined in: schema/types/string-type.ts:186
Returns
unknown
required
Get Signature
get required():
boolean
|RequiredOption
|RequiredFunction
Defined in: schema/types/core-type.ts:31
Returns
boolean
| RequiredOption
| RequiredFunction
Inherited from
validator
Get Signature
get validator():
undefined
|string
|ValidatorFunction
|ValidatorOption
Defined in: schema/types/core-type.ts:35
Returns
undefined
| string
| ValidatorFunction
| ValidatorOption
Inherited from
Methods
buildDefault()
buildDefault():
undefined
|string
Defined in: schema/types/string-type.ts:212
Returns
undefined
| string
Overrides
cast()
cast(
value
,strategy
):any
Defined in: schema/types/string-type.ts:220
Parameters
value
unknown
strategy
CAST_STRATEGY
= CAST_STRATEGY.DEFAULT_OR_DROP
Returns
any
Overrides
checkRequired()
checkRequired():
string
|void
Defined in: schema/types/core-type.ts:62
Returns
string
| void
Inherited from
checkValidator()
checkValidator(
value
):void
Defined in: schema/types/core-type.ts:71
Parameters
value
unknown
Returns
void
Inherited from
isEmpty()
isEmpty(
value
):boolean
Defined in: schema/types/string-type.ts:302
Parameters
value
string
Returns
boolean
Overrides
isStrictStrategy()
isStrictStrategy(
strategy
):boolean
Defined in: schema/types/core-type.ts:79
Parameters
strategy
Returns
boolean
Inherited from
validate()
validate(
value
,strategy
):undefined
|null
|string
Defined in: schema/types/string-type.ts:240
Parameters
value
unknown
strategy
any
Returns
undefined
| null
| string