Options
All
  • Public
  • Public/Protected
  • All
Menu

The lang package

Languages are awesome! Well... most of them are. And that's the case for TypeScript.

Sometimes there are a couple things we miss though...

And, when that happens, instead of complaining about it, we create a lang package :)

Check the API documentation at http://tokilabs.github.io/lang

Changelog

v1.0.2

  • Updates Class-transformer version from 0.1.8 to 0.3.1

v1.0.1

  • Removes broken mixin Sortable
  • Fixes Guid and NanoGuid exports

v1.0.0

  • Adds NanoGuid class

v0.8.1

  • Add deserializeArray method for use with JSON array strings

v0.8.0

  • [BREAKING CHANGE] Removes the ExtendedObject class
  • New (de)serialization methods: serialize, deserialize, primitify and classify
  • Decorators for controlling serialization

v0.7.1

  • Add FQN decorator and decorate package's classes
  • Move symbols into Symbols object
  • Add default value ({}) for ConcreteType type parameter

v0.7

  • Add FQN support (parseFQN() and requireByFQN())
  • Add StringWrapper and NumberWrapper classes for easy primitive subclassing
  • Add Exception class which properly extends native Error
  • Add Constructor type
  • Add tests for Decimal, FQN and Guid
  • Improve code documentation and add API documentation
  • Refactor Decimal and Guid classes to extend wrappers
  • Deprecated ExtendedObject and serialization decorators

Breaking Changes

  • OrderDirection enum values are now 'ASC' and 'DESC' (previously 1 and -1 respectivelly)
  • Removed IEnumerable and Iterator interfaces
  • Sortable class is now a mixin

Index

Type aliases

Constructor

Constructor<T>: new (...args: any[]) => T

Represents a constructor for objects of type T

Type parameters

  • T = {}

Type declaration

    • new (...args: any[]): T
    • Parameters

      • Rest ...args: any[]

      Returns T

Expression

Expression<TObj, TKey>: (value: TObj) => TKey

A function which receives an object and returns one of it's properties

Type parameters

  • TObj

  • TKey

Type declaration

    • (value: TObj): TKey
    • Parameters

      • value: TObj

      Returns TKey

FqnDetails

FqnDetails: { className: string; namespace: string; package: string; propertyPath?: string }

An object that holds the parts that make up a FQN

Type declaration

  • className: string
  • namespace: string
  • package: string
  • Optional propertyPath?: string

Serialized

Serialized<T>: {[ P in keyof T]: T[P] }

Represents a serialized version of another type

Type parameters

  • T

TransformFn

TransformFn: (value: any, obj: any, transformationType: CT.TransformationType) => any

Type declaration

    • (value: any, obj: any, transformationType: CT.TransformationType): any
    • Parameters

      • value: any
      • obj: any
      • transformationType: CT.TransformationType

      Returns any

Functions

Class

  • Class(typeFunction?: (type?: CT.TypeOptions) => Function): (target: any, key: string | symbol, parameterIndex?: number) => void
  • Specifies the class of a property.

    decorator

    Parameters

    • Optional typeFunction: (type?: CT.TypeOptions) => Function
        • (type?: CT.TypeOptions): Function
        • Parameters

          • Optional type: CT.TypeOptions

          Returns Function

    Returns (target: any, key: string | symbol, parameterIndex?: number) => void

      • (target: any, key: string | symbol, parameterIndex?: number): void
      • Parameters

        • target: any
        • key: string | symbol
        • Optional parameterIndex: number

        Returns void

Classify

  • Defines custom transformation logic when converting from a primitive to a class

    Parameters

    Returns (target: any, key: string) => void

      • (target: any, key: string): void
      • Parameters

        • target: any
        • key: string

        Returns void

Exclude

  • Exclude(options?: IExcludeOptions): (object: Object | Function, propertyName?: string) => void
  • Marks property as excluded from the process of transformation. By default it excludes the property for both constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types you want to skip this property.

    Parameters

    Returns (object: Object | Function, propertyName?: string) => void

      • (object: Object | Function, propertyName?: string): void
      • Parameters

        • object: Object | Function
        • Optional propertyName: string

        Returns void

Expose

  • Expose(options?: IExposeOptions): (object: Object | Function, propertyName?: string) => void
  • Marks property as included in the process of transformation. By default it includes the property for both constructorToPlain and plainToConstructor transformations, however you can specify on which of transformation types you want to skip this property.

    Parameters

    Returns (object: Object | Function, propertyName?: string) => void

      • (object: Object | Function, propertyName?: string): void
      • Parameters

        • object: Object | Function
        • Optional propertyName: string

        Returns void

