Skip to main content

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

Constructors

constructor

new StringType(name, options?)

Parameters

NameType
namestring
optionsStringTypeOptions

Overrides

CoreType.constructor

Defined in

schema/types/string-type.ts:179

Properties

name

name: string

Inherited from

CoreType.name

Defined in

schema/interfaces/schema.types.ts:51


options

options: StringTypeOptions

Inherited from

CoreType.options

Defined in

schema/types/string-type.ts:179


typeName

typeName: string

Inherited from

CoreType.typeName

Defined in

schema/interfaces/schema.types.ts:51


sName

Static sName: string = String.name

Overrides

CoreType.sName

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

schema/types/core-type.ts:39


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

schema/types/core-type.ts:31


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

schema/types/core-type.ts:35

Methods

_checkEnum

Private _checkEnum(value, errors): void

Parameters

NameType
valuestring
errorsstring[]

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

NameType
valuestring
errorsstring[]

Returns

void

Defined in

schema/types/string-type.ts:277


_checkMinLength

Private _checkMinLength(value, errors): void

Parameters

NameType
valuestring
errorsstring[]

Returns

void

Defined in

schema/types/string-type.ts:270


buildDefault

buildDefault(): undefined | string

Returns

undefined | string

Overrides

CoreType.buildDefault

Defined in

schema/types/string-type.ts:212


cast

cast(value, strategy?): any

Parameters

NameTypeDefault value
valueunknownundefined
strategyCAST_STRATEGYCAST_STRATEGY.DEFAULT_OR_DROP

Returns

any

Overrides

CoreType.cast

Defined in

schema/types/string-type.ts:220


checkRequired

checkRequired(): string | void

Returns

string | void

Inherited from

CoreType.checkRequired

Defined in

schema/types/core-type.ts:62


checkValidator

checkValidator(value): void

Parameters

NameType
valueunknown

Returns

void

Inherited from

CoreType.checkValidator

Defined in

schema/types/core-type.ts:71


isEmpty

isEmpty(value): boolean

Parameters

NameType
valuestring

Returns

boolean

Overrides

CoreType.isEmpty

Defined in

schema/types/string-type.ts:302


isStrictStrategy

isStrictStrategy(strategy): boolean

Parameters

NameType
strategyVALIDATION_STRATEGY

Returns

boolean

Inherited from

CoreType.isStrictStrategy

Defined in

schema/types/core-type.ts:79


validate

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

Parameters

NameType
valueunknown
strategyany

Returns

undefined | null | string

Overrides

CoreType.validate

Defined in

schema/types/string-type.ts:240