An implementation of the SM-2 algorithm written in TypeScript.
$ npm install @dtjv/sm-2// example.js
const { sm2, SuperMemoQuality, SuperMemoItemDefaults } = require('@dtjv/sm-2')// example.mjs
import SM2 from '@dtjv/sm-2'
const { sm2, SuperMemoQuality, SuperMemoItemDefaults } = SM2// example.ts
import { sm2, SuperMemoQuality, SuperMemoItemDefaults } from '@dtjv/sm-2'
import type { SuperMemoItem } from '@dtjv/sm-2'For more examples, see test file.
// example.ts
import { sm2, SuperMemoQuality, SuperMemoItemDefaults } from '@dtjv/sm-2'
import type { SuperMemoItem } from '@dtjv/sm-2'
interface Card extends SuperMemoItem {
term: string
definition: string
}
const card: Card = {
term: '🍩',
definition: '😋😋😋',
...SuperMemoItemDefaults, // adds read-only default values
}
const newCard = sm2<Card>(card, SuperMemoQuality.PASS_WITH_PERFECT_RECALL)
console.log(newCard)
/*
* expect `newCard` to be:
*
* {
* term: '🍩',
* definition: '😋😋😋',
* rep: 1,
* repInterval: 1,
* easyFactor: 2.6,
* }
*/interface SuperMemoItem {
readonly rep: number
readonly repInterval: number
readonly easyFactor: number
}enum SuperMemoQuality {
FAIL_WITH_TOTAL_BLACKOUT,
FAIL_BUT_FAMILIAR,
FAIL_BUT_EASY,
PASS_WITH_DIFFICULTY,
PASS_WITH_HESITATION,
PASS_WITH_PERFECT_RECALL,
}Returns a new item with updated SM-2 fields. Throws an error for invalid
parameters.
Type: SuperMemoItem
Required
The item to compute new SM-2 values.
Type: SuperMemoQuality
Required
The quality grade used to compute new SM-2 values.