Options
All
  • Public
  • Public/Protected
  • All
Menu

Utils

Index

Type aliases

WaitForResult

WaitForResult<T>: [] | []

Type parameters

  • T

Variables

Const HOUR_IN_MINUTES

HOUR_IN_MINUTES: 60 = 60

Const HOUR_IN_MS

HOUR_IN_MS: number = HOUR_IN_SECONDS * SECOND_IN_MS

Const HOUR_IN_SECONDS

HOUR_IN_SECONDS: number = HOUR_IN_MINUTES * MINUTE_IN_SECONDS

Const MINUTE_IN_MS

MINUTE_IN_MS: number = MINUTE_IN_SECONDS * SECOND_IN_MS

Const MINUTE_IN_SECONDS

MINUTE_IN_SECONDS: 60 = 60

Const SECOND_IN_MS

SECOND_IN_MS: 1000 = 1000

Const cache

cache: {}

Type declaration

  • [key: string]: any

Const emToNumber

emToNumber: (Anonymous function) = asNumber(/^([0-9\.]*?)em$/)

Convert em number to a plain number

Const hoursInMinutes

hoursInMinutes: (Anonymous function) = multiplyBy(HOUR_IN_MINUTES)

Const hoursInMs

hoursInMs: (Anonymous function) = chain(multiplyBy(HOUR_IN_MINUTES), multiplyBy(MINUTE_IN_SECONDS), multiplyBy(SECOND_IN_MS))

Const hoursInSeconds

hoursInSeconds: (Anonymous function) = chain(multiplyBy(HOUR_IN_MINUTES), multiplyBy(MINUTE_IN_SECONDS))

Const minutesAsHours

minutesAsHours: (Anonymous function) = divideBy(HOUR_IN_MINUTES)

Const minutesInMs

minutesInMs: (Anonymous function) = chain(multiplyBy(MINUTE_IN_SECONDS), multiplyBy(SECOND_IN_MS))

Const minutesInSeconds

minutesInSeconds: (Anonymous function) = multiplyBy(MINUTE_IN_SECONDS)

Const msAsHour

msAsHour: (Anonymous function) = chain(divideBy(SECOND_IN_MS), divideBy(MINUTE_IN_SECONDS), divideBy(HOUR_IN_MINUTES))

Const msAsMinutes

msAsMinutes: (Anonymous function) = chain(divideBy(SECOND_IN_MS), divideBy(MINUTE_IN_SECONDS))

Const msAsSeconds

msAsSeconds: (Anonymous function) = divideBy(SECOND_IN_MS)

Const numberToEm

numberToEm: (Anonymous function) = asUnit('em')

Conver a number to em

Const numberToPx

numberToPx: (Anonymous function) = asUnit('px')

Conver a number to px

Const numberToRem

numberToRem: (Anonymous function) = asUnit('rem')

Conver a number to rem

Const numberToVh

numberToVh: (Anonymous function) = asUnit('vh')

Conver a number to vh

Const numberToVw

numberToVw: (Anonymous function) = asUnit('vw')

Conver a number to vw

Const pxToNumber

pxToNumber: (Anonymous function) = asNumber(/^([0-9\.]*?)px$/)

Convert px number to a plain number

Const remToNumber

remToNumber: (Anonymous function) = asNumber(/^([0-9\.]*?)rem$/)

Convert rem number to a plain number

Const secondsAsHours

secondsAsHours: (Anonymous function) = chain(divideBy(MINUTE_IN_SECONDS), divideBy(HOUR_IN_MINUTES))

Const secondsAsMinutes

secondsAsMinutes: (Anonymous function) = divideBy(MINUTE_IN_SECONDS)

Const secondsInMs

secondsInMs: (Anonymous function) = multiplyBy(SECOND_IN_MS)

Const vhToNumber

vhToNumber: (Anonymous function) = asNumber(/^([0-9\.]*?)vh$/)

Convert vh number to a plain number

Const vwToNumber

vwToNumber: (Anonymous function) = asNumber(/^([0-9\.]*?)vw$/)

Convert vw number to a plain number

Functions

Const asNumber

  • asNumber(regex: RegExp): (Anonymous function)
  • Creates a function that turns 1unit into 1

    Parameters

    • regex: RegExp

      The regex to remove the unit e.g. /^([0-9\.]*?)px$/

    Returns (Anonymous function)

Const asUnit

  • asUnit(unit: string): (Anonymous function)
  • Creates a function to add a unit to the number.

    Parameters

    • unit: string

      The unit to append.

    Returns (Anonymous function)

Const asyncForEach

  • asyncForEach<T>(array: T[], itterator: (value: T, index: number, array: T[]) => Promise<void>): Promise<void>
  • Runs the supplied itterator for all elements in the array asyncronously.

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to itterate through.

    • itterator: (value: T, index: number, array: T[]) => Promise<void>

      The async function to run for each element.

        • (value: T, index: number, array: T[]): Promise<void>
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns Promise<void>

    Returns Promise<void>

Const asyncMap

  • asyncMap<T, K>(list: T[], executor: (element: T, index: number, array: T[]) => Promise<K>): Promise<K[]>
  • Runs Array.map asyncronously.

    Type parameters

    • T

    • K

    Parameters

    • list: T[]

      The array to map

    • executor: (element: T, index: number, array: T[]) => Promise<K>

      The function to run for each

        • (element: T, index: number, array: T[]): Promise<K>
        • Parameters

          • element: T
          • index: number
          • array: T[]

          Returns Promise<K>

    Returns Promise<K[]>

