# 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


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



# Constructors

# constructor

+ new StringType(name: string, options: StringTypeOptions): StringType

Overrides CoreType.constructor


Name Type Default
name string -
options StringTypeOptions {} as StringTypeOptions

Returns: StringType

# Properties

# name

name: string

Inherited from IOttomanType.name

# options

options: StringTypeOptions

Overrides CoreType.options

# typeName

typeName: string

Inherited from IOttomanType.typeName

# Static sName

sName: string = String.name

Overrides CoreType.sName

# Accessors

# auto

get auto(): string | AutoFunction | undefined

Returns: string | AutoFunction | undefined

# default

get default(): unknown

Inherited from CoreType.default

Returns: unknown

# enumValues

get enumValues(): unknown

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(): string | undefined

Overrides CoreType.buildDefault

Returns: string | undefined

# cast

cast(value: unknown, strategy: CAST_STRATEGY): any

Overrides IOttomanType.cast


Name Type Default
value unknown -

Returns: any

# checkRequired

checkRequired(): string | void

Inherited from CoreType.checkRequired

Returns: string | void

# checkValidator

checkValidator(value: unknown): void

Inherited from CoreType.checkValidator


Name Type
value unknown

Returns: void

# isEmpty

isEmpty(value: string): boolean

Overrides CoreType.isEmpty


Name Type
value string

Returns: boolean

# isStrictStrategy

isStrictStrategy(strategy: VALIDATION_STRATEGY): boolean

Inherited from CoreType.isStrictStrategy


Name Type

Returns: boolean

# validate

validate(value: unknown, strategy: any): null | string

Overrides CoreType.validate


Name Type
value unknown
strategy any

Returns: null | string