Options
All
  • Public
  • Public/Protected
  • All
Menu

@tomiocodes/sled

Index

Type aliases

GenericType

GenericType: string | number | Record<string, unknown> | never

Properties

default

default: { all: () => (Record<string, string | number | Record<string, unknown>> | never)[]; array: () => GenericType[]; clear: () => void; every: <T>(predicate: (value: GenericType, index: number, array: GenericType[]) => value is T, thisArg?: any) => boolean; filter: <T>(predicate: (value: T, index: number, array: T[]) => value is T, thisArg?: any) => T[]; first: () => GenericType; forEach: (callbackFn: (value: GenericType, index: number, array: GenericType[]) => void, thisArg?: any) => void; get: (key: string) => GenericType | undefined; getBuffer: (key: string) => Buffer | undefined; has: (key: string) => boolean; hasAll: (...keys: string[]) => boolean; hasAny: (...keys: string[]) => boolean; keyArray: () => (string | never)[]; map: <T>(callbackFn: (value: GenericType, index: number, array: GenericType[]) => T, thisArg?: any) => T[]; reduce: (callbackFn: (previousValue: GenericType, currentValue: GenericType, currentIndex: number, array: GenericType[]) => GenericType, initialValue?: GenericType) => GenericType; remove: (key: string) => boolean; set: (key: string, value: string | number | Record<string, unknown>) => string; setBuffer: (key: string, value: Buffer) => void; size: number; some: (predicate: (value: GenericType, index: number, array: GenericType[]) => unknown, thisArg?: any) => boolean; sort: (compareFn?: (a: GenericType, b: GenericType) => number) => GenericType[] }

