@frecency/core
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Overview

Installation

npm i --save @frecency/core
npm i --save @frecency/indexeddb-datasource # if you need persistence

Usage

import createVisit from "@frecency/core";

const halflife = 7 * 24 * 60 * 60 * 1000; // 7 days
const visit = createVisit(halflife);

const visita = visit();
const visitb = visit(visita);
// ...
//
// Very often you are not going to want keep the scores in memory, you may want
// to persist them so that they can be recalled later between pages, app
// launches, etc.
//
// For those working in the browser, we provide a datasource that can persist
// and recall scores from IndexedDB.
//

import { initDB } from "@frecency/indexeddb-datasource";

const datasource = initDB("unique-identitier-used-as-name-of-database");

await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "acme");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "acme");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");

// Results are returned ordered by their score
const list = await datasource.list("namespace.selector");
console.table({ list });

/@frecency/core/

    Package Sidebar

    Install

    npm i @frecency/core

    Weekly Downloads

    231

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    4.97 kB

    Total Files

    7

    Last publish

    Collaborators

    • jamesdphillips