-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/Support iteration in the
repeat
(#121)
* Feat/Support iteration in the `repeat` method * update test * update README * bump version to 4.2.0
- Loading branch information
Showing
11 changed files
with
108 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ The workflow for TS-FSRS can be referenced from the following resources: | |
|
||
# Usage | ||
The [email protected] package requires Node.js version `16.0.0` or higher. Starting with `[email protected]`, the minimum required Node.js version is 18.0.0. | ||
The `[email protected]` package requires Node.js version `16.0.0` or higher. Starting with `[email protected]`, the minimum required Node.js version is `18.0.0`. | ||
From version `3.5.6` onwards, ts-fsrs supports CommonJS, ESM, and UMD module systems. | ||
|
||
``` | ||
|
@@ -32,15 +32,17 @@ bun install ts-fsrs | |
```typescript | ||
import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating, Grades} from 'ts-fsrs'; | ||
|
||
const params = generatorParameters({ enable_fuzz: true }); | ||
const params = generatorParameters({ enable_fuzz: true, enable_short_term: false }); | ||
const f = fsrs(params); | ||
const card = createEmptyCard(new Date('2022-2-1 10:00:00'));// createEmptyCard(); | ||
const now = new Date('2022-2-2 10:00:00');// new Date(); | ||
const scheduling_cards = f.repeat(card, now); | ||
|
||
// console.log(scheduling_cards); | ||
Grades.forEach(grade => { // [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy] | ||
const { log, card } = scheduling_cards[grade]; | ||
for (const item of scheduling_cards) { | ||
// grades = [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy] | ||
const grade = item.log.rating | ||
const { log, card } = item; | ||
console.group(`${Rating[grade]}`); | ||
console.table({ | ||
[`card_${Rating[grade]}`]: { | ||
|
@@ -57,7 +59,7 @@ Grades.forEach(grade => { // [Rating.Again, Rating.Hard, Rating.Good, Rating.Eas | |
}); | ||
console.groupEnd(); | ||
console.log('----------------------------------------------------------------'); | ||
}); | ||
} | ||
``` | ||
|
||
More refer: | ||
|
@@ -105,6 +107,8 @@ import { | |
let card: Card = createEmptyCard(); | ||
const f: FSRS = new FSRS(); // or const f: FSRS = fsrs(params); | ||
let scheduling_cards: RecordLog = f.repeat(card, new Date()); | ||
// if you want to specify the grade, you can use the following code: (ts-fsrs >=4.0.0) | ||
// let scheduling_card: RecordLog = f.next(card, new Date(), Rating.Good); | ||
``` | ||
|
||
## 4. **Retrieving Scheduled Cards**: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
createEmptyCard, | ||
fsrs, | ||
Grade, | ||
type IPreview, | ||
Rating, | ||
} from '../../src/fsrs' | ||
|
||
describe('basic schduler', () => { | ||
const now = new Date() | ||
|
||
it('[Symbol.iterator]', () => { | ||
const card = createEmptyCard(now) | ||
const f = fsrs() | ||
const preview = f.repeat(card, now) | ||
const again = f.next(card, now, Rating.Again) | ||
const hard = f.next(card, now, Rating.Hard) | ||
const good = f.next(card, now, Rating.Good) | ||
const easy = f.next(card, now, Rating.Easy) | ||
|
||
const expect_preview = { | ||
[Rating.Again]: again, | ||
[Rating.Hard]: hard, | ||
[Rating.Good]: good, | ||
[Rating.Easy]: easy, | ||
[Symbol.iterator]: preview[Symbol.iterator], | ||
} satisfies IPreview | ||
expect(preview).toEqual(expect_preview) | ||
for (const item of preview) { | ||
expect(item).toEqual(expect_preview[<Grade>item.log.rating]) | ||
} | ||
const iterator = preview[Symbol.iterator]() | ||
expect(iterator.next().value).toEqual(again) | ||
expect(iterator.next().value).toEqual(hard) | ||
expect(iterator.next().value).toEqual(good) | ||
expect(iterator.next().value).toEqual(easy) | ||
expect(iterator.next().done).toBeTruthy() | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters