Options
All
  • Public
  • Public/Protected
  • All
Menu

@itryapitsin/ts-decorators

Index

Type aliases

Constructor

Constructor: object

Constructor for class type

Type declaration

Mixin

Mixin: Constructor<T> | object

Type of class mixin

Variables

Const INFO_COLOR

INFO_COLOR: "#208BDA" = "#208BDA"

Information message color in console

Const WARNING_COLOR

WARNING_COLOR: "#DA940B" = "#DA940B"

Warning message color in console

Const jsonMetadataKey

jsonMetadataKey: "json-property" = "json-property"

Const maxLengthMetadataKey

maxLengthMetadataKey: unique symbol = Symbol('max-length')

Const minLengthMetadataKey

minLengthMetadataKey: unique symbol = Symbol('min-length')

Const regexMetadataKey

regexMetadataKey: unique symbol = Symbol('regex')

Const requiredMetadataKey

requiredMetadataKey: unique symbol = Symbol('required')

Const rulePool

rulePool: RuleFunction[] = [validateNulls,validateMaxLength,validateMinLength,validateRegex,]

Container of rules

Functions

IsArray

  • IsArray(object: any): boolean
  • Parameters

    • object: any

    Returns boolean

IsBoolean

  • IsBoolean(x: any): boolean

IsFunction

  • IsFunction(x: any): boolean

IsNotNullAndUndefined

  • IsNotNullAndUndefined(x: any): boolean

IsNull

  • IsNull(x: any): boolean

IsNullOrUndefined

  • IsNullOrUndefined(x: any): boolean

IsNumber

  • IsNumber(x: any): boolean

IsObject

  • IsObject(x: any): boolean

IsPrimitive

  • IsPrimitive(x: any): boolean

IsString

  • IsString(x: any): boolean

IsSymbol

  • IsSymbol(x: any): boolean

IsUndefined

  • IsUndefined(x: any): boolean

cached

  • cached(): (Anonymous function)

customValidator

  • customValidator<T>(name: string, data?: T): ParameterDecorator

deprecated

  • deprecated(enabled?: boolean): PropertyDecorator
  • Write into console Deprecated warning for a property

    Parameters

    • Default value enabled: boolean = true

    Returns PropertyDecorator

deserialize

  • deserialize<T>(clazz: object, jsonObject: any): T

getClazz

  • getClazz(target: any, propertyKey: string): any

getJsonProperty

  • getJsonProperty<T>(target: any, propertyKey: string): JsonMetaData<T>

getMixables

  • getMixables(clientKeys: string[], mixin: Mixin<any>): PropertyDescriptorMap
  • Returns a map of mixables. That is things that can be mixed in

    Parameters

    • clientKeys: string[]
    • mixin: Mixin<any>

    Returns PropertyDescriptorMap

getPropertyDescriptorMap

  • getPropertyDescriptorMap(clientKeys: string[], object: any): PropertyDescriptorMap

isEmail

  • isEmail(): PropertyDecorator

jsonProperty

logMethod

  • logMethod(enabled?: boolean | Lambda): MethodDecorator

logParameter

  • logParameter(target: any, key: string, index: number): void

logProperty

  • logProperty(enabled?: boolean | Lambda): PropertyDecorator

maxLength

  • maxLength(max: number): PropertyDecorator
  • Passed value should not be less than maximum

    example

    class TestClass { @maxLength(10) testValue: string; }

    Parameters

    • max: number

      A maximum value

    Returns PropertyDecorator

maxValue

  • maxValue(maxValue: number): PropertyDecorator
  • Passed value should not be greater than minimum

    example

    class TestClass { @maxValue(10) testValue: number; }

    Parameters

    • maxValue: number

      A maximum value for validation

    Returns PropertyDecorator

minLength

  • minLength(min: number): PropertyDecorator
  • Passed value should not be greater than minimum

    example

    class TestClass { @minLength(10) testValue: string; }

    Parameters

    • min: number

      A minimum value

    Returns PropertyDecorator

minValue

  • minValue(minValue: number): PropertyDecorator

mix

mixin

  • mixin(...options: Mixin<any>[]): ClassDecorator
  • Takes a list of classes or object literals and adds their methods to the class calling it.

    Parameters

    • Rest ...options: Mixin<any>[]

    Returns ClassDecorator

Const notEmptyString

  • notEmptyString(): PropertyDecorator
  • notEmptyString(): ParameterDecorator

notNull

  • notNull(target: Record<string, any>, propertyKey: string): void
  • Passed value should not be null

    example

    class TestClass { @notNull testValue: Object; }

    Parameters

    • target: Record<string, any>

      A class of method

    • propertyKey: string

      A method name

    Returns void

Const propertyMetadataFn

  • propertyMetadataFn(propertyMetadata: any, jsonObject: any, target: any, propertyKey: string): any

regex

  • regex(regex: RegExp | string): PropertyDecorator
  • Passed value should be valid in pattern

    Parameters

    • regex: RegExp | string

      RegExp instance or the regular expression literal

    Returns PropertyDecorator

serialize

  • serialize<T>(clazz: T): any

tryCatch

  • tryCatch(func: Lambda1<Error>): (Anonymous function)

validate

  • validate(target: any, propertyName: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor
  • Validate method's arguments by rules from rulePool

    Parameters

    • target: any
    • propertyName: string | symbol
    • descriptor: PropertyDescriptor

    Returns PropertyDescriptor

validateMaxLength

  • validateMaxLength(target: any, propertyName: string | symbol, arguments_: any): void
  • Test decorated parameters for maximal length

    Parameters

    • target: any

      A class of method

    • propertyName: string | symbol

      A method name

    • arguments_: any

    Returns void

validateMinLength

  • validateMinLength(target: any, propertyName: string | symbol, arguments_: any): void
  • Test decorated parameters for minimal length

    Parameters

    • target: any

      A class of method

    • propertyName: string | symbol

      A method name

    • arguments_: any

    Returns void

validateNulls

  • validateNulls(target: any, propertyName: string | symbol, arguments_: any): void
  • Test decorated parameters for null or undefined

    Parameters

    • target: any

      A class of method

    • propertyName: string | symbol

      A method name

    • arguments_: any

    Returns void

validateRegex

  • validateRegex(target: any, propertyName: string | symbol, arguments_: any): void
  • Test decorated parameters for a pattern

    Parameters

    • target: any

      A class of method

    • propertyName: string | symbol

      A method name

    • arguments_: any

    Returns void

Generated using TypeDoc