Class: StringType
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 }
})
Hierarchy
↳
StringType
Constructors
constructor
• new StringType(name
, options?
)
Parameters
Name | Type |
---|---|
name | string |
options | StringTypeOptions |
Overrides
Defined in
schema/types/string-type.ts:179
Properties
name
• name: string
Inherited from
Defined in
schema/interfaces/schema.types.ts:51
options
• options: StringTypeOptions
Inherited from
Defined in
schema/types/string-type.ts:179
typeName
• typeName: string
Inherited from
Defined in
schema/interfaces/schema.types.ts:51
sName
▪ Static
sName: string
= String.name
Overrides
Defined in
schema/types/string-type.ts:184
Accessors
auto
• get
auto(): undefined
| string
| AutoFunction
Returns
undefined
| string
| AutoFunction
Defined in
schema/types/string-type.ts:190
default
• get
default(): unknown
Returns
unknown
Inherited from
CoreType.default
Defined in
enumValues
• get
enumValues(): unknown
Returns
unknown
Defined in
schema/types/string-type.ts:186
lowercase
• Private
get
lowercase(): boolean
Returns
boolean
Defined in
schema/types/string-type.ts:194
maxLength
• Private
get
maxLength(): undefined
| number
Returns
undefined
| number
Defined in
schema/types/string-type.ts:208
minLength
• Private
get
minLength(): undefined
| number
Returns
undefined
| number
Defined in
schema/types/string-type.ts:205
required
• get
required(): boolean
| RequiredOption
| RequiredFunction
Returns
boolean
| RequiredOption
| RequiredFunction
Inherited from
CoreType.required
Defined in
trim
• Private
get
trim(): boolean
Returns
boolean
Defined in
schema/types/string-type.ts:202
uppercase
• Private
get
uppercase(): boolean
Returns
boolean
Defined in
schema/types/string-type.ts:198
validator
• get
validator(): undefined
| string
| ValidatorFunction
| ValidatorOption
Returns
undefined
| string
| ValidatorFunction
| ValidatorOption
Inherited from
CoreType.validator
Defined in
Methods
_checkEnum
▸ Private
_checkEnum(value
, errors
): void
Parameters
Name | Type |
---|---|
value | string |
errors | string [] |
Returns
void
Defined in
schema/types/string-type.ts:261
_checkIntegrity
▸ Private
_checkIntegrity(): void
Returns
void
Defined in
schema/types/string-type.ts:284
_checkMaxLength
▸ Private
_checkMaxLength(value
, errors
): void
Parameters
Name | Type |
---|---|
value | string |
errors | string [] |
Returns
void
Defined in
schema/types/string-type.ts:277
_checkMinLength
▸ Private
_checkMinLength(value
, errors
): void
Parameters
Name | Type |
---|---|
value | string |
errors | string [] |
Returns
void
Defined in
schema/types/string-type.ts:270
buildDefault
▸ buildDefault(): undefined
| string
Returns
undefined
| string
Overrides
Defined in
schema/types/string-type.ts:212
cast
▸ cast(value
, strategy?
): any
Parameters
Name | Type | Default value |
---|---|---|
value | unknown | undefined |
strategy | CAST_STRATEGY | CAST_STRATEGY.DEFAULT_OR_DROP |
Returns
any
Overrides
Defined in
schema/types/string-type.ts:220
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 | string |
Returns
boolean
Overrides
Defined in
schema/types/string-type.ts:302
isStrictStrategy
▸ isStrictStrategy(strategy
): boolean
Parameters
Name | Type |
---|---|
strategy | VALIDATION_STRATEGY |
Returns
boolean
Inherited from
Defined in
validate
▸ validate(value
, strategy
): undefined
| null
| string
Parameters
Name | Type |
---|---|
value | unknown |
strategy | any |
Returns
undefined
| null
| string