FQN

  • FQN(fqn: string): ClassDecorator
  • Decorates a class or function with a Fully Qualified Name

    An FQN string has the following format: {package}:{namespace}.{class}

    Examples:

    • @tokilabs/lang:Decimal
    • @tokilabs/lang:serialization.Expose

    Parameters

    • fqn: string

      The Fully Qualified Name of the class

    Returns ClassDecorator

Primitify

  • Defines custom transformation logic when converting from a primitive to a class

    Parameters

    Returns (target: any, key: string) => void

      • (target: any, key: string): void
      • Parameters

        • target: any
        • key: string

        Returns void

SerializeOptions

TransformClassToPlain

classify

delay

  • delay(milliseconds: number): Promise<void>
  • Creates a promise which always resolves in the specified milliseconds

    Parameters

    • milliseconds: number

    Returns Promise<void>

deserialize

deserializeArray

escapeRegExp

  • escapeRegExp(regex: string): string
  • Escapes a regular expression

    Parameters

    • regex: string

    Returns string

hydrate

  • Hydrates an existing class instance with data from a plain object

    Type parameters

    • TClass

    Parameters

    • instance: TClass

      An instance to fill

    • objects: Object

      An object to get the data from

    • Optional options: ITransformationOptions

      Transformation options

    Returns TClass

  • Hydrates many existing instances with data from plain objects

    Type parameters

    • TClass

    Parameters

    • instances: TClass[]

      An array of instances to fill

    • objects: Object[]

      An array of plain objects to get the data from

    • Optional options: ITransformationOptions

      Transformation options

    Returns TClass[]

hydratePrimitive

  • Hydrates an existing plain object with data from a class instance

    Type parameters

    • TClass

    Parameters

    • instance: TClass

      An instance to get the data from

    • object: Object

      An object to fill

    • Optional options: ITransformationOptions

      Transformation options

    Returns Object

  • Hydrates an existing plain object with data from a class instance

    Type parameters

    • TClass

    Parameters

    • instances: TClass[]

      An array of instances to get the data from

    • objects: Object[]

      An array of objects to fill

    • Optional options: ITransformationOptions

      Transformation options

    Returns Object[]

isArray

  • isArray(value: any): value is any[]
  • export

    Parameters

    • value: any

    Returns value is any[]

isBlank

  • isBlank(value: any): boolean
  • Checks if value is undefined, null or an empty string

    export

    Parameters

    • value: any

    Returns boolean

    true if value is undefined, null or empty

isBoolean

  • isBoolean(value: any): value is boolean
  • Checks if value is of type boolean

    export

    Parameters

    • value: any

    Returns value is boolean

isDate

  • isDate(value: any): value is Date
  • Returns true if value is a Date

    export

    Parameters

    • value: any

    Returns value is Date

isEmpty

  • isEmpty(value: any): boolean
  • Checks if value is undefined, null or an empty string

    export

    Parameters

    • value: any

    Returns boolean

    true if value is undefined, null or empty

isFunction

  • isFunction(value: any): value is Function
  • export

    Parameters

    • value: any

    Returns value is Function

isJsobject

  • isJsobject(val: any): boolean
  • Returns true if val is either a function or an object

    export

    Parameters

    • val: any

    Returns boolean

isNumber

  • isNumber(value: any): boolean
  • export

    Parameters

    • value: any

    Returns boolean

isPresent

  • isPresent(value: any): boolean
  • Checks if value is defined and has a value other than null.

    export

    Parameters

    • value: any

    Returns boolean

    true if value is neither undefined or null; false otherwise

isPrimitive

  • isPrimitive(value: any): boolean
  • Returns true if val is not a function nor an object

    export

    Parameters

    • value: any

    Returns boolean

isPromise

  • isPromise(value: any): value is Promise<any>
  • export

    Parameters

    • value: any

    Returns value is Promise<any>

isString

  • isString(value: any): value is string
  • export

    Parameters

    • value: any

    Returns value is string

makeCompareFn

  • Creates a compare function based on an Expression and an OrderDirection

    Type parameters

    • T

      The type of the objects being compared

    Parameters

    • expr: Expression<T, string | number>

      Expression for the property to be compared

    • order: OrderDirection = ...

      The order direction

    Returns (a: T, b: T) => number

    A function that compares two objects of type T

      • (a: T, b: T): number
      • Parameters

        • a: T
        • b: T

        Returns number

noop

  • noop(): void
  • A function which does nothing

    Returns void

parseFQN

primitify

requireByFQN

  • requireByFQN(fqn: string): any
  • Requires a class by it's FQN

    Parameters

    • fqn: string

    Returns any

serialize

today

  • today(): Date
  • Returns a new Date object set to 00:00:00 of today

    Returns Date

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited method
  • Property
  • Private property
  • Static method

Generated using TypeDoc