ts-fsrs 3.0.1 → 3.0.2
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/dist/default.js +1 -1
- package/dist/fsrs.d.ts +4 -0
- package/dist/fsrs.js +12 -1
- package/dist/help.d.ts +3 -0
- package/dist/help.js +25 -1
- package/package.json +1 -1
package/dist/default.js
CHANGED
|
@@ -29,7 +29,7 @@ exports.default_w = exports.envParams.FSRS_W || [
|
|
|
29
29
|
0.34, 1.26, 0.29, 2.61,
|
|
30
30
|
];
|
|
31
31
|
exports.default_enable_fuzz = exports.envParams.FSRS_ENABLE_FUZZ || false;
|
|
32
|
-
exports.FSRSVersion = "3.0.
|
|
32
|
+
exports.FSRSVersion = "3.0.2";
|
|
33
33
|
const generatorParameters = (props) => {
|
|
34
34
|
return {
|
|
35
35
|
request_retention: props?.request_retention || exports.default_request_retention,
|
package/dist/fsrs.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare class FSRS {
|
|
|
6
6
|
private readonly intervalModifier;
|
|
7
7
|
private seed?;
|
|
8
8
|
constructor(param: Partial<FSRSParameters>);
|
|
9
|
+
preProcess(card: Card, now: Date): {
|
|
10
|
+
card: Card;
|
|
11
|
+
now: Date;
|
|
12
|
+
};
|
|
9
13
|
repeat: (card: Card, now: Date) => {
|
|
10
14
|
1: {
|
|
11
15
|
card: Card;
|
package/dist/fsrs.js
CHANGED
|
@@ -19,12 +19,20 @@ class FSRS {
|
|
|
19
19
|
// The formula used is : I(r,s)=9 \cdot s \cdot (\frac{1}{r}-1)
|
|
20
20
|
this.intervalModifier = 9 * (1 / this.param.request_retention - 1);
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
preProcess(card, now) {
|
|
23
23
|
card = {
|
|
24
24
|
...card,
|
|
25
|
+
state: (0, help_1.fixState)(card.state),
|
|
26
|
+
due: (0, help_1.fixDate)(card.due),
|
|
25
27
|
last_review: card.last_review ? (0, help_1.fixDate)(card.last_review) : undefined,
|
|
26
28
|
};
|
|
27
29
|
now = (0, help_1.fixDate)(now);
|
|
30
|
+
return { card, now };
|
|
31
|
+
}
|
|
32
|
+
repeat = (card, now) => {
|
|
33
|
+
const process = this.preProcess(card, now);
|
|
34
|
+
card = process.card;
|
|
35
|
+
now = process.now;
|
|
28
36
|
card.elapsed_days =
|
|
29
37
|
card.state === models_1.State.New ? 0 : now.diff(card.last_review, "days"); //相距时间
|
|
30
38
|
card.last_review = now; // 上次复习时间
|
|
@@ -68,6 +76,9 @@ class FSRS {
|
|
|
68
76
|
return s.record_log(card, now);
|
|
69
77
|
};
|
|
70
78
|
get_retrievability = (card, now) => {
|
|
79
|
+
const process = this.preProcess(card, now);
|
|
80
|
+
card = process.card;
|
|
81
|
+
now = process.now;
|
|
71
82
|
if (card.state !== models_1.State.Review) {
|
|
72
83
|
return undefined;
|
|
73
84
|
}
|
package/dist/help.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { int, unit } from "./type";
|
|
2
|
+
import { Rating, State } from "./models";
|
|
2
3
|
declare global {
|
|
3
4
|
export interface Date {
|
|
4
5
|
scheduler(t: int, isDay?: boolean): Date;
|
|
@@ -12,3 +13,5 @@ export declare function date_diff(now: Date, pre: Date, unit: unit): number;
|
|
|
12
13
|
export declare function formatDate(date: Date): string;
|
|
13
14
|
export declare function show_diff_message(due: Date, last_review: Date, unit?: boolean, timeUnit?: string[]): string;
|
|
14
15
|
export declare function fixDate(value: unknown): Date;
|
|
16
|
+
export declare function fixState(value: unknown): State;
|
|
17
|
+
export declare function fixRating(value: unknown): Rating;
|
package/dist/help.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fixDate = exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = void 0;
|
|
3
|
+
exports.fixRating = exports.fixState = exports.fixDate = exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = void 0;
|
|
4
|
+
const models_1 = require("./models");
|
|
4
5
|
Date.prototype.scheduler = function (t, isDay) {
|
|
5
6
|
return date_scheduler(this, t, isDay);
|
|
6
7
|
};
|
|
@@ -25,6 +26,9 @@ function date_scheduler(now, t, isDay) {
|
|
|
25
26
|
}
|
|
26
27
|
exports.date_scheduler = date_scheduler;
|
|
27
28
|
function date_diff(now, pre, unit) {
|
|
29
|
+
if (!now || !pre) {
|
|
30
|
+
throw new Error("Invalid date");
|
|
31
|
+
}
|
|
28
32
|
const diff = now.getTime() - pre.getTime();
|
|
29
33
|
let r = 0;
|
|
30
34
|
switch (unit) {
|
|
@@ -92,3 +96,23 @@ function fixDate(value) {
|
|
|
92
96
|
throw new Error(`Invalid date:[${value}]`);
|
|
93
97
|
}
|
|
94
98
|
exports.fixDate = fixDate;
|
|
99
|
+
function fixState(value) {
|
|
100
|
+
if (typeof value === "string") {
|
|
101
|
+
return models_1.State[value];
|
|
102
|
+
}
|
|
103
|
+
else if (typeof value === "number") {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Invalid state:[${value}]`);
|
|
107
|
+
}
|
|
108
|
+
exports.fixState = fixState;
|
|
109
|
+
function fixRating(value) {
|
|
110
|
+
if (typeof value === "string") {
|
|
111
|
+
return models_1.Rating[value];
|
|
112
|
+
}
|
|
113
|
+
else if (typeof value === "number") {
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`Invalid rating:[${value}]`);
|
|
117
|
+
}
|
|
118
|
+
exports.fixRating = fixRating;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-fsrs",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|