smart-score-queue
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

Smart Queue Lib - Typescript

How to import

  import { LinearBased, ScoreBased } from 'smart-score-queue'

Example test data for reference

export const TestObj: ScoreData[] = [
  {
    name: 'Flaschard 1',
    description: 'Hola como no',
  },
  {
    name: 'Flaschard 2',
    description: 'Hola como no',

  },
  {
    name: 'Flaschard 3',
    description: 'Hola como no',

  },
  ...

LinearBased

new LinearBased(TestObj, 10, 0) Create a new LinearBased instance witht the array of data, amount of records and offset

  const linearBased = new LinearBased(TestObj, 10, 0);

.getNext() => ScoreData Gets the next object in the queue initiated by new LinearBased(...)

  let nextObj = linearBased.getNext();

.score(id, 4) Sets the score to a given record id (id: string, score: number)

  let nextObj = linearBased.getNext();
  linearBased.score(nextObj.id, 4);

.getCurrentSession() => ScoreData[] Gets the current session of the queue with all the elements limited by the amount provided in the constructor

  linearBased.getCurrentSession();

.save() => ScoreData[] will merge the array objects with the modified values in the current section

  linearBased.save()

ScoreBased

new ScoreBased(TestObj, 10) Create a new ScoreBased instance witht the array of data, amount of records

  const scoreBased = new ScoreBased(TestObj, 10, 0);

.getNext() => ScoreData Gets the next object in the queue initiated by new ScoreBased(...)

  let nextObj = scoreBased.getNext();

.score(id, 4) Sets the score to a given record id (id: string, score: number)

  let nextObj = scoreBased.getNext();
  scoreBased.score(nextObj.id, 4);

.getCurrentSession() => ScoreData[] Gets the current session of the queue with all the elements limited by the amount provided in the constructor

  scoreBased.getCurrentSession();

.save() => ScoreData[] will merge the array objects with the modified values in the current section

  scoreBased.save()

ScoreData - Type

  interface ScoreData {
    score?: number;
    order?: number;
    id?: string;
    lastFetched?: Date;
    lastScored?: Date;
    duplicatedObj?: boolean
    duplicatedObjId?: string
    [x: string | number | symbol]: unknown;
  }

Readme

Keywords

none

Package Sidebar

Install

npm i smart-score-queue

Weekly Downloads

1

Version

0.1.4

License

ISC

Unpacked Size

195 kB

Total Files

35

Last publish

Collaborators

  • juanjoslopezv