Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/micro

Index

Type aliases

ArrayFilterFilter

ArrayFilterFilter<ItemType>: ArrayMapMapper<ItemType, boolean>

Type parameters

  • ItemType

ArrayGroupGrouper

ArrayGroupGrouper<ItemType>: (item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => string | number

Type parameters

  • ItemType

Type declaration

    • (item: Readonly<ItemType>, index: number, array: keyof ItemType[]): string | number
    • Parameters

      • item: Readonly<ItemType>
      • index: number
      • array: keyof ItemType[]

      Returns string | number

ArrayGroupObject

ArrayGroupObject<ItemType>: {}

Type parameters

  • ItemType

Type declaration

  • [group: string]: keyof ItemType[]

ArrayMapMapper

ArrayMapMapper<ItemType, OutputType>: (value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType

Type parameters

  • ItemType

  • OutputType

Type declaration

    • (value: Readonly<ItemType>, index: number, array: keyof ItemType[]): OutputType
    • Parameters

      • value: Readonly<ItemType>
      • index: number
      • array: keyof ItemType[]

      Returns OutputType

ArrayReduceReducer

ArrayReduceReducer<ItemType, OutputType>: (previousValue: Readonly<OutputType>, item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType

Type parameters

  • ItemType

  • OutputType

Type declaration

    • (previousValue: Readonly<OutputType>, item: Readonly<ItemType>, index: number, array: keyof ItemType[]): OutputType
    • Parameters

      • previousValue: Readonly<OutputType>
      • item: Readonly<ItemType>
      • index: number
      • array: keyof ItemType[]

      Returns OutputType

JSONParseReviver

JSONParseReviver<OutputType>: (this: OutputType, key: string, value: OutputType[keyof OutputType]) => OutputType[keyof OutputType]

Type parameters

  • OutputType

Type declaration

    • (this: OutputType, key: string, value: OutputType[keyof OutputType]): OutputType[keyof OutputType]
    • Parameters

      • this: OutputType
      • key: string
      • value: OutputType[keyof OutputType]

      Returns OutputType[keyof OutputType]

ObjectMapMapper

ObjectMapMapper<ObjectType, OutputType>: (value: Readonly<ObjectType[keyof ObjectType]>, key: string, targetObject: Readonly<ObjectType>) => OutputType

Type parameters

  • ObjectType

  • OutputType

Type declaration

    • (value: Readonly<ObjectType[keyof ObjectType]>, key: string, targetObject: Readonly<ObjectType>): OutputType
    • Parameters

      • value: Readonly<ObjectType[keyof ObjectType]>
      • key: string
      • targetObject: Readonly<ObjectType>

      Returns OutputType

StringMapReplaceMap

StringMapReplaceMap: {}

Type declaration

  • [match: string]: string | number

TapObserver

TapObserver<ValueType>: (value: Readonly<ValueType>) => Readonly<ValueType>

Type parameters

  • ValueType

Type declaration

    • (value: Readonly<ValueType>): Readonly<ValueType>
    • Parameters

      • value: Readonly<ValueType>

      Returns Readonly<ValueType>

TapWrapper

TapWrapper<ValueType>: (value: ValueType) => ValueType

Type parameters

  • ValueType

Type declaration

    • (value: ValueType): ValueType
    • Parameters

      • value: ValueType

      Returns ValueType

WhenNotNullishCallback

WhenNotNullishCallback<ValueType, OutputType>: (value: NonNullable<ValueType>) => OutputType

Type parameters

  • ValueType

  • OutputType

Type declaration

    • (value: NonNullable<ValueType>): OutputType
    • Parameters

      • value: NonNullable<ValueType>

      Returns OutputType

WhenNullishCallback

WhenNullishCallback<OutputType>: () => OutputType

Type parameters

  • OutputType

Type declaration

    • (): OutputType
    • Returns OutputType

Variables

Const EMPTY_ARRAY

EMPTY_ARRAY: keyof never[] = objectFreeze([])

Empty array.

Const EMPTY_OBJECT

EMPTY_OBJECT: {} = objectCreate()

Empty object (with no prototype).

Type declaration

Const EMPTY_STRING

EMPTY_STRING: "" = ""

Empty string.

Const TIME_DAY

TIME_DAY: number = 24 * TIME_HOUR

1 day in milliseconds

Const TIME_HOUR

TIME_HOUR: number = 60 * TIME_MINUTE

1 hour in milliseconds

Const TIME_MINUTE

TIME_MINUTE: number = 60 * TIME_SECOND

1 minute in milliseconds

Const TIME_SECOND

TIME_SECOND: 1000 = 1000

1 second in milliseconds

Const TIME_WEEK

TIME_WEEK: number = 7 * TIME_DAY

1 week in milliseconds

Const TIME_WEEK_WORK

TIME_WEEK_WORK: number = 5 * TIME_DAY

1 work week in milliseconds

Const TIME_YEAR

TIME_YEAR: number = 365 * TIME_DAY

1 year in milliseconds

Const TIME_YEAR_LEAP

TIME_YEAR_LEAP: number = 366 * TIME_DAY

1 year leap in milliseconds

Functions

Const arrayFilter

  • arrayFilter(target: ReadonlyArray<ItemType>, filter?: undefined | ((value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType)): ReadonlyArray<ItemType>
  • Array.prototype.filter wrapper.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • Default value filter: undefined | ((value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType) = _ => true

      Filter function.

    Returns ReadonlyArray<ItemType>

    An array of elements matching the given filter.

Const arrayFilterTuple

  • arrayFilterTuple(target: ReadonlyArray<ItemType>, filter: (value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType): [ReadonlyArray<ItemType>, ReadonlyArray<ItemType>]
  • Like Array.prototype.filter, but returns a tuple [matching, notMatching].

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • filter: (value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType

      Filter function.

        • (value: Readonly<ItemType>, index: number, array: keyof ItemType[]): OutputType
        • Parameters

          • value: Readonly<ItemType>
          • index: number
          • array: keyof ItemType[]

          Returns OutputType

    Returns [ReadonlyArray<ItemType>, ReadonlyArray<ItemType>]

    Array of 2 elements (the matching and the non matching values).

Const arrayGroup

  • arrayGroup(target: ReadonlyArray<ItemType>, grouper: (item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => string | number): {}
  • Creates object with properties grouped by grouper function.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • grouper: (item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => string | number

      Grouper function (returns the group name).

        • (item: Readonly<ItemType>, index: number, array: keyof ItemType[]): string | number
        • Parameters

          • item: Readonly<ItemType>
          • index: number
          • array: keyof ItemType[]

          Returns string | number

    Returns {}

    An object with the shape { [group]: [items] }.

Const arrayInsert

  • arrayInsert(target: ReadonlyArray<ItemType>, index: number, item: ItemType): ReadonlyArray<ItemType>
  • Insert value in array at given index.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • index: number

      Index to insert item.

    • item: ItemType

      Item to be inserted.

    Returns ReadonlyArray<ItemType>

    New array with inserted values in it.

Const arrayMap

  • arrayMap(target: ReadonlyArray<ItemType>, mapper: (value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType): ReadonlyArray<OutputType>
  • Array.prototype.map wrapper that can take an undefined value.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • mapper: (value: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType

      Map callback (to be called for every array item).

        • (value: Readonly<ItemType>, index: number, array: keyof ItemType[]): OutputType
        • Parameters

          • value: Readonly<ItemType>
          • index: number
          • array: keyof ItemType[]

          Returns OutputType

    Returns ReadonlyArray<OutputType>

    Mapped array.

Const arrayPush

  • arrayPush(target: ReadonlyArray<ItemType>, item: ItemType): ReadonlyArray<ItemType>
  • Insert given item at the end of given array.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • item: ItemType

      Item to be inserted.

    Returns ReadonlyArray<ItemType>

    New array with inserted values in it.

Const arrayReduce

  • arrayReduce(target: ReadonlyArray<ItemType>, reducer: (previousValue: Readonly<OutputType>, item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType, initialValue: OutputType): {}
  • Array.prototype.reduce wrapper that can take an undefined value.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • reducer: (previousValue: Readonly<OutputType>, item: Readonly<ItemType>, index: number, array: keyof ItemType[]) => OutputType

      Map callback (to be called for every array item).

        • (previousValue: Readonly<OutputType>, item: Readonly<ItemType>, index: number, array: keyof ItemType[]): OutputType
        • Parameters

          • previousValue: Readonly<OutputType>
          • item: Readonly<ItemType>
          • index: number
          • array: keyof ItemType[]

          Returns OutputType

    • initialValue: OutputType

      Initial value of reducer.

    Returns {}

    Reduced value.

Const arrayReplace

  • arrayReplace(target: ReadonlyArray<ItemType>, index: number, item: ItemType): ReadonlyArray<ItemType>
  • Replace value in array at given index.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • index: number

      Index to start replace item.

    • item: ItemType

      Replacing item.

    Returns ReadonlyArray<ItemType>

    Array with replaced elements.

Const arraySlice

  • arraySlice(target: ReadonlyArray<ItemType>, start?: undefined | number, end?: undefined | number): ReadonlyArray<ItemType>
  • Array.prototype.slice wrapper.

    Parameters

    • target: ReadonlyArray<ItemType>

      Target array.

    • Default value start: undefined | number = 0

      Slice start.

    • Default value end: undefined | number = target.length

      Slice end.

    Returns ReadonlyArray<ItemType>

    A slice of the given array (from start to end).

Const arraySplit

  • arraySplit<ItemType>(target: keyof ItemType[], length: number, vertical?: boolean): ReadonlyArray<ReadonlyArray<ItemType>>
  • Split array into multiple arrays of the given size.

    Type parameters

    • ItemType

    Parameters

    • target: keyof ItemType[]

      Target array.

    • length: number

      Size of every piece.

    • Default value vertical: boolean = false

      Changes the orientation of the split.

    Returns ReadonlyArray<ReadonlyArray<ItemType>>

    Array of arrays of the given length.

Const isArray

  • isArray<ValueType, ItemType>(value: ValueType | keyof ItemType[]): value is keyof ItemType[]
  • Check if given value is an instance of Array.

    Type parameters

    • ValueType

    • ItemType

    Parameters

    • value: ValueType | keyof ItemType[]

      Value to check.

    Returns value is keyof ItemType[]

    True if is an array, false if not.

Const isBigInt

  • isBigInt<ValueType>(value: ValueType | BigInt): value is BigInt
  • Check if given value is an instance of BigInt.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | BigInt

      Value to check.

    Returns value is BigInt

    True if is a BigInt, false if not.

Const isBoolean

  • isBoolean<ValueType>(value: ValueType | boolean): value is boolean
  • Check if given value is an instance of Boolean.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | boolean

      Value to check.

    Returns value is boolean

    True if is a Boolean, false if not.

Const isDate

  • isDate<ValueType>(value: ValueType | Date): value is Date
  • Check if given value is an instance of Date.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | Date

      Value to check.

    Returns value is Date

    True if is a Date, false if not.

Const isFunction

  • isFunction<ValueType>(value: ValueType | Function): value is Function
  • Check if given value is an instance of Function.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | Function

      Value to check.

    Returns value is Function

    True if is a Function, false if not.

Const isInstanceOf

  • isInstanceOf(value: ValueType, constructor: Function): boolean
  • Check if the given value is an instance of the given constructor.

    Parameters

    • value: ValueType

      Value to check.

    • constructor: Function

      Possible constructor of given value.

    Returns boolean

    True if is an instance of the given constructor, false if not.

Const isNull

  • isNull<ValueType>(value: ValueType | null): value is null
  • Check if given value is null.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | null

      Value to check.

    Returns value is null

    True if is a null, false if not.

Const isNullish

  • isNullish<ValueType>(value: ValueType | null | undefined): value is null | undefined
  • Check if given value is null or undefined.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | null | undefined

      Value to check.

    Returns value is null | undefined

    True if is a null or undefined, false if not.

Const isNumber

  • isNumber<ValueType>(value: ValueType | number): value is number
  • Check if given value is instance of Number.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | number

      Value to check.

    Returns value is number

    True if is a number, false if not.

Const isObject

  • isObject<ValueType>(value: ValueType | object): value is object
  • Check if given value is instance of Object (and is not null).

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | object

      Value to check.

    Returns value is object

    True if is an object, false if not.

Const isPromise

  • isPromise<ValueType, PromiseValue>(value: ValueType | Promise<PromiseValue>): value is Promise<PromiseValue>
  • Check if given value is an instance of Promise.

    Type parameters

    • ValueType

    • PromiseValue

    Parameters

    • value: ValueType | Promise<PromiseValue>

      Value to check.

    Returns value is Promise<PromiseValue>

    True if is a Promise, false if not.

Const isRegExp

  • isRegExp<ValueType>(value: ValueType | RegExp): value is RegExp
  • Check if given value is an instance of RegExp.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | RegExp

      Value to check.

    Returns value is RegExp

    True if is a RegExp, false if not.

Const isString

  • isString<ValueType>(value: ValueType | string): value is string
  • Check if given value is instance of String.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | string

      Value to check.

    Returns value is string

    True if is a string, false if not.

Const isSymbol

  • isSymbol<ValueType>(value: ValueType | symbol): value is symbol
  • Check if given value is instance of Symbol.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | symbol

      Value to check.

    Returns value is symbol

    True if is a symbol, false if not.

Const isUndefined

  • isUndefined<ValueType>(value: ValueType | undefined): value is undefined
  • Check if given value is undefined.

    Type parameters

    • ValueType

    Parameters

    • value: ValueType | undefined

      Value to check.

    Returns value is undefined

    True if is undefined, false if not.

Const jsonParsePromise

  • jsonParsePromise(text: string, reviver: undefined | ((this: OutputType, key: string, value: OutputType[keyof OutputType]) => OutputType[keyof OutputType])): Promise<OutputType>
  • Promise wrapper of JSON.parse.

    Parameters

    • text: string

      Text value to parse.

    • reviver: undefined | ((this: OutputType, key: string, value: OutputType[keyof OutputType]) => OutputType[keyof OutputType])

      Transformer function.

    Returns Promise<OutputType>

    Promise with parsed JSON. Can be catch if any error is thrown.

Const noop

  • noop(value: ValueType): ValueType
  • No operation placeholder function.

    Parameters

    • value: ValueType

      Value will be returned without changing it.

    Returns ValueType

    The given value.

Const objectCreate

  • objectCreate(base?: undefined | {} | Base, prototype?: undefined | null | Prototype): any
  • Object.create + Object.assign wrapper with default null prototype.

    Parameters

    • Default value base: undefined | {} | Base = {}

      Base object (null by default).

    • Default value prototype: undefined | null | Prototype = null

      Base prototype of the new object (null by default).

    Returns any

    New object with given base and prototype.

Const objectEntries

  • objectEntries(target: ObjectType): ReadonlyArray<[string, {}]>
  • Object.entries wrapper.

    Parameters

    • target: ObjectType

      Target object.

    Returns ReadonlyArray<[string, {}]>

    Array of tuples ([key, value]) of the given object.

Const objectFreeze

  • objectFreeze(target: TargetType): TargetType
  • Object.freeze wrapper (returns a frozen copy of the object).

    Parameters

    • target: TargetType

      Object to be frozen.

    Returns TargetType

    Frozen object.

Const objectMap

  • objectMap(target: ObjectType, mapper: (value: Readonly<ObjectType[keyof ObjectType]>, key: string, targetObject: Readonly<ObjectType>) => OutputType): ReadonlyArray<OutputType>
  • Object mapping.

    Parameters

    • target: ObjectType

      Target object.

    • mapper: (value: Readonly<ObjectType[keyof ObjectType]>, key: string, targetObject: Readonly<ObjectType>) => OutputType

      Map callback (to be called for every object key).

        • (value: Readonly<ObjectType[keyof ObjectType]>, key: string, targetObject: Readonly<ObjectType>): OutputType
        • Parameters

          • value: Readonly<ObjectType[keyof ObjectType]>
          • key: string
          • targetObject: Readonly<ObjectType>

          Returns OutputType

    Returns ReadonlyArray<OutputType>

    An array with the object mapped values/keys.

Const stringMapReplace

  • stringMapReplace(target: string, replaceMap?: {}): string
  • Takes a string and an object and makes a regex map replace

    Parameters

    • target: string

      Target string.

    • Default value replaceMap: {} = EMPTY_OBJECT

      Map with format { "match": "replacing string" }.

      • [match: string]: string | number

    Returns string

    String with replaced values.

Const tap

  • tap(observer: (value: Readonly<ValueType>) => Readonly<ValueType>): (Anonymous function)
  • Tap into any value.

    Parameters

    • observer: (value: Readonly<ValueType>) => Readonly<ValueType>

      Observer function.

        • (value: Readonly<ValueType>): Readonly<ValueType>
        • Parameters

          • value: Readonly<ValueType>

          Returns Readonly<ValueType>

    Returns (Anonymous function)

    Tapped function (calls observer with value and returns it).

Const when

  • when(value: ValueType, notNullishCallback: (value: NonNullable<ValueType>) => OutputType, nullishCallback: undefined | (() => OutputType)): undefined | OutputType
  • Ternary wrapper based on callbacks.

    Parameters

    • value: ValueType

      Value to be checked (truthy/falsy).

    • notNullishCallback: (value: NonNullable<ValueType>) => OutputType

      Callback when value is not nullish.

        • (value: NonNullable<ValueType>): OutputType
        • Parameters

          • value: NonNullable<ValueType>

          Returns OutputType

    • nullishCallback: undefined | (() => OutputType)

      Callback when value is nullish.

    Returns undefined | OutputType

    The returned value of notNullishCallback or nullishCallback.

Generated using TypeDoc