Type declaration

  • all: () => (Record<string, string | number | Record<string, unknown>> | never)[]
      • (): (Record<string, string | number | Record<string, unknown>> | never)[]
      • Gets all of the key-value pairs in the database.

        Returns (Record<string, string | number | Record<string, unknown>> | never)[]

        An array of objects or an empty arr if the database is empty.

  • array: () => GenericType[]
  • clear: () => void
      • (): void
      • Removes all elements from the database.

        Returns void

  • every: <T>(predicate: (value: GenericType, index: number, array: GenericType[]) => value is T, thisArg?: any) => boolean
      • <T>(predicate: (value: GenericType, index: number, array: GenericType[]) => value is T, thisArg?: any): boolean
      • Determines whether all the members of an array satisfy the specified test.

        Type parameters

        Parameters

        • predicate: (value: GenericType, index: number, array: GenericType[]) => value is T

          A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

        • Optional thisArg: any

          An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

        Returns boolean

        If the array has every value.

  • filter: <T>(predicate: (value: T, index: number, array: T[]) => value is T, thisArg?: any) => T[]
      • <T>(predicate: (value: T, index: number, array: T[]) => value is T, thisArg?: any): T[]
      • Returns the elements of an array that meet the condition specified in a callback function.

        Type parameters

        Parameters

        • predicate: (value: T, index: number, array: T[]) => value is T

          A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

            • (value: T, index: number, array: T[]): value is T
            • Parameters

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

              Returns value is T

        • Optional thisArg: any

          An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

        Returns T[]

        The filtered items.

  • first: () => GenericType
  • forEach: (callbackFn: (value: GenericType, index: number, array: GenericType[]) => void, thisArg?: any) => void
      • Performs the specified action for each element in an array.

        Parameters

        • callbackFn: (value: GenericType, index: number, array: GenericType[]) => void

          A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

        • Optional thisArg: any

          An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

        Returns void

  • get: (key: string) => GenericType | undefined
      • Gets an element with the specified key, and returns its value, or undefined if the key does not exist.

        Parameters

        • key: string

          The key to get from the database.

        Returns GenericType | undefined

        The value.

  • getBuffer: (key: string) => Buffer | undefined
      • (key: string): Buffer | undefined
      • Gets an element with the specified key, and returns a buffer, or undefined if the key does not exist.

        Parameters

        • key: string

          The key to get from the database.

        Returns Buffer | undefined

        The buffer.

  • has: (key: string) => boolean
      • (key: string): boolean
      • Checks if an element exists in the database.

        Parameters

        • key: string

          The key of the element to check for.

        Returns boolean

        true if the element exists, false if it does not exist.

  • hasAll: (...keys: string[]) => boolean
      • (...keys: string[]): boolean
      • Checks if all of the elements exist in the database.

        Parameters

        • Rest ...keys: string[]

          The keys of the elements to check for.

        Returns boolean

        true if all of the elements exist, false if at least one does not exist.

  • hasAny: (...keys: string[]) => boolean
      • (...keys: string[]): boolean
      • Checks if any of the elements exist in the database.

        Parameters

        • Rest ...keys: string[]

          The keys of the elements to check for.

        Returns boolean

        true if any of the elements exist, false if none exist.

  • keyArray: () => (string | never)[]
      • (): (string | never)[]
      • Returns an array of the database keys.

        Returns (string | never)[]

        The database keys.

  • map: <T>(callbackFn: (value: GenericType, index: number, array: GenericType[]) => T, thisArg?: any) => T[]
      • Calls a defined callback function on each element of an array, and returns an array that contains the results.

        Type parameters

        • T

        Parameters

        • callbackFn: (value: GenericType, index: number, array: GenericType[]) => T

          A function that accepts up to three arguments. The map method calls the callbackFn function one time for each element in the array.

        • Optional thisArg: any

          An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

        Returns T[]

        The new array.

  • reduce: (callbackFn: (previousValue: GenericType, currentValue: GenericType, currentIndex: number, array: GenericType[]) => GenericType, initialValue?: GenericType) => GenericType
      • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

        Parameters

        • callbackFn: (previousValue: GenericType, currentValue: GenericType, currentIndex: number, array: GenericType[]) => GenericType

          A function that accepts up to four arguments. The reduce method calls the callbackFn function one time for each element in the array.

        • Optional initialValue: GenericType

          If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

        Returns GenericType

        The reduced array.

  • remove: (key: string) => boolean
      • (key: string): boolean
      • Removes an element from the database.

        Parameters

        • key: string

          The key to remove from the database.

        Returns boolean

        true if the element was removed, false if the element does not exist.

  • set: (key: string, value: string | number | Record<string, unknown>) => string
      • (key: string, value: string | number | Record<string, unknown>): string
      • Sets a new element in the database with the specified key and value.

        Parameters

        • key: string

          The key of the element to add.

        • value: string | number | Record<string, unknown>

          The value of the element to add.

        Returns string

        The value.

  • setBuffer: (key: string, value: Buffer) => void
      • (key: string, value: Buffer): void
      • Sets a buffer.

        Parameters

        • key: string

          The key of the element to add.

        • value: Buffer

          The value of the element to add.

        Returns void

  • size: number
  • some: (predicate: (value: GenericType, index: number, array: GenericType[]) => unknown, thisArg?: any) => boolean
      • Determines whether the specified callback function returns true for any element of an array.

        Parameters

        • predicate: (value: GenericType, index: number, array: GenericType[]) => unknown

          A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

        • Optional thisArg: any

          An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

        Returns boolean

        If the array has at least a value.

  • sort: (compareFn?: (a: GenericType, b: GenericType) => number) => GenericType[]
      • Sorts an array in place. This method mutates the array and returns a reference to the same array.

        Parameters

        • Optional compareFn: (a: GenericType, b: GenericType) => number

          Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.

        Returns GenericType[]

        The sorted array.

Variables

Const size

size: number = ...

The size of key-value pairs in the database.

Functions

all

  • all(): (Record<string, string | number | Record<string, unknown>> | never)[]
  • Gets all of the key-value pairs in the database.

    Returns (Record<string, string | number | Record<string, unknown>> | never)[]

    An array of objects or an empty arr if the database is empty.

array

  • Returns an array of the database values.

    Returns GenericType[]

    The database values.

clear

  • clear(): void
  • Removes all elements from the database.

    Returns void

every

  • every<T>(predicate: (value: GenericType, index: number, array: GenericType[]) => value is T, thisArg?: any): boolean
  • Determines whether all the members of an array satisfy the specified test.

    Type parameters

    Parameters

    • predicate: (value: GenericType, index: number, array: GenericType[]) => value is T

      A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

    • Optional thisArg: any

      An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

    Returns boolean

    If the array has every value.

