ts-fsrs 2.0.2 → 2.1.1

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 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,46 @@
1
- # About The
2
-
3
- ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps
4
- developers apply FSRS to their flashcard applications, thereby improving the user learning experience.
5
-
6
- # Usage
7
-
8
- ```
9
- npm install ts-fsrs
10
- ```
11
-
12
- # Example
13
-
14
- ```typescript
15
- import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating} from 'ts-fsrs';
16
-
17
- const params = generatorParameters({ enable_fuzz: true });
18
- const f = fsrs(params);
19
- const card = createEmptyCard(new Date('2022-2-1 10:00:00'));// createEmptyCard();
20
- const now = new Date('2022-2-2 10:00:00');// new Date();
21
- const scheduling_cards = f.repeat(card, now);
22
-
23
- // console.log(scheduling_cards);
24
- Object.keys(Rating).filter(key => typeof Rating[key as any] === 'number').forEach(key => {
25
- // @ts-ignore
26
- const { log, card } = scheduling_cards[Rating[key]];
27
- console.group(`${key}`);
28
- console.table({
29
- [`card_${key}`]: {
30
- ...card,
31
- due: formatDate(card.due),
32
- last_review: formatDate(card.last_review),
33
- },
34
- });
35
- console.table({
36
- [`log_${key}`]: {
37
- ...log,
38
- review: formatDate(log.review),
39
- },
40
- });
41
- console.groupEnd();
42
- console.log('----------------------------------------------------------------');
43
- });
44
- ```
45
-
46
- > More examples refer to the [Example](https://github.com/ishiko732/ts-fsrs/blob/master/test/index.ts)
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
+ # Example
13
+
14
+ ```typescript
15
+ import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating} from 'ts-fsrs';
16
+
17
+ const params = generatorParameters({ enable_fuzz: true });
18
+ const f = fsrs(params);
19
+ const card = createEmptyCard(new Date('2022-2-1 10:00:00'));// createEmptyCard();
20
+ const now = new Date('2022-2-2 10:00:00');// new Date();
21
+ const scheduling_cards = f.repeat(card, now);
22
+
23
+ // console.log(scheduling_cards);
24
+ Object.keys(Rating).filter(key => typeof Rating[key as any] === 'number').forEach(key => {
25
+ // @ts-ignore
26
+ const { log, card } = scheduling_cards[Rating[key]];
27
+ console.group(`${key}`);
28
+ console.table({
29
+ [`card_${key}`]: {
30
+ ...card,
31
+ due: formatDate(card.due),
32
+ last_review: formatDate(card.last_review),
33
+ },
34
+ });
35
+ console.table({
36
+ [`log_${key}`]: {
37
+ ...log,
38
+ review: formatDate(log.review),
39
+ },
40
+ });
41
+ console.groupEnd();
42
+ console.log('----------------------------------------------------------------');
43
+ });
44
+ ```
45
+
46
+ > More examples refer to the [Example](https://github.com/ishiko732/ts-fsrs/blob/master/example/index.ts)
@@ -1,126 +1,126 @@
1
- import { Card, FSRSParameters, Rating, SchedulingCard, State } from "./index";
2
- import { int } from './help';
3
- export default class FSRS {
4
- private param;
5
- private readonly intervalModifier;
6
- private seed?;
7
- constructor(param?: FSRSParameters);
8
- repeat: (card: Card, now: Date) => {
9
- 0: {
10
- card: Card;
11
- log: {
12
- rating: Rating;
13
- state: State;
14
- elapsed_days: number;
15
- scheduled_days: number;
16
- review: Date;
17
- };
18
- };
19
- 1: {
20
- card: Card;
21
- log: {
22
- rating: Rating;
23
- state: State;
24
- elapsed_days: number;
25
- scheduled_days: number;
26
- review: Date;
27
- };
28
- };
29
- 2: {
30
- card: Card;
31
- log: {
32
- rating: Rating;
33
- state: State;
34
- elapsed_days: number;
35
- scheduled_days: number;
36
- review: Date;
37
- };
38
- };
39
- 3: {
40
- card: Card;
41
- log: {
42
- rating: Rating;
43
- state: State;
44
- elapsed_days: number;
45
- scheduled_days: number;
46
- review: Date;
47
- };
48
- };
49
- };
50
- get_retrievability: (card: Card, now: Date) => undefined | string;
51
- init_ds(s: SchedulingCard): void;
52
- /**
53
- *
54
- * @param s scheduling Card
55
- * @param last_d Difficulty
56
- * @param last_s Stability
57
- * @param retrievability Retrievability
58
- */
59
- next_ds(s: SchedulingCard, last_d: number, last_s: number, retrievability: number): void;
60
- /**
61
- * The formula used is :
62
- * $$S_0(G) = w_0 + G \cdot w_1$$
63
- * $$\max \{S_0,0.1\}$$
64
- * @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
65
- * @return Stability (interval when R=90%)
66
- */
67
- init_stability(g: number): number;
68
- /**
69
- * The formula used is :
70
- * $$D_0(G) = w_2 + (G-2) \cdot w_3$$
71
- * $$\min \{\max \{D_0(G),1\},10\}$$
72
- * @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
73
- * @return Difficulty D \in [1,10]
74
- */
75
- init_difficulty(g: number): number;
76
- apply_fuzz(ivl: number): number;
77
- next_interval(s: number): int;
78
- /**
79
- * The formula used is :
80
- * $$next_d = D + w_4 \cdot (R - 2)$$
81
- * $$D^\prime(D,R) = w_5 \cdot D_0(2) +(1 - w_5) \cdot next_d$$
82
- * @param d
83
- * @param g Grade (Rating[0.again,1.hard,2.good,3.easy])
84
- * @return next_D
85
- */
86
- next_difficulty(d: number, g: number): number;
87
- /**
88
- * The formula used is :
89
- * $$\min \{\max \{D_0,1\},10\}$$
90
- */
91
- constrain_difficulty(difficulty: number): number;
92
- /**
93
- * The formula used is :
94
- * $$w_5 \cdot init +(1 - w_5) \cdot current$$
95
- * @param init $$w_2 : D_0(2) = w_2 + (R-2) \cdot w_3= w_2$$
96
- * @param current $$D + w_4 \cdot (R - 2)$$
97
- * @return difficulty
98
- */
99
- mean_reversion(init: number, current: number): number;
100
- /**
101
- * The formula used is :
102
- * $$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)$$
103
- * @param d Difficulty D \in [1,10]
104
- * @param s Stability (interval when R=90%)
105
- * @param r Retrievability (probability of recall)
106
- * @return S^\prime_r new stability after recall
107
- */
108
- next_recall_stability(d: number, s: number, r: number): number;
109
- /**
110
- * The formula used is :
111
- * $$S^\prime_f(D,S,R) = w_9\cdot D^{w_{10}}\cdot S^{w_{11}}\cdot e^{w_{12}\cdot(1-R)}.$$
112
- * @param d Difficulty D \in [1,10]
113
- * @param s Stability (interval when R=90%)
114
- * @param r Retrievability (probability of recall)
115
- * @return S^\prime_f new stability after forgetting
116
- */
117
- next_forget_stability(d: number, s: number, r: number): number;
118
- /**
119
- * The formula used is :
120
- * $$R(t,S) = 0.9^{\frac{t}{S}}$$
121
- * @param t t days since the last review
122
- * @param s Stability (interval when R=90%)
123
- * @return r Retrievability (probability of recall)
124
- */
125
- current_retrievability(t: number, s: number): number;
126
- }
1
+ import { Card, FSRSParameters, Rating, SchedulingCard, State } from "./index";
2
+ import { int } from "./help";
3
+ export default class FSRS {
4
+ private param;
5
+ private readonly intervalModifier;
6
+ private seed?;
7
+ constructor(param?: FSRSParameters);
8
+ repeat: (card: Card, now: Date) => {
9
+ 0: {
10
+ card: Card;
11
+ log: {
12
+ rating: Rating;
13
+ state: State;
14
+ elapsed_days: number;
15
+ scheduled_days: number;
16
+ review: Date;
17
+ };
18
+ };
19
+ 1: {
20
+ card: Card;
21
+ log: {
22
+ rating: Rating;
23
+ state: State;
24
+ elapsed_days: number;
25
+ scheduled_days: number;
26
+ review: Date;
27
+ };
28
+ };
29
+ 2: {
30
+ card: Card;
31
+ log: {
32
+ rating: Rating;
33
+ state: State;
34
+ elapsed_days: number;
35
+ scheduled_days: number;
36
+ review: Date;
37
+ };
38
+ };
39
+ 3: {
40
+ card: Card;
41
+ log: {
42
+ rating: Rating;
43
+ state: State;
44
+ elapsed_days: number;
45
+ scheduled_days: number;
46
+ review: Date;
47
+ };
48
+ };
49
+ };
50
+ get_retrievability: (card: Card, now: Date) => undefined | string;
51
+ init_ds(s: SchedulingCard): void;
52
+ /**
53
+ *
54
+ * @param s scheduling Card
55
+ * @param last_d Difficulty
56
+ * @param last_s Stability
57
+ * @param retrievability Retrievability
58
+ */
59
+ next_ds(s: SchedulingCard, last_d: number, last_s: number, retrievability: number): void;
60
+ /**
61
+ * The formula used is :
62
+ * $$S_0(G) = w_0 + G \cdot w_1$$
63
+ * $$\max \{S_0,0.1\}$$
64
+ * @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
65
+ * @return Stability (interval when R=90%)
66
+ */
67
+ init_stability(g: number): number;
68
+ /**
69
+ * The formula used is :
70
+ * $$D_0(G) = w_2 + (G-2) \cdot w_3$$
71
+ * $$\min \{\max \{D_0(G),1\},10\}$$
72
+ * @param g Grade (rating at Anki) [0.again,1.hard,2.good,3.easy]
73
+ * @return Difficulty D \in [1,10]
74
+ */
75
+ init_difficulty(g: number): number;
76
+ apply_fuzz(ivl: number): number;
77
+ next_interval(s: number): int;
78
+ /**
79
+ * The formula used is :
80
+ * $$next_d = D + w_4 \cdot (R - 2)$$
81
+ * $$D^\prime(D,R) = w_5 \cdot D_0(2) +(1 - w_5) \cdot next_d$$
82
+ * @param d
83
+ * @param g Grade (Rating[0.again,1.hard,2.good,3.easy])
84
+ * @return next_D
85
+ */
86
+ next_difficulty(d: number, g: number): number;
87
+ /**
88
+ * The formula used is :
89
+ * $$\min \{\max \{D_0,1\},10\}$$
90
+ */
91
+ constrain_difficulty(difficulty: number): number;
92
+ /**
93
+ * The formula used is :
94
+ * $$w_5 \cdot init +(1 - w_5) \cdot current$$
95
+ * @param init $$w_2 : D_0(2) = w_2 + (R-2) \cdot w_3= w_2$$
96
+ * @param current $$D + w_4 \cdot (R - 2)$$
97
+ * @return difficulty
98
+ */
99
+ mean_reversion(init: number, current: number): number;
100
+ /**
101
+ * The formula used is :
102
+ * $$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)$$
103
+ * @param d Difficulty D \in [1,10]
104
+ * @param s Stability (interval when R=90%)
105
+ * @param r Retrievability (probability of recall)
106
+ * @return S^\prime_r new stability after recall
107
+ */
108
+ next_recall_stability(d: number, s: number, r: number): number;
109
+ /**
110
+ * The formula used is :
111
+ * $$S^\prime_f(D,S,R) = w_9\cdot D^{w_{10}}\cdot S^{w_{11}}\cdot e^{w_{12}\cdot(1-R)}.$$
112
+ * @param d Difficulty D \in [1,10]
113
+ * @param s Stability (interval when R=90%)
114
+ * @param r Retrievability (probability of recall)
115
+ * @return S^\prime_f new stability after forgetting
116
+ */
117
+ next_forget_stability(d: number, s: number, r: number): number;
118
+ /**
119
+ * The formula used is :
120
+ * $$R(t,S) = 0.9^{\frac{t}{S}}$$
121
+ * @param t t days since the last review
122
+ * @param s Stability (interval when R=90%)
123
+ * @return r Retrievability (probability of recall)
124
+ */
125
+ current_retrievability(t: number, s: number): number;
126
+ }