# 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

CoreType

StringType

# Constructors

# constructor

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

Overrides CoreType.constructor

Parameters:

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

Parameters:

Name Type Default
value unknown -
strategy CAST_STRATEGY CAST_STRATEGY.DEFAULT_OR_DROP

Returns: any


# checkRequired

checkRequired(): string | void

Inherited from CoreType.checkRequired

Returns: string | void


# checkValidator

checkValidator(value: unknown): void

Inherited from CoreType.checkValidator

Parameters:

Name Type
value unknown

Returns: void


# isEmpty

isEmpty(value: string): boolean

Overrides CoreType.isEmpty

Parameters:

Name Type
value string

Returns: boolean


# isStrictStrategy

isStrictStrategy(strategy: VALIDATION_STRATEGY): boolean

Inherited from CoreType.isStrictStrategy

Parameters:

Name Type
strategy VALIDATION_STRATEGY

Returns: boolean


# validate

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

Overrides CoreType.validate

Parameters:

Name Type
value unknown
strategy any

Returns: null | string