ts-fsrs 2.0.2 → 2.0.3

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/lib/scheduler.js CHANGED
@@ -1,95 +1,95 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchedulingCard = void 0;
4
- const models_1 = require("./models");
5
- const help_1 = require("./help");
6
- class SchedulingCard {
7
- copy(card) {
8
- return Object.assign({}, card);
9
- }
10
- constructor(card) {
11
- this.again = this.copy(card);
12
- this.hard = this.copy(card);
13
- this.good = this.copy(card);
14
- this.easy = this.copy(card);
15
- }
16
- update_state(state) {
17
- if (state === models_1.State.New) {
18
- this.again.state = models_1.State.Learning;
19
- this.hard.state = models_1.State.Learning;
20
- this.good.state = models_1.State.Learning;
21
- this.easy.state = models_1.State.Review;
22
- this.again.lapses += 1;
23
- }
24
- else if (state === models_1.State.Learning || state === models_1.State.Relearning) {
25
- this.again.state = state;
26
- this.hard.state = state;
27
- this.good.state = models_1.State.Review;
28
- this.easy.state = models_1.State.Review;
29
- }
30
- else if (state === models_1.State.Review) {
31
- this.again.state = models_1.State.Relearning;
32
- this.hard.state = models_1.State.Review;
33
- this.good.state = models_1.State.Review;
34
- this.easy.state = models_1.State.Review;
35
- this.again.lapses += 1;
36
- }
37
- return this;
38
- }
39
- schedule(now, hard_interval, good_interval, easy_interval) {
40
- this.again.scheduled_days = 0;
41
- this.hard.scheduled_days = hard_interval;
42
- this.good.scheduled_days = good_interval;
43
- this.easy.scheduled_days = easy_interval;
44
- this.again.due = (0, help_1.date_scheduler)(now, 5);
45
- this.hard.due = hard_interval > 0 ? (0, help_1.date_scheduler)(now, hard_interval, true) : (0, help_1.date_scheduler)(now, 10);
46
- this.good.due = (0, help_1.date_scheduler)(now, good_interval, true);
47
- this.easy.due = (0, help_1.date_scheduler)(now, easy_interval, true);
48
- return this;
49
- }
50
- record_log(card, now) {
51
- return {
52
- [models_1.Rating.Again]: {
53
- card: this.again,
54
- log: {
55
- rating: models_1.Rating.Again,
56
- state: card.state,
57
- elapsed_days: this.again.scheduled_days,
58
- scheduled_days: card.elapsed_days,
59
- review: now
60
- }
61
- },
62
- [models_1.Rating.Hard]: {
63
- card: this.hard,
64
- log: {
65
- rating: models_1.Rating.Hard,
66
- state: card.state,
67
- elapsed_days: this.again.scheduled_days,
68
- scheduled_days: card.elapsed_days,
69
- review: now
70
- }
71
- },
72
- [models_1.Rating.Good]: {
73
- card: this.good,
74
- log: {
75
- rating: models_1.Rating.Good,
76
- state: card.state,
77
- elapsed_days: this.again.scheduled_days,
78
- scheduled_days: card.elapsed_days,
79
- review: now
80
- }
81
- },
82
- [models_1.Rating.Easy]: {
83
- card: this.easy,
84
- log: {
85
- rating: models_1.Rating.Easy,
86
- state: card.state,
87
- elapsed_days: this.again.scheduled_days,
88
- scheduled_days: card.elapsed_days,
89
- review: now
90
- }
91
- }
92
- };
93
- }
94
- }
95
- exports.SchedulingCard = SchedulingCard;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchedulingCard = void 0;
4
+ const models_1 = require("./models");
5
+ const help_1 = require("./help");
6
+ class SchedulingCard {
7
+ copy(card) {
8
+ return Object.assign({}, card);
9
+ }
10
+ constructor(card) {
11
+ this.again = this.copy(card);
12
+ this.hard = this.copy(card);
13
+ this.good = this.copy(card);
14
+ this.easy = this.copy(card);
15
+ }
16
+ update_state(state) {
17
+ if (state === models_1.State.New) {
18
+ this.again.state = models_1.State.Learning;
19
+ this.hard.state = models_1.State.Learning;
20
+ this.good.state = models_1.State.Learning;
21
+ this.easy.state = models_1.State.Review;
22
+ this.again.lapses += 1;
23
+ }
24
+ else if (state === models_1.State.Learning || state === models_1.State.Relearning) {
25
+ this.again.state = state;
26
+ this.hard.state = state;
27
+ this.good.state = models_1.State.Review;
28
+ this.easy.state = models_1.State.Review;
29
+ }
30
+ else if (state === models_1.State.Review) {
31
+ this.again.state = models_1.State.Relearning;
32
+ this.hard.state = models_1.State.Review;
33
+ this.good.state = models_1.State.Review;
34
+ this.easy.state = models_1.State.Review;
35
+ this.again.lapses += 1;
36
+ }
37
+ return this;
38
+ }
39
+ schedule(now, hard_interval, good_interval, easy_interval) {
40
+ this.again.scheduled_days = 0;
41
+ this.hard.scheduled_days = hard_interval;
42
+ this.good.scheduled_days = good_interval;
43
+ this.easy.scheduled_days = easy_interval;
44
+ this.again.due = (0, help_1.date_scheduler)(now, 5);
45
+ this.hard.due = hard_interval > 0 ? (0, help_1.date_scheduler)(now, hard_interval, true) : (0, help_1.date_scheduler)(now, 10);
46
+ this.good.due = (0, help_1.date_scheduler)(now, good_interval, true);
47
+ this.easy.due = (0, help_1.date_scheduler)(now, easy_interval, true);
48
+ return this;
49
+ }
50
+ record_log(card, now) {
51
+ return {
52
+ [models_1.Rating.Again]: {
53
+ card: this.again,
54
+ log: {
55
+ rating: models_1.Rating.Again,
56
+ state: card.state,
57
+ elapsed_days: this.again.scheduled_days,
58
+ scheduled_days: card.elapsed_days,
59
+ review: now
60
+ }
61
+ },
62
+ [models_1.Rating.Hard]: {
63
+ card: this.hard,
64
+ log: {
65
+ rating: models_1.Rating.Hard,
66
+ state: card.state,
67
+ elapsed_days: this.hard.scheduled_days,
68
+ scheduled_days: card.elapsed_days,
69
+ review: now
70
+ }
71
+ },
72
+ [models_1.Rating.Good]: {
73
+ card: this.good,
74
+ log: {
75
+ rating: models_1.Rating.Good,
76
+ state: card.state,
77
+ elapsed_days: this.good.scheduled_days,
78
+ scheduled_days: card.elapsed_days,
79
+ review: now
80
+ }
81
+ },
82
+ [models_1.Rating.Easy]: {
83
+ card: this.easy,
84
+ log: {
85
+ rating: models_1.Rating.Easy,
86
+ state: card.state,
87
+ elapsed_days: this.easy.scheduled_days,
88
+ scheduled_days: card.elapsed_days,
89
+ review: now
90
+ }
91
+ }
92
+ };
93
+ }
94
+ }
95
+ exports.SchedulingCard = SchedulingCard;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-fsrs",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
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
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/seedrandom": "^3.0.5",
17
- "eslint": "^8.34.0",
18
- "typescript": "^4.9.5"
17
+ "eslint": "^8.44.0",
18
+ "typescript": "^5.1.6"
19
19
  },
20
20
  "scripts": {
21
21
  "test": "ts-node test/index.ts",