filter

  • filter<T>(predicate: (value: T, index: number, array: T[]) => value is T, thisArg?: any): T[]
  • Returns the elements of an array that meet the condition specified in a callback function.

    Type parameters

    Parameters

    • predicate: (value: T, index: number, array: T[]) => value is T

      A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

        • (value: T, index: number, array: T[]): value is T
        • Parameters

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

          Returns value is T

    • Optional thisArg: any

      An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

    Returns T[]

    The filtered items.

first

  • Gets the first value in the database.

    Returns GenericType

    The first value.

forEach

  • Performs the specified action for each element in an array.

    Parameters

    • callbackFn: (value: GenericType, index: number, array: GenericType[]) => void

      A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns void

get

  • Gets an element with the specified key, and returns its value, or undefined if the key does not exist.

    Parameters

    • key: string

      The key to get from the database.

    Returns GenericType | undefined

    The value.

getBuffer

  • getBuffer(key: string): Buffer | undefined
  • Gets an element with the specified key, and returns a buffer, or undefined if the key does not exist.

    Parameters

    • key: string

      The key to get from the database.

    Returns Buffer | undefined

    The buffer.

has

  • has(key: string): boolean
  • Checks if an element exists in the database.

    Parameters

    • key: string

      The key of the element to check for.

    Returns boolean

    true if the element exists, false if it does not exist.

hasAll

  • hasAll(...keys: string[]): boolean
  • Checks if all of the elements exist in the database.

    Parameters

    • Rest ...keys: string[]

      The keys of the elements to check for.

    Returns boolean

    true if all of the elements exist, false if at least one does not exist.

hasAny

  • hasAny(...keys: string[]): boolean
  • Checks if any of the elements exist in the database.

    Parameters

    • Rest ...keys: string[]

      The keys of the elements to check for.

    Returns boolean

    true if any of the elements exist, false if none exist.

keyArray

  • keyArray(): (string | never)[]
  • Returns an array of the database keys.

    Returns (string | never)[]

    The database keys.

last

  • Gets the last value in the database.

    Returns GenericType

    The last value.

map

  • Calls a defined callback function on each element of an array, and returns an array that contains the results.

    Type parameters

    • T

    Parameters

    • callbackFn: (value: GenericType, index: number, array: GenericType[]) => T

      A function that accepts up to three arguments. The map method calls the callbackFn function one time for each element in the array.

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns T[]

    The new array.

random

  • Returns a random value in the database.

    Returns GenericType

    The random value.

reduce

  • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • callbackFn: (previousValue: GenericType, currentValue: GenericType, currentIndex: number, array: GenericType[]) => GenericType

      A function that accepts up to four arguments. The reduce method calls the callbackFn function one time for each element in the array.

    • Optional initialValue: GenericType

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

    Returns GenericType

    The reduced array.

remove

  • remove(key: string): boolean
  • Removes an element from the database.

    Parameters

    • key: string

      The key to remove from the database.

    Returns boolean

    true if the element was removed, false if the element does not exist.

set

  • set(key: string, value: string | number | Record<string, unknown>): string
  • Sets a new element in the database with the specified key and value.

    Parameters

    • key: string

      The key of the element to add.

    • value: string | number | Record<string, unknown>

      The value of the element to add.

    Returns string

    The value.

setBuffer

  • setBuffer(key: string, value: Buffer): void
  • Sets a buffer.

    Parameters

    • key: string

      The key of the element to add.

    • value: Buffer

      The value of the element to add.

    Returns void

some

  • some(predicate: (value: GenericType, index: number, array: GenericType[]) => unknown, thisArg?: any): boolean
  • Determines whether the specified callback function returns true for any element of an array.

    Parameters

    • predicate: (value: GenericType, index: number, array: GenericType[]) => unknown

      A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

    • Optional thisArg: any

      An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

    Returns boolean

    If the array has at least a value.

sort

  • Sorts an array in place. This method mutates the array and returns a reference to the same array.

    Parameters

    • Optional compareFn: (a: GenericType, b: GenericType) => number

      Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.

    Returns GenericType[]

    The sorted array.

Generated using TypeDoc