New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

spacerepetition

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spacerepetition

Spaced Repetition Library

latest
Source
npmnpm
Version
0.0.45
Version published
Maintainers
1
Created
Source

Space Repetition

A Spaced Repetition Library

NPM Version NPM Install Size

space spaced repetition logo

Install + Import

$ npm install spacerepetition

And import it

import SpaceRepetition from 'spacerepetition';

It doesn't matter what your data looks like, it will always return an array of flashcards:

const deck = new SpaceRepetition([{ 
    question: "What types does Space Repetition accept?", 
    answer: "Any type of data" 
}]);

Or you can include it from a CDN:

<script src="https://cdn.jsdelivr.net/npm/spacerepetition@0.0/dist/spacerepetition.min.js"></script>

And use it:

<script>
    const deck = new Spacerepetition();
</script>

Usage

A deck contains multiple cards (in this case a single card):

const deck = new Deck(1);

Here is what it contains:

/* 
Deck {
  cards: [
    Card {
      interval: 1,
      repetition: 0,
      easeFactor: 2.7,
      minEaseFactor: 1.3,
      dueDate: 1734034389755,
      value: 1,
      learningAlgorithm: 'default'
    }
  ]
}
*/

You can get the next card to study by calling getNextCard which finds a random card that is due:

const currentCard = deck.getNextCard();

On the card you can call the following convenience methods after you've studied it:

currentCard.again() // 0
currentCard.hard()  // 1
currentCard.good()  // 2
currentCard.easy()  // 3
currentCard.updateDifficulty(3) // easy

The corresponding values are in comments next to the methods.

Spaced Repetition Algorithms

There is support for SM-2 and a custom-made algorithm called fenestral-lacuna..

new SpaceRepetition([], 'sm-2');
new SpaceRepetition([], 'fenestral-lacuna');

Here is an overview:

AlgorithmAcceptable ValuesPurposeExplanation
SM-2sm-2, default and moreThe default algorithmImplements the SM-2 algorithm, designed for long-term spaced repetition.
Fenestral-Lacunafenestral-lacunaFor short study sessionsAdds few minutes to the next review time based on difficulty, prioritizing speed over retention.

Furthermore, you could also pass your own algorithm like below. Both parameters are optional:

function myAlgorithm(card, difficulty) {
    return "use the card parameter to update the state of the card";
}

new SpaceRepetition([], myAlgorithm);

Utility Functions

If you don't want to work with the Deck class, the library also provides some utility functions:

import { createFlashcards, getNextCard, createUI } from 'spacerepetition'
Function NameDescription
createFlashcardsCreates a single Card.
getNextCardRetrieves the next card to review.
createUICreates a HTML UI for flashcard reviews

Config

Besides manually adjusting values on the cards, you can also pass a config object as the third parameter to initialize cards with different values:

const config = {
    interval: 7
};

const flashcards = new SpaceRepetition([], "default", config);

Here is what the config object looks like:

KeyDefault ValueTarget Algorithm
easeFactor2.7SM-2
minEaseFactor1.3SM-2
interval1SM-2
repetition0SM-2

UI

You can use the built-in UI for HTML. You can style the front and back property with text or any HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Space Repetition</title>
    <script src="https://cdn.jsdelivr.net/npm/spacerepetition@0.0/dist/spacerepetition.min.js"></script>
</head>
<body>
    
    <script>
        const cards = [
            {   
                front: "<h1 style='color: red'>Front 1</h1>", 
                back: `<div>
                            <p style='color: blue;'>Space Repetition</p>
                            <img src='https://raw.githubusercontent.com/anderslatif/SpaceRepetition/main/assets/spacerepetitionlogo.png'>
                       </div>` 
            },
            {   front: "Front 2", back: "Back 2" }
        ];

        SpaceRepetition.createUI(cards);
    </script>
</body>
</html>

The end result will look like this:

space spaced repetition logo

Keywords

spaced

FAQs

Package last updated on 13 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts