ts-fsrs 3.5.7 → 4.0.0
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/README.md +11 -5
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +100 -37
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +40 -38
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[Introduction](./README.md) | [简体中文](./README_CN.md) |[はじめに](./
|
|
1
|
+
[Introduction](./README.md) | [简体中文](./README_CN.md) |[はじめに](./README_JA.md)
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
@@ -9,16 +9,22 @@
|
|
|
9
9
|
[](https://github.com/open-spaced-repetition/ts-fsrs/actions/workflows/npm-publish.yml)
|
|
10
10
|
[](https://github.com/open-spaced-repetition/ts-fsrs/actions/workflows/deploy.yml)
|
|
11
11
|
|
|
12
|
-
ts-fsrs is a [ES modules
|
|
13
|
-
|
|
12
|
+
ts-fsrs is a versatile package based on TypeScript that supports [ES modules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), [CommonJS](https://en.wikipedia.org/wiki/CommonJS), and UMD. It implements the [Free Spaced Repetition Scheduler (FSRS) algorithm](https://github.com/open-spaced-repetition/free-spaced-repetition-scheduler), enabling developers to integrate FSRS into their flashcard applications to enhance the user learning experience.
|
|
13
|
+
|
|
14
|
+
The workflow for TS-FSRS can be referenced from the following resources:
|
|
15
|
+
> - google driver: [ts-fsrs-workflow.drawio](https://drive.google.com/file/d/1FLKjpt4T3Iis02vjoA10q7vxKCWwClfR/view?usp=sharing) (You may provide commentary)
|
|
16
|
+
> - github: [ts-fsrs-workflow.drawio](./ts-fsrs-workflow.drawio)
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
# Usage
|
|
16
|
-
|
|
20
|
+
The ts-fsrs@3.x package requires Node.js version `16.0.0` or higher. Starting with `ts-fsrs@4.x`, the minimum required Node.js version is 18.0.0.
|
|
21
|
+
From version `3.5.6` onwards, ts-fsrs supports CommonJS, ESM, and UMD module systems.
|
|
17
22
|
|
|
18
23
|
```
|
|
19
24
|
npm install ts-fsrs
|
|
20
25
|
yarn install ts-fsrs
|
|
21
26
|
pnpm install ts-fsrs
|
|
27
|
+
bun install ts-fsrs
|
|
22
28
|
```
|
|
23
29
|
|
|
24
30
|
# Example
|
|
@@ -59,7 +65,7 @@ More refer:
|
|
|
59
65
|
- [Example.html - Github Pages](https://open-spaced-repetition.github.io/ts-fsrs/example)
|
|
60
66
|
- [Browser](https://github.com/open-spaced-repetition/ts-fsrs/blob/master/example/example.html) (ts-fsrs package using CDN)
|
|
61
67
|
- [ts-fsrs-demo - Next.js+Prisma](https://github.com/ishiko732/ts-fsrs-demo)
|
|
62
|
-
|
|
68
|
+
- [spaced - Next.js+Drizzle+tRPC](https://github.com/zsh-eng/spaced)
|
|
63
69
|
|
|
64
70
|
# Basic Use
|
|
65
71
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var G=require("seedrandom"),d=(t=>(t[t.New=0]="New",t[t.Learning=1]="Learning",t[t.Review=2]="Review",t[t.Relearning=3]="Relearning",t))(d||{}),n=(t=>(t[t.Manual=0]="Manual",t[t.Again=1]="Again",t[t.Hard=2]="Hard",t[t.Good=3]="Good",t[t.Easy=4]="Easy",t))(n||{});Date.prototype.scheduler=function(t,e){return f(this,t,e)},Date.prototype.diff=function(t,e){return M(this,t,e)},Date.prototype.format=function(){return R(this)},Date.prototype.dueFormat=function(t,e,a){return E(this,t,e,a)};function f(t,e,a){return new Date(a?h(t).getTime()+e*24*60*60*1e3:h(t).getTime()+e*60*1e3)}function M(t,e,a){if(!t||!e)throw new Error("Invalid date");const r=h(t).getTime()-h(e).getTime();let i=0;switch(a){case"days":i=Math.floor(r/(24*60*60*1e3));break;case"minutes":i=Math.floor(r/(60*1e3));break}return i}function R(t){const e=h(t),a=e.getFullYear(),r=e.getMonth()+1,i=e.getDate(),s=e.getHours(),l=e.getMinutes(),o=e.getSeconds();return`${a}-${y(r)}-${y(i)} ${y(s)}:${y(l)}:${y(o)}`}function y(t){return t<10?`0${t}`:`${t}`}const p=[60,60,24,31,12],g=["second","min","hour","day","month","year"];function E(t,e,a,r=g){t=h(t),e=h(e),r.length!==g.length&&(r=g);let i=t.getTime()-e.getTime(),s;for(i/=1e3,s=0;s<p.length&&!(i<p[s]);s++)i/=p[s];return`${Math.floor(i)}${a?r[s]:""}`}function h(t){if(typeof t=="object"&&t instanceof Date)return t;if(typeof t=="string"){const e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid date:[${t}]`);return new Date(e)}else if(typeof t=="number")return new Date(t);throw new Error(`Invalid date:[${t}]`)}function _(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),a=t.slice(1).toLowerCase(),r=d[`${e}${a}`];if(r===void 0)throw new Error(`Invalid state:[${t}]`);return r}else if(typeof t=="number")return t;throw new Error(`Invalid state:[${t}]`)}function $(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),a=t.slice(1).toLowerCase(),r=n[`${e}${a}`];if(r===void 0)throw new Error(`Invalid rating:[${t}]`);return r}else if(typeof t=="number")return t;throw new Error(`Invalid rating:[${t}]`)}const k=[n.Again,n.Hard,n.Good,n.Easy],T=[{start:2.5,end:7,factor:.15},{start:7,end:20,factor:.1},{start:20,end:1/0,factor:.05}];function D(t,e,a){let r=1;for(const l of T)r+=l.factor*Math.max(Math.min(t,l.end)-l.start,0);t=Math.min(t,a);let i=Math.max(2,Math.round(t-r));const s=Math.min(Math.round(t+r),a);return t>e&&(i=Math.max(i,e+1)),i=Math.min(i,s),{min_ivl:i,max_ivl:s}}class S{again;hard;good;easy;last_review;last_elapsed_days;copy(e){return{...e}}constructor(e,a){this.last_review=e.last_review||e.due,this.last_elapsed_days=e.elapsed_days,e.elapsed_days=e.state===d.New?0:a.diff(e.last_review,"days"),e.last_review=a,e.reps+=1,this.again=this.copy(e),this.hard=this.copy(e),this.good=this.copy(e),this.easy=this.copy(e)}update_state(e){return e===d.New?(this.again.state=d.Learning,this.hard.state=d.Learning,this.good.state=d.Learning,this.easy.state=d.Review):e===d.Learning||e===d.Relearning?(this.again.state=e,this.hard.state=e,this.good.state=d.Review,this.easy.state=d.Review):e===d.Review&&(this.again.state=d.Relearning,this.hard.state=d.Review,this.good.state=d.Review,this.easy.state=d.Review,this.again.lapses+=1),this}schedule(e,a,r,i){return this.again.scheduled_days=0,this.hard.scheduled_days=a,this.good.scheduled_days=r,this.easy.scheduled_days=i,this.again.due=f(e,5),this.hard.due=a>0?f(e,a,!0):f(e,10),this.good.due=f(e,r,!0),this.easy.due=f(e,i,!0),this}record_log(e,a){return{[n.Again]:{card:this.again,log:{rating:n.Again,state:e.state,due:this.last_review,stability:e.stability,difficulty:e.difficulty,elapsed_days:e.elapsed_days,last_elapsed_days:this.last_elapsed_days,scheduled_days:e.scheduled_days,review:a}},[n.Hard]:{card:this.hard,log:{rating:n.Hard,state:e.state,due:this.last_review,stability:e.stability,difficulty:e.difficulty,elapsed_days:e.elapsed_days,last_elapsed_days:this.last_elapsed_days,scheduled_days:e.scheduled_days,review:a}},[n.Good]:{card:this.good,log:{rating:n.Good,state:e.state,due:this.last_review,stability:e.stability,difficulty:e.difficulty,elapsed_days:e.elapsed_days,last_elapsed_days:this.last_elapsed_days,scheduled_days:e.scheduled_days,review:a}},[n.Easy]:{card:this.easy,log:{rating:n.Easy,state:e.state,due:this.last_review,stability:e.stability,difficulty:e.difficulty,elapsed_days:e.elapsed_days,last_elapsed_days:this.last_elapsed_days,scheduled_days:e.scheduled_days,review:a}}}}}const z=.9,F=36500,A=[.5701,1.4436,4.1386,10.9355,5.1443,1.2006,.8627,.0362,1.629,.1342,1.0166,2.1174,.0839,.3204,1.4676,.219,2.8237],C=!1,q="3.5.7",m=t=>({request_retention:(t==null?void 0:t.request_retention)||z,maximum_interval:(t==null?void 0:t.maximum_interval)||F,w:(t==null?void 0:t.w)||A,enable_fuzz:(t==null?void 0:t.enable_fuzz)||C});function I(t,e){const a={due:t?h(t):new Date,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:0,lapses:0,state:d.New,last_review:void 0};return e&&typeof e=="function"?e(a):a}const w=-.5,v=19/81;class H{param;intervalModifier;seed;constructor(e){this.param=new Proxy(m(e),this.params_handler_proxy()),this.intervalModifier=this.calculate_interval_modifier(this.param.request_retention)}get interval_modifier(){return this.intervalModifier}calculate_interval_modifier(e){if(e<=0||e>1)throw new Error("Requested retention rate should be in the range (0,1]");return+((Math.pow(e,1/w)-1)/v).toFixed(8)}get parameters(){return this.param}set parameters(e){this.update_parameters(e)}params_handler_proxy(){const e=this;return{set:function(a,r,i){return r==="request_retention"&&Number.isFinite(i)&&(e.intervalModifier=e.calculate_interval_modifier(Number(i))),a[r]=i,!0}}}update_parameters(e){const a=m(e);for(const r in a)if(r in this.param){const i=r;this.param[i]=a[i]}}init_ds(e){e.again.difficulty=this.init_difficulty(n.Again),e.again.stability=this.init_stability(n.Again),e.hard.difficulty=this.init_difficulty(n.Hard),e.hard.stability=this.init_stability(n.Hard),e.good.difficulty=this.init_difficulty(n.Good),e.good.stability=this.init_stability(n.Good),e.easy.difficulty=this.init_difficulty(n.Easy),e.easy.stability=this.init_stability(n.Easy)}next_ds(e,a,r,i){e.again.difficulty=this.next_difficulty(a,n.Again),e.again.stability=this.next_forget_stability(a,r,i),e.hard.difficulty=this.next_difficulty(a,n.Hard),e.hard.stability=this.next_recall_stability(a,r,i,n.Hard),e.good.difficulty=this.next_difficulty(a,n.Good),e.good.stability=this.next_recall_stability(a,r,i,n.Good),e.easy.difficulty=this.next_difficulty(a,n.Easy),e.easy.stability=this.next_recall_stability(a,r,i,n.Easy)}init_stability(e){return Math.max(this.param.w[e-1],.1)}init_difficulty(e){return+Math.min(Math.max(this.param.w[4]-(e-3)*this.param.w[5],1),10).toFixed(8)}apply_fuzz(e,a,r){if(!r||e<2.5)return Math.round(e);const i=G(this.seed)(),{min_ivl:s,max_ivl:l}=D(e,a,this.param.maximum_interval);return Math.floor(i*(l-s+1)+s)}next_interval(e,a,r=this.param.enable_fuzz){const i=Math.min(Math.max(1,Math.round(e*this.intervalModifier)),this.param.maximum_interval);return this.apply_fuzz(i,a,r)}next_difficulty(e,a){const r=e-this.param.w[6]*(a-3);return this.constrain_difficulty(this.mean_reversion(this.param.w[4],r))}constrain_difficulty(e){return Math.min(Math.max(+e.toFixed(8),1),10)}mean_reversion(e,a){return+(this.param.w[7]*e+(1-this.param.w[7])*a).toFixed(8)}next_recall_stability(e,a,r,i){const s=n.Hard===i?this.param.w[15]:1,l=n.Easy===i?this.param.w[16]:1;return+(a*(1+Math.exp(this.param.w[8])*(11-e)*Math.pow(a,-this.param.w[9])*(Math.exp((1-r)*this.param.w[10])-1)*s*l)).toFixed(8)}next_forget_stability(e,a,r){return+(this.param.w[11]*Math.pow(e,-this.param.w[12])*(Math.pow(a+1,this.param.w[13])-1)*Math.exp((1-r)*this.param.w[14])).toFixed(8)}forgetting_curve(e,a){return+Math.pow(1+v*e/a,w).toFixed(8)}}class P extends H{constructor(e){super(e)}preProcessCard(e){return{...e,state:_(e.state),due:h(e.due),last_review:e.last_review?h(e.last_review):void 0}}preProcessDate(e){return h(e)}preProcessLog(e){return{...e,due:h(e.due),rating:$(e.rating),state:_(e.state),review:h(e.review)}}repeat(e,a,r){const i=this.preProcessCard(e);a=this.preProcessDate(a);const s=new S(i,a).update_state(i.state);this.seed=String(a.getTime())+String(i.reps);let l,o,u;const c=i.elapsed_days;switch(i.state){case d.New:this.init_ds(s),s.again.due=a.scheduler(1),s.hard.due=a.scheduler(5),s.good.due=a.scheduler(10),l=this.next_interval(s.easy.stability,c),s.easy.scheduled_days=l,s.easy.due=a.scheduler(l,!0);break;case d.Learning:case d.Relearning:u=0,o=this.next_interval(s.good.stability,c),l=Math.max(this.next_interval(s.easy.stability,c),o+1),s.schedule(a,u,o,l);break;case d.Review:{const N=i.difficulty,x=i.stability,L=this.forgetting_curve(c,x);this.next_ds(s,N,x,L),u=this.next_interval(s.hard.stability,c),o=this.next_interval(s.good.stability,c),u=Math.min(u,o),o=Math.max(o,u+1),l=Math.max(this.next_interval(s.easy.stability,c),o+1),s.schedule(a,u,o,l);break}}const b=s.record_log(i,a);return r&&typeof r=="function"?r(b):b}get_retrievability(e,a,r=!0){const i=this.preProcessCard(e);if(a=this.preProcessDate(a),i.state!==d.Review)return;const s=Math.max(a.diff(i.last_review,"days"),0),l=this.forgetting_curve(s,Math.round(i.stability));return r?`${(l*100).toFixed(2)}%`:l}rollback(e,a,r){const i=this.preProcessCard(e),s=this.preProcessLog(a);if(s.rating===n.Manual)throw new Error("Cannot rollback a manual rating");let l,o,u;switch(s.state){case d.New:l=s.due,o=void 0,u=0;break;case d.Learning:case d.Relearning:case d.Review:l=s.review,o=s.due,u=i.lapses-(s.rating===n.Again&&s.state===d.Review?1:0);break}const c={...i,due:l,stability:s.stability,difficulty:s.difficulty,elapsed_days:s.last_elapsed_days,scheduled_days:s.scheduled_days,reps:Math.max(0,i.reps-1),lapses:Math.max(0,u),state:s.state,last_review:o};return r&&typeof r=="function"?r(c):c}forget(e,a,r=!1,i){const s=this.preProcessCard(e);a=this.preProcessDate(a);const l=s.state===d.New?0:a.diff(s.last_review,"days"),o={rating:n.Manual,state:s.state,due:s.due,stability:s.stability,difficulty:s.difficulty,elapsed_days:0,last_elapsed_days:s.elapsed_days,scheduled_days:l,review:a},u={card:{...s,due:a,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:r?0:s.reps,lapses:r?0:s.lapses,state:d.New,last_review:s.last_review},log:o};return i&&typeof i=="function"?i(u):u}reschedule(e,a={}){if(!Array.isArray(e))throw new Error("cards must be an array");const r=[];for(const i of e){if(_(i.state)!==d.Review||!i.last_review)continue;const s=Math.floor(i.scheduled_days),l=this.next_interval(+i.stability.toFixed(2),Math.round(i.elapsed_days),a.enable_fuzz??!0);if(l===s||l===0)continue;const o={...i};o.scheduled_days=l;const u=f(o.last_review,l,!0);a.dateHandler&&typeof a.dateHandler=="function"?o.due=a.dateHandler(u):o.due=u,r.push(o)}return r}}const O=t=>new P(t||{});exports.DECAY=w,exports.FACTOR=v,exports.FSRS=P,exports.FSRSAlgorithm=H,exports.FSRSVersion=q,exports.Grades=k,exports.Rating=n,exports.SchedulingCard=S,exports.State=d,exports.createEmptyCard=I,exports.date_diff=M,exports.date_scheduler=f,exports.default_enable_fuzz=C,exports.default_maximum_interval=F,exports.default_request_retention=z,exports.default_w=A,exports.fixDate=h,exports.fixRating=$,exports.fixState=_,exports.formatDate=R,exports.fsrs=O,exports.generatorParameters=m,exports.get_fuzz_range=D,exports.show_diff_message=E,module.exports=Object.assign(exports.default||{},exports);
|
|
1
|
+
"use strict";var T=require("seedrandom"),u=(s=>(s[s.New=0]="New",s[s.Learning=1]="Learning",s[s.Review=2]="Review",s[s.Relearning=3]="Relearning",s))(u||{}),l=(s=>(s[s.Manual=0]="Manual",s[s.Again=1]="Again",s[s.Hard=2]="Hard",s[s.Good=3]="Good",s[s.Easy=4]="Easy",s))(l||{});class o{static card(t){return{...t,state:o.state(t.state),due:o.time(t.due),last_review:t.last_review?o.time(t.last_review):void 0}}static rating(t){if(typeof t=="string"){const i=t.charAt(0).toUpperCase(),e=t.slice(1).toLowerCase(),a=l[`${i}${e}`];if(a===void 0)throw new Error(`Invalid rating:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid rating:[${t}]`)}static state(t){if(typeof t=="string"){const i=t.charAt(0).toUpperCase(),e=t.slice(1).toLowerCase(),a=u[`${i}${e}`];if(a===void 0)throw new Error(`Invalid state:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid state:[${t}]`)}static time(t){if(typeof t=="object"&&t instanceof Date)return t;if(typeof t=="string"){const i=Date.parse(t);if(isNaN(i))throw new Error(`Invalid date:[${t}]`);return new Date(i)}else if(typeof t=="number")return new Date(t);throw new Error(`Invalid date:[${t}]`)}static review_log(t){return{...t,due:o.time(t.due),rating:o.rating(t.rating),state:o.state(t.state),review:o.time(t.review)}}}const M=.9,S=36500,R=[.4197,1.1869,3.0412,15.2441,7.1434,.6477,1.0007,.0674,1.6597,.1712,1.1178,2.0225,.0904,.3025,2.1214,.2498,2.9466,.4891,.6468],E=!1,A=!0,V="v4.0.0 using FSRS V5.0",g=s=>{let t=R;return s!=null&&s.w&&(s.w.length===19?t=s==null?void 0:s.w:s.w.length===17&&(t=s==null?void 0:s.w.concat([0,0]),console.debug("[FSRS V5]auto fill w to 19 length"))),{request_retention:(s==null?void 0:s.request_retention)||M,maximum_interval:(s==null?void 0:s.maximum_interval)||S,w:t,enable_fuzz:(s==null?void 0:s.enable_fuzz)??E,enable_short_term:(s==null?void 0:s.enable_short_term)??A}};function O(s,t){const i={due:s?o.time(s):new Date,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:0,lapses:0,state:u.New,last_review:void 0};return t&&typeof t=="function"?t(i):i}Date.prototype.scheduler=function(s,t){return w(this,s,t)},Date.prototype.diff=function(s,t){return $(this,s,t)},Date.prototype.format=function(){return F(this)},Date.prototype.dueFormat=function(s,t,i){return z(this,s,t,i)};function w(s,t,i){return new Date(i?f(s).getTime()+t*24*60*60*1e3:f(s).getTime()+t*60*1e3)}function $(s,t,i){if(!s||!t)throw new Error("Invalid date");const e=f(s).getTime()-f(t).getTime();let a=0;switch(i){case"days":a=Math.floor(e/(24*60*60*1e3));break;case"minutes":a=Math.floor(e/(60*1e3));break}return a}function F(s){const t=f(s),i=t.getFullYear(),e=t.getMonth()+1,a=t.getDate(),r=t.getHours(),n=t.getMinutes(),d=t.getSeconds();return`${i}-${m(e)}-${m(a)} ${m(r)}:${m(n)}:${m(d)}`}function m(s){return s<10?`0${s}`:`${s}`}const v=[60,60,24,31,12],x=["second","min","hour","day","month","year"];function z(s,t,i,e=x){s=f(s),t=f(t),e.length!==x.length&&(e=x);let a=s.getTime()-t.getTime(),r;for(a/=1e3,r=0;r<v.length&&!(a<v[r]);r++)a/=v[r];return`${Math.floor(a)}${i?e[r]:""}`}function f(s){return o.time(s)}function P(s){return o.state(s)}function Y(s){return o.rating(s)}const j=[l.Again,l.Hard,l.Good,l.Easy],U=[{start:2.5,end:7,factor:.15},{start:7,end:20,factor:.1},{start:20,end:1/0,factor:.05}];function H(s,t,i){let e=1;for(const n of U)e+=n.factor*Math.max(Math.min(s,n.end)-n.start,0);s=Math.min(s,i);let a=Math.max(2,Math.round(s-e));const r=Math.min(Math.round(s+e),i);return s>t&&(a=Math.max(a,t+1)),a=Math.min(a,r),{min_ivl:a,max_ivl:r}}const p=-.5,b=19/81;class G{param;intervalModifier;_seed;constructor(t){this.param=new Proxy(g(t),this.params_handler_proxy()),this.intervalModifier=this.calculate_interval_modifier(this.param.request_retention)}get interval_modifier(){return this.intervalModifier}set seed(t){this._seed=t}calculate_interval_modifier(t){if(t<=0||t>1)throw new Error("Requested retention rate should be in the range (0,1]");return+((Math.pow(t,1/p)-1)/b).toFixed(8)}get parameters(){return this.param}set parameters(t){this.update_parameters(t)}params_handler_proxy(){const t=this;return{set:function(i,e,a){return e==="request_retention"&&Number.isFinite(a)&&(t.intervalModifier=t.calculate_interval_modifier(Number(a))),i[e]=a,!0}}}update_parameters(t){const i=g(t);for(const e in i)if(e in this.param){const a=e;this.param[a]=i[a]}}init_stability(t){return Math.max(this.param.w[t-1],.1)}init_difficulty(t){return this.constrain_difficulty(this.param.w[4]-Math.exp((t-1)*this.param.w[5])+1)}apply_fuzz(t,i,e){if(!e||t<2.5)return Math.round(t);const a=T(this.seed)(),{min_ivl:r,max_ivl:n}=H(t,i,this.param.maximum_interval);return Math.floor(a*(n-r+1)+r)}next_interval(t,i,e=this.param.enable_fuzz){const a=Math.min(Math.max(1,Math.round(t*this.intervalModifier)),this.param.maximum_interval);return this.apply_fuzz(a,i,e)}next_difficulty(t,i){const e=t-this.param.w[6]*(i-3);return this.constrain_difficulty(this.mean_reversion(this.param.w[4],e))}constrain_difficulty(t){return Math.min(Math.max(+t.toFixed(8),1),10)}mean_reversion(t,i){return+(this.param.w[7]*t+(1-this.param.w[7])*i).toFixed(8)}next_recall_stability(t,i,e,a){const r=l.Hard===a?this.param.w[15]:1,n=l.Easy===a?this.param.w[16]:1;return+(i*(1+Math.exp(this.param.w[8])*(11-t)*Math.pow(i,-this.param.w[9])*(Math.exp((1-e)*this.param.w[10])-1)*r*n)).toFixed(8)}next_forget_stability(t,i,e){return+(this.param.w[11]*Math.pow(t,-this.param.w[12])*(Math.pow(i+1,this.param.w[13])-1)*Math.exp((1-e)*this.param.w[14])).toFixed(8)}next_short_term_stability(t,i){return+(t*Math.exp(this.param.w[17]*(i-3+this.param.w[18]))).toFixed(8)}forgetting_curve(t,i){return+Math.pow(1+b*t/i,p).toFixed(8)}}class L{last;current;review_time;next=new Map;algorithm;constructor(t,i,e){this.algorithm=e,this.last=o.card(t),this.current=o.card(t),this.review_time=o.time(i),this.init()}init(){const{state:t,last_review:i}=this.current;let e=0;t!==u.New&&i&&(e=this.review_time.diff(i,"days")),this.current.last_review=this.review_time,this.current.elapsed_days=e,this.current.reps+=1,this.initSeed()}preview(){return{[l.Again]:this.review(l.Again),[l.Hard]:this.review(l.Hard),[l.Good]:this.review(l.Good),[l.Easy]:this.review(l.Easy)}}review(t){const{state:i}=this.last;let e;switch(i){case u.New:e=this.newState(t);break;case u.Learning:case u.Relearning:e=this.learningState(t);break;case u.Review:e=this.reviewState(t);break}if(e)return e;throw new Error("Invalid grade")}initSeed(){const t=this.review_time.getTime(),i=this.current.reps,e=this.current.difficulty*this.current.stability;this.algorithm.seed=`${t}_${i}_${e}`}buildLog(t){const{last_review:i,due:e,elapsed_days:a}=this.last;return{rating:t,state:this.current.state,due:i||e,stability:this.current.stability,difficulty:this.current.difficulty,elapsed_days:this.current.elapsed_days,last_elapsed_days:a,scheduled_days:this.current.scheduled_days,review:this.review_time}}}class k extends L{newState(t){const i=this.next.get(t);if(i)return i;const e=o.card(this.current);switch(e.difficulty=this.algorithm.init_difficulty(t),e.stability=this.algorithm.init_stability(t),t){case l.Again:e.scheduled_days=0,e.due=this.review_time.scheduler(1),e.state=u.Learning;break;case l.Hard:e.scheduled_days=0,e.due=this.review_time.scheduler(5),e.state=u.Learning;break;case l.Good:e.scheduled_days=0,e.due=this.review_time.scheduler(10),e.state=u.Learning;break;case l.Easy:{const r=this.algorithm.next_interval(e.stability,this.current.elapsed_days,this.algorithm.parameters.enable_fuzz);e.scheduled_days=r,e.due=this.review_time.scheduler(r,!0),e.state=u.Review;break}default:throw new Error("Invalid grade")}const a={card:e,log:this.buildLog(t)};return this.next.set(t,a),a}learningState(t){const i=this.next.get(t);if(i)return i;const{state:e,difficulty:a,stability:r}=this.last,n=o.card(this.current),d=this.current.elapsed_days;switch(n.difficulty=this.algorithm.next_difficulty(a,t),n.stability=this.algorithm.next_short_term_stability(r,t),t){case l.Again:{n.scheduled_days=0,n.due=this.review_time.scheduler(5,!1),n.state=e;break}case l.Hard:{n.scheduled_days=0,n.due=this.review_time.scheduler(10),n.state=e;break}case l.Good:{const c=this.algorithm.next_interval(n.stability,d);n.scheduled_days=c,n.due=this.review_time.scheduler(c,!0),n.state=u.Review;break}case l.Easy:{const c=this.algorithm.next_short_term_stability(r,l.Good),_=this.algorithm.next_interval(c,d),y=Math.max(this.algorithm.next_interval(n.stability,d),_+1);n.scheduled_days=y,n.due=this.review_time.scheduler(y,!0),n.state=u.Review;break}default:throw new Error("Invalid grade")}const h={card:n,log:this.buildLog(t)};return this.next.set(t,h),h}reviewState(t){const i=this.next.get(t);if(i)return i;const e=this.current.elapsed_days,{difficulty:a,stability:r}=this.last,n=this.algorithm.forgetting_curve(e,r),d=o.card(this.current),h=o.card(this.current),c=o.card(this.current),_=o.card(this.current);this.next_ds(d,h,c,_,a,r,n),this.next_interval(d,h,c,_,e),this.next_state(d,h,c,_),d.lapses+=1;const y={card:d,log:this.buildLog(l.Again)},I={card:h,log:super.buildLog(l.Hard)},q={card:c,log:super.buildLog(l.Good)},C={card:_,log:super.buildLog(l.Easy)};return this.next.set(l.Again,y),this.next.set(l.Hard,I),this.next.set(l.Good,q),this.next.set(l.Easy,C),this.next.get(t)}next_ds(t,i,e,a,r,n,d){t.difficulty=this.algorithm.next_difficulty(r,l.Again),t.stability=this.algorithm.next_forget_stability(r,n,d),i.difficulty=this.algorithm.next_difficulty(r,l.Hard),i.stability=this.algorithm.next_recall_stability(r,n,d,l.Hard),e.difficulty=this.algorithm.next_difficulty(r,l.Good),e.stability=this.algorithm.next_recall_stability(r,n,d,l.Good),a.difficulty=this.algorithm.next_difficulty(r,l.Easy),a.stability=this.algorithm.next_recall_stability(r,n,d,l.Easy)}next_interval(t,i,e,a,r){let n,d;n=this.algorithm.next_interval(i.stability,r),d=this.algorithm.next_interval(e.stability,r),n=Math.min(n,d),d=Math.max(d,n+1);const h=Math.max(this.algorithm.next_interval(a.stability,r),d+1);t.scheduled_days=0,t.due=this.review_time.scheduler(5),i.scheduled_days=n,i.due=this.review_time.scheduler(n,!0),e.scheduled_days=d,e.due=this.review_time.scheduler(d,!0),a.scheduled_days=h,a.due=this.review_time.scheduler(h,!0)}next_state(t,i,e,a){t.state=u.Relearning,i.state=u.Review,e.state=u.Review,a.state=u.Review}}class D extends L{newState(t){const i=this.next.get(t);if(i)return i;const e=this.algorithm.init_difficulty(t),a=this.algorithm.init_stability(t),r=0;this.current.difficulty=e,this.current.stability=a,this.current.scheduled_days=0,this.current.elapsed_days=0;const n=o.card(this.current),d=o.card(this.current),h=o.card(this.current),c=o.card(this.current);return this.next_short_term_ds(n,d,h,c,e,a),this.next_interval(n,d,h,c,r),this.next_state(n,d,h,c),this.update_next(n,d,h,c),this.next.get(t)}next_short_term_ds(t,i,e,a,r,n){t.difficulty=this.algorithm.next_difficulty(r,l.Again),t.stability=this.algorithm.next_short_term_stability(n,l.Again),i.difficulty=this.algorithm.next_difficulty(r,l.Hard),i.stability=this.algorithm.next_short_term_stability(n,l.Hard),e.difficulty=this.algorithm.next_difficulty(r,l.Good),e.stability=this.algorithm.next_short_term_stability(n,l.Good),a.difficulty=this.algorithm.next_difficulty(r,l.Easy),a.stability=this.algorithm.next_short_term_stability(n,l.Easy)}learningState(t){return this.reviewState(t)}reviewState(t){const i=this.next.get(t);if(i)return i;const e=this.current.elapsed_days,{difficulty:a,stability:r}=this.last,n=this.algorithm.forgetting_curve(e,r),d=o.card(this.current),h=o.card(this.current),c=o.card(this.current),_=o.card(this.current);return this.next_ds(d,h,c,_,a,r,n),this.next_interval(d,h,c,_,e),this.next_state(d,h,c,_),d.lapses+=1,this.update_next(d,h,c,_),this.next.get(t)}next_ds(t,i,e,a,r,n,d){t.difficulty=this.algorithm.next_difficulty(r,l.Again),t.stability=this.algorithm.next_forget_stability(r,n,d),i.difficulty=this.algorithm.next_difficulty(r,l.Hard),i.stability=this.algorithm.next_recall_stability(r,n,d,l.Hard),e.difficulty=this.algorithm.next_difficulty(r,l.Good),e.stability=this.algorithm.next_recall_stability(r,n,d,l.Good),a.difficulty=this.algorithm.next_difficulty(r,l.Easy),a.stability=this.algorithm.next_recall_stability(r,n,d,l.Easy)}next_interval(t,i,e,a,r){let n,d,h,c;n=this.algorithm.next_interval(t.stability,r),d=this.algorithm.next_interval(i.stability,r),h=this.algorithm.next_interval(e.stability,r),c=this.algorithm.next_interval(a.stability,r),n=Math.min(n,d),d=Math.max(d,n+1),h=Math.max(h,d+1),c=Math.max(c,h+1),t.scheduled_days=n,t.due=this.review_time.scheduler(n,!0),i.scheduled_days=d,i.due=this.review_time.scheduler(d,!0),e.scheduled_days=h,e.due=this.review_time.scheduler(h,!0),a.scheduled_days=c,a.due=this.review_time.scheduler(c,!0)}next_state(t,i,e,a){t.state=u.Review,i.state=u.Review,e.state=u.Review,a.state=u.Review}update_next(t,i,e,a){const r={card:t,log:this.buildLog(l.Again)},n={card:i,log:super.buildLog(l.Hard)},d={card:e,log:super.buildLog(l.Good)},h={card:a,log:super.buildLog(l.Easy)};this.next.set(l.Again,r),this.next.set(l.Hard,n),this.next.set(l.Good,d),this.next.set(l.Easy,h)}}class N extends G{Schduler;constructor(t){super(t);const{enable_short_term:i}=this.parameters;this.Schduler=i?k:D}params_handler_proxy(){const t=this;return{set:function(i,e,a){return e==="request_retention"&&Number.isFinite(a)?t.intervalModifier=t.calculate_interval_modifier(Number(a)):e==="enable_short_term"&&(t.Schduler=a===!0?k:D),i[e]=a,!0}}}repeat(t,i,e){const a=this.Schduler,r=new a(t,i,this).preview();return e&&typeof e=="function"?e(r):r}next(t,i,e,a){const r=this.Schduler,n=new r(t,i,this),d=o.rating(e);if(d===l.Manual)throw new Error("Cannot review a manual rating");const h=n.review(d);return a&&typeof a=="function"?a(h):h}get_retrievability(t,i,e=!0){const a=o.card(t);if(i=o.time(i),a.state!==u.Review)return;const r=Math.max(i.diff(a.last_review,"days"),0),n=this.forgetting_curve(r,Math.round(a.stability));return e?`${(n*100).toFixed(2)}%`:n}rollback(t,i,e){const a=o.card(t),r=o.review_log(i);if(r.rating===l.Manual)throw new Error("Cannot rollback a manual rating");let n,d,h;switch(r.state){case u.New:n=r.due,d=void 0,h=0;break;case u.Learning:case u.Relearning:case u.Review:n=r.review,d=r.due,h=a.lapses-(r.rating===l.Again&&r.state===u.Review?1:0);break}const c={...a,due:n,stability:r.stability,difficulty:r.difficulty,elapsed_days:r.last_elapsed_days,scheduled_days:r.scheduled_days,reps:Math.max(0,a.reps-1),lapses:Math.max(0,h),state:r.state,last_review:d};return e&&typeof e=="function"?e(c):c}forget(t,i,e=!1,a){const r=o.card(t);i=o.time(i);const n=r.state===u.New?0:i.diff(r.last_review,"days"),d={rating:l.Manual,state:r.state,due:r.due,stability:r.stability,difficulty:r.difficulty,elapsed_days:0,last_elapsed_days:r.elapsed_days,scheduled_days:n,review:i},h={card:{...r,due:i,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:e?0:r.reps,lapses:e?0:r.lapses,state:u.New,last_review:r.last_review},log:d};return a&&typeof a=="function"?a(h):h}reschedule(t,i={}){if(!Array.isArray(t))throw new Error("cards must be an array");const e=[];for(const a of t){if(o.state(a.state)!==u.Review||!a.last_review)continue;const r=Math.floor(a.scheduled_days),n=this.next_interval(+a.stability.toFixed(2),Math.round(a.elapsed_days),i.enable_fuzz??!0);if(n===r||n===0)continue;const d={...a};d.scheduled_days=n;const h=w(d.last_review,n,!0);i.dateHandler&&typeof i.dateHandler=="function"?d.due=i.dateHandler(h):d.due=h,e.push(d)}return e}}const B=s=>new N(s||{});exports.DECAY=p,exports.FACTOR=b,exports.FSRS=N,exports.FSRSAlgorithm=G,exports.FSRSVersion=V,exports.Grades=j,exports.Rating=l,exports.State=u,exports.TypeConvert=o,exports.createEmptyCard=O,exports.date_diff=$,exports.date_scheduler=w,exports.default_enable_fuzz=E,exports.default_maximum_interval=S,exports.default_request_retention=M,exports.default_w=R,exports.defualt_enable_short_term=A,exports.fixDate=f,exports.fixRating=Y,exports.fixState=P,exports.formatDate=F,exports.fsrs=B,exports.generatorParameters=g,exports.get_fuzz_range=H,exports.show_diff_message=z,module.exports=Object.assign(exports.default||{},exports);
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/fsrs/models.ts","../src/fsrs/help.ts","../src/fsrs/scheduler.ts","../src/fsrs/default.ts","../src/fsrs/algorithm.ts","../src/fsrs/fsrs.ts"],"sourcesContent":["export type StateType = \"New\" | \"Learning\" | \"Review\" | \"Relearning\";\n\nexport enum State {\n New = 0,\n Learning = 1,\n Review = 2,\n Relearning = 3,\n}\n\nexport type RatingType = \"Manual\" | \"Again\" | \"Hard\" | \"Good\" | \"Easy\";\n\nexport enum Rating {\n Manual = 0,\n Again = 1,\n Hard = 2,\n Good = 3,\n Easy = 4,\n}\n\ntype ExcludeManual<T> = Exclude<T, Rating.Manual>;\n\nexport type Grade = ExcludeManual<Rating>;\n\nexport interface ReviewLog {\n rating: Rating; // Rating of the review (Again, Hard, Good, Easy)\n state: State; // State of the review (New, Learning, Review, Relearning)\n due: Date; // Date of the last scheduling\n stability: number; // Memory stability during the review\n difficulty: number; // Difficulty of the card during the review\n elapsed_days: number; // Number of days elapsed since the last review\n last_elapsed_days: number; // Number of days between the last two reviews\n scheduled_days: number; // Number of days until the next review\n review: Date; // Date of the review\n}\n\nexport type RecordLogItem = {\n card: Card;\n log: ReviewLog;\n};\nexport type RecordLog = {\n [key in Grade]: RecordLogItem;\n};\n\nexport interface Card {\n due: Date; // Due date\n stability: number; // Stability\n difficulty: number; // Difficulty level\n elapsed_days: number; // Number of days elapsed\n scheduled_days: number; // Number of days scheduled\n reps: number; // Repetition count\n lapses: number; // Number of lapses or mistakes\n state: State; // Card's state (New, Learning, Review, Relearning)\n last_review?: Date; // Date of the last review (optional)\n}\n\nexport interface CardInput extends Omit<Card, \"state\" | \"due\" | \"last_review\"> {\n state: StateType | State; // Card's state (New, Learning, Review, Relearning)\n due: DateInput; // Due date\n last_review?: DateInput | null; // Date of the last review (optional)\n}\n\nexport type DateInput = Date | number | string;\n\nexport interface ReviewLogInput\n extends Omit<ReviewLog, \"rating\" | \"state\" | \"due\" | \"review\"> {\n rating: RatingType | Rating; // Rating of the review (Again, Hard, Good, Easy)\n state: StateType | State; // Card's state (New, Learning, Review, Relearning)\n due: DateInput; // Due date\n review: DateInput; // Date of the last review\n}\n\nexport interface FSRSParameters {\n request_retention: number;\n maximum_interval: number;\n w: number[];\n enable_fuzz: boolean;\n}\n\nexport type RescheduleOptions = {\n enable_fuzz?: boolean;\n dateHandler?: (date: Date) => DateInput;\n};\n","import type { int, unit } from \"./type\";\nimport type { DateInput, Grade } from \"./models\";\nimport { Rating, State } from \"./models\";\n\ndeclare global {\n export interface Date {\n scheduler(t: int, isDay?: boolean): Date;\n\n diff(pre: Date, unit: unit): int;\n\n format(): string;\n\n dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string;\n }\n}\n\nDate.prototype.scheduler = function (t: int, isDay?: boolean): Date {\n return date_scheduler(this, t, isDay);\n};\n\n/**\n * 当前时间与之前的时间差值\n * @param pre 比当前时间还要之前\n * @param unit 单位: days | minutes\n */\nDate.prototype.diff = function (pre: Date, unit: unit): int {\n return date_diff(this, pre, unit) as int;\n};\n\nDate.prototype.format = function (): string {\n return formatDate(this);\n};\n\nDate.prototype.dueFormat = function (\n last_review: Date,\n unit?: boolean,\n timeUnit?: string[],\n) {\n return show_diff_message(this, last_review, unit, timeUnit);\n};\n\n/**\n * 计算日期和时间的偏移,并返回一个新的日期对象。\n * @param now 当前日期和时间\n * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟\n * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移\n * @returns 偏移后的日期和时间对象\n */\nexport function date_scheduler(\n now: DateInput,\n t: number,\n isDay?: boolean,\n): Date {\n return new Date(\n isDay\n ? fixDate(now).getTime() + t * 24 * 60 * 60 * 1000\n : fixDate(now).getTime() + t * 60 * 1000,\n );\n}\n\nexport function date_diff(now: DateInput, pre: DateInput, unit: unit): number {\n if (!now || !pre) {\n throw new Error(\"Invalid date\");\n }\n const diff = fixDate(now).getTime() - fixDate(pre).getTime();\n let r = 0;\n switch (unit) {\n case \"days\":\n r = Math.floor(diff / (24 * 60 * 60 * 1000));\n break;\n case \"minutes\":\n r = Math.floor(diff / (60 * 1000));\n break;\n }\n return r;\n}\n\nexport function formatDate(dateInput: DateInput): string {\n const date = fixDate(dateInput);\n const year: number = date.getFullYear();\n const month: number = date.getMonth() + 1;\n const day: number = date.getDate();\n const hours: number = date.getHours();\n const minutes: number = date.getMinutes();\n const seconds: number = date.getSeconds();\n\n return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(\n minutes,\n )}:${padZero(seconds)}`;\n}\n\nfunction padZero(num: number): string {\n return num < 10 ? `0${num}` : `${num}`;\n}\n\nconst TIMEUNIT = [60, 60, 24, 31, 12];\nconst TIMEUNITFORMAT = [\"second\", \"min\", \"hour\", \"day\", \"month\", \"year\"];\n\nexport function show_diff_message(\n due: DateInput,\n last_review: DateInput,\n unit?: boolean,\n timeUnit: string[] = TIMEUNITFORMAT,\n): string {\n due = fixDate(due);\n last_review = fixDate(last_review);\n if (timeUnit.length !== TIMEUNITFORMAT.length) {\n timeUnit = TIMEUNITFORMAT;\n }\n let diff = due.getTime() - last_review.getTime();\n let i;\n diff /= 1000;\n for (i = 0; i < TIMEUNIT.length; i++) {\n if (diff < TIMEUNIT[i]) {\n break;\n } else {\n diff /= TIMEUNIT[i];\n }\n }\n return `${Math.floor(diff)}${unit ? timeUnit[i] : \"\"}`;\n}\n\nexport function fixDate(value: unknown) {\n if (typeof value === \"object\" && value instanceof Date) {\n return value;\n } else if (typeof value === \"string\") {\n const timestamp = Date.parse(value);\n if (!isNaN(timestamp)) {\n return new Date(timestamp);\n } else {\n throw new Error(`Invalid date:[${value}]`);\n }\n } else if (typeof value === \"number\") {\n return new Date(value);\n }\n throw new Error(`Invalid date:[${value}]`);\n}\n\nexport function fixState(value: unknown): State {\n if (typeof value === \"string\") {\n const firstLetter = value.charAt(0).toUpperCase();\n const restOfString = value.slice(1).toLowerCase();\n const ret = State[`${firstLetter}${restOfString}` as keyof typeof State];\n if (ret === undefined) {\n throw new Error(`Invalid state:[${value}]`);\n }\n return ret;\n } else if (typeof value === \"number\") {\n return value as State;\n }\n throw new Error(`Invalid state:[${value}]`);\n}\n\nexport function fixRating(value: unknown): Rating {\n if (typeof value === \"string\") {\n const firstLetter = value.charAt(0).toUpperCase();\n const restOfString = value.slice(1).toLowerCase();\n const ret = Rating[`${firstLetter}${restOfString}` as keyof typeof Rating];\n if (ret === undefined) {\n throw new Error(`Invalid rating:[${value}]`);\n }\n return ret;\n } else if (typeof value === \"number\") {\n return value as Rating;\n }\n throw new Error(`Invalid rating:[${value}]`);\n}\n\nexport const Grades: Readonly<Grade[]> = [\n Rating.Again,\n Rating.Hard,\n Rating.Good,\n Rating.Easy,\n] as const;\n\nconst FUZZ_RANGES = [\n {\n start: 2.5,\n end: 7.0,\n factor: 0.15,\n },\n {\n start: 7.0,\n end: 20.0,\n factor: 0.1,\n },\n {\n start: 20.0,\n end: Infinity,\n factor: 0.05,\n },\n] as const;\n\nexport function get_fuzz_range(\n interval: number,\n elapsed_days: number,\n maximum_interval: number,\n) {\n let delta = 1.0;\n for (const range of FUZZ_RANGES) {\n delta +=\n range.factor * Math.max(Math.min(interval, range.end) - range.start, 0.0);\n }\n interval = Math.min(interval, maximum_interval);\n let min_ivl = Math.max(2, Math.round(interval - delta));\n const max_ivl = Math.min(Math.round(interval + delta), maximum_interval);\n if (interval > elapsed_days) {\n min_ivl = Math.max(min_ivl, elapsed_days + 1);\n }\n min_ivl = Math.min(min_ivl, max_ivl);\n return { min_ivl, max_ivl };\n}\n","import { Card, Rating, RecordLog, State } from \"./models\";\nimport { date_scheduler } from \"./help\";\n\nexport class SchedulingCard {\n again: Card;\n hard: Card;\n good: Card;\n easy: Card;\n last_review: Date;\n last_elapsed_days: number;\n\n private copy(card: Card): Card {\n return {\n ...card,\n };\n }\n\n constructor(card: Card, now: Date) {\n this.last_review = card.last_review || card.due;\n this.last_elapsed_days = card.elapsed_days;\n card.elapsed_days =\n card.state === State.New ? 0 : now.diff(card.last_review as Date, \"days\"); //相距时间\n card.last_review = now; // 上次复习时间\n card.reps += 1;\n this.again = this.copy(card);\n this.hard = this.copy(card);\n this.good = this.copy(card);\n this.easy = this.copy(card);\n }\n\n update_state(state: State) {\n if (state === State.New) {\n this.again.state = State.Learning;\n this.hard.state = State.Learning;\n this.good.state = State.Learning;\n this.easy.state = State.Review;\n } else if (state === State.Learning || state === State.Relearning) {\n this.again.state = state;\n this.hard.state = state;\n this.good.state = State.Review;\n this.easy.state = State.Review;\n } else if (state === State.Review) {\n this.again.state = State.Relearning;\n this.hard.state = State.Review;\n this.good.state = State.Review;\n this.easy.state = State.Review;\n this.again.lapses += 1;\n }\n return this;\n }\n\n schedule(\n now: Date,\n hard_interval: number,\n good_interval: number,\n easy_interval: number,\n ): SchedulingCard {\n this.again.scheduled_days = 0;\n this.hard.scheduled_days = hard_interval;\n this.good.scheduled_days = good_interval;\n this.easy.scheduled_days = easy_interval;\n this.again.due = date_scheduler(now, 5);\n this.hard.due =\n hard_interval > 0\n ? date_scheduler(now, hard_interval, true)\n : date_scheduler(now, 10);\n this.good.due = date_scheduler(now, good_interval, true);\n this.easy.due = date_scheduler(now, easy_interval, true);\n return this;\n }\n\n record_log(card: Card, now: Date): RecordLog {\n return {\n [Rating.Again]: {\n card: this.again,\n log: {\n rating: Rating.Again,\n state: card.state,\n due: this.last_review,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: card.elapsed_days,\n last_elapsed_days: this.last_elapsed_days,\n scheduled_days: card.scheduled_days,\n review: now,\n },\n },\n [Rating.Hard]: {\n card: this.hard,\n log: {\n rating: Rating.Hard,\n state: card.state,\n due: this.last_review,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: card.elapsed_days,\n last_elapsed_days: this.last_elapsed_days,\n scheduled_days: card.scheduled_days,\n review: now,\n },\n },\n [Rating.Good]: {\n card: this.good,\n log: {\n rating: Rating.Good,\n state: card.state,\n due: this.last_review,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: card.elapsed_days,\n last_elapsed_days: this.last_elapsed_days,\n scheduled_days: card.scheduled_days,\n review: now,\n },\n },\n [Rating.Easy]: {\n card: this.easy,\n log: {\n rating: Rating.Easy,\n state: card.state,\n due: this.last_review,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: card.elapsed_days,\n last_elapsed_days: this.last_elapsed_days,\n scheduled_days: card.scheduled_days,\n review: now,\n },\n },\n };\n }\n}\n","import { Card, DateInput, FSRSParameters, State } from \"./models\";\nimport { fixDate } from \"./help\";\n\nexport const default_request_retention = 0.9;\nexport const default_maximum_interval = 36500;\nexport const default_w = [\n 0.5701, 1.4436, 4.1386, 10.9355, 5.1443, 1.2006, 0.8627, 0.0362, 1.629,\n 0.1342, 1.0166, 2.1174, 0.0839, 0.3204, 1.4676, 0.219, 2.8237,\n];\nexport const default_enable_fuzz = false;\n\nexport const FSRSVersion: string = \"3.5.7\";\n\nexport const generatorParameters = (\n props?: Partial<FSRSParameters>,\n): FSRSParameters => {\n return {\n request_retention: props?.request_retention || default_request_retention,\n maximum_interval: props?.maximum_interval || default_maximum_interval,\n w: props?.w || default_w,\n enable_fuzz: props?.enable_fuzz || default_enable_fuzz,\n };\n};\n\n/**\n * Create an empty card\n * @param now Current time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * ```\n * @example\n * ```\n * interface CardUnChecked\n * extends Omit<Card, \"due\" | \"last_review\" | \"state\"> {\n * cid: string;\n * due: Date | number;\n * last_review: Date | null | number;\n * state: StateType;\n * }\n *\n * function cardAfterHandler(card: Card) {\n * return {\n * ...card,\n * cid: \"test001\",\n * state: State[card.state],\n * last_review: card.last_review ?? null,\n * } as CardUnChecked;\n * }\n *\n * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);\n * ```\n */\nexport function createEmptyCard<R = Card>(\n now?: DateInput,\n afterHandler?: (card: Card) => R,\n): R {\n const emptyCard: Card = {\n due: now ? fixDate(now) : new Date(),\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: 0,\n lapses: 0,\n state: State.New,\n last_review: undefined,\n };\n if (afterHandler && typeof afterHandler === \"function\") {\n return afterHandler(emptyCard);\n } else {\n return emptyCard as R;\n }\n}\n","import pseudorandom from \"seedrandom\";\nimport { generatorParameters } from \"./default\";\nimport { SchedulingCard } from \"./scheduler\";\nimport { FSRSParameters, Grade, Rating } from \"./models\";\nimport type { int } from \"./type\";\nimport { get_fuzz_range } from \"./help\";\n\n/**\n * @default DECAY = -0.5\n */\nexport const DECAY: number = -0.5;\n/**\n * FACTOR = Math.pow(0.9, 1 / DECAY) - 1= 19 / 81\n *\n * $$\\text{FACTOR} = \\frac{19}{81}$$\n * @default FACTOR = 19 / 81\n */\nexport const FACTOR: number = 19 / 81;\n\n/**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n */\nexport class FSRSAlgorithm {\n protected param!: FSRSParameters;\n protected intervalModifier!: number;\n protected seed?: string;\n\n constructor(params: Partial<FSRSParameters>) {\n this.param = new Proxy(\n generatorParameters(params),\n this.params_handler_proxy(),\n );\n this.intervalModifier = this.calculate_interval_modifier(\n this.param.request_retention,\n );\n }\n\n get interval_modifier(): number {\n return this.intervalModifier;\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n *\n * The formula used is: $$I(r,s) = (r^{\\frac{1}{DECAY}} - 1) / FACTOR \\times s$$\n * @param request_retention 0<request_retention<=1,Requested retention rate\n * @throws {Error} Requested retention rate should be in the range (0,1]\n */\n calculate_interval_modifier(request_retention: number): number {\n if (request_retention <= 0 || request_retention > 1) {\n throw new Error(\"Requested retention rate should be in the range (0,1]\");\n }\n return +((Math.pow(request_retention, 1 / DECAY) - 1) / FACTOR).toFixed(8);\n }\n\n /**\n * Get the parameters of the algorithm.\n */\n get parameters(): FSRSParameters {\n return this.param;\n }\n\n /**\n * Set the parameters of the algorithm.\n * @param params Partial<FSRSParameters>\n */\n set parameters(params: Partial<FSRSParameters>) {\n this.update_parameters(params);\n }\n\n private params_handler_proxy(): ProxyHandler<FSRSParameters> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const _this: FSRSAlgorithm = this;\n return {\n set: function (target, prop, value) {\n if (prop === \"request_retention\" && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value),\n );\n }\n // @ts-ignore\n target[prop] = value;\n return true;\n },\n };\n }\n\n private update_parameters(params: Partial<FSRSParameters>): void {\n const _params = generatorParameters(params);\n for (const key in _params) {\n if (key in this.param) {\n const paramKey = key as keyof FSRSParameters;\n this.param[paramKey] = _params[paramKey] as never;\n }\n }\n }\n\n init_ds(s: SchedulingCard): void {\n s.again.difficulty = this.init_difficulty(Rating.Again);\n s.again.stability = this.init_stability(Rating.Again);\n s.hard.difficulty = this.init_difficulty(Rating.Hard);\n s.hard.stability = this.init_stability(Rating.Hard);\n s.good.difficulty = this.init_difficulty(Rating.Good);\n s.good.stability = this.init_stability(Rating.Good);\n s.easy.difficulty = this.init_difficulty(Rating.Easy);\n s.easy.stability = this.init_stability(Rating.Easy);\n }\n\n /**\n * Updates the difficulty and stability values of the scheduling card based on the last difficulty,\n * last stability, and the current retrievability.\n * @param {SchedulingCard} s scheduling Card\n * @param {number} last_d Difficulty\n * @param {number} last_s Stability\n * @param retrievability Retrievability\n */\n next_ds(\n s: SchedulingCard,\n last_d: number,\n last_s: number,\n retrievability: number,\n ): void {\n s.again.difficulty = this.next_difficulty(last_d, Rating.Again);\n s.again.stability = this.next_forget_stability(\n last_d,\n last_s,\n retrievability,\n );\n s.hard.difficulty = this.next_difficulty(last_d, Rating.Hard);\n s.hard.stability = this.next_recall_stability(\n last_d,\n last_s,\n retrievability,\n Rating.Hard,\n );\n s.good.difficulty = this.next_difficulty(last_d, Rating.Good);\n s.good.stability = this.next_recall_stability(\n last_d,\n last_s,\n retrievability,\n Rating.Good,\n );\n s.easy.difficulty = this.next_difficulty(last_d, Rating.Easy);\n s.easy.stability = this.next_recall_stability(\n last_d,\n last_s,\n retrievability,\n Rating.Easy,\n );\n }\n\n /**\n * The formula used is :\n * $$ S_0(G) = w_{G-1}$$\n * $$S_0 = \\max \\lbrace S_0,0.1\\rbrace $$\n\n * @param g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return Stability (interval when R=90%)\n */\n init_stability(g: Grade): number {\n return Math.max(this.param.w[g - 1], 0.1);\n }\n\n /**\n * The formula used is :\n * $$D_0(G) = w_4 - (G-3) \\cdot w_5 $$\n * $$D_0 = \\min \\lbrace \\max \\lbrace D_0(G),1 \\rbrace,10 \\rbrace$$\n * where the $$D_0(3)=w_4$$ when the first rating is good.\n *\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} Difficulty $$D \\in [1,10]$$\n */\n init_difficulty(g: Grade): number {\n return +Math.min(\n Math.max(this.param.w[4] - (g - 3) * this.param.w[5], 1),\n 10,\n ).toFixed(8);\n }\n\n /**\n * If fuzzing is disabled or ivl is less than 2.5, it returns the original interval.\n * @param {number} ivl - The interval to be fuzzed.\n * @param {number} elapsed_days t days since the last review\n * @param {number} enable_fuzz - This adds a small random delay to the new interval time to prevent cards from sticking together and always being reviewed on the same day.\n * @return {number} - The fuzzed interval.\n **/\n apply_fuzz(ivl: number, elapsed_days: number, enable_fuzz?: boolean): int {\n if (!enable_fuzz || ivl < 2.5) return Math.round(ivl) as int;\n const generator = pseudorandom(this.seed);\n const fuzz_factor = generator();\n const { min_ivl, max_ivl } = get_fuzz_range(\n ivl,\n elapsed_days,\n this.param.maximum_interval,\n );\n return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl) as int;\n }\n\n /**\n * @see The formula used is : {@link FSRSAlgorithm.calculate_interval_modifier}\n * @param {number} s - Stability (interval when R=90%)\n * @param {number} elapsed_days t days since the last review\n * @param {number} enable_fuzz - This adds a small random delay to the new interval time to prevent cards from sticking together and always being reviewed on the same day.\n */\n next_interval(\n s: number,\n elapsed_days: number,\n enable_fuzz: boolean = this.param.enable_fuzz,\n ): int {\n const newInterval = Math.min(\n Math.max(1, Math.round(s * this.intervalModifier)),\n this.param.maximum_interval,\n ) as int;\n return this.apply_fuzz(newInterval, elapsed_days, enable_fuzz);\n }\n\n /**\n * The formula used is :\n * $$\\text{next}_d = D - w_6 \\cdot (R - 2)$$\n * $$D^\\prime(D,R) = w_5 \\cdot D_0(2) +(1 - w_5) \\cdot \\text{next}_d$$\n * @param {number} d Difficulty $$D \\in [1,10]$$\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} $$\\text{next}_D$$\n */\n next_difficulty(d: number, g: Grade): number {\n const next_d = d - this.param.w[6] * (g - 3);\n return this.constrain_difficulty(\n this.mean_reversion(this.param.w[4], next_d),\n );\n }\n\n /**\n * The formula used is :\n * $$\\min \\lbrace \\max \\lbrace D_0,1 \\rbrace,10\\rbrace$$\n * @param {number} difficulty $$D \\in [1,10]$$\n */\n constrain_difficulty(difficulty: number): number {\n return Math.min(Math.max(+difficulty.toFixed(8), 1), 10);\n }\n\n /**\n * The formula used is :\n * $$w_7 \\cdot \\text{init} +(1 - w_7) \\cdot \\text{current}$$\n * @param {number} init $$w_2 : D_0(3) = w_2 + (R-2) \\cdot w_3= w_2$$\n * @param {number} current $$D - w_6 \\cdot (R - 2)$$\n * @return {number} difficulty\n */\n mean_reversion(init: number, current: number): number {\n return +(this.param.w[7] * init + (1 - this.param.w[7]) * current).toFixed(\n 8,\n );\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_r(D,S,R,G) = S\\cdot(e^{w_8}\\cdot (11-D)\\cdot S^{-w_9}\\cdot(e^{w_{10}\\cdot(1-R)}-1)\\cdot w_{15}(\\text{if} G=2) \\cdot w_{16}(\\text{if} G=4)+1)$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n * @return {number} S^\\prime_r new stability after recall\n */\n next_recall_stability(d: number, s: number, r: number, g: Grade): number {\n const hard_penalty = Rating.Hard === g ? this.param.w[15] : 1;\n const easy_bound = Rating.Easy === g ? this.param.w[16] : 1;\n return +(\n s *\n (1 +\n Math.exp(this.param.w[8]) *\n (11 - d) *\n Math.pow(s, -this.param.w[9]) *\n (Math.exp((1 - r) * this.param.w[10]) - 1) *\n hard_penalty *\n easy_bound)\n ).toFixed(8);\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_f(D,S,R) = w_{11}\\cdot D^{-w_{12}}\\cdot ((S+1)^{w_{13}}-1) \\cdot e^{w_{14}\\cdot(1-R)}$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @return {number} S^\\prime_f new stability after forgetting\n */\n next_forget_stability(d: number, s: number, r: number): number {\n return +(\n this.param.w[11] *\n Math.pow(d, -this.param.w[12]) *\n (Math.pow(s + 1, this.param.w[13]) - 1) *\n Math.exp((1 - r) * this.param.w[14])\n ).toFixed(8);\n }\n\n /**\n * The formula used is :\n * $$R(t,S) = (1 + \\text{FACTOR} \\times \\frac{t}{9 \\cdot S})^{\\text{DECAY}}$$\n * @param {number} elapsed_days t days since the last review\n * @param {number} stability Stability (interval when R=90%)\n * @return {number} r Retrievability (probability of recall)\n */\n forgetting_curve(elapsed_days: number, stability: number): number {\n return +Math.pow(1 + (FACTOR * elapsed_days) / stability, DECAY).toFixed(8);\n }\n}\n","import { SchedulingCard } from \"./scheduler\";\nimport { date_scheduler, fixDate, fixRating, fixState } from \"./help\";\nimport {\n Card,\n CardInput,\n DateInput,\n FSRSParameters,\n Rating,\n RecordLog,\n RecordLogItem,\n RescheduleOptions,\n ReviewLog,\n ReviewLogInput,\n State,\n} from \"./models\";\nimport type { int } from \"./type\";\nimport { FSRSAlgorithm } from \"./algorithm\";\n\nexport class FSRS extends FSRSAlgorithm {\n constructor(param: Partial<FSRSParameters>) {\n super(param);\n }\n\n private preProcessCard(_card: CardInput | Card): Card {\n return {\n ..._card,\n state: fixState(_card.state),\n due: fixDate(_card.due),\n last_review: _card.last_review ? fixDate(_card.last_review) : undefined,\n };\n }\n\n private preProcessDate(_date: DateInput): Date {\n return fixDate(_date);\n }\n\n private preProcessLog(_log: ReviewLogInput | ReviewLog): ReviewLog {\n return {\n ..._log,\n due: fixDate(_log.due),\n rating: fixRating(_log.rating),\n state: fixState(_log.state),\n review: fixDate(_log.review),\n };\n }\n\n /**\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date());\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n * function repeatAfterHandler(recordLog: RecordLog) {\n * const record: { [key in Grade]: RepeatRecordLog } = {} as {\n * [key in Grade]: RepeatRecordLog;\n * };\n * for (const grade of Grades) {\n * record[grade] = {\n * card: {\n * ...(recordLog[grade].card as Card & { cid: string }),\n * due: recordLog[grade].card.due.getTime(),\n * state: State[recordLog[grade].card.state] as StateType,\n * last_review: recordLog[grade].card.last_review\n * ? recordLog[grade].card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLog[grade].log,\n * cid: (recordLog[grade].card as Card & { cid: string }).cid,\n * due: recordLog[grade].log.due.getTime(),\n * review: recordLog[grade].log.review.getTime(),\n * state: State[recordLog[grade].log.state] as StateType,\n * rating: Rating[recordLog[grade].log.rating] as RatingType,\n * },\n * };\n * }\n * return record;\n * }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date(), repeatAfterHandler);\n * ```\n */\n repeat<R = RecordLog>(\n card: CardInput | Card,\n now: DateInput,\n afterHandler?: (recordLog: RecordLog) => R,\n ): R {\n const processedCard = this.preProcessCard(card);\n now = this.preProcessDate(now);\n const s = new SchedulingCard(processedCard, now).update_state(\n processedCard.state,\n );\n this.seed = String(now.getTime()) + String(processedCard.reps);\n let easy_interval, good_interval, hard_interval;\n const interval = processedCard.elapsed_days;\n switch (processedCard.state) {\n case State.New:\n this.init_ds(s);\n s.again.due = now.scheduler(1 as int);\n s.hard.due = now.scheduler(5 as int);\n s.good.due = now.scheduler(10 as int);\n easy_interval = this.next_interval(s.easy.stability, interval);\n s.easy.scheduled_days = easy_interval;\n s.easy.due = now.scheduler(easy_interval, true);\n break;\n case State.Learning:\n case State.Relearning:\n hard_interval = 0;\n good_interval = this.next_interval(s.good.stability, interval);\n easy_interval = Math.max(\n this.next_interval(s.easy.stability, interval),\n good_interval + 1,\n );\n s.schedule(now, hard_interval, good_interval, easy_interval);\n break;\n case State.Review: {\n const last_d = processedCard.difficulty;\n const last_s = processedCard.stability;\n const retrievability = this.forgetting_curve(interval, last_s);\n this.next_ds(s, last_d, last_s, retrievability);\n hard_interval = this.next_interval(s.hard.stability, interval);\n good_interval = this.next_interval(s.good.stability, interval);\n hard_interval = Math.min(hard_interval, good_interval);\n good_interval = Math.max(good_interval, hard_interval + 1);\n easy_interval = Math.max(\n this.next_interval(s.easy.stability, interval),\n good_interval + 1,\n );\n s.schedule(now, hard_interval, good_interval, easy_interval);\n break;\n }\n }\n const recordLog = s.record_log(processedCard, now);\n if (afterHandler && typeof afterHandler === \"function\") {\n return afterHandler(recordLog);\n } else {\n return recordLog as R;\n }\n }\n\n /**\n * Get the retrievability of the card\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param format default:true , Convert the result to another type. (Optional)\n * @returns The retrievability of the card,if format is true, the result is a string, otherwise it is a number\n */\n get_retrievability<T extends boolean>(\n card: CardInput | Card,\n now: DateInput,\n format: T = true as T,\n ): undefined | (T extends true ? string : number) {\n const processedCard = this.preProcessCard(card);\n now = this.preProcessDate(now);\n if (processedCard.state !== State.Review) {\n return undefined;\n }\n const t = Math.max(now.diff(processedCard.last_review as Date, \"days\"), 0);\n const r = this.forgetting_curve(t, Math.round(processedCard.stability));\n return (format ? `${(r * 100).toFixed(2)}%` : r) as T extends true\n ? string\n : number;\n }\n\n /**\n *\n * @param card Card to be processed\n * @param log last review log\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now);\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now);\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log);\n * ```\n *\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);\n * ```\n */\n rollback<R = Card>(\n card: CardInput | Card,\n log: ReviewLogInput,\n afterHandler?: (prevCard: Card) => R,\n ): R {\n const processedCard = this.preProcessCard(card);\n const processedLog = this.preProcessLog(log);\n if (processedLog.rating === Rating.Manual) {\n throw new Error(\"Cannot rollback a manual rating\");\n }\n let last_due, last_review, last_lapses;\n switch (processedLog.state) {\n case State.New:\n last_due = processedLog.due;\n last_review = undefined;\n last_lapses = 0;\n break;\n case State.Learning:\n case State.Relearning:\n case State.Review:\n last_due = processedLog.review;\n last_review = processedLog.due;\n last_lapses =\n processedCard.lapses -\n (processedLog.rating === Rating.Again &&\n processedLog.state === State.Review\n ? 1\n : 0);\n break;\n }\n\n const prevCard: Card = {\n ...processedCard,\n due: last_due,\n stability: processedLog.stability,\n difficulty: processedLog.difficulty,\n elapsed_days: processedLog.last_elapsed_days,\n scheduled_days: processedLog.scheduled_days,\n reps: Math.max(0, processedCard.reps - 1),\n lapses: Math.max(0, last_lapses),\n state: processedLog.state,\n last_review: last_review,\n };\n if (afterHandler && typeof afterHandler === \"function\") {\n return afterHandler(prevCard);\n } else {\n return prevCard as R;\n }\n }\n\n /**\n *\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param reset_count Should the review count information(reps,lapses) be reset. (Optional)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCard = createEmptyCard(now);\n * const scheduling_cards = f.repeat(emptyCard, now);\n * const { card, log } = scheduling_cards[Rating.Hard];\n * const forgetCard = f.forget(card, new Date(), true);\n * ```\n *\n * @example\n * ```\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked; //see method: fsrs.repeat()\n * }\n *\n * function forgetAfterHandler(recordLogItem: RecordLogItem): RepeatRecordLog {\n * return {\n * card: {\n * ...(recordLogItem.card as Card & { cid: string }),\n * due: recordLogItem.card.due.getTime(),\n * state: State[recordLogItem.card.state] as StateType,\n * last_review: recordLogItem.card.last_review\n * ? recordLogItem.card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLogItem.log,\n * cid: (recordLogItem.card as Card & { cid: string }).cid,\n * due: recordLogItem.log.due.getTime(),\n * review: recordLogItem.log.review.getTime(),\n * state: State[recordLogItem.log.state] as StateType,\n * rating: Rating[recordLogItem.log.rating] as RatingType,\n * },\n * };\n * }\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card } = repeatFormAfterHandler[Rating.Hard];\n * const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);\n * ```\n */\n forget<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n reset_count: boolean = false,\n afterHandler?: (recordLogItem: RecordLogItem) => R,\n ): R {\n const processedCard = this.preProcessCard(card);\n now = this.preProcessDate(now);\n const scheduled_days =\n processedCard.state === State.New\n ? 0\n : now.diff(processedCard.last_review as Date, \"days\");\n const forget_log: ReviewLog = {\n rating: Rating.Manual,\n state: processedCard.state,\n due: processedCard.due,\n stability: processedCard.stability,\n difficulty: processedCard.difficulty,\n elapsed_days: 0,\n last_elapsed_days: processedCard.elapsed_days,\n scheduled_days: scheduled_days,\n review: now,\n };\n const forget_card: Card = {\n ...processedCard,\n due: now,\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: reset_count ? 0 : processedCard.reps,\n lapses: reset_count ? 0 : processedCard.lapses,\n state: State.New,\n last_review: processedCard.last_review,\n };\n const recordLogItem: RecordLogItem = { card: forget_card, log: forget_log };\n if (afterHandler && typeof afterHandler === \"function\") {\n return afterHandler(recordLogItem);\n } else {\n return recordLogItem as R;\n }\n }\n\n /**\n *\n * @param cards scheduled card collection\n * @param options Reschedule options,fuzz is enabled by default.If the type of due is not Date, please implement dataHandler.\n * @example\n * ```typescript\n * type CardType = Card & {\n * cid: number;\n * };\n * const reviewCard: CardType = {\n * cid: 1,\n * due: new Date(\"2024-03-17 04:43:02\"),\n * stability: 48.26139059062234,\n * difficulty: 5.67,\n * elapsed_days: 18,\n * scheduled_days: 51,\n * reps: 8,\n * lapses: 1,\n * state: State.Review,\n * last_review: new Date(\"2024-01-26 04:43:02\"),\n * };\n * const f = fsrs();\n * const reschedule_cards = f.reschedule([reviewCard]);\n * ```\n *\n */\n reschedule<T extends CardInput | Card>(\n cards: Array<T>,\n options: RescheduleOptions = {},\n ): Array<T> {\n if (!Array.isArray(cards)) {\n throw new Error(\"cards must be an array\");\n }\n const processedCard: T[] = [];\n for (const card of cards) {\n if (fixState(card.state) !== State.Review || !card.last_review) continue;\n const scheduled_days = Math.floor(card.scheduled_days) as int;\n const next_ivl = this.next_interval(\n +card.stability.toFixed(2),\n Math.round(card.elapsed_days),\n options.enable_fuzz ?? true,\n );\n if (next_ivl === scheduled_days || next_ivl === 0) continue;\n\n const processCard: T = { ...card };\n processCard.scheduled_days = next_ivl;\n const new_due = date_scheduler(processCard.last_review!, next_ivl, true);\n if (options.dateHandler && typeof options.dateHandler === \"function\") {\n processCard.due = options.dateHandler(new_due);\n } else {\n processCard.due = new_due;\n }\n processedCard.push(processCard);\n }\n return processedCard;\n }\n}\n\n/**\n * Create a new instance of TS-FSRS\n * @param params FSRSParameters\n * @example\n * ```typescript\n * const f = fsrs();\n * ```\n * @example\n * ```typescript\n * const params: FSRSParameters = generatorParameters({ maximum_interval: 1000 });\n * const f = fsrs(params);\n * ```\n * @example\n * ```typescript\n * const f = fsrs({ maximum_interval: 1000 });\n * ```\n */\nexport const fsrs = (params?: Partial<FSRSParameters>) => {\n return new FSRS(params || {});\n};\n"],"names":["State","Rating","e","isDay","date_scheduler","pre","unit","date_diff","formatDate","last_review","timeUnit","show_diff_message","now","t","fixDate","diff","r","dateInput","date","year","month","day","hours","minutes","seconds","padZero","num","TIMEUNIT","TIMEUNITFORMAT","due","i","value","timestamp","fixState","firstLetter","restOfString","ret","fixRating","Grades","FUZZ_RANGES","get_fuzz_range","interval","elapsed_days","maximum_interval","delta","range","min_ivl","max_ivl","SchedulingCard","card","state","hard_interval","good_interval","easy_interval","default_request_retention","default_maximum_interval","default_w","default_enable_fuzz","FSRSVersion","generatorParameters","props","createEmptyCard","afterHandler","emptyCard","DECAY","FACTOR","FSRSAlgorithm","params","request_retention","_this","target","prop","_params","key","paramKey","s","last_d","last_s","retrievability","g","ivl","enable_fuzz","fuzz_factor","pseudorandom","newInterval","d","next_d","difficulty","init","current","hard_penalty","easy_bound","stability","FSRS","param","_card","_date","_log","processedCard","recordLog","format","log","processedLog","last_due","last_lapses","prevCard","reset_count","scheduled_days","forget_log","recordLogItem","cards","options","next_ivl","processCard","new_due","fsrs"],"mappings":"yCAEYA,GAAAA,IACVA,EAAAA,EAAA,IAAM,CAAN,EAAA,MACAA,IAAA,SAAW,CAAA,EAAX,WACAA,EAAA,EAAA,OAAS,GAAT,SACAA,EAAAA,EAAA,WAAa,CAAb,EAAA,aAJUA,IAAAA,GASA,CAAA,CAAA,EAAAC,GAAAA,IACVA,EAAAA,EAAA,OAAS,CAAT,EAAA,SACAA,IAAA,MAAQ,CAAA,EAAR,QACAA,EAAAC,EAAA,KAA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","../src/fsrs/algorithm.ts","../src/fsrs/abstract_schduler.ts","../src/fsrs/impl/basic_schduler.ts","../src/fsrs/impl/long_term_schduler.ts","../src/fsrs/fsrs.ts"],"sourcesContent":["export type StateType = 'New' | 'Learning' | 'Review' | 'Relearning'\n\nexport enum State {\n New = 0,\n Learning = 1,\n Review = 2,\n Relearning = 3,\n}\n\nexport type RatingType = 'Manual' | 'Again' | 'Hard' | 'Good' | 'Easy'\n\nexport enum Rating {\n Manual = 0,\n Again = 1,\n Hard = 2,\n Good = 3,\n Easy = 4,\n}\n\ntype ExcludeManual<T> = Exclude<T, Rating.Manual>\n\nexport type Grade = ExcludeManual<Rating>\n\nexport interface ReviewLog {\n rating: Rating // Rating of the review (Again, Hard, Good, Easy)\n state: State // State of the review (New, Learning, Review, Relearning)\n due: Date // Date of the last scheduling\n stability: number // Memory stability during the review\n difficulty: number // Difficulty of the card during the review\n elapsed_days: number // Number of days elapsed since the last review\n last_elapsed_days: number // Number of days between the last two reviews\n scheduled_days: number // Number of days until the next review\n review: Date // Date of the review\n}\n\nexport type RecordLogItem = {\n card: Card\n log: ReviewLog\n}\nexport type RecordLog = {\n [key in Grade]: RecordLogItem\n}\n\nexport interface Card {\n due: Date // Due date\n stability: number // Stability\n difficulty: number // Difficulty level\n elapsed_days: number // Number of days elapsed\n scheduled_days: number // Number of days scheduled\n reps: number // Repetition count\n lapses: number // Number of lapses or mistakes\n state: State // Card's state (New, Learning, Review, Relearning)\n last_review?: Date // Date of the last review (optional)\n}\n\nexport interface CardInput extends Omit<Card, 'state' | 'due' | 'last_review'> {\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n last_review?: DateInput | null // Date of the last review (optional)\n}\n\nexport type DateInput = Date | number | string\n\nexport interface ReviewLogInput\n extends Omit<ReviewLog, 'rating' | 'state' | 'due' | 'review'> {\n rating: RatingType | Rating // Rating of the review (Again, Hard, Good, Easy)\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n review: DateInput // Date of the last review\n}\n\nexport interface FSRSParameters {\n request_retention: number\n maximum_interval: number\n w: number[]\n enable_fuzz: boolean\n enable_short_term: boolean\n}\n\nexport type RescheduleOptions = {\n enable_fuzz?: boolean\n dateHandler?: (date: Date) => DateInput\n}\n","import {\n Card,\n CardInput,\n DateInput,\n Rating,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\n\nexport class TypeConvert {\n static card<T extends Card | CardInput>(card: T): Card {\n return {\n ...card,\n state: TypeConvert.state(card.state),\n due: TypeConvert.time(card.due),\n last_review: card.last_review\n ? TypeConvert.time(card.last_review)\n : undefined,\n } as Card\n }\n static rating(value: unknown): Rating {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = Rating[`${firstLetter}${restOfString}` as keyof typeof Rating]\n if (ret === undefined) {\n throw new Error(`Invalid rating:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as Rating\n }\n throw new Error(`Invalid rating:[${value}]`)\n }\n static state(value: unknown): State {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = State[`${firstLetter}${restOfString}` as keyof typeof State]\n if (ret === undefined) {\n throw new Error(`Invalid state:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as State\n }\n throw new Error(`Invalid state:[${value}]`)\n }\n static time(value: unknown): Date {\n if (typeof value === 'object' && value instanceof Date) {\n return value\n } else if (typeof value === 'string') {\n const timestamp = Date.parse(value)\n if (!isNaN(timestamp)) {\n return new Date(timestamp)\n } else {\n throw new Error(`Invalid date:[${value}]`)\n }\n } else if (typeof value === 'number') {\n return new Date(value)\n }\n throw new Error(`Invalid date:[${value}]`)\n }\n static review_log(log: ReviewLogInput | ReviewLog): ReviewLog {\n return {\n ...log,\n due: TypeConvert.time(log.due),\n rating: TypeConvert.rating(log.rating),\n state: TypeConvert.state(log.state),\n review: TypeConvert.time(log.review),\n } satisfies ReviewLog\n }\n}\n","import { Card, DateInput, FSRSParameters, State } from './models'\nimport { TypeConvert } from './convert'\n\nexport const default_request_retention = 0.9\nexport const default_maximum_interval = 36500\nexport const default_w = [\n 0.4197, 1.1869, 3.0412, 15.2441, 7.1434, 0.6477, 1.0007, 0.0674, 1.6597,\n 0.1712, 1.1178, 2.0225, 0.0904, 0.3025, 2.1214, 0.2498, 2.9466, 0.4891,\n 0.6468,\n]\nexport const default_enable_fuzz = false\nexport const defualt_enable_short_term = true\n\nexport const FSRSVersion: string = 'v4.0.0 using FSRS V5.0'\n\nexport const generatorParameters = (\n props?: Partial<FSRSParameters>\n): FSRSParameters => {\n let w = default_w\n if (props?.w) {\n if (props.w.length === 19) {\n w = props?.w\n } else if (props.w.length === 17) {\n w = props?.w.concat([0.0, 0.0])\n console.debug('[FSRS V5]auto fill w to 19 length')\n }\n }\n return {\n request_retention: props?.request_retention || default_request_retention,\n maximum_interval: props?.maximum_interval || default_maximum_interval,\n w: w,\n enable_fuzz: props?.enable_fuzz ?? default_enable_fuzz,\n enable_short_term:\n props?.enable_short_term ?? defualt_enable_short_term,\n } satisfies FSRSParameters\n}\n\n/**\n * Create an empty card\n * @param now Current time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * ```\n * @example\n * ```\n * interface CardUnChecked\n * extends Omit<Card, \"due\" | \"last_review\" | \"state\"> {\n * cid: string;\n * due: Date | number;\n * last_review: Date | null | number;\n * state: StateType;\n * }\n *\n * function cardAfterHandler(card: Card) {\n * return {\n * ...card,\n * cid: \"test001\",\n * state: State[card.state],\n * last_review: card.last_review ?? null,\n * } as CardUnChecked;\n * }\n *\n * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);\n * ```\n */\nexport function createEmptyCard<R = Card>(\n now?: DateInput,\n afterHandler?: (card: Card) => R\n): R {\n const emptyCard: Card = {\n due: now ? TypeConvert.time(now) : new Date(),\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: 0,\n lapses: 0,\n state: State.New,\n last_review: undefined,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(emptyCard)\n } else {\n return emptyCard as R\n }\n}\n","import type { int, unit } from './types'\nimport type { DateInput, Grade } from './models'\nimport { Rating, State } from './models'\nimport { TypeConvert } from './convert'\n\ndeclare global {\n export interface Date {\n scheduler(t: int, isDay?: boolean): Date\n\n diff(pre: Date, unit: unit): int\n\n format(): string\n\n dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string\n }\n}\n\nDate.prototype.scheduler = function (t: int, isDay?: boolean): Date {\n return date_scheduler(this, t, isDay)\n}\n\n/**\n * 当前时间与之前的时间差值\n * @param pre 比当前时间还要之前\n * @param unit 单位: days | minutes\n */\nDate.prototype.diff = function (pre: Date, unit: unit): int {\n return date_diff(this, pre, unit) as int\n}\n\nDate.prototype.format = function (): string {\n return formatDate(this)\n}\n\nDate.prototype.dueFormat = function (\n last_review: Date,\n unit?: boolean,\n timeUnit?: string[]\n) {\n return show_diff_message(this, last_review, unit, timeUnit)\n}\n\n/**\n * 计算日期和时间的偏移,并返回一个新的日期对象。\n * @param now 当前日期和时间\n * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟\n * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移\n * @returns 偏移后的日期和时间对象\n */\nexport function date_scheduler(\n now: DateInput,\n t: number,\n isDay?: boolean\n): Date {\n return new Date(\n isDay\n ? fixDate(now).getTime() + t * 24 * 60 * 60 * 1000\n : fixDate(now).getTime() + t * 60 * 1000\n )\n}\n\nexport function date_diff(now: DateInput, pre: DateInput, unit: unit): number {\n if (!now || !pre) {\n throw new Error('Invalid date')\n }\n const diff = fixDate(now).getTime() - fixDate(pre).getTime()\n let r = 0\n switch (unit) {\n case 'days':\n r = Math.floor(diff / (24 * 60 * 60 * 1000))\n break\n case 'minutes':\n r = Math.floor(diff / (60 * 1000))\n break\n }\n return r\n}\n\nexport function formatDate(dateInput: DateInput): string {\n const date = fixDate(dateInput)\n const year: number = date.getFullYear()\n const month: number = date.getMonth() + 1\n const day: number = date.getDate()\n const hours: number = date.getHours()\n const minutes: number = date.getMinutes()\n const seconds: number = date.getSeconds()\n\n return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(\n minutes\n )}:${padZero(seconds)}`\n}\n\nfunction padZero(num: number): string {\n return num < 10 ? `0${num}` : `${num}`\n}\n\nconst TIMEUNIT = [60, 60, 24, 31, 12]\nconst TIMEUNITFORMAT = ['second', 'min', 'hour', 'day', 'month', 'year']\n\nexport function show_diff_message(\n due: DateInput,\n last_review: DateInput,\n unit?: boolean,\n timeUnit: string[] = TIMEUNITFORMAT\n): string {\n due = fixDate(due)\n last_review = fixDate(last_review)\n if (timeUnit.length !== TIMEUNITFORMAT.length) {\n timeUnit = TIMEUNITFORMAT\n }\n let diff = due.getTime() - last_review.getTime()\n let i\n diff /= 1000\n for (i = 0; i < TIMEUNIT.length; i++) {\n if (diff < TIMEUNIT[i]) {\n break\n } else {\n diff /= TIMEUNIT[i]\n }\n }\n return `${Math.floor(diff)}${unit ? timeUnit[i] : ''}`\n}\n\n/**\n *\n * @deprecated Use TypeConvert.time instead\n */\nexport function fixDate(value: unknown) {\n return TypeConvert.time(value)\n}\n\n/**\n * @deprecated Use TypeConvert.state instead\n */\nexport function fixState(value: unknown): State {\n return TypeConvert.state(value)\n}\n\n/**\n * @deprecated Use TypeConvert.rating instead\n */\nexport function fixRating(value: unknown): Rating {\n return TypeConvert.rating(value)\n}\n\nexport const Grades: Readonly<Grade[]> = [\n Rating.Again,\n Rating.Hard,\n Rating.Good,\n Rating.Easy,\n] as const\n\nconst FUZZ_RANGES = [\n {\n start: 2.5,\n end: 7.0,\n factor: 0.15,\n },\n {\n start: 7.0,\n end: 20.0,\n factor: 0.1,\n },\n {\n start: 20.0,\n end: Infinity,\n factor: 0.05,\n },\n] as const\n\nexport function get_fuzz_range(\n interval: number,\n elapsed_days: number,\n maximum_interval: number\n) {\n let delta = 1.0\n for (const range of FUZZ_RANGES) {\n delta +=\n range.factor * Math.max(Math.min(interval, range.end) - range.start, 0.0)\n }\n interval = Math.min(interval, maximum_interval)\n let min_ivl = Math.max(2, Math.round(interval - delta))\n const max_ivl = Math.min(Math.round(interval + delta), maximum_interval)\n if (interval > elapsed_days) {\n min_ivl = Math.max(min_ivl, elapsed_days + 1)\n }\n min_ivl = Math.min(min_ivl, max_ivl)\n return { min_ivl, max_ivl }\n}\n","import pseudorandom from 'seedrandom'\nimport { generatorParameters } from './default'\nimport { FSRSParameters, Grade, Rating } from './models'\nimport type { int } from './types'\nimport { get_fuzz_range } from './help'\n\n/**\n * @default DECAY = -0.5\n */\nexport const DECAY: number = -0.5\n/**\n * FACTOR = Math.pow(0.9, 1 / DECAY) - 1= 19 / 81\n *\n * $$\\text{FACTOR} = \\frac{19}{81}$$\n * @default FACTOR = 19 / 81\n */\nexport const FACTOR: number = 19 / 81\n\n/**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n */\nexport class FSRSAlgorithm {\n protected param!: FSRSParameters\n protected intervalModifier!: number\n protected _seed?: string\n\n constructor(params: Partial<FSRSParameters>) {\n this.param = new Proxy(\n generatorParameters(params),\n this.params_handler_proxy()\n )\n this.intervalModifier = this.calculate_interval_modifier(\n this.param.request_retention\n )\n }\n\n get interval_modifier(): number {\n return this.intervalModifier\n }\n\n set seed(seed: string) {\n this._seed = seed\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n *\n * The formula used is: $$I(r,s) = (r^{\\frac{1}{DECAY}} - 1) / FACTOR \\times s$$\n * @param request_retention 0<request_retention<=1,Requested retention rate\n * @throws {Error} Requested retention rate should be in the range (0,1]\n */\n calculate_interval_modifier(request_retention: number): number {\n if (request_retention <= 0 || request_retention > 1) {\n throw new Error('Requested retention rate should be in the range (0,1]')\n }\n return +((Math.pow(request_retention, 1 / DECAY) - 1) / FACTOR).toFixed(8)\n }\n\n /**\n * Get the parameters of the algorithm.\n */\n get parameters(): FSRSParameters {\n return this.param\n }\n\n /**\n * Set the parameters of the algorithm.\n * @param params Partial<FSRSParameters>\n */\n set parameters(params: Partial<FSRSParameters>) {\n this.update_parameters(params)\n }\n\n protected params_handler_proxy(): ProxyHandler<FSRSParameters> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const _this: FSRSAlgorithm = this\n return {\n set: function (target, prop, value) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n }\n // @ts-ignore\n target[prop] = value\n return true\n },\n }\n }\n\n private update_parameters(params: Partial<FSRSParameters>): void {\n const _params = generatorParameters(params)\n for (const key in _params) {\n if (key in this.param) {\n const paramKey = key as keyof FSRSParameters\n this.param[paramKey] = _params[paramKey] as never\n }\n }\n }\n\n\n /**\n * The formula used is :\n * $$ S_0(G) = w_{G-1}$$\n * $$S_0 = \\max \\lbrace S_0,0.1\\rbrace $$\n\n * @param g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return Stability (interval when R=90%)\n */\n init_stability(g: Grade): number {\n return Math.max(this.param.w[g - 1], 0.1)\n }\n\n /**\n * The formula used is :\n * $$D_0(G) = w_4 - e^{(G-1) \\cdot w_5} + 1 $$\n * $$D_0 = \\min \\lbrace \\max \\lbrace D_0(G),1 \\rbrace,10 \\rbrace$$\n * where the $$D_0(1)=w_4$$ when the first rating is good.\n *\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} Difficulty $$D \\in [1,10]$$\n */\n init_difficulty(g: Grade): number {\n return this.constrain_difficulty(\n this.param.w[4] - Math.exp((g - 1) * this.param.w[5]) + 1\n )\n }\n\n /**\n * If fuzzing is disabled or ivl is less than 2.5, it returns the original interval.\n * @param {number} ivl - The interval to be fuzzed.\n * @param {number} elapsed_days t days since the last review\n * @param {number} enable_fuzz - This adds a small random delay to the new interval time to prevent cards from sticking together and always being reviewed on the same day.\n * @return {number} - The fuzzed interval.\n **/\n apply_fuzz(ivl: number, elapsed_days: number, enable_fuzz?: boolean): int {\n if (!enable_fuzz || ivl < 2.5) return Math.round(ivl) as int\n const generator = pseudorandom(this.seed)\n const fuzz_factor = generator()\n const { min_ivl, max_ivl } = get_fuzz_range(\n ivl,\n elapsed_days,\n this.param.maximum_interval\n )\n return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl) as int\n }\n\n /**\n * @see The formula used is : {@link FSRSAlgorithm.calculate_interval_modifier}\n * @param {number} s - Stability (interval when R=90%)\n * @param {number} elapsed_days t days since the last review\n * @param {number} enable_fuzz - This adds a small random delay to the new interval time to prevent cards from sticking together and always being reviewed on the same day.\n */\n next_interval(\n s: number,\n elapsed_days: number,\n enable_fuzz: boolean = this.param.enable_fuzz\n ): int {\n const newInterval = Math.min(\n Math.max(1, Math.round(s * this.intervalModifier)),\n this.param.maximum_interval\n ) as int\n return this.apply_fuzz(newInterval, elapsed_days, enable_fuzz)\n }\n\n /**\n * The formula used is :\n * $$\\text{next}_d = D - w_6 \\cdot (R - 2)$$\n * $$D^\\prime(D,R) = w_5 \\cdot D_0(2) +(1 - w_5) \\cdot \\text{next}_d$$\n * @param {number} d Difficulty $$D \\in [1,10]$$\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} $$\\text{next}_D$$\n */\n next_difficulty(d: number, g: Grade): number {\n const next_d = d - this.param.w[6] * (g - 3)\n return this.constrain_difficulty(\n this.mean_reversion(this.param.w[4], next_d)\n )\n }\n\n /**\n * The formula used is :\n * $$\\min \\lbrace \\max \\lbrace D_0,1 \\rbrace,10\\rbrace$$\n * @param {number} difficulty $$D \\in [1,10]$$\n */\n constrain_difficulty(difficulty: number): number {\n return Math.min(Math.max(+difficulty.toFixed(8), 1), 10)\n }\n\n /**\n * The formula used is :\n * $$w_7 \\cdot \\text{init} +(1 - w_7) \\cdot \\text{current}$$\n * @param {number} init $$w_2 : D_0(3) = w_2 + (R-2) \\cdot w_3= w_2$$\n * @param {number} current $$D - w_6 \\cdot (R - 2)$$\n * @return {number} difficulty\n */\n mean_reversion(init: number, current: number): number {\n return +(this.param.w[7] * init + (1 - this.param.w[7]) * current).toFixed(\n 8\n )\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_r(D,S,R,G) = S\\cdot(e^{w_8}\\cdot (11-D)\\cdot S^{-w_9}\\cdot(e^{w_{10}\\cdot(1-R)}-1)\\cdot w_{15}(\\text{if} G=2) \\cdot w_{16}(\\text{if} G=4)+1)$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n * @return {number} S^\\prime_r new stability after recall\n */\n next_recall_stability(d: number, s: number, r: number, g: Grade): number {\n const hard_penalty = Rating.Hard === g ? this.param.w[15] : 1\n const easy_bound = Rating.Easy === g ? this.param.w[16] : 1\n return +(\n s *\n (1 +\n Math.exp(this.param.w[8]) *\n (11 - d) *\n Math.pow(s, -this.param.w[9]) *\n (Math.exp((1 - r) * this.param.w[10]) - 1) *\n hard_penalty *\n easy_bound)\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_f(D,S,R) = w_{11}\\cdot D^{-w_{12}}\\cdot ((S+1)^{w_{13}}-1) \\cdot e^{w_{14}\\cdot(1-R)}$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @return {number} S^\\prime_f new stability after forgetting\n */\n next_forget_stability(d: number, s: number, r: number): number {\n return +(\n this.param.w[11] *\n Math.pow(d, -this.param.w[12]) *\n (Math.pow(s + 1, this.param.w[13]) - 1) *\n Math.exp((1 - r) * this.param.w[14])\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_s(S,G) = S \\cdot e^{w_{17} \\cdot (G-3+w_{18})}$$\n * @param {number} s Stability (interval when R=90%)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n */\n next_short_term_stability(s: number, g: Grade): number {\n return +(\n s * Math.exp(this.param.w[17] * (g - 3 + this.param.w[18]))\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$R(t,S) = (1 + \\text{FACTOR} \\times \\frac{t}{9 \\cdot S})^{\\text{DECAY}}$$\n * @param {number} elapsed_days t days since the last review\n * @param {number} stability Stability (interval when R=90%)\n * @return {number} r Retrievability (probability of recall)\n */\n forgetting_curve(elapsed_days: number, stability: number): number {\n return +Math.pow(1 + (FACTOR * elapsed_days) / stability, DECAY).toFixed(8)\n }\n}\n","import { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport {\n type Card,\n type RecordLog,\n type Grade,\n type RecordLogItem,\n State,\n Rating,\n type ReviewLog,\n type CardInput,\n type DateInput,\n} from './models'\nimport type { IScheduler } from './types'\n\nexport abstract class AbstractScheduler implements IScheduler {\n protected last: Card\n protected current: Card\n protected review_time: Date\n protected next: Map<Grade, RecordLogItem> = new Map()\n protected algorithm: FSRSAlgorithm\n\n constructor(\n card: CardInput | Card,\n now: DateInput,\n algorithm: FSRSAlgorithm\n ) {\n this.algorithm = algorithm\n\n this.last = TypeConvert.card(card)\n this.current = TypeConvert.card(card)\n this.review_time = TypeConvert.time(now)\n this.init()\n }\n\n private init() {\n const { state, last_review } = this.current\n let interval = 0 // card.state === State.New => 0\n if (state !== State.New && last_review) {\n interval = this.review_time.diff(last_review as Date, 'days')\n }\n this.current.last_review = this.review_time\n this.current.elapsed_days = interval\n this.current.reps += 1\n this.initSeed()\n }\n\n public preview(): RecordLog {\n return {\n [Rating.Again]: this.review(Rating.Again),\n [Rating.Hard]: this.review(Rating.Hard),\n [Rating.Good]: this.review(Rating.Good),\n [Rating.Easy]: this.review(Rating.Easy),\n } satisfies RecordLog\n }\n public review(grade: Grade): RecordLogItem {\n const { state } = this.last\n let item: RecordLogItem | undefined\n switch (state) {\n case State.New:\n item = this.newState(grade)\n break\n case State.Learning:\n case State.Relearning:\n item = this.learningState(grade)\n break\n case State.Review:\n item = this.reviewState(grade)\n break\n }\n if (item) {\n return item\n }\n throw new Error('Invalid grade')\n }\n\n protected abstract newState(grade: Grade): RecordLogItem\n\n protected abstract learningState(grade: Grade): RecordLogItem\n\n protected abstract reviewState(grade: Grade): RecordLogItem\n\n private initSeed() {\n const time = this.review_time.getTime()\n const reps = this.current.reps\n const mul = this.current.difficulty * this.current.stability\n this.algorithm.seed = `${time}_${reps}_${mul}`\n }\n\n protected buildLog(rating: Grade): ReviewLog {\n const { last_review, due, elapsed_days } = this.last\n\n return {\n rating: rating,\n state: this.current.state,\n due: last_review || due,\n stability: this.current.stability,\n difficulty: this.current.difficulty,\n elapsed_days: this.current.elapsed_days,\n last_elapsed_days: elapsed_days,\n scheduled_days: this.current.scheduled_days,\n review: this.review_time,\n } satisfies ReviewLog\n }\n}\n","import { AbstractScheduler } from '../abstract_schduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class BasicScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const next = TypeConvert.card(this.current)\n next.difficulty = this.algorithm.init_difficulty(grade)\n next.stability = this.algorithm.init_stability(grade)\n\n switch (grade) {\n case Rating.Again:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(1 as int)\n next.state = State.Learning\n break\n case Rating.Hard:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int)\n next.state = State.Learning\n break\n case Rating.Good:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = State.Learning\n break\n case Rating.Easy: {\n const easy_interval = this.algorithm.next_interval(\n next.stability,\n this.current.elapsed_days,\n this.algorithm.parameters.enable_fuzz\n )\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override learningState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const { state, difficulty, stability } = this.last\n const next = TypeConvert.card(this.current)\n const interval = this.current.elapsed_days\n next.difficulty = this.algorithm.next_difficulty(difficulty, grade)\n next.stability = this.algorithm.next_short_term_stability(stability, grade)\n\n switch (grade) {\n case Rating.Again: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int, false)\n next.state = state\n break\n }\n case Rating.Hard: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = state\n break\n }\n case Rating.Good: {\n const good_interval = this.algorithm.next_interval(\n next.stability,\n interval\n )\n next.scheduled_days = good_interval\n next.due = this.review_time.scheduler(good_interval as int, true)\n next.state = State.Review\n break\n }\n case Rating.Easy: {\n const good_stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Good\n )\n const good_interval = this.algorithm.next_interval(\n good_stability,\n interval\n )\n const easy_interval = Math.max(\n this.algorithm.next_interval(next.stability, interval),\n good_interval + 1\n ) as int\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n next_again.stability = this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let hard_interval: int, good_interval: int\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n hard_interval = Math.min(hard_interval, good_interval) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n const easy_interval = Math.max(\n this.algorithm.next_interval(next_easy.stability, interval),\n good_interval + 1\n ) as int\n next_again.scheduled_days = 0\n next_again.due = this.review_time.scheduler(5 as int)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Relearning\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n}\n","import { AbstractScheduler } from '../abstract_schduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class LongTermScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n\n const first_difficulty = this.algorithm.init_difficulty(grade)\n const first_stability = this.algorithm.init_stability(grade)\n const first_interval = 0\n\n this.current.difficulty = first_difficulty\n this.current.stability = first_stability\n this.current.scheduled_days = 0\n this.current.elapsed_days = 0\n\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_short_term_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n first_difficulty,\n first_stability\n )\n this.next_interval(\n next_again,\n next_hard,\n next_good,\n next_easy,\n first_interval\n )\n\n this.next_state(next_again, next_hard, next_good, next_easy)\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n private next_short_term_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n next_again.stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Again\n )\n\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Hard\n )\n\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Good\n )\n\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Easy\n )\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/ts-fsrs/issues/98#issuecomment-2241923194\n */\n protected override learningState(grade: Grade): RecordLogItem {\n return this.reviewState(grade)\n }\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n next_again.stability = this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review/New next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let again_interval: int,\n hard_interval: int,\n good_interval: int,\n easy_interval: int\n again_interval = this.algorithm.next_interval(\n next_again.stability,\n interval\n )\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n easy_interval = this.algorithm.next_interval(next_easy.stability, interval)\n\n again_interval = Math.min(again_interval, hard_interval) as int\n hard_interval = Math.max(hard_interval, again_interval + 1) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n easy_interval = Math.max(easy_interval, good_interval + 1) as int\n\n next_again.scheduled_days = again_interval\n next_again.due = this.review_time.scheduler(again_interval, true)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review/New next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Review\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n\n private update_next(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n }\n}\n","import { date_scheduler } from './help'\nimport {\n Card,\n CardInput,\n DateInput,\n FSRSParameters,\n Grade,\n Rating,\n RecordLog,\n RecordLogItem,\n RescheduleOptions,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\nimport type { int } from './types'\nimport { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport BasicScheduler from './impl/basic_schduler'\nimport LongTermScheduler from './impl/long_term_schduler'\n\nexport class FSRS extends FSRSAlgorithm {\n private Schduler\n constructor(param: Partial<FSRSParameters>) {\n super(param)\n const { enable_short_term } = this.parameters\n this.Schduler = enable_short_term ? BasicScheduler : LongTermScheduler\n }\n\n protected override params_handler_proxy(): ProxyHandler<FSRSParameters> {\n const _this: FSRS = this satisfies FSRS\n return {\n set: function (target, prop, value) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n } else if (prop === 'enable_short_term') {\n _this.Schduler = value === true ? BasicScheduler : LongTermScheduler\n }\n // @ts-ignore\n target[prop] = value\n return true\n },\n }\n }\n\n /**\n * Display the collection of cards and logs for the four scenarios after scheduling the card at the current time.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date());\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n * function repeatAfterHandler(recordLog: RecordLog) {\n * const record: { [key in Grade]: RepeatRecordLog } = {} as {\n * [key in Grade]: RepeatRecordLog;\n * };\n * for (const grade of Grades) {\n * record[grade] = {\n * card: {\n * ...(recordLog[grade].card as Card & { cid: string }),\n * due: recordLog[grade].card.due.getTime(),\n * state: State[recordLog[grade].card.state] as StateType,\n * last_review: recordLog[grade].card.last_review\n * ? recordLog[grade].card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLog[grade].log,\n * cid: (recordLog[grade].card as Card & { cid: string }).cid,\n * due: recordLog[grade].log.due.getTime(),\n * review: recordLog[grade].log.review.getTime(),\n * state: State[recordLog[grade].log.state] as StateType,\n * rating: Rating[recordLog[grade].log.rating] as RatingType,\n * },\n * };\n * }\n * return record;\n * }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date(), repeatAfterHandler);\n * ```\n */\n repeat<R = RecordLog>(\n card: CardInput | Card,\n now: DateInput,\n afterHandler?: (recordLog: RecordLog) => R\n ): R {\n const Schduler = this.Schduler\n const instace = new Schduler(card, now, this satisfies FSRSAlgorithm)\n const recordLog = instace.preview()\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLog)\n } else {\n return recordLog as R\n }\n }\n\n /**\n * Display the collection of cards and logs for the card scheduled at the current time, after applying a specific grade rating.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param grade Rating of the review (Again, Hard, Good, Easy)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLogItem = f.next(card, new Date(), Rating.Again);\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface NextRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n function nextAfterHandler(recordLogItem: RecordLogItem) {\n const recordItem = {\n card: {\n ...(recordLogItem.card as Card & { cid: string }),\n due: recordLogItem.card.due.getTime(),\n state: State[recordLogItem.card.state] as StateType,\n last_review: recordLogItem.card.last_review\n ? recordLogItem.card.last_review!.getTime()\n : null,\n },\n log: {\n ...recordLogItem.log,\n cid: (recordLogItem.card as Card & { cid: string }).cid,\n due: recordLogItem.log.due.getTime(),\n review: recordLogItem.log.review.getTime(),\n state: State[recordLogItem.log.state] as StateType,\n rating: Rating[recordLogItem.log.rating] as RatingType,\n },\n };\n return recordItem\n }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLogItem = f.repeat(card, new Date(), Rating.Again, nextAfterHandler);\n * ```\n */\n next<R = RecordLog>(\n card: CardInput | Card,\n now: DateInput,\n grade: Grade,\n afterHandler?: (recordLog: RecordLogItem) => R\n ): R {\n const Schduler = this.Schduler\n const instace = new Schduler(card, now, this satisfies FSRSAlgorithm)\n const g = TypeConvert.rating(grade)\n if (g === Rating.Manual) {\n throw new Error('Cannot review a manual rating')\n }\n const recordLogItem = instace.review(g)\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n * Get the retrievability of the card\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param format default:true , Convert the result to another type. (Optional)\n * @returns The retrievability of the card,if format is true, the result is a string, otherwise it is a number\n */\n get_retrievability<T extends boolean>(\n card: CardInput | Card,\n now: DateInput,\n format: T = true as T\n ): undefined | (T extends true ? string : number) {\n const processedCard = TypeConvert.card(card)\n now = TypeConvert.time(now)\n if (processedCard.state !== State.Review) {\n return undefined\n }\n const t = Math.max(now.diff(processedCard.last_review as Date, 'days'), 0)\n const r = this.forgetting_curve(t, Math.round(processedCard.stability))\n return (format ? `${(r * 100).toFixed(2)}%` : r) as T extends true\n ? string\n : number\n }\n\n /**\n *\n * @param card Card to be processed\n * @param log last review log\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now);\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now);\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log);\n * ```\n *\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);\n * ```\n */\n rollback<R = Card>(\n card: CardInput | Card,\n log: ReviewLogInput,\n afterHandler?: (prevCard: Card) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n const processedLog = TypeConvert.review_log(log)\n if (processedLog.rating === Rating.Manual) {\n throw new Error('Cannot rollback a manual rating')\n }\n let last_due, last_review, last_lapses\n switch (processedLog.state) {\n case State.New:\n last_due = processedLog.due\n last_review = undefined\n last_lapses = 0\n break\n case State.Learning:\n case State.Relearning:\n case State.Review:\n last_due = processedLog.review\n last_review = processedLog.due\n last_lapses =\n processedCard.lapses -\n (processedLog.rating === Rating.Again &&\n processedLog.state === State.Review\n ? 1\n : 0)\n break\n }\n\n const prevCard: Card = {\n ...processedCard,\n due: last_due,\n stability: processedLog.stability,\n difficulty: processedLog.difficulty,\n elapsed_days: processedLog.last_elapsed_days,\n scheduled_days: processedLog.scheduled_days,\n reps: Math.max(0, processedCard.reps - 1),\n lapses: Math.max(0, last_lapses),\n state: processedLog.state,\n last_review: last_review,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(prevCard)\n } else {\n return prevCard as R\n }\n }\n\n /**\n *\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param reset_count Should the review count information(reps,lapses) be reset. (Optional)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCard = createEmptyCard(now);\n * const scheduling_cards = f.repeat(emptyCard, now);\n * const { card, log } = scheduling_cards[Rating.Hard];\n * const forgetCard = f.forget(card, new Date(), true);\n * ```\n *\n * @example\n * ```\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked; //see method: fsrs.repeat()\n * }\n *\n * function forgetAfterHandler(recordLogItem: RecordLogItem): RepeatRecordLog {\n * return {\n * card: {\n * ...(recordLogItem.card as Card & { cid: string }),\n * due: recordLogItem.card.due.getTime(),\n * state: State[recordLogItem.card.state] as StateType,\n * last_review: recordLogItem.card.last_review\n * ? recordLogItem.card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLogItem.log,\n * cid: (recordLogItem.card as Card & { cid: string }).cid,\n * due: recordLogItem.log.due.getTime(),\n * review: recordLogItem.log.review.getTime(),\n * state: State[recordLogItem.log.state] as StateType,\n * rating: Rating[recordLogItem.log.rating] as RatingType,\n * },\n * };\n * }\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card } = repeatFormAfterHandler[Rating.Hard];\n * const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);\n * ```\n */\n forget<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n reset_count: boolean = false,\n afterHandler?: (recordLogItem: RecordLogItem) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n now = TypeConvert.time(now)\n const scheduled_days =\n processedCard.state === State.New\n ? 0\n : now.diff(processedCard.last_review as Date, 'days')\n const forget_log: ReviewLog = {\n rating: Rating.Manual,\n state: processedCard.state,\n due: processedCard.due,\n stability: processedCard.stability,\n difficulty: processedCard.difficulty,\n elapsed_days: 0,\n last_elapsed_days: processedCard.elapsed_days,\n scheduled_days: scheduled_days,\n review: now,\n }\n const forget_card: Card = {\n ...processedCard,\n due: now,\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: reset_count ? 0 : processedCard.reps,\n lapses: reset_count ? 0 : processedCard.lapses,\n state: State.New,\n last_review: processedCard.last_review,\n }\n const recordLogItem: RecordLogItem = { card: forget_card, log: forget_log }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n *\n * @param cards scheduled card collection\n * @param options Reschedule options,fuzz is enabled by default.If the type of due is not Date, please implement dataHandler.\n * @example\n * ```typescript\n * type CardType = Card & {\n * cid: number;\n * };\n * const reviewCard: CardType = {\n * cid: 1,\n * due: new Date(\"2024-03-17 04:43:02\"),\n * stability: 48.26139059062234,\n * difficulty: 5.67,\n * elapsed_days: 18,\n * scheduled_days: 51,\n * reps: 8,\n * lapses: 1,\n * state: State.Review,\n * last_review: new Date(\"2024-01-26 04:43:02\"),\n * };\n * const f = fsrs();\n * const reschedule_cards = f.reschedule([reviewCard]);\n * ```\n *\n */\n reschedule<T extends CardInput | Card>(\n cards: Array<T>,\n options: RescheduleOptions = {}\n ): Array<T> {\n if (!Array.isArray(cards)) {\n throw new Error('cards must be an array')\n }\n const processedCard: T[] = []\n for (const card of cards) {\n if (TypeConvert.state(card.state) !== State.Review || !card.last_review)\n continue\n const scheduled_days = Math.floor(card.scheduled_days) as int\n const next_ivl = this.next_interval(\n +card.stability.toFixed(2),\n Math.round(card.elapsed_days),\n options.enable_fuzz ?? true\n )\n if (next_ivl === scheduled_days || next_ivl === 0) continue\n\n const processCard: T = { ...card }\n processCard.scheduled_days = next_ivl\n const new_due = date_scheduler(processCard.last_review!, next_ivl, true)\n if (options.dateHandler && typeof options.dateHandler === 'function') {\n processCard.due = options.dateHandler(new_due)\n } else {\n processCard.due = new_due\n }\n processedCard.push(processCard)\n }\n return processedCard\n }\n}\n\n/**\n * Create a new instance of TS-FSRS\n * @param params FSRSParameters\n * @example\n * ```typescript\n * const f = fsrs();\n * ```\n * @example\n * ```typescript\n * const params: FSRSParameters = generatorParameters({ maximum_interval: 1000 });\n * const f = fsrs(params);\n * ```\n * @example\n * ```typescript\n * const f = fsrs({ maximum_interval: 1000 });\n * ```\n */\nexport const fsrs = (params?: Partial<FSRSParameters>) => {\n return new FSRS(params || {})\n}\n"],"names":["State","t","Rating","e","TypeConvert","card","value","firstLetter","restOfString","ret","timestamp","log","default_request_retention","default_maximum_interval","default_w","default_enable_fuzz","defualt_enable_short_term","FSRSVersion","generatorParameters","props","w","createEmptyCard","now","afterHandler","emptyCard","isDay","date_scheduler","pre","unit","date_diff","formatDate","last_review","timeUnit","show_diff_message","fixDate","diff","r","dateInput","date","year","month","day","hours","minutes","seconds","padZero","num","TIMEUNIT","TIMEUNITFORMAT","due","i","fixState","fixRating","Grades","FUZZ_RANGES","get_fuzz_range","interval","elapsed_days","maximum_interval","delta","range","min_ivl","max_ivl","DECAY","FACTOR","FSRSAlgorithm","params","seed","request_retention","_this","target","prop","_params","key","paramKey","g","ivl","enable_fuzz","fuzz_factor","pseudorandom","s","newInterval","d","next_d","difficulty","init","current","hard_penalty","easy_bound","stability","AbstractScheduler","algorithm","state","grade","item","time","reps","mul","rating","BasicScheduler","exist","next","easy_interval","good_interval","good_stability","retrievability","next_again","next_hard","next_good","next_easy","item_again","item_hard","item_good","item_easy","hard_interval","LongTermScheduler","first_difficulty","first_stability","first_interval","again_interval","FSRS","param","enable_short_term","Schduler","recordLog","instace","recordLogItem","format","processedCard","processedLog","last_due","last_lapses","prevCard","reset_count","scheduled_days","forget_log","cards","options","next_ivl","processCard","new_due","fsrs"],"mappings":"yCAEYA,GAAAA,IACVA,EAAAA,EAAA,IAAM,CAAN,EAAA,MACAA,IAAA,SAAW,CAAA,EAAX,WACAA,EAAAC,EAAA,OAAS,GAAT,SACAD,EAAAA,EAAA,WAAa,CAAb,EAAA,aAJUA,IAAAA,GASA,CAAA,CAAA,EAAAE,GAAAA,IACVA,EAAAA,EAAA,OAAS,CAAT,EAAA,SACAA,IAAA,MAAQ,CAAA,EAAR,QACAA,EAAAC,EAAA,KAAO,GAAP,OACAD,EAAAA,EAAA,KAAO,CAAP,EAAA,OACAA,IAAA,KAAO,CAAA,EAAP,OALUA,IAAAA,GAAA,CAAA,CAAA,ECDC,MAAAE,CAAY,CACvB,OAAO,KAAiCC,EAAe,CACrD,MAAO,CACL,GAAGA,EACH,MAAOD,EAAY,MAAMC,EAAK,KAAK,EACnC,IAAKD,EAAY,KAAKC,EAAK,GAAG,EAC9B,YAAaA,EAAK,YACdD,EAAY,KAAKC,EAAK,WAAW,EACjC,MACN,CACF,CACA,OAAO,OAAOC,EAAwB,CACpC,GAAI,OAAOA,GAAU,SAAU,CAC7B,MAAMC,EAAcD,EAAM,OAAO,CAAC,EAAE,cAC9BE,EAAeF,EAAM,MAAM,CAAC,EAAE,cAC9BG,EAAMP,EAAO,GAAGK,CAAW,GAAGC,CAAY,EAAyB,EACzE,GAAIC,IAAQ,OACV,MAAM,IAAI,MAAM,mBAAmBH,CAAK,GAAG,EAE7C,OAAOG,CACT,SAAW,OAAOH,GAAU,SAC1B,OAAOA,EAET,MAAM,IAAI,MAAM,mBAA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