Skip to content

Commit

Permalink
Fix/input not array in reschedule method (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishiko732 committed Mar 21, 2024
1 parent cb59bf1 commit 9894ca4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions __tests__/reschedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,17 @@ describe("FSRS reschedule", () => {
);
expect(reschedule_cards.length).toEqual(0);
});

it("reschedule by empty array", () => {
const f: FSRS = fsrs();
const reschedule_cards = f.reschedule([]);
expect(reschedule_cards.length).toEqual(0);
});

it("reschedule by not array", () => {
const f: FSRS = fsrs();
expect(() =>{f.reschedule(createEmptyCard() as unknown as Card[])}).toThrow(
"cards must be an array",
);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-fsrs",
"version": "3.5.2",
"version": "3.5.3",
"description": "ts-fsrs is a ES modules package based on TypeScript, used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, there by improving the user learning experience.",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/fsrs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const default_w = [
];
export const default_enable_fuzz = false;

export const FSRSVersion: string = "3.5.2";
export const FSRSVersion: string = "3.5.3";

export const generatorParameters = (
props?: Partial<FSRSParameters>,
Expand Down
3 changes: 3 additions & 0 deletions src/fsrs/fsrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ export class FSRS extends FSRSAlgorithm {
cards: Array<T>,
options: RescheduleOptions = {},
): Array<T> {
if (!Array.isArray(cards)) {
throw new Error("cards must be an array");
}
const processedCard: T[] = [];
for (const card of cards) {
if (fixState(card.state) !== State.Review || !card.last_review) continue;
Expand Down

0 comments on commit 9894ca4

Please sign in to comment.