ts-fsrs 5.2.2 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.cjs +112 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +112 -193
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +112 -192
- package/dist/index.umd.js.map +1 -1
- package/package.json +25 -36
- package/README.md +0 -174
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-fsrs",
|
|
3
|
-
"
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "5.3.0",
|
|
4
5
|
"description": "ts-fsrs is a versatile package written in TypeScript that supports ES modules, CommonJS, and UMD. It implements the Free Spaced Repetition Scheduler (FSRS) algorithm, enabling developers to integrate FSRS into their flashcard applications to enhance the user learning experience.",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"main": "dist/index.cjs",
|
|
@@ -15,39 +16,17 @@
|
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"type": "module",
|
|
18
|
-
"scripts": {
|
|
19
|
-
"check": "biome check ./src ./__tests__",
|
|
20
|
-
"check::fix": "biome check --write ./src ./__tests__",
|
|
21
|
-
"dev": "rollup -c rollup.config.ts --configPlugin esbuild -w",
|
|
22
|
-
"test": "jest --config=jest.config.ts --passWithNoTests",
|
|
23
|
-
"test::coverage": "jest --config=jest.config.ts --coverage",
|
|
24
|
-
"test::publish": "yalc publish",
|
|
25
|
-
"prebuild": "rimraf ./dist",
|
|
26
|
-
"prepare": "rollup -c rollup.config.ts --configPlugin esbuild",
|
|
27
|
-
"build:types": "tsc --project ./tsconfig.json --declaration true",
|
|
28
|
-
"predocs": "rimraf ./docs",
|
|
29
|
-
"docs": "tsx ./typedoc.ts"
|
|
30
|
-
},
|
|
31
19
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@rollup/plugin-commonjs": "^28.0.6",
|
|
20
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
34
21
|
"@rollup/plugin-json": "^6.1.0",
|
|
35
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
36
|
-
"@types/jest": "^30.0.0",
|
|
37
|
-
"@types/node": "^24.0.7",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
38
23
|
"decimal.js": "^10.5.0",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"rollup": "^4.44.1",
|
|
42
|
-
"rollup-plugin-dts": "^6.2.1",
|
|
24
|
+
"rollup": "^4.54.0",
|
|
25
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
43
26
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
44
|
-
"ts-jest": "^29.4.0",
|
|
45
|
-
"ts-node": "^10.9.2",
|
|
46
27
|
"tslib": "^2.8.1",
|
|
47
|
-
"
|
|
48
|
-
"typedoc": "0.
|
|
49
|
-
"typedoc-plugin-extras": "4.0.0",
|
|
50
|
-
"typescript": "^5.8.3"
|
|
28
|
+
"typedoc": "0.28.12",
|
|
29
|
+
"typedoc-plugin-extras": "4.0.0"
|
|
51
30
|
},
|
|
52
31
|
"author": "ishiko",
|
|
53
32
|
"license": "MIT",
|
|
@@ -58,23 +37,33 @@
|
|
|
58
37
|
],
|
|
59
38
|
"files": [
|
|
60
39
|
"dist",
|
|
40
|
+
"CHANGELOG.md",
|
|
61
41
|
"README.md",
|
|
62
42
|
"LICENSE"
|
|
63
43
|
],
|
|
64
44
|
"repository": {
|
|
65
45
|
"type": "git",
|
|
66
|
-
"url": "git+https://github.com/open-spaced-repetition/ts-fsrs.git"
|
|
46
|
+
"url": "git+https://github.com/open-spaced-repetition/ts-fsrs.git",
|
|
47
|
+
"directory": "packages/fsrs"
|
|
67
48
|
},
|
|
68
49
|
"bugs": {
|
|
69
50
|
"url": "https://github.com/open-spaced-repetition/ts-fsrs/issues"
|
|
70
51
|
},
|
|
71
52
|
"homepage": "https://github.com/open-spaced-repetition/ts-fsrs#readme",
|
|
72
53
|
"engines": {
|
|
73
|
-
"node": ">=
|
|
54
|
+
"node": ">=20.0.0"
|
|
74
55
|
},
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
"scripts": {
|
|
57
|
+
"check": "biome check ./src",
|
|
58
|
+
"check:fix": "biome check --write ./src",
|
|
59
|
+
"dev": "rollup -c rollup.config.ts --configPlugin esbuild -w",
|
|
60
|
+
"test": "vitest run --config=vitest.config.ts --passWithNoTests",
|
|
61
|
+
"test:coverage": "vitest run --config=vitest.config.ts --passWithNoTests --coverage",
|
|
62
|
+
"test::publish": "yalc publish",
|
|
63
|
+
"prebuild": "rimraf ./dist",
|
|
64
|
+
"build": "rollup -c rollup.config.ts --configPlugin esbuild",
|
|
65
|
+
"build:types": "tsc --project ./tsconfig.json --declaration true",
|
|
66
|
+
"predocs": "rimraf ../../docs",
|
|
67
|
+
"docs": "tsx ./typedoc.ts"
|
|
79
68
|
}
|
|
80
|
-
}
|
|
69
|
+
}
|
package/README.md
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
[Introduction](./README.md) | [简体中文](./README_CN.md) |[はじめに](./README_JA.md)
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# About
|
|
6
|
-
[](https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-6)
|
|
7
|
-
[](https://www.npmjs.com/package/ts-fsrs)
|
|
8
|
-
[](https://www.npmjs.com/package/ts-fsrs)
|
|
9
|
-
[](https://codecov.io/gh/open-spaced-repetition/ts-fsrs)
|
|
11
|
-
[](https://github.com/open-spaced-repetition/ts-fsrs/actions/workflows/publish.yml)
|
|
13
|
-
[](https://github.com/open-spaced-repetition/ts-fsrs/actions/workflows/deploy.yml)
|
|
15
|
-
|
|
16
|
-
ts-fsrs is a versatile package written in TypeScript that supports [ES modules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), [CommonJS](https://en.wikipedia.org/wiki/CommonJS), and UMD. It implements the [Free Spaced Repetition Scheduler (FSRS) algorithm](https://github.com/open-spaced-repetition/free-spaced-repetition-scheduler), enabling developers to integrate FSRS into their flashcard applications to enhance the user learning experience.
|
|
17
|
-
|
|
18
|
-
You can find the state transition diagram for cards here:
|
|
19
|
-
> - google drive: [ts-fsrs-workflow.drawio](https://drive.google.com/file/d/1FLKjpt4T3Iis02vjoA10q7vxKCWwClfR/view?usp=sharing) (You're free to leave comments)
|
|
20
|
-
> - github: [ts-fsrs-workflow.drawio](./ts-fsrs-workflow.drawio)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Usage
|
|
24
|
-
`ts-fsrs@3.x` requires Node.js version `16.0.0` or higher. Starting with `ts-fsrs@4.x`, the minimum required Node.js version is `18.0.0`.
|
|
25
|
-
From version `3.5.6` onwards, ts-fsrs supports CommonJS, ESM, and UMD module systems.
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install ts-fsrs # npm install github:open-spaced-repetition/ts-fsrs
|
|
29
|
-
yarn add ts-fsrs
|
|
30
|
-
pnpm install ts-fsrs # pnpm install github:open-spaced-repetition/ts-fsrs
|
|
31
|
-
bun add ts-fsrs
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
# Example
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating, Grades} from 'ts-fsrs';
|
|
38
|
-
|
|
39
|
-
const params = generatorParameters({ enable_fuzz: true, enable_short_term: false });
|
|
40
|
-
const f = fsrs(params);
|
|
41
|
-
const card = createEmptyCard(new Date('2022-2-1 10:00:00'));// createEmptyCard();
|
|
42
|
-
const now = new Date('2022-2-2 10:00:00');// new Date();
|
|
43
|
-
const scheduling_cards = f.repeat(card, now);
|
|
44
|
-
|
|
45
|
-
for (const item of scheduling_cards) {
|
|
46
|
-
// grades = [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy]
|
|
47
|
-
const grade = item.log.rating
|
|
48
|
-
const { log, card } = item;
|
|
49
|
-
console.group(`${Rating[grade]}`);
|
|
50
|
-
console.table({
|
|
51
|
-
[`card_${Rating[grade]}`]: {
|
|
52
|
-
...card,
|
|
53
|
-
due: formatDate(card.due),
|
|
54
|
-
last_review: formatDate(card.last_review as Date),
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
console.table({
|
|
58
|
-
[`log_${Rating[grade]}`]: {
|
|
59
|
-
...log,
|
|
60
|
-
review: formatDate(log.review),
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
console.groupEnd();
|
|
64
|
-
console.log('----------------------------------------------------------------');
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
More resources:
|
|
69
|
-
- [Docs - Github Pages](https://open-spaced-repetition.github.io/ts-fsrs/)
|
|
70
|
-
- [Example.html - Github Pages](https://open-spaced-repetition.github.io/ts-fsrs/example)
|
|
71
|
-
- [Browser](https://github.com/open-spaced-repetition/ts-fsrs/blob/main/example/example.html) (ts-fsrs package using CDN)
|
|
72
|
-
- [ts-fsrs-demo - Next.js+Hono.js+kysely](https://github.com/ishiko732/ts-fsrs-demo)
|
|
73
|
-
- [spaced - Next.js+Drizzle+tRPC](https://github.com/zsh-eng/spaced)
|
|
74
|
-
|
|
75
|
-
# Basic Use
|
|
76
|
-
|
|
77
|
-
## 1. **Initialization**:
|
|
78
|
-
To begin, create an empty card instance and set the current date (default: current time from the system):
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { Card, createEmptyCard } from "ts-fsrs";
|
|
82
|
-
let card: Card = createEmptyCard();
|
|
83
|
-
// createEmptyCard(new Date('2022-2-1 10:00:00'));
|
|
84
|
-
// createEmptyCard(new Date(Date.UTC(2023, 9, 18, 14, 32, 3, 370)));
|
|
85
|
-
// createEmptyCard(new Date('2023-09-18T14:32:03.370Z'));
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## 2. **Parameter Configuration**:
|
|
89
|
-
The library has multiple modifiable "SRS parameters" (settings, besides the weight/parameter values). Use `generatorParameters` to set these parameters for the SRS algorithm. Here's an example for setting a maximum interval:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { Card, createEmptyCard, generatorParameters, FSRSParameters } from "ts-fsrs";
|
|
93
|
-
let card: Card = createEmptyCard();
|
|
94
|
-
const params: FSRSParameters = generatorParameters({ maximum_interval: 1000 });
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## 3. **Scheduling with FSRS**:
|
|
98
|
-
The core functionality lies in the `repeat` function of the `fsrs` class. When invoked, it returns a set of cards scheduled based on different potential user ratings:
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
import {
|
|
102
|
-
Card,
|
|
103
|
-
createEmptyCard,
|
|
104
|
-
generatorParameters,
|
|
105
|
-
FSRSParameters,
|
|
106
|
-
FSRS,
|
|
107
|
-
RecordLog,
|
|
108
|
-
} from "ts-fsrs";
|
|
109
|
-
|
|
110
|
-
let card: Card = createEmptyCard();
|
|
111
|
-
const f: FSRS = new FSRS(); // or const f: FSRS = fsrs(params);
|
|
112
|
-
let scheduling_cards: RecordLog = f.repeat(card, new Date());
|
|
113
|
-
// if you want to specify the grade, you can use the following code: (ts-fsrs >=4.0.0)
|
|
114
|
-
// let scheduling_card: RecordLog = f.next(card, new Date(), Rating.Good);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## 4. **Retrieving Scheduled Cards**:
|
|
118
|
-
Once you have the `scheduling_cards` object, you can retrieve cards based on user ratings. For instance, to access the card scheduled for a 'Good' rating:
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
const good: RecordLogItem = scheduling_cards[Rating.Good];
|
|
122
|
-
const newCard: Card = good.card;
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Get the new state of card for each rating:
|
|
126
|
-
```typescript
|
|
127
|
-
scheduling_cards[Rating.Again].card
|
|
128
|
-
scheduling_cards[Rating.Again].log
|
|
129
|
-
|
|
130
|
-
scheduling_cards[Rating.Hard].card
|
|
131
|
-
scheduling_cards[Rating.Hard].log
|
|
132
|
-
|
|
133
|
-
scheduling_cards[Rating.Good].card
|
|
134
|
-
scheduling_cards[Rating.Good].log
|
|
135
|
-
|
|
136
|
-
scheduling_cards[Rating.Easy].card
|
|
137
|
-
scheduling_cards[Rating.Easy].log
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## 5. **Understanding Card Attributes**:
|
|
141
|
-
Each `Card` object consists of various attributes that determine its status, scheduling, and other metrics:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
type Card = {
|
|
145
|
-
due: Date; // Date when the card is next due for review
|
|
146
|
-
stability: number; // A measure of how well the information is retained
|
|
147
|
-
difficulty: number; // Reflects the inherent difficulty of the card content
|
|
148
|
-
elapsed_days: number; // Days since the card was last reviewed
|
|
149
|
-
scheduled_days: number;// The interval of time in days between this review and the next one
|
|
150
|
-
learning_steps: number;// Keeps track of the current step during the (re)learning stages
|
|
151
|
-
reps: number; // Total number of times the card has been reviewed
|
|
152
|
-
lapses: number; // Times the card was forgotten or remembered incorrectly
|
|
153
|
-
state: State; // The current state of the card (New, Learning, Review, Relearning)
|
|
154
|
-
last_review?: Date; // The most recent review date, if applicable
|
|
155
|
-
};
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## 6. **Understanding Log Attributes**:
|
|
159
|
-
Each `ReviewLog` object contains various attributes that represent a review that was done on a card. Used for analysis, undoing the review, and [optimization (WIP)](https://github.com/open-spaced-repetition/fsrs-rs-nodejs).
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
type ReviewLog = {
|
|
163
|
-
rating: Rating; // Rating of the review (Again, Hard, Good, Easy)
|
|
164
|
-
state: State; // State of the review (New, Learning, Review, Relearning)
|
|
165
|
-
due: Date; // Date of the last scheduling
|
|
166
|
-
stability: number; // Stability of the card before the review
|
|
167
|
-
difficulty: number; // Difficulty of the card before the review
|
|
168
|
-
elapsed_days: number; // Number of days elapsed since the last review
|
|
169
|
-
last_elapsed_days: number; // Number of days between the last two reviews
|
|
170
|
-
scheduled_days: number; // Number of days until the next review
|
|
171
|
-
learning_steps: number; // Keeps track of the current step during the (re)learning stages
|
|
172
|
-
review: Date; // Date of the review
|
|
173
|
-
}
|
|
174
|
-
```
|