Options
All
  • Public
  • Public/Protected
  • All
Menu

@mantlebee/ts-core

Index

Type Aliases

AlarmDelegate: ((stop: (() => void), snooze: ((time: number) => void)) => void)

Type declaration

    • (stop: (() => void), snooze: ((time: number) => void)): void
    • Parameters

      • stop: (() => void)
          • (): void
          • Returns void

      • snooze: ((time: number) => void)
          • (time: number): void
          • Parameters

            • time: number

            Returns void

      Returns void

Any: any

Any type. Useful when:

  1. you don't know the type of a parameter, like check functions (function isString(arg: Any): boolean)
  2. you have to deal with generic type variables, but the type of the value is not important or is not the same for each item. ATTENTION: its intent is not to avoid eslint checks.
ConstructorOf<TClass>: {}

Contructor of a specific class. Useful when a constructor must be passed to a generic function as parameter.

Type Parameters

  • TClass

    Instantiable class.

Type declaration

    DailySchedule: Schedule & { every: number }

    Execute the schedule every X days

    param every

    days occur between an execution and the next one

    Dictionary<TValue, TKey>: { [ key in TKey]: TValue }

    Dictionary of items of the same type. A list of keys can be specified.

    example

    Simple dictionary, any string key is allowed.

    const examResultsBoard: Dictionary<number> = {
    john: 877,
    jane: 931,
    // ...
    }
    example

    Dictionary with specific keys only.

    const permissionsMap: Dictionary<boolean, "read" | "write"> = {
    read: true,
    write: false
    }

    Type Parameters

    • TValue

      Type of the item.

    • TKey extends string = string

      Type of the key, default is string.

    KeyOf<TObject, TKey>: Extract<keyof TObject, TKey>

    Key of an object.

    Type Parameters

    • TObject

      Object from which to extract the key.

    • TKey = string

      Type of the key, default is string.

    KeysOf<TObject, TValue>: { [ TKey in keyof TObject]: TValue }

    Keys of an object. Value is the same of the original object or different, if specified.

    Type Parameters

    • TObject

      Object from which to extract the keys.

    • TValue = TObject[keyof TObject]

      Type of the values of the dictionary. The default is the same of the object.

    List<TItem>: TItem[]

    List of items of the same type.

    Type Parameters

    • TItem

      Type of item.

    LogDelegate: ((type: LogTypes, message: string, data?: any) => void)

    Type declaration

      • (type: LogTypes, message: string, data?: any): void
      • Parameters

        • type: LogTypes
        • message: string
        • Optional data: any

        Returns void

    MonthlyByDaySchedule: Schedule & { days: List<number>; months: List<Months> }

    Execute the schedule on a specific day (number, eg: 5), every X months

    param days

    days of the month in which execute the schedule

    param months

    months in which execute the schedule

    MonthlyByWeeklyDaySchedule: Schedule & { conditions: List<MonthWeekConditions>; months: List<Months>; weekDays: List<WeekDays> }

    Execute the schedule on a specific day of the week (eg: first monday), every X months

    param conditions

    list of specific weekly days of the month (eg: first, last)

    param weekDays

    days of the week in which execute the schedule

    param months

    months in which execute the schedule

    Nullable<T>: T | null

    Type of value that can be null too.

    Type Parameters

    • T

    OneTimeSchedule: Schedule

    Execute the schedule once at a specific DateTime

    OptionalKeysOf<TObject, TValue>: { [ TKey in keyof TObject]?: TValue }

    Keys of an object; all keys are optional. Value is the same of the original object or different, if specified.

    Type Parameters

    • TObject

      Object from which to extract the keys.

    • TValue = TObject[keyof TObject]

      Type of the values of the dictionary. The default is the same of the object.

    RgbColor: { a?: number; b: number; g: number; r: number }

    Type declaration

    • Optional a?: number
    • b: number
    • g: number
    • r: number
    RgbaColor: { a: number; b: number; g: number; r: number }

    Type declaration

    • a: number
    • b: number
    • g: number
    • r: number
    Schedule: { expireDate?: Date; repeat?: ScheduleRepeat; startDate: Date }

    Type declaration

    • Optional expireDate?: Date
    • Optional repeat?: ScheduleRepeat
    • startDate: Date
    ScheduleRepeat: { duration?: ScheduleTime; every: ScheduleTime }

    Repeat the schedule execution every X time for an optional amount of time

    param every

    after how much time the schedule has to be executed

    param duration

    after how much time the schedule has to be executed

    Type declaration

    ScheduleTime: { hours: number; minutes: number }

    Type declaration

    • hours: number
    • minutes: number
    Stringable: { toString: any }

    Any type that contains the toString method.

    Type declaration

    SubscribableLoggerData: { data?: any; message: string; type: LogTypes }

    Type declaration

    • Optional data?: any
    • message: string
    • type: LogTypes
    Subscription<TData>: ((data: TData) => void)

    Type Parameters

    • TData

    Type declaration

      • (data: TData): void
      • Parameters

        • data: TData

        Returns void

    Undefinable<T>: T | undefined

    Type of value that can be undefined too.

    Type Parameters

    • T

    WeeklySchedule: Schedule & { days: List<WeekDays>; every: number }

    Execute the schedule at specific weekly days

    param days

    the list of WeekDays on which execute the schedule

    param every

    weeks occur between an execution and the next one

    WizardContext: { canAbort?: boolean; canComplete: boolean; abort?: any; complete: any }

    Type declaration

    Variables

    DebugMode: Enablable = ...

    Enable/disable the debug mode. Default is disabled. Debug mode is used by IFactory to instantiate classes into debug/release mode.

    Functions

    • firstOrDefault<T>(list: List<T>, delegate: ((a: T) => boolean), defaultItem?: Nullable<T>): Nullable<T>
    • Looks for and returns an item in a list or a default one if item is not found.

      example
      firstOrDefault([1, 2, 3], a => a === 1)      // 1
      firstOrDefault([1, 2, 3], a => a === 4) // null
      firstOrDefault([1, 2, 3], a => a === 4, 5) // 5

      Type Parameters

      • T

      Parameters

      • list: List<T>

        List where to look for the item.

      • delegate: ((a: T) => boolean)

        Function to find the item.

          • (a: T): boolean
          • Parameters

            • a: T

            Returns boolean

      • defaultItem: Nullable<T> = null

        Item used as default value if item is not found.

      Returns Nullable<T>

      the found item or the default one provided.

    • Formats a string, replacing the placeholders with the given values.

      example
      formatString("Hi {0}, this is {1}. Goodbye, {0}.", "John", "Jane")
      // "Hi John, this is Jane. Goodbye, John."

      Parameters

      • str: string

        String to format.

      • Rest ...args: List<Stringable>

        List of values to insert in the string.

      Returns string

      a formatted string with given values.

    • generateGuid(): string
    • getCharsFromCharCodesRange(startIndex: number, length: number): string
    • getLowercaseChars(): string
    • getNumberChars(): string
    • getSpecialChars(): string
    • getUppercaseChars(): string
    • Converts an HEX color to a RgbaColor object.

      example
      hexToRgba("#FF0000") // {a: 1, b: 0, g: 0, r: 255}
      

      Parameters

      • hex: string

        HEX to convert to RGBA.

      Returns RgbaColor

      RgbaColor.

    • isBoolean(arg: any): boolean
    • isDate(arg: any): boolean
    • isDefined<TValue>(value: TValue): boolean
    • Checks if value is not null and not undefined.

      Type Parameters

      • TValue

      Parameters

      • value: TValue

        Value to check

      Returns boolean

      true if value is not null and not undefined.

    • isEmail(arg: string): boolean
    • isGuid(arg: string): boolean
    • isNull<TValue>(value: TValue): boolean
    • Checks if value is null.

      Type Parameters

      • TValue

      Parameters

      • value: TValue

        Value to check

      Returns boolean

      true if value is null.

    • isNullOrUndefined<TValue>(value: TValue): boolean
    • Checks if value is null or undefined.

      Type Parameters

      • TValue

      Parameters

      • value: TValue

        Value to check

      Returns boolean

      true if value is null or undefined.

    • isNumber(arg: any): boolean
    • isString(arg: any): boolean
    • isUndefined<TValue>(value: TValue): boolean
    • Checks if value is undefined.

      Type Parameters

      • TValue

      Parameters

      • value: TValue

        Value to check

      Returns boolean

      true if value is undefined.

    • listToDictionary<T>(list: List<T>, key: Extract<keyof T, string>): Dictionary<T>
    • Creates a dictionary from the given items, using the item[key] value as key of the dictionary.

      example
      const list = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]
      listToDictionary(list, "id")
      // {
      // 1: {id: 1, name: "John"},
      // 2: {id: 2, name: "Jane"}
      // }

      Type Parameters

      • T

      Parameters

      • list: List<T>

        Items to map.

      • key: Extract<keyof T, string>

        Key of the item to use as dictionary key.

      Returns Dictionary<T>

      a dictionary where the key is the value of item[key] and the value is the item itself

    • numberIsInteger(numb: number): boolean
    • Checks if a number is integer.

      Parameters

      • numb: number

        Number to check.

      Returns boolean

      true if number is integer.

    • objectHasKey(obj: any, key: string): boolean
    • Checks if the given object has the given key.

      example
      objectHasKey({name: "John"}, "name")     // true
      objectHasKey({name: "John"}, "surname") // false

      Parameters

      • obj: any

        Object to check for the key.

      • key: string

        Key to search in the object.

      Returns boolean

      true if the object has the key.

    • replaceListItems<T>(list: List<T>, items: List<T>): void
    • Replaces all the list items with new items. Usefull when the array instance can not change.

      const list = [1, 2, 3]
      const listRef = list
      replaceListItems(list, [4, 5, 6])
      // listRef is [4, 5, 6]

      Type Parameters

      • T

      Parameters

      • list: List<T>

        Instance with items to replace.

      • items: List<T>

        Items to replace.

      Returns void

    • rgbaToHex(r: number, g: number, b: number, a?: number): string
    • Converts RGBA values to an HEX string. If the alpha value is provided, the HEX result will contain the alpha channel: #rrggbbAA.

      example
      rgbaToHex(255, 0, 0) // "#FF0000"
      

      Parameters

      • r: number

        Red value (0-255).

      • g: number

        Green value (0-255).

      • b: number

        Blue value (0-255).

      • Optional a: number

        Alpha value (0-1). Default is 1.

      Returns string

      an HEX string of the RGBA values.

    • roundNumber(numb: number, decimals?: number): number
    • shortHexToFullHex(shortHex: string): string
    • Converts a short HEX to the full version (eg. #f8a > #ff88aa).

      example
      shortHexToFullHex("#F00") // "#FF0000"
      

      Parameters

      • shortHex: string

        Short HEX (eg. #f8a).

      Returns string

      a full HEX (eg. #ff88aa).

    Generated using TypeDoc