Const asyncTimes

  • asyncTimes<T>(number: number, cb: (i: number) => Promise<T>): Promise<T[]>
  • Repeat the given function number times asyncronously

    Type parameters

    • T

    Parameters

    • number: number

      The number of times to itterate

    • cb: (i: number) => Promise<T>

      The function to run

        • (i: number): Promise<T>
        • Parameters

          • i: number

          Returns Promise<T>

    Returns Promise<T[]>

Const cacheFor

  • cacheFor<T>(__namedParameters: { duration: number; key: string }, generator: () => Promise<T>): Promise<T>
  • A crude caching system that will cache values for the given time.

    Type parameters

    • T

    Parameters

    • __namedParameters: { duration: number; key: string }
      • duration: number
      • key: string
    • generator: () => Promise<T>

      The promise function that returns the cached value.

        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

Const cacheForSync

  • cacheForSync<T>(__namedParameters: { duration: number; key: string }, generator: () => T): T
  • A crude caching system that will cache values for the given time.

    Type parameters

    • T

    Parameters

    • __namedParameters: { duration: number; key: string }
      • duration: number
      • key: string
    • generator: () => T

      The function that returns the cached value.

        • (): T
        • Returns T

    Returns T

Const chain

  • chain(...actions: ((v: number) => number)[]): (Anonymous function)
  • Parameters

    • Rest ...actions: ((v: number) => number)[]

    Returns (Anonymous function)

Const diffArray

  • diffArray<T>(original: T[], compare: T[]): { additional: T[]; missing: T[] }
  • Returns an object with 2 parameters. additional which is elements in compare that are not in original, and missing which are elements in original that are not in compare

    Type parameters

    • T

    Parameters

    • original: T[]

      The base array to compare against

    • compare: T[]

      The array to compare to

    Returns { additional: T[]; missing: T[] }

    • additional: T[]
    • missing: T[]

Const divideBy

  • divideBy(factor: number): (Anonymous function)

Const expireKey

  • expireKey(key: string): void

Const groupedBy

  • Takes an array of objects and returns an object with a property for each value in the key containing an array of all the objects that have that value.

    Type parameters

    • T: {}

    • K: keyof T

    Parameters

    • key: K

      The key to group by.

    • array: T[]

      The array of objects.

    Returns GroupedArray<T>

Const indexedBy

  • Returns an object indexed by the given field from the array of objects.

    Type parameters

    • T: {}

    • K: keyof T

    Parameters

    • key: K

      The key to index by.

    • array: T[]

      The array of Objects.

    • Optional options: Partial<IndexedByOptions>

      See IndexedByOptions

    Returns IndexedArray<T>

Const mapProperty

  • mapProperty<T, K>(array: T[], property: K): T[K][]
  • Takes an array of objects and returns an array of values from the given property

    Type parameters

    • T

    • K: keyof T

    Parameters

    • array: T[]

      The array of objects

    • property: K

      The property to extract

    Returns T[K][]

Const multiplyBy

  • multiplyBy(factor: number): (Anonymous function)

Const nl2br

  • nl2br(string: string): string
  • Adds
    for new lines in a string

    Parameters

    • string: string

      The multi line string to add
      tags to

    Returns string

Const parameterize

  • parameterize(slug: string): string
  • Takes a string and makes it safe for url slugs.

    For Example: My Article's title becomes my-articles-title

    Parameters

    • slug: string

      The string to parameterize

    Returns string

Const propIs

  • propIs<T, K>(items: T[], prop: K, value: T[K]): T[]
  • Find all entires in an array where prop equals value.

    Type parameters

    • T

    • K: keyof T

    Parameters

    • items: T[]

      The Items to filter

    • prop: K

      The property to filter

    • value: T[K]

      The value to check for

    Returns T[]

Const propIsNot

  • propIsNot<T, K>(items: T[], prop: K, value: T[K]): T[]
  • Find all entires in an array where prop does not equals value.

    Type parameters

    • T

    • K: keyof T

    Parameters

    • items: T[]

      The Items to filter

    • prop: K

      The property to filter

    • value: T[K]

      The value to check for

    Returns T[]

Const rangeAsArray

  • rangeAsArray(range: number[]): [][]
  • Returns an array of ranges

    e.g. [[1,3], [5,6], [10,15], [20,20]]

    Parameters

    • range: number[]

      An array of integers to describe

    Returns [][]

Const rangeAsString

  • rangeAsString(range: number[]): string[]
  • Returns an array of string describing the range.

    e.g. ['1-3','5,6','10-15','20']

    Parameters

    • range: number[]

      An array of integers to describe

    Returns string[]

Const times

  • times<T>(number: number, cb: (i: number) => T): T[]
  • Repeat the given function number times

    Type parameters

    • T

    Parameters

    • number: number

      The number of times to itterate

    • cb: (i: number) => T

      The function to run

        • (i: number): T
        • Parameters

          • i: number

          Returns T

    Returns T[]

Const valueOr

  • valueOr<T>(value: T | undefined, or: T): T
  • Returns the supplied value if it is not undefined otherwise it returns the or value.

    Type parameters

    • T

    Parameters

    • value: T | undefined

      The Value that could be undefined

    • or: T

      The fallback value

    Returns T

Const waitFor

  • Normalises a promise that errors into an awaitable [result, error] array.

    Type parameters

    • T

    Parameters

    • promise: Promise<T>

      The resolveable promise

    Returns Promise<WaitForResult<T>>

Object literals

Const defaultOptions

defaultOptions: object

collide

collide: false = false

Generated using TypeDoc