Skip to main content

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​

CoreType.constructor

Properties​

name​

name: string

Defined in: schema/interfaces/schema.types.ts:51

Inherited from​

CoreType.name


options​

options: StringTypeOptions

Defined in: schema/types/string-type.ts:179

Inherited from​

CoreType.options


typeName​

typeName: string

Defined in: schema/interfaces/schema.types.ts:51

Inherited from​

CoreType.typeName


sName​

static sName: string = String.name

Defined in: schema/types/string-type.ts:184

Overrides​

CoreType.sName

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​

CoreType.default


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​

CoreType.required


validator​

Get Signature​

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

Defined in: schema/types/core-type.ts:35

Returns​

undefined | string | ValidatorFunction | ValidatorOption

Inherited from​

CoreType.validator

Methods​

buildDefault()​

buildDefault(): undefined | string

Defined in: schema/types/string-type.ts:212

Returns​

undefined | string

Overrides​

CoreType.buildDefault


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​

CoreType.cast


checkRequired()​

checkRequired(): string | void

Defined in: schema/types/core-type.ts:62

Returns​

string | void

Inherited from​

CoreType.checkRequired


checkValidator()​

checkValidator(value): void

Defined in: schema/types/core-type.ts:71

Parameters​

value​

unknown

Returns​

void

Inherited from​

CoreType.checkValidator


isEmpty()​

isEmpty(value): boolean

Defined in: schema/types/string-type.ts:302

Parameters​

value​

string

Returns​

boolean

Overrides​

CoreType.isEmpty


isStrictStrategy()​

isStrictStrategy(strategy): boolean

Defined in: schema/types/core-type.ts:79

Parameters​

strategy​

VALIDATION_STRATEGY

Returns​

boolean

Inherited from​

CoreType.isStrictStrategy


validate()​

validate(value, strategy): undefined | null | string

Defined in: schema/types/string-type.ts:240

Parameters​

value​

unknown

strategy​

any

Returns​

undefined | null | string

Overrides​

CoreType.validate