ts-fsrs 2.0.3 → 2.2.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/LICENSE +21 -21
- package/README.md +55 -46
- package/dist/default.d.ts +20 -0
- package/dist/default.js +67 -0
- package/{lib → dist}/fsrs.d.ts +5 -4
- package/dist/fsrs.js +206 -0
- package/{lib → dist}/help.d.ts +3 -8
- package/dist/help.js +94 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +27 -0
- package/{lib → dist}/models.d.ts +0 -12
- package/{lib → dist}/models.js +1 -7
- package/{lib → dist}/scheduler.d.ts +1 -1
- package/{lib → dist}/scheduler.js +20 -11
- package/dist/type.d.ts +15 -0
- package/dist/type.js +2 -0
- package/package.json +55 -43
- package/lib/fsrs.js +0 -189
- package/lib/help.js +0 -70
- package/lib/index.d.ts +0 -25
- package/lib/index.js +0 -64
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 ishiko
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ishiko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
|
-
# About The
|
|
2
|
-
|
|
3
|
-
ts-fsrs is a TypeScript package used to implement the [Free Spaced Repetition Scheduler (FSRS) algorithm](https://github.com/open-spaced-repetition/free-spaced-repetition-scheduler). It helps
|
|
4
|
-
developers apply FSRS to their flashcard applications, there by improving the user learning experience.
|
|
5
|
-
|
|
6
|
-
# Usage
|
|
7
|
-
|
|
8
|
-
```
|
|
9
|
-
npm install ts-fsrs
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
# About The
|
|
2
|
+
|
|
3
|
+
ts-fsrs is a TypeScript package used to implement the [Free Spaced Repetition Scheduler (FSRS) algorithm](https://github.com/open-spaced-repetition/free-spaced-repetition-scheduler). It helps
|
|
4
|
+
developers apply FSRS to their flashcard applications, there by improving the user learning experience.
|
|
5
|
+
|
|
6
|
+
# Usage
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install ts-fsrs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
# Environment Variables
|
|
13
|
+
If you need to customize default parameters, you can modify the values using `.env`/`.env.local`/`.env.production`/`.env.development`.
|
|
14
|
+
|
|
15
|
+
Copy the [.env.local.example](./example/.env.local.example) file in this directory to .env.local (which will be ignored by Git):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cp .env.local.example .env.local
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
# Example
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating} from 'ts-fsrs';
|
|
25
|
+
|
|
26
|
+
const params = generatorParameters({ enable_fuzz: true });
|
|
27
|
+
const f = fsrs(params);
|
|
28
|
+
const card = createEmptyCard(new Date('2022-2-1 10:00:00'));// createEmptyCard();
|
|
29
|
+
const now = new Date('2022-2-2 10:00:00');// new Date();
|
|
30
|
+
const scheduling_cards = f.repeat(card, now);
|
|
31
|
+
|
|
32
|
+
// console.log(scheduling_cards);
|
|
33
|
+
Object.keys(Rating).filter(key => typeof Rating[key as any] === 'number').forEach(key => {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const { log, card } = scheduling_cards[Rating[key]];
|
|
36
|
+
console.group(`${key}`);
|
|
37
|
+
console.table({
|
|
38
|
+
[`card_${key}`]: {
|
|
39
|
+
...card,
|
|
40
|
+
due: formatDate(card.due),
|
|
41
|
+
last_review: formatDate(card.last_review),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
console.table({
|
|
45
|
+
[`log_${key}`]: {
|
|
46
|
+
...log,
|
|
47
|
+
review: formatDate(log.review),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
console.groupEnd();
|
|
51
|
+
console.log('----------------------------------------------------------------');
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
> More examples refer to the [Example](https://github.com/ishiko732/ts-fsrs/blob/master/example/index.ts)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Card, FSRSParameters, FSRS } from "./index";
|
|
2
|
+
import { EnvParams } from "./type";
|
|
3
|
+
export declare const envParams: EnvParams;
|
|
4
|
+
export declare const default_request_retention: number;
|
|
5
|
+
export declare const default_maximum_interval: number;
|
|
6
|
+
export declare const default_easy_bonus: number;
|
|
7
|
+
export declare const default_hard_factor: number;
|
|
8
|
+
export declare const default_w: number[];
|
|
9
|
+
export declare const default_enable_fuzz: boolean;
|
|
10
|
+
export declare const FSRSVersion: string;
|
|
11
|
+
export declare const generatorParameters: (props?: Partial<FSRSParameters>) => {
|
|
12
|
+
request_retention: number;
|
|
13
|
+
maximum_interval: number;
|
|
14
|
+
easy_bonus: number;
|
|
15
|
+
hard_factor: number;
|
|
16
|
+
w: number[];
|
|
17
|
+
enable_fuzz: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const createEmptyCard: (now?: Date) => Card;
|
|
20
|
+
export declare const fsrs: (params?: Partial<FSRSParameters>) => FSRS;
|
package/dist/default.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fsrs = exports.createEmptyCard = exports.generatorParameters = exports.FSRSVersion = exports.default_enable_fuzz = exports.default_w = exports.default_hard_factor = exports.default_easy_bonus = exports.default_maximum_interval = exports.default_request_retention = exports.envParams = void 0;
|
|
7
|
+
const index_1 = require("./index");
|
|
8
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
+
dotenv_1.default.config({ path: `./.env.local` });
|
|
10
|
+
dotenv_1.default.config({ path: `./.env.production` });
|
|
11
|
+
dotenv_1.default.config({ path: `./.env.` });
|
|
12
|
+
dotenv_1.default.config({ path: `./.env.development` });
|
|
13
|
+
exports.envParams = {
|
|
14
|
+
FSRS_REQUEST_RETENTION: Number(process.env.FSRS_REQUEST_RETENTION),
|
|
15
|
+
FSRS_MAXIMUM_INTERVAL: Number(process.env.FSRS_MAXIMUM_INTERVAL),
|
|
16
|
+
FSRS_EASY_BOUND: Number(process.env.FSRS_EASY_BOUND),
|
|
17
|
+
FSRS_HARD_FACTOR: Number(process.env.FSRS_HARD_FACTOR),
|
|
18
|
+
FSRS_W: process.env.FSRS_W
|
|
19
|
+
? JSON.parse(process.env.FSRS_W)
|
|
20
|
+
: undefined,
|
|
21
|
+
FSRS_ENABLE_FUZZ: Boolean(process.env.FSRS_ENABLE_FUZZ),
|
|
22
|
+
};
|
|
23
|
+
exports.default_request_retention = !isNaN(exports.envParams.FSRS_REQUEST_RETENTION)
|
|
24
|
+
? exports.envParams.FSRS_REQUEST_RETENTION
|
|
25
|
+
: 0.9;
|
|
26
|
+
exports.default_maximum_interval = !isNaN(exports.envParams.FSRS_MAXIMUM_INTERVAL)
|
|
27
|
+
? exports.envParams.FSRS_MAXIMUM_INTERVAL
|
|
28
|
+
: 36500;
|
|
29
|
+
exports.default_easy_bonus = !isNaN(exports.envParams.FSRS_EASY_BOUND)
|
|
30
|
+
? exports.envParams.FSRS_EASY_BOUND
|
|
31
|
+
: 1.3;
|
|
32
|
+
exports.default_hard_factor = !isNaN(exports.envParams.FSRS_HARD_FACTOR)
|
|
33
|
+
? exports.envParams.FSRS_HARD_FACTOR
|
|
34
|
+
: 1.2;
|
|
35
|
+
exports.default_w = exports.envParams.FSRS_W || [
|
|
36
|
+
1, 1, 5, -0.5, -0.5, 0.2, 1.4, -0.12, 0.8, 2, -0.2, 0.2, 1,
|
|
37
|
+
];
|
|
38
|
+
exports.default_enable_fuzz = exports.envParams.FSRS_ENABLE_FUZZ || false;
|
|
39
|
+
exports.FSRSVersion = "2.2.0";
|
|
40
|
+
const generatorParameters = (props) => {
|
|
41
|
+
return {
|
|
42
|
+
request_retention: props?.request_retention || exports.default_request_retention,
|
|
43
|
+
maximum_interval: props?.maximum_interval || exports.default_maximum_interval,
|
|
44
|
+
easy_bonus: props?.easy_bonus || exports.default_easy_bonus,
|
|
45
|
+
hard_factor: props?.hard_factor || exports.default_hard_factor,
|
|
46
|
+
w: props?.w || exports.default_w,
|
|
47
|
+
enable_fuzz: props?.enable_fuzz || exports.default_enable_fuzz,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.generatorParameters = generatorParameters;
|
|
51
|
+
const createEmptyCard = (now) => {
|
|
52
|
+
return {
|
|
53
|
+
due: now || new Date(),
|
|
54
|
+
stability: 0,
|
|
55
|
+
difficulty: 0,
|
|
56
|
+
elapsed_days: 0,
|
|
57
|
+
scheduled_days: 0,
|
|
58
|
+
reps: 0,
|
|
59
|
+
lapses: 0,
|
|
60
|
+
state: index_1.State.New,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.createEmptyCard = createEmptyCard;
|
|
64
|
+
const fsrs = (params) => {
|
|
65
|
+
return new index_1.FSRS(params || {});
|
|
66
|
+
};
|
|
67
|
+
exports.fsrs = fsrs;
|
package/{lib → dist}/fsrs.d.ts
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { SchedulingCard } from "./index";
|
|
2
|
+
import { FSRSParameters, Card, State, Rating } from "./models";
|
|
3
|
+
import type { int } from "./type";
|
|
4
|
+
export declare class FSRS {
|
|
4
5
|
private param;
|
|
5
6
|
private readonly intervalModifier;
|
|
6
7
|
private seed?;
|
|
7
|
-
constructor(param
|
|
8
|
+
constructor(param: Partial<FSRSParameters>);
|
|
8
9
|
repeat: (card: Card, now: Date) => {
|
|
9
10
|
0: {
|
|
10
11
|
card: Card;
|
package/dist/fsrs.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FSRS = void 0;
|
|
7
|
+
const seedrandom_1 = __importDefault(require("seedrandom"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const help_1 = require("./help");
|
|
10
|
+
const models_1 = require("./models");
|
|
11
|
+
class FSRS {
|
|
12
|
+
param;
|
|
13
|
+
intervalModifier;
|
|
14
|
+
seed;
|
|
15
|
+
constructor(param) {
|
|
16
|
+
this.param = (0, index_1.generatorParameters)(param);
|
|
17
|
+
this.intervalModifier =
|
|
18
|
+
Math.log(this.param.request_retention) / Math.log(0.9);
|
|
19
|
+
}
|
|
20
|
+
repeat = (card, now) => {
|
|
21
|
+
card = {
|
|
22
|
+
...card,
|
|
23
|
+
last_review: card.last_review ? (0, help_1.fixDate)(card.last_review) : undefined,
|
|
24
|
+
};
|
|
25
|
+
now = new Date((0, help_1.fixDate)(now));
|
|
26
|
+
card.elapsed_days =
|
|
27
|
+
card.state === models_1.State.New ? 0 : now.diff(card.last_review, "days"); //相距时间
|
|
28
|
+
card.last_review = now; // 上次复习时间
|
|
29
|
+
card.reps += 1;
|
|
30
|
+
const s = new index_1.SchedulingCard(card);
|
|
31
|
+
s.update_state(card.state);
|
|
32
|
+
this.seed = String(card.last_review.getTime()) + String(card.elapsed_days);
|
|
33
|
+
let easy_interval, good_interval, hard_interval;
|
|
34
|
+
switch (card.state) {
|
|
35
|
+
case models_1.State.New:
|
|
36
|
+
this.init_ds(s);
|
|
37
|
+
s.again.due = now.scheduler(1);
|
|
38
|
+
s.hard.due = now.scheduler(5);
|
|
39
|
+
s.good.due = now.scheduler(10);
|
|
40
|
+
easy_interval = this.next_interval(s.easy.stability * this.param.easy_bonus);
|
|
41
|
+
s.easy.scheduled_days = easy_interval;
|
|
42
|
+
s.easy.due = now.scheduler(easy_interval, true);
|
|
43
|
+
break;
|
|
44
|
+
case models_1.State.Learning:
|
|
45
|
+
case models_1.State.Relearning:
|
|
46
|
+
hard_interval = 0;
|
|
47
|
+
good_interval = this.next_interval(s.good.stability);
|
|
48
|
+
easy_interval = Math.max(this.next_interval(s.easy.stability * this.param.easy_bonus), good_interval + 1);
|
|
49
|
+
s.schedule(now, hard_interval, good_interval, easy_interval);
|
|
50
|
+
break;
|
|
51
|
+
case models_1.State.Review: {
|
|
52
|
+
const interval = card.elapsed_days;
|
|
53
|
+
const last_d = card.difficulty;
|
|
54
|
+
const last_s = card.stability;
|
|
55
|
+
const retrievability = this.current_retrievability(interval, last_s);
|
|
56
|
+
this.next_ds(s, last_d, last_s, retrievability);
|
|
57
|
+
hard_interval = this.next_interval(last_s * this.param.hard_factor);
|
|
58
|
+
good_interval = this.next_interval(s.good.stability);
|
|
59
|
+
hard_interval = Math.min(hard_interval, good_interval);
|
|
60
|
+
good_interval = Math.max(good_interval, hard_interval + 1);
|
|
61
|
+
easy_interval = Math.max(this.next_interval(s.easy.stability * this.param.easy_bonus), good_interval + 1);
|
|
62
|
+
s.schedule(now, hard_interval, good_interval, easy_interval);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return s.record_log(card, now);
|
|
67
|
+
};
|
|
68
|
+
get_retrievability = (card, now) => {
|
|
69
|
+
if (card.state !== models_1.State.Review) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const t = Math.max(now.diff(card.last_review, "days"), 0);
|
|
73
|
+
return ((this.current_retrievability(t, card.stability) * 100).toFixed(2) + "%");
|
|
74
|
+
};
|
|
75
|
+
init_ds(s) {
|
|
76
|
+
s.again.difficulty = this.init_difficulty(models_1.Rating.Again);
|
|
77
|
+
s.again.stability = this.init_stability(models_1.Rating.Again);
|
|
78
|
+
s.hard.difficulty = this.init_difficulty(models_1.Rating.Hard);
|
|
79
|
+
s.hard.stability = this.init_stability(models_1.Rating.Hard);
|
|
80
|
+
s.good.difficulty = this.init_difficulty(models_1.Rating.Good);
|
|
81
|
+
s.good.stability = this.init_stability(models_1.Rating.Good);
|
|
82
|
+
s.easy.difficulty = this.init_difficulty(models_1.Rating.Easy);
|
|
83
|
+
s.easy.stability = this.init_stability(models_1.Rating.Easy);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param s scheduling Card
|
|
88
|
+
* @param last_d Difficulty
|
|
89
|
+
* @param last_s Stability
|
|
90
|
+
* @param retrievability Retrievability
|
|
91
|
+
*/
|
|
92
|
+
next_ds(s, last_d, last_s, retrievability) {
|
|
93
|
+
s.again.difficulty = this.next_difficulty(last_d, models_1.Rating.Again);
|
|
94
|
+
s.again.stability = this.next_forget_stability(s.again.difficulty, last_s, retrievability);
|
|
95
|
+
s.hard.difficulty = this.next_difficulty(last_d, models_1.Rating.Hard);
|
|
96
|
+
s.hard.stability = this.next_recall_stability(s.hard.difficulty, last_s, retrievability);
|
|
97
|
+
s.good.difficulty = this.next_difficulty(last_d, models_1.Rating.Good);
|
|
98
|
+
s.good.stability = this.next_recall_stability(s.good.difficulty, last_s, retrievability);
|
|
99
|
+
s.easy.difficulty = this.next_difficulty(last_d, models_1.Rating.Easy);
|
|
100
|
+
s.easy.stability = this.next_recall_stability(s.easy.difficulty, last_s, retrievability);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The formula used is :
|
|
104
|
+
* $$S_0(G) = w_0 + G \cdot w_1$$
|
|
105
|
+
* $$\max \{S_0,0.1\}$$
|
|
106
|
+
* @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
|
|
107
|
+
* @return Stability (interval when R=90%)
|
|
108
|
+
*/
|
|
109
|
+
init_stability(g) {
|
|
110
|
+
return Math.max(this.param.w[0] + this.param.w[1] * g, 0.1);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The formula used is :
|
|
114
|
+
* $$D_0(G) = w_2 + (G-2) \cdot w_3$$
|
|
115
|
+
* $$\min \{\max \{D_0(G),1\},10\}$$
|
|
116
|
+
* @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
|
|
117
|
+
* @return Difficulty D \in [1,10]
|
|
118
|
+
*/
|
|
119
|
+
init_difficulty(g) {
|
|
120
|
+
return Math.min(Math.max(this.param.w[2] + this.param.w[3] * (g - 2), 1), 10);
|
|
121
|
+
}
|
|
122
|
+
apply_fuzz(ivl) {
|
|
123
|
+
if (!this.param.enable_fuzz || ivl < 2.5)
|
|
124
|
+
return ivl;
|
|
125
|
+
const generator = (0, seedrandom_1.default)(this.seed);
|
|
126
|
+
const fuzz_factor = generator();
|
|
127
|
+
ivl = Math.round(ivl);
|
|
128
|
+
const min_ivl = Math.max(2, Math.round(ivl * 0.95 - 1));
|
|
129
|
+
const max_ivl = Math.round(ivl * 1.05 + 1);
|
|
130
|
+
return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl);
|
|
131
|
+
}
|
|
132
|
+
next_interval(s) {
|
|
133
|
+
const newInterval = this.apply_fuzz(s * this.intervalModifier);
|
|
134
|
+
return Math.min(Math.max(Math.round(newInterval), 1), this.param.maximum_interval);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The formula used is :
|
|
138
|
+
* $$next_d = D + w_4 \cdot (R - 2)$$
|
|
139
|
+
* $$D^\prime(D,R) = w_5 \cdot D_0(2) +(1 - w_5) \cdot next_d$$
|
|
140
|
+
* @param d
|
|
141
|
+
* @param g Grade (Rating[0.again,1.hard,2.good,3.easy])
|
|
142
|
+
* @return next_D
|
|
143
|
+
*/
|
|
144
|
+
next_difficulty(d, g) {
|
|
145
|
+
const next_d = d + this.param.w[4] * (g - 2);
|
|
146
|
+
return this.constrain_difficulty(this.mean_reversion(this.param.w[2], next_d));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The formula used is :
|
|
150
|
+
* $$\min \{\max \{D_0,1\},10\}$$
|
|
151
|
+
*/
|
|
152
|
+
constrain_difficulty(difficulty) {
|
|
153
|
+
return Math.min(Math.max(Number(difficulty.toFixed(2)), 1), 10);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The formula used is :
|
|
157
|
+
* $$w_5 \cdot init +(1 - w_5) \cdot current$$
|
|
158
|
+
* @param init $$w_2 : D_0(2) = w_2 + (R-2) \cdot w_3= w_2$$
|
|
159
|
+
* @param current $$D + w_4 \cdot (R - 2)$$
|
|
160
|
+
* @return difficulty
|
|
161
|
+
*/
|
|
162
|
+
mean_reversion(init, current) {
|
|
163
|
+
return this.param.w[5] * init + (1 - this.param.w[5]) * current;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The formula used is :
|
|
167
|
+
* $$S^\prime_r(D,S,R) = S\cdot(e^{w_6}\cdot (11-D)\cdot S^{w_7}\cdot(e^{w_8\cdot(1-R)}-1)+1)$$
|
|
168
|
+
* @param d Difficulty D \in [1,10]
|
|
169
|
+
* @param s Stability (interval when R=90%)
|
|
170
|
+
* @param r Retrievability (probability of recall)
|
|
171
|
+
* @return S^\prime_r new stability after recall
|
|
172
|
+
*/
|
|
173
|
+
next_recall_stability(d, s, r) {
|
|
174
|
+
return (s *
|
|
175
|
+
(1 +
|
|
176
|
+
Math.exp(this.param.w[6]) *
|
|
177
|
+
(11 - d) *
|
|
178
|
+
Math.pow(s, this.param.w[7]) *
|
|
179
|
+
(Math.exp((1 - r) * this.param.w[8]) - 1)));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The formula used is :
|
|
183
|
+
* $$S^\prime_f(D,S,R) = w_9\cdot D^{w_{10}}\cdot S^{w_{11}}\cdot e^{w_{12}\cdot(1-R)}.$$
|
|
184
|
+
* @param d Difficulty D \in [1,10]
|
|
185
|
+
* @param s Stability (interval when R=90%)
|
|
186
|
+
* @param r Retrievability (probability of recall)
|
|
187
|
+
* @return S^\prime_f new stability after forgetting
|
|
188
|
+
*/
|
|
189
|
+
next_forget_stability(d, s, r) {
|
|
190
|
+
return (this.param.w[9] *
|
|
191
|
+
Math.pow(d, this.param.w[10]) *
|
|
192
|
+
Math.pow(s, this.param.w[11]) *
|
|
193
|
+
Math.exp((1 - r) * this.param.w[12]));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The formula used is :
|
|
197
|
+
* $$R(t,S) = 0.9^{\frac{t}{S}}$$
|
|
198
|
+
* @param t t days since the last review
|
|
199
|
+
* @param s Stability (interval when R=90%)
|
|
200
|
+
* @return r Retrievability (probability of recall)
|
|
201
|
+
*/
|
|
202
|
+
current_retrievability(t, s) {
|
|
203
|
+
return Math.exp((Math.log(0.9) * t) / s);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.FSRS = FSRS;
|
package/{lib → dist}/help.d.ts
RENAMED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type int = number & {
|
|
3
|
-
__int__: void;
|
|
4
|
-
};
|
|
5
|
-
export type double = number & {
|
|
6
|
-
__double__: void;
|
|
7
|
-
};
|
|
1
|
+
import type { int, unit } from "./type";
|
|
8
2
|
declare global {
|
|
9
3
|
export interface Date {
|
|
10
4
|
scheduler(t: int, isDay?: boolean): Date;
|
|
@@ -16,4 +10,5 @@ declare global {
|
|
|
16
10
|
export declare function date_scheduler(now: Date, t: number, isDay?: boolean): Date;
|
|
17
11
|
export declare function date_diff(now: Date, pre: Date, unit: unit): number;
|
|
18
12
|
export declare function formatDate(date: Date): string;
|
|
19
|
-
export declare function show_diff_message(due: Date, last_review: Date, unit?: boolean): string;
|
|
13
|
+
export declare function show_diff_message(due: Date, last_review: Date, unit?: boolean, timeUnit?: string[]): string;
|
|
14
|
+
export declare function fixDate(value: unknown): Date;
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixDate = exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = void 0;
|
|
4
|
+
Date.prototype.scheduler = function (t, isDay) {
|
|
5
|
+
return date_scheduler(this, t, isDay);
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 当前时间与之前的时间差值
|
|
9
|
+
* @param pre 比当前时间还要之前
|
|
10
|
+
* @param unit 单位: days | minutes
|
|
11
|
+
*/
|
|
12
|
+
Date.prototype.diff = function (pre, unit) {
|
|
13
|
+
return date_diff(this, pre, unit);
|
|
14
|
+
};
|
|
15
|
+
Date.prototype.format = function () {
|
|
16
|
+
return formatDate(this);
|
|
17
|
+
};
|
|
18
|
+
Date.prototype.dueFormat = function (last_review, unit) {
|
|
19
|
+
return show_diff_message(this, last_review, unit);
|
|
20
|
+
};
|
|
21
|
+
function date_scheduler(now, t, isDay) {
|
|
22
|
+
return new Date(isDay
|
|
23
|
+
? now.getTime() + t * 24 * 60 * 60 * 1000
|
|
24
|
+
: now.getTime() + t * 60 * 1000);
|
|
25
|
+
}
|
|
26
|
+
exports.date_scheduler = date_scheduler;
|
|
27
|
+
function date_diff(now, pre, unit) {
|
|
28
|
+
const diff = now.getTime() - pre.getTime();
|
|
29
|
+
let r = 0;
|
|
30
|
+
switch (unit) {
|
|
31
|
+
case "days":
|
|
32
|
+
r = Math.floor(diff / (24 * 60 * 60 * 1000));
|
|
33
|
+
break;
|
|
34
|
+
case "minutes":
|
|
35
|
+
r = Math.floor(diff / (60 * 1000));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
exports.date_diff = date_diff;
|
|
41
|
+
function formatDate(date) {
|
|
42
|
+
const year = date.getFullYear();
|
|
43
|
+
const month = date.getMonth() + 1;
|
|
44
|
+
const day = date.getDate();
|
|
45
|
+
const hours = date.getHours();
|
|
46
|
+
const minutes = date.getMinutes();
|
|
47
|
+
const seconds = date.getSeconds();
|
|
48
|
+
return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
|
|
49
|
+
}
|
|
50
|
+
exports.formatDate = formatDate;
|
|
51
|
+
function padZero(num) {
|
|
52
|
+
return num < 10 ? `0${num}` : `${num}`;
|
|
53
|
+
}
|
|
54
|
+
const TIMEUNIT = [60, 60, 24, 31, 12];
|
|
55
|
+
const TIMEUNITFORMAT = ["second", "min", "hour", "day", "month", "year"];
|
|
56
|
+
function show_diff_message(due, last_review, unit, timeUnit = TIMEUNITFORMAT) {
|
|
57
|
+
due = fixDate(due);
|
|
58
|
+
last_review = fixDate(last_review);
|
|
59
|
+
if (timeUnit.length !== TIMEUNITFORMAT.length) {
|
|
60
|
+
timeUnit = TIMEUNITFORMAT;
|
|
61
|
+
}
|
|
62
|
+
let diff = due.getTime() - last_review.getTime();
|
|
63
|
+
let i;
|
|
64
|
+
diff /= 1000;
|
|
65
|
+
for (i = 0; i < TIMEUNIT.length; i++) {
|
|
66
|
+
if (diff < TIMEUNIT[i]) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
diff /= TIMEUNIT[i];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return `${Math.floor(diff)}${unit ? timeUnit[i] : ""}`;
|
|
74
|
+
}
|
|
75
|
+
exports.show_diff_message = show_diff_message;
|
|
76
|
+
function fixDate(value) {
|
|
77
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
else if (typeof value === "string") {
|
|
81
|
+
const timestamp = Date.parse(value);
|
|
82
|
+
if (!isNaN(timestamp)) {
|
|
83
|
+
return new Date(timestamp);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error(`Invalid date:[${value}]`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (typeof value === "number") {
|
|
90
|
+
return new Date(value);
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`Invalid date:[${value}]`);
|
|
93
|
+
}
|
|
94
|
+
exports.fixDate = fixDate;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { SchedulingCard } from "./scheduler";
|
|
2
|
+
export { default_request_retention, default_maximum_interval, default_easy_bonus, default_hard_factor, default_w, default_enable_fuzz, FSRSVersion, generatorParameters, createEmptyCard, fsrs, envParams } from "./default";
|
|
3
|
+
export { date_scheduler, date_diff, formatDate, show_diff_message, } from "./help";
|
|
4
|
+
export type { int, double } from "./type";
|
|
5
|
+
export type { FSRSParameters, Card, ReviewLog, StateType, RatingType, } from "./models";
|
|
6
|
+
export { State, Rating } from "./models";
|
|
7
|
+
export { FSRS } from "./fsrs";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FSRS = exports.Rating = exports.State = exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = exports.envParams = exports.fsrs = exports.createEmptyCard = exports.generatorParameters = exports.FSRSVersion = exports.default_enable_fuzz = exports.default_w = exports.default_hard_factor = exports.default_easy_bonus = exports.default_maximum_interval = exports.default_request_retention = exports.SchedulingCard = void 0;
|
|
4
|
+
var scheduler_1 = require("./scheduler");
|
|
5
|
+
Object.defineProperty(exports, "SchedulingCard", { enumerable: true, get: function () { return scheduler_1.SchedulingCard; } });
|
|
6
|
+
var default_1 = require("./default");
|
|
7
|
+
Object.defineProperty(exports, "default_request_retention", { enumerable: true, get: function () { return default_1.default_request_retention; } });
|
|
8
|
+
Object.defineProperty(exports, "default_maximum_interval", { enumerable: true, get: function () { return default_1.default_maximum_interval; } });
|
|
9
|
+
Object.defineProperty(exports, "default_easy_bonus", { enumerable: true, get: function () { return default_1.default_easy_bonus; } });
|
|
10
|
+
Object.defineProperty(exports, "default_hard_factor", { enumerable: true, get: function () { return default_1.default_hard_factor; } });
|
|
11
|
+
Object.defineProperty(exports, "default_w", { enumerable: true, get: function () { return default_1.default_w; } });
|
|
12
|
+
Object.defineProperty(exports, "default_enable_fuzz", { enumerable: true, get: function () { return default_1.default_enable_fuzz; } });
|
|
13
|
+
Object.defineProperty(exports, "FSRSVersion", { enumerable: true, get: function () { return default_1.FSRSVersion; } });
|
|
14
|
+
Object.defineProperty(exports, "generatorParameters", { enumerable: true, get: function () { return default_1.generatorParameters; } });
|
|
15
|
+
Object.defineProperty(exports, "createEmptyCard", { enumerable: true, get: function () { return default_1.createEmptyCard; } });
|
|
16
|
+
Object.defineProperty(exports, "fsrs", { enumerable: true, get: function () { return default_1.fsrs; } });
|
|
17
|
+
Object.defineProperty(exports, "envParams", { enumerable: true, get: function () { return default_1.envParams; } });
|
|
18
|
+
var help_1 = require("./help");
|
|
19
|
+
Object.defineProperty(exports, "date_scheduler", { enumerable: true, get: function () { return help_1.date_scheduler; } });
|
|
20
|
+
Object.defineProperty(exports, "date_diff", { enumerable: true, get: function () { return help_1.date_diff; } });
|
|
21
|
+
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return help_1.formatDate; } });
|
|
22
|
+
Object.defineProperty(exports, "show_diff_message", { enumerable: true, get: function () { return help_1.show_diff_message; } });
|
|
23
|
+
var models_1 = require("./models");
|
|
24
|
+
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return models_1.State; } });
|
|
25
|
+
Object.defineProperty(exports, "Rating", { enumerable: true, get: function () { return models_1.Rating; } });
|
|
26
|
+
var fsrs_1 = require("./fsrs");
|
|
27
|
+
Object.defineProperty(exports, "FSRS", { enumerable: true, get: function () { return fsrs_1.FSRS; } });
|
package/{lib → dist}/models.d.ts
RENAMED
|
@@ -30,12 +30,6 @@ export interface Card {
|
|
|
30
30
|
state: State;
|
|
31
31
|
last_review?: Date;
|
|
32
32
|
}
|
|
33
|
-
export interface SchedulingLog {
|
|
34
|
-
[key: number]: {
|
|
35
|
-
card: Card;
|
|
36
|
-
log: ReviewLog;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
33
|
export interface FSRSParameters {
|
|
40
34
|
request_retention: number;
|
|
41
35
|
maximum_interval: number;
|
|
@@ -44,9 +38,3 @@ export interface FSRSParameters {
|
|
|
44
38
|
w: number[];
|
|
45
39
|
enable_fuzz: boolean;
|
|
46
40
|
}
|
|
47
|
-
export declare const default_request_retention = 0.9;
|
|
48
|
-
export declare const default_maximum_interval = 36500;
|
|
49
|
-
export declare const default_easy_bonus = 1.3;
|
|
50
|
-
export declare const default_hard_factor = 1.2;
|
|
51
|
-
export declare const default_w: number[];
|
|
52
|
-
export declare const default_enable_fuzz = false;
|
package/{lib → dist}/models.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Rating = exports.State = void 0;
|
|
4
4
|
var State;
|
|
5
5
|
(function (State) {
|
|
6
6
|
State[State["New"] = 0] = "New";
|
|
@@ -15,9 +15,3 @@ var Rating;
|
|
|
15
15
|
Rating[Rating["Good"] = 2] = "Good";
|
|
16
16
|
Rating[Rating["Easy"] = 3] = "Easy";
|
|
17
17
|
})(Rating || (exports.Rating = Rating = {}));
|
|
18
|
-
exports.default_request_retention = 0.9;
|
|
19
|
-
exports.default_maximum_interval = 36500;
|
|
20
|
-
exports.default_easy_bonus = 1.3;
|
|
21
|
-
exports.default_hard_factor = 1.2;
|
|
22
|
-
exports.default_w = [1, 1, 5, -0.5, -0.5, 0.2, 1.4, -0.12, 0.8, 2, -0.2, 0.2, 1];
|
|
23
|
-
exports.default_enable_fuzz = false;
|
|
@@ -4,8 +4,14 @@ exports.SchedulingCard = void 0;
|
|
|
4
4
|
const models_1 = require("./models");
|
|
5
5
|
const help_1 = require("./help");
|
|
6
6
|
class SchedulingCard {
|
|
7
|
+
again;
|
|
8
|
+
hard;
|
|
9
|
+
good;
|
|
10
|
+
easy;
|
|
7
11
|
copy(card) {
|
|
8
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
...card,
|
|
14
|
+
};
|
|
9
15
|
}
|
|
10
16
|
constructor(card) {
|
|
11
17
|
this.again = this.copy(card);
|
|
@@ -42,7 +48,10 @@ class SchedulingCard {
|
|
|
42
48
|
this.good.scheduled_days = good_interval;
|
|
43
49
|
this.easy.scheduled_days = easy_interval;
|
|
44
50
|
this.again.due = (0, help_1.date_scheduler)(now, 5);
|
|
45
|
-
this.hard.due =
|
|
51
|
+
this.hard.due =
|
|
52
|
+
hard_interval > 0
|
|
53
|
+
? (0, help_1.date_scheduler)(now, hard_interval, true)
|
|
54
|
+
: (0, help_1.date_scheduler)(now, 10);
|
|
46
55
|
this.good.due = (0, help_1.date_scheduler)(now, good_interval, true);
|
|
47
56
|
this.easy.due = (0, help_1.date_scheduler)(now, easy_interval, true);
|
|
48
57
|
return this;
|
|
@@ -56,8 +65,8 @@ class SchedulingCard {
|
|
|
56
65
|
state: card.state,
|
|
57
66
|
elapsed_days: this.again.scheduled_days,
|
|
58
67
|
scheduled_days: card.elapsed_days,
|
|
59
|
-
review: now
|
|
60
|
-
}
|
|
68
|
+
review: now,
|
|
69
|
+
},
|
|
61
70
|
},
|
|
62
71
|
[models_1.Rating.Hard]: {
|
|
63
72
|
card: this.hard,
|
|
@@ -66,8 +75,8 @@ class SchedulingCard {
|
|
|
66
75
|
state: card.state,
|
|
67
76
|
elapsed_days: this.hard.scheduled_days,
|
|
68
77
|
scheduled_days: card.elapsed_days,
|
|
69
|
-
review: now
|
|
70
|
-
}
|
|
78
|
+
review: now,
|
|
79
|
+
},
|
|
71
80
|
},
|
|
72
81
|
[models_1.Rating.Good]: {
|
|
73
82
|
card: this.good,
|
|
@@ -76,8 +85,8 @@ class SchedulingCard {
|
|
|
76
85
|
state: card.state,
|
|
77
86
|
elapsed_days: this.good.scheduled_days,
|
|
78
87
|
scheduled_days: card.elapsed_days,
|
|
79
|
-
review: now
|
|
80
|
-
}
|
|
88
|
+
review: now,
|
|
89
|
+
},
|
|
81
90
|
},
|
|
82
91
|
[models_1.Rating.Easy]: {
|
|
83
92
|
card: this.easy,
|
|
@@ -86,9 +95,9 @@ class SchedulingCard {
|
|
|
86
95
|
state: card.state,
|
|
87
96
|
elapsed_days: this.easy.scheduled_days,
|
|
88
97
|
scheduled_days: card.elapsed_days,
|
|
89
|
-
review: now
|
|
90
|
-
}
|
|
91
|
-
}
|
|
98
|
+
review: now,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
92
101
|
};
|
|
93
102
|
}
|
|
94
103
|
}
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type unit = "days" | "minutes";
|
|
2
|
+
export type int = number & {
|
|
3
|
+
__int__: void;
|
|
4
|
+
};
|
|
5
|
+
export type double = number & {
|
|
6
|
+
__double__: void;
|
|
7
|
+
};
|
|
8
|
+
export interface EnvParams {
|
|
9
|
+
FSRS_REQUEST_RETENTION: number;
|
|
10
|
+
FSRS_MAXIMUM_INTERVAL: number;
|
|
11
|
+
FSRS_EASY_BOUND: number;
|
|
12
|
+
FSRS_HARD_FACTOR: number;
|
|
13
|
+
FSRS_W?: number[];
|
|
14
|
+
FSRS_ENABLE_FUZZ?: boolean;
|
|
15
|
+
}
|
package/dist/type.js
ADDED
package/package.json
CHANGED
|
@@ -1,43 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ts-fsrs",
|
|
3
|
-
"version": "2.0
|
|
4
|
-
"description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
7
|
-
"keywords": [
|
|
8
|
-
"SuperMemo",
|
|
9
|
-
"Anki",
|
|
10
|
-
"FSRS"
|
|
11
|
-
],
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-fsrs",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"SuperMemo",
|
|
9
|
+
"Anki",
|
|
10
|
+
"FSRS"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"dotenv": "^16.3.1",
|
|
14
|
+
"seedrandom": "^3.0.5"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jest": "^29.5.5",
|
|
18
|
+
"@types/node": "^20.6.2",
|
|
19
|
+
"@types/seedrandom": "^3.0.5",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
21
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
22
|
+
"eslint": "^8.44.0",
|
|
23
|
+
"eslint-config-prettier": "^9.0.0",
|
|
24
|
+
"jest": "^29.7.0",
|
|
25
|
+
"prettier": "^3.0.3",
|
|
26
|
+
"ts-jest": "^29.1.1",
|
|
27
|
+
"ts-node": "^10.9.1",
|
|
28
|
+
"typescript": "^5.1.6"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"lint": "eslint --fix src/ && prettier --write src/",
|
|
32
|
+
"dev": "ts-node src/fsrs/index.ts",
|
|
33
|
+
"test": "jest --passWithNoTests",
|
|
34
|
+
"build": "tsc --project ./tsconfig.json",
|
|
35
|
+
"major": "npm version major",
|
|
36
|
+
"minor": "npm version minor",
|
|
37
|
+
"patch": "npm version patch",
|
|
38
|
+
"test_publish": "yalc publish"
|
|
39
|
+
},
|
|
40
|
+
"author": "ishiko",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/**/*",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/ishiko732/ts-fsrs.git"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/ishiko732/ts-fsrs/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/ishiko732/ts-fsrs#readme"
|
|
55
|
+
}
|
package/lib/fsrs.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const seedrandom_1 = __importDefault(require("seedrandom"));
|
|
7
|
-
const index_1 = require("./index");
|
|
8
|
-
class FSRS {
|
|
9
|
-
constructor(param) {
|
|
10
|
-
this.repeat = (card, now) => {
|
|
11
|
-
card = Object.assign({}, card);
|
|
12
|
-
now = new Date(now.getTime());
|
|
13
|
-
card.elapsed_days = card.state === index_1.State.New ? 0 : now.diff(card.last_review, "days"); //相距时间
|
|
14
|
-
card.last_review = now; // 上次复习时间
|
|
15
|
-
card.reps += 1;
|
|
16
|
-
const s = new index_1.SchedulingCard(card);
|
|
17
|
-
s.update_state(card.state);
|
|
18
|
-
this.seed = String(card.last_review.getTime()) + String(card.elapsed_days);
|
|
19
|
-
let easy_interval, good_interval, hard_interval;
|
|
20
|
-
switch (card.state) {
|
|
21
|
-
case index_1.State.New:
|
|
22
|
-
this.init_ds(s);
|
|
23
|
-
s.again.due = now.scheduler(1);
|
|
24
|
-
s.hard.due = now.scheduler(5);
|
|
25
|
-
s.good.due = now.scheduler(10);
|
|
26
|
-
easy_interval = this.next_interval(s.easy.stability * this.param.easy_bonus);
|
|
27
|
-
s.easy.scheduled_days = easy_interval;
|
|
28
|
-
s.easy.due = now.scheduler(easy_interval, true);
|
|
29
|
-
break;
|
|
30
|
-
case index_1.State.Learning:
|
|
31
|
-
case index_1.State.Relearning:
|
|
32
|
-
hard_interval = 0;
|
|
33
|
-
good_interval = this.next_interval(s.good.stability);
|
|
34
|
-
easy_interval = Math.max(this.next_interval(s.easy.stability * this.param.easy_bonus), good_interval + 1);
|
|
35
|
-
s.schedule(now, hard_interval, good_interval, easy_interval);
|
|
36
|
-
break;
|
|
37
|
-
case index_1.State.Review:
|
|
38
|
-
const interval = card.elapsed_days;
|
|
39
|
-
const last_d = card.difficulty;
|
|
40
|
-
const last_s = card.stability;
|
|
41
|
-
const retrievability = this.current_retrievability(interval, last_s);
|
|
42
|
-
this.next_ds(s, last_d, last_s, retrievability);
|
|
43
|
-
hard_interval = this.next_interval(last_s * this.param.hard_factor);
|
|
44
|
-
good_interval = this.next_interval(s.good.stability);
|
|
45
|
-
hard_interval = Math.min(hard_interval, good_interval);
|
|
46
|
-
good_interval = Math.max(good_interval, hard_interval + 1);
|
|
47
|
-
easy_interval = Math.max(this.next_interval(s.easy.stability * this.param.easy_bonus), good_interval + 1);
|
|
48
|
-
s.schedule(now, hard_interval, good_interval, easy_interval);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return s.record_log(card, now);
|
|
52
|
-
};
|
|
53
|
-
this.get_retrievability = (card, now) => {
|
|
54
|
-
if (card.state !== index_1.State.Review) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
const t = Math.max(now.diff(card.last_review, "days"), 0);
|
|
58
|
-
return (this.current_retrievability(t, card.stability) * 100).toFixed(2) + '%';
|
|
59
|
-
};
|
|
60
|
-
this.param = param || (0, index_1.generatorParameters)();
|
|
61
|
-
this.intervalModifier = Math.log(this.param.request_retention) / Math.log(0.9);
|
|
62
|
-
}
|
|
63
|
-
init_ds(s) {
|
|
64
|
-
s.again.difficulty = this.init_difficulty(index_1.Rating.Again);
|
|
65
|
-
s.again.stability = this.init_stability(index_1.Rating.Again);
|
|
66
|
-
s.hard.difficulty = this.init_difficulty(index_1.Rating.Hard);
|
|
67
|
-
s.hard.stability = this.init_stability(index_1.Rating.Hard);
|
|
68
|
-
s.good.difficulty = this.init_difficulty(index_1.Rating.Good);
|
|
69
|
-
s.good.stability = this.init_stability(index_1.Rating.Good);
|
|
70
|
-
s.easy.difficulty = this.init_difficulty(index_1.Rating.Easy);
|
|
71
|
-
s.easy.stability = this.init_stability(index_1.Rating.Easy);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @param s scheduling Card
|
|
76
|
-
* @param last_d Difficulty
|
|
77
|
-
* @param last_s Stability
|
|
78
|
-
* @param retrievability Retrievability
|
|
79
|
-
*/
|
|
80
|
-
next_ds(s, last_d, last_s, retrievability) {
|
|
81
|
-
s.again.difficulty = this.next_difficulty(last_d, index_1.Rating.Again);
|
|
82
|
-
s.again.stability = this.next_forget_stability(s.again.difficulty, last_s, retrievability);
|
|
83
|
-
s.hard.difficulty = this.next_difficulty(last_d, index_1.Rating.Hard);
|
|
84
|
-
s.hard.stability = this.next_recall_stability(s.hard.difficulty, last_s, retrievability);
|
|
85
|
-
s.good.difficulty = this.next_difficulty(last_d, index_1.Rating.Good);
|
|
86
|
-
s.good.stability = this.next_recall_stability(s.good.difficulty, last_s, retrievability);
|
|
87
|
-
s.easy.difficulty = this.next_difficulty(last_d, index_1.Rating.Easy);
|
|
88
|
-
s.easy.stability = this.next_recall_stability(s.easy.difficulty, last_s, retrievability);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* The formula used is :
|
|
92
|
-
* $$S_0(G) = w_0 + G \cdot w_1$$
|
|
93
|
-
* $$\max \{S_0,0.1\}$$
|
|
94
|
-
* @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
|
|
95
|
-
* @return Stability (interval when R=90%)
|
|
96
|
-
*/
|
|
97
|
-
init_stability(g) {
|
|
98
|
-
return Math.max(this.param.w[0] + this.param.w[1] * g, 0.1);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The formula used is :
|
|
102
|
-
* $$D_0(G) = w_2 + (G-2) \cdot w_3$$
|
|
103
|
-
* $$\min \{\max \{D_0(G),1\},10\}$$
|
|
104
|
-
* @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
|
|
105
|
-
* @return Difficulty D \in [1,10]
|
|
106
|
-
*/
|
|
107
|
-
init_difficulty(g) {
|
|
108
|
-
return Math.min(Math.max(this.param.w[2] + this.param.w[3] * (g - 2), 1), 10);
|
|
109
|
-
}
|
|
110
|
-
apply_fuzz(ivl) {
|
|
111
|
-
if (!this.param.enable_fuzz || ivl < 2.5)
|
|
112
|
-
return ivl;
|
|
113
|
-
const generator = (0, seedrandom_1.default)(this.seed);
|
|
114
|
-
const fuzz_factor = generator();
|
|
115
|
-
ivl = Math.round(ivl);
|
|
116
|
-
const min_ivl = Math.max(2, Math.round(ivl * 0.95 - 1));
|
|
117
|
-
const max_ivl = Math.round(ivl * 1.05 + 1);
|
|
118
|
-
return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl);
|
|
119
|
-
}
|
|
120
|
-
next_interval(s) {
|
|
121
|
-
const newInterval = this.apply_fuzz(s * this.intervalModifier);
|
|
122
|
-
return Math.min(Math.max(Math.round(newInterval), 1), this.param.maximum_interval);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* The formula used is :
|
|
126
|
-
* $$next_d = D + w_4 \cdot (R - 2)$$
|
|
127
|
-
* $$D^\prime(D,R) = w_5 \cdot D_0(2) +(1 - w_5) \cdot next_d$$
|
|
128
|
-
* @param d
|
|
129
|
-
* @param g Grade (Rating[0.again,1.hard,2.good,3.easy])
|
|
130
|
-
* @return next_D
|
|
131
|
-
*/
|
|
132
|
-
next_difficulty(d, g) {
|
|
133
|
-
const next_d = d + this.param.w[4] * (g - 2);
|
|
134
|
-
return this.constrain_difficulty(this.mean_reversion(this.param.w[2], next_d));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* The formula used is :
|
|
138
|
-
* $$\min \{\max \{D_0,1\},10\}$$
|
|
139
|
-
*/
|
|
140
|
-
constrain_difficulty(difficulty) {
|
|
141
|
-
return Math.min(Math.max(Number(difficulty.toFixed(2)), 1), 10);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* The formula used is :
|
|
145
|
-
* $$w_5 \cdot init +(1 - w_5) \cdot current$$
|
|
146
|
-
* @param init $$w_2 : D_0(2) = w_2 + (R-2) \cdot w_3= w_2$$
|
|
147
|
-
* @param current $$D + w_4 \cdot (R - 2)$$
|
|
148
|
-
* @return difficulty
|
|
149
|
-
*/
|
|
150
|
-
mean_reversion(init, current) {
|
|
151
|
-
return this.param.w[5] * init + (1 - this.param.w[5]) * current;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* The formula used is :
|
|
155
|
-
* $$S^\prime_r(D,S,R) = S\cdot(e^{w_6}\cdot (11-D)\cdot S^{w_7}\cdot(e^{w_8\cdot(1-R)}-1)+1)$$
|
|
156
|
-
* @param d Difficulty D \in [1,10]
|
|
157
|
-
* @param s Stability (interval when R=90%)
|
|
158
|
-
* @param r Retrievability (probability of recall)
|
|
159
|
-
* @return S^\prime_r new stability after recall
|
|
160
|
-
*/
|
|
161
|
-
next_recall_stability(d, s, r) {
|
|
162
|
-
return s * (1 + Math.exp(this.param.w[6]) *
|
|
163
|
-
(11 - d) *
|
|
164
|
-
Math.pow(s, this.param.w[7]) *
|
|
165
|
-
(Math.exp((1 - r) * this.param.w[8]) - 1));
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* The formula used is :
|
|
169
|
-
* $$S^\prime_f(D,S,R) = w_9\cdot D^{w_{10}}\cdot S^{w_{11}}\cdot e^{w_{12}\cdot(1-R)}.$$
|
|
170
|
-
* @param d Difficulty D \in [1,10]
|
|
171
|
-
* @param s Stability (interval when R=90%)
|
|
172
|
-
* @param r Retrievability (probability of recall)
|
|
173
|
-
* @return S^\prime_f new stability after forgetting
|
|
174
|
-
*/
|
|
175
|
-
next_forget_stability(d, s, r) {
|
|
176
|
-
return this.param.w[9] * Math.pow(d, this.param.w[10]) * Math.pow(s, this.param.w[11]) * Math.exp((1 - r) * this.param.w[12]);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* The formula used is :
|
|
180
|
-
* $$R(t,S) = 0.9^{\frac{t}{S}}$$
|
|
181
|
-
* @param t t days since the last review
|
|
182
|
-
* @param s Stability (interval when R=90%)
|
|
183
|
-
* @return r Retrievability (probability of recall)
|
|
184
|
-
*/
|
|
185
|
-
current_retrievability(t, s) {
|
|
186
|
-
return Math.exp(Math.log(0.9) * t / s);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.default = FSRS;
|
package/lib/help.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = void 0;
|
|
4
|
-
Date.prototype.scheduler = function (t, isDay) {
|
|
5
|
-
return date_scheduler(this, t, isDay);
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* 当前时间与之前的时间差值
|
|
9
|
-
* @param pre 比当前时间还要之前
|
|
10
|
-
* @param unit 单位: days | minutes
|
|
11
|
-
*/
|
|
12
|
-
Date.prototype.diff = function (pre, unit) {
|
|
13
|
-
return date_diff(this, pre, unit);
|
|
14
|
-
};
|
|
15
|
-
Date.prototype.format = function () {
|
|
16
|
-
return formatDate(this);
|
|
17
|
-
};
|
|
18
|
-
Date.prototype.dueFormat = function (last_review, unit) {
|
|
19
|
-
return show_diff_message(this, last_review, unit);
|
|
20
|
-
};
|
|
21
|
-
function date_scheduler(now, t, isDay) {
|
|
22
|
-
return new Date(isDay ? now.getTime() + t * 24 * 60 * 60 * 1000 : now.getTime() + t * 60 * 1000);
|
|
23
|
-
}
|
|
24
|
-
exports.date_scheduler = date_scheduler;
|
|
25
|
-
function date_diff(now, pre, unit) {
|
|
26
|
-
const diff = now.getTime() - pre.getTime();
|
|
27
|
-
let r = 0;
|
|
28
|
-
switch (unit) {
|
|
29
|
-
case 'days':
|
|
30
|
-
r = Math.floor((diff) / (24 * 60 * 60 * 1000));
|
|
31
|
-
break;
|
|
32
|
-
case 'minutes':
|
|
33
|
-
r = Math.floor((diff) / (60 * 1000));
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
return r;
|
|
37
|
-
}
|
|
38
|
-
exports.date_diff = date_diff;
|
|
39
|
-
function formatDate(date) {
|
|
40
|
-
const year = date.getFullYear();
|
|
41
|
-
const month = date.getMonth() + 1;
|
|
42
|
-
const day = date.getDate();
|
|
43
|
-
const hours = date.getHours();
|
|
44
|
-
const minutes = date.getMinutes();
|
|
45
|
-
const seconds = date.getSeconds();
|
|
46
|
-
return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
|
|
47
|
-
}
|
|
48
|
-
exports.formatDate = formatDate;
|
|
49
|
-
function padZero(num) {
|
|
50
|
-
return num < 10 ? `0${num}` : `${num}`;
|
|
51
|
-
}
|
|
52
|
-
function show_diff_message(due, last_review, unit) {
|
|
53
|
-
const diff = due.getTime() - last_review.getTime();
|
|
54
|
-
if (diff < 1000 * 60 * 60) { // 小于1小时
|
|
55
|
-
return unit ? Math.floor((diff) / (60 * 1000)) + 'min' : String(Math.floor((diff) / (60 * 1000)));
|
|
56
|
-
}
|
|
57
|
-
else if (diff >= 1000 * 60 * 60 && diff < 1000 * 60 * 60 * 24) { // 大于1小时,小于1天
|
|
58
|
-
return unit ? Math.floor((diff) / (60 * 60 * 1000)) + 'hour' : String(Math.floor((diff) / (60 * 60 * 1000)));
|
|
59
|
-
}
|
|
60
|
-
else if (diff >= 1000 * 60 * 60 * 24 && diff < 1000 * 60 * 60 * 24 * 31) { // 大于1天,小于31天
|
|
61
|
-
return unit ? Math.floor((diff) / (24 * 60 * 60 * 1000)) + 'day' : String(Math.floor((diff) / (24 * 60 * 60 * 1000 * 1000)));
|
|
62
|
-
}
|
|
63
|
-
else if (diff >= 1000 * 60 * 60 * 24 * 31 && diff < 1000 * 60 * 60 * 24 * 365) { // 大于31天,小于365天
|
|
64
|
-
return unit ? ((diff) / (30 * 24 * 60 * 60 * 1000)).toFixed(2) + 'month' : ((diff) / (30 * 24 * 60 * 60 * 1000)).toFixed(2);
|
|
65
|
-
}
|
|
66
|
-
else { // 大于365天
|
|
67
|
-
return unit ? ((diff) / (365 * 24 * 60 * 60 * 1000)).toFixed(2) + 'year' : ((diff) / (365 * 24 * 60 * 60 * 1000)).toFixed(2);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.show_diff_message = show_diff_message;
|
package/lib/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import FSRS from "./fsrs";
|
|
2
|
-
import { Card, default_easy_bonus, default_enable_fuzz, default_hard_factor, default_maximum_interval, default_request_retention, default_w, FSRSParameters, Rating, RatingType, ReviewLog, SchedulingLog, State, StateType } from "./models";
|
|
3
|
-
import { SchedulingCard } from "./scheduler";
|
|
4
|
-
declare const fsrs: (param?: FSRSParameters) => FSRS;
|
|
5
|
-
declare const createEmptyCard: (now?: Date) => Card;
|
|
6
|
-
declare const generatorParameters: (props?: {
|
|
7
|
-
request_retention?: number;
|
|
8
|
-
maximum_interval?: number;
|
|
9
|
-
easy_bonus?: number;
|
|
10
|
-
hard_factor?: number;
|
|
11
|
-
w?: number[];
|
|
12
|
-
enable_fuzz?: boolean;
|
|
13
|
-
}) => {
|
|
14
|
-
request_retention: number;
|
|
15
|
-
maximum_interval: number;
|
|
16
|
-
easy_bonus: number;
|
|
17
|
-
hard_factor: number;
|
|
18
|
-
w: number[];
|
|
19
|
-
enable_fuzz: boolean;
|
|
20
|
-
};
|
|
21
|
-
declare const FSRS_Version = "2.0.3";
|
|
22
|
-
export { fsrs, FSRS_Version, State, Rating, SchedulingCard, createEmptyCard, generatorParameters };
|
|
23
|
-
export type { StateType, RatingType, ReviewLog, Card, SchedulingLog, FSRSParameters };
|
|
24
|
-
export { default_request_retention, default_maximum_interval, default_easy_bonus, default_hard_factor, default_w, default_enable_fuzz };
|
|
25
|
-
export { date_scheduler, date_diff, formatDate, show_diff_message } from './help';
|
package/lib/index.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = exports.default_enable_fuzz = exports.default_w = exports.default_hard_factor = exports.default_easy_bonus = exports.default_maximum_interval = exports.default_request_retention = exports.generatorParameters = exports.createEmptyCard = exports.SchedulingCard = exports.Rating = exports.State = exports.FSRS_Version = exports.fsrs = void 0;
|
|
7
|
-
const fsrs_1 = __importDefault(require("./fsrs"));
|
|
8
|
-
const models_1 = require("./models");
|
|
9
|
-
Object.defineProperty(exports, "default_easy_bonus", { enumerable: true, get: function () { return models_1.default_easy_bonus; } });
|
|
10
|
-
Object.defineProperty(exports, "default_enable_fuzz", { enumerable: true, get: function () { return models_1.default_enable_fuzz; } });
|
|
11
|
-
Object.defineProperty(exports, "default_hard_factor", { enumerable: true, get: function () { return models_1.default_hard_factor; } });
|
|
12
|
-
Object.defineProperty(exports, "default_maximum_interval", { enumerable: true, get: function () { return models_1.default_maximum_interval; } });
|
|
13
|
-
Object.defineProperty(exports, "default_request_retention", { enumerable: true, get: function () { return models_1.default_request_retention; } });
|
|
14
|
-
Object.defineProperty(exports, "default_w", { enumerable: true, get: function () { return models_1.default_w; } });
|
|
15
|
-
Object.defineProperty(exports, "Rating", { enumerable: true, get: function () { return models_1.Rating; } });
|
|
16
|
-
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return models_1.State; } });
|
|
17
|
-
const scheduler_1 = require("./scheduler");
|
|
18
|
-
Object.defineProperty(exports, "SchedulingCard", { enumerable: true, get: function () { return scheduler_1.SchedulingCard; } });
|
|
19
|
-
const fsrs = (param) => {
|
|
20
|
-
return new fsrs_1.default(param);
|
|
21
|
-
};
|
|
22
|
-
exports.fsrs = fsrs;
|
|
23
|
-
const createEmptyCard = (now) => {
|
|
24
|
-
return {
|
|
25
|
-
due: now || new Date(),
|
|
26
|
-
stability: 0,
|
|
27
|
-
difficulty: 0,
|
|
28
|
-
elapsed_days: 0,
|
|
29
|
-
scheduled_days: 0,
|
|
30
|
-
reps: 0,
|
|
31
|
-
lapses: 0,
|
|
32
|
-
state: models_1.State.New,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
exports.createEmptyCard = createEmptyCard;
|
|
36
|
-
const generatorParameters = (props) => {
|
|
37
|
-
if (!props) {
|
|
38
|
-
return {
|
|
39
|
-
request_retention: models_1.default_request_retention,
|
|
40
|
-
maximum_interval: models_1.default_maximum_interval,
|
|
41
|
-
easy_bonus: models_1.default_easy_bonus,
|
|
42
|
-
hard_factor: models_1.default_hard_factor,
|
|
43
|
-
w: models_1.default_w,
|
|
44
|
-
enable_fuzz: models_1.default_enable_fuzz,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const { w, request_retention, hard_factor, maximum_interval, enable_fuzz, easy_bonus } = props;
|
|
48
|
-
return {
|
|
49
|
-
request_retention: request_retention || models_1.default_request_retention,
|
|
50
|
-
maximum_interval: maximum_interval || models_1.default_maximum_interval,
|
|
51
|
-
easy_bonus: easy_bonus || models_1.default_easy_bonus,
|
|
52
|
-
hard_factor: hard_factor || models_1.default_hard_factor,
|
|
53
|
-
w: w || models_1.default_w,
|
|
54
|
-
enable_fuzz: enable_fuzz || models_1.default_enable_fuzz,
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
exports.generatorParameters = generatorParameters;
|
|
58
|
-
const FSRS_Version = "2.0.3";
|
|
59
|
-
exports.FSRS_Version = FSRS_Version;
|
|
60
|
-
var help_1 = require("./help");
|
|
61
|
-
Object.defineProperty(exports, "date_scheduler", { enumerable: true, get: function () { return help_1.date_scheduler; } });
|
|
62
|
-
Object.defineProperty(exports, "date_diff", { enumerable: true, get: function () { return help_1.date_diff; } });
|
|
63
|
-
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return help_1.formatDate; } });
|
|
64
|
-
Object.defineProperty(exports, "show_diff_message", { enumerable: true, get: function () { return help_1.show_diff_message; } });
|