ts-fsrs 5.2.0 → 5.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -124,75 +124,12 @@ interface FSRSState {
124
124
  difficulty: number;
125
125
  }
126
126
 
127
- declare const clipParameters: (parameters: number[], numRelearningSteps: number) => number[];
128
- /**
129
- * @returns The input if the parameters are valid, throws if they are invalid
130
- * @example
131
- * try {
132
- * generatorParameters({
133
- * w: checkParameters([0.40255])
134
- * });
135
- * } catch (e: any) {
136
- * alert(e);
137
- * }
138
- */
139
- declare const checkParameters: (parameters: number[] | readonly number[]) => number[] | readonly number[];
140
- declare const migrateParameters: (parameters?: number[] | readonly number[]) => number[];
141
- declare const generatorParameters: (props?: Partial<FSRSParameters>) => FSRSParameters;
142
- /**
143
- * Create an empty card
144
- * @param now Current time
145
- * @param afterHandler Convert the result to another type. (Optional)
146
- * @example
147
- * ```typescript
148
- * const card: Card = createEmptyCard(new Date());
149
- * ```
150
- * @example
151
- * ```typescript
152
- * interface CardUnChecked
153
- * extends Omit<Card, "due" | "last_review" | "state"> {
154
- * cid: string;
155
- * due: Date | number;
156
- * last_review: Date | null | number;
157
- * state: StateType;
158
- * }
159
- *
160
- * function cardAfterHandler(card: Card) {
161
- * return {
162
- * ...card,
163
- * cid: "test001",
164
- * state: State[card.state],
165
- * last_review: card.last_review ?? null,
166
- * } as CardUnChecked;
167
- * }
168
- *
169
- * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);
170
- * ```
171
- */
172
- declare function createEmptyCard<R = Card>(now?: DateInput, afterHandler?: (card: Card) => R): R;
173
-
174
- declare const default_request_retention = 0.9;
175
- declare const default_maximum_interval = 36500;
176
- declare const default_enable_fuzz = false;
177
- declare const default_enable_short_term = true;
178
- declare const default_learning_steps: readonly StepUnit[];
179
- declare const default_relearning_steps: readonly StepUnit[];
180
- declare const FSRSVersion: string;
181
- declare const S_MIN = 0.001;
182
- declare const S_MAX = 36500;
183
- declare const INIT_S_MAX = 100;
184
- declare const FSRS5_DEFAULT_DECAY = 0.5;
185
- declare const FSRS6_DEFAULT_DECAY = 0.1542;
186
- declare const default_w: readonly number[];
187
- declare const W17_W18_Ceiling = 2;
188
- declare const CLAMP_PARAMETERS: (w17_w18_ceiling: number) => number[][];
189
-
190
127
  type unit = 'days' | 'minutes';
191
128
  type int = number & {
192
- __int__: void;
129
+ __int__: undefined;
193
130
  };
194
131
  type double = number & {
195
- __double__: void;
132
+ __double__: undefined;
196
133
  };
197
134
  interface IPreview extends RecordLog {
198
135
  [Symbol.iterator](): IterableIterator<RecordLogItem>;
@@ -244,65 +181,6 @@ type IReschedule<T = RecordLogItem> = {
244
181
  reschedule_item: T | null;
245
182
  };
246
183
 
247
- declare global {
248
- export interface Date {
249
- /**
250
- * @deprecated This method will be removed in version 6.0.0.
251
- *
252
- */
253
- scheduler(t: int, isDay?: boolean): Date;
254
- /**
255
- * @deprecated This method will be removed in version 6.0.0.
256
- *
257
- */
258
- diff(pre: Date, unit: unit): int;
259
- /**
260
- * @deprecated This method will be removed in version 6.0.0.
261
- *
262
- */
263
- format(): string;
264
- /**
265
- * @deprecated This method will be removed in version 6.0.0.
266
- *
267
- */
268
- dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string;
269
- }
270
- }
271
- /**
272
- * 计算日期和时间的偏移,并返回一个新的日期对象。
273
- * @param now 当前日期和时间
274
- * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟
275
- * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移
276
- * @returns 偏移后的日期和时间对象
277
- */
278
- declare function date_scheduler(now: DateInput, t: number, isDay?: boolean): Date;
279
- declare function date_diff(now: DateInput, pre: DateInput, unit: unit): number;
280
- declare function formatDate(dateInput: DateInput): string;
281
- declare function show_diff_message(due: DateInput, last_review: DateInput, unit?: boolean, timeUnit?: string[]): string;
282
- /**
283
- *
284
- * @deprecated Use TypeConvert.time instead
285
- * @deprecated This function will be removed in version 6.0.0.
286
- */
287
- declare function fixDate(value: unknown): Date;
288
- /**
289
- * @deprecated Use TypeConvert.state instead
290
- * @deprecated This function will be removed in version 6.0.0.
291
- */
292
- declare function fixState(value: unknown): State;
293
- /**
294
- * @deprecated Use TypeConvert.rating instead
295
- * @deprecated This function will be removed in version 6.0.0.
296
- */
297
- declare function fixRating(value: unknown): Rating;
298
- declare const Grades: Readonly<Grade[]>;
299
- declare function get_fuzz_range(interval: number, elapsed_days: number, maximum_interval: number): {
300
- min_ivl: number;
301
- max_ivl: number;
302
- };
303
- declare function clamp(value: number, min: number, max: number): number;
304
- declare function dateDiffInDays(last: Date, cur: Date): number;
305
-
306
184
  /**
307
185
  * $$\text{decay} = -w_{20}$$
308
186
  *
@@ -315,6 +193,7 @@ declare const computeDecayFactor: (decayOrParams: number | number[] | readonly n
315
193
  /**
316
194
  * The formula used is :
317
195
  * $$R(t,S) = (1 + \text{FACTOR} \times \frac{t}{9 \cdot S})^{\text{DECAY}}$$
196
+ * @param {number} decay - The decay factor, decay should be greater than or equal to 0.1 and less than or equal to 0.8.
318
197
  * @param {number} elapsed_days t days since the last review
319
198
  * @param {number} stability Stability (interval when R=90%)
320
199
  * @return {number} r Retrievability (probability of recall)
@@ -451,6 +330,29 @@ declare class FSRSAlgorithm {
451
330
  next_state(memory_state: FSRSState | null, t: number, g: number): FSRSState;
452
331
  }
453
332
 
333
+ declare enum StrategyMode {
334
+ SCHEDULER = "Scheduler",
335
+ LEARNING_STEPS = "LearningSteps",
336
+ SEED = "Seed"
337
+ }
338
+ type TSeedStrategy = (this: AbstractScheduler) => string;
339
+ type TSchedulerStrategy<T extends CardInput | Card = CardInput | Card> = new (card: T, now: DateInput, algorithm: FSRSAlgorithm, strategies: Map<StrategyMode, TStrategyHandler>) => IScheduler;
340
+ /**
341
+ * When enable_short_term = false, the learning steps strategy will not take effect.
342
+ */
343
+ type TLearningStepsStrategy = (params: FSRSParameters, state: State, cur_step: number) => {
344
+ [K in Grade]?: {
345
+ scheduled_minutes: number;
346
+ next_step: number;
347
+ };
348
+ };
349
+ type StrategyMap = {
350
+ [StrategyMode.SCHEDULER]: TSchedulerStrategy;
351
+ [StrategyMode.SEED]: TSeedStrategy;
352
+ [StrategyMode.LEARNING_STEPS]: TLearningStepsStrategy;
353
+ };
354
+ type TStrategyHandler<E = StrategyMode> = E extends StrategyMode ? StrategyMap[E] : never;
355
+
454
356
  declare abstract class AbstractScheduler implements IScheduler {
455
357
  protected last: Card;
456
358
  protected current: Card;
@@ -471,28 +373,76 @@ declare abstract class AbstractScheduler implements IScheduler {
471
373
  protected buildLog(rating: Grade): ReviewLog;
472
374
  }
473
375
 
474
- declare enum StrategyMode {
475
- SCHEDULER = "Scheduler",
476
- LEARNING_STEPS = "LearningSteps",
477
- SEED = "Seed"
376
+ declare const default_request_retention = 0.9;
377
+ declare const default_maximum_interval = 36500;
378
+ declare const default_enable_fuzz = false;
379
+ declare const default_enable_short_term = true;
380
+ declare const default_learning_steps: readonly StepUnit[];
381
+ declare const default_relearning_steps: readonly StepUnit[];
382
+ declare const FSRSVersion: string;
383
+ declare const S_MIN = 0.001;
384
+ declare const S_MAX = 36500;
385
+ declare const INIT_S_MAX = 100;
386
+ declare const FSRS5_DEFAULT_DECAY = 0.5;
387
+ declare const FSRS6_DEFAULT_DECAY = 0.1542;
388
+ declare const default_w: readonly number[];
389
+ declare const W17_W18_Ceiling = 2;
390
+ declare const CLAMP_PARAMETERS: (w17_w18_ceiling: number, enable_short_term?: boolean) => number[][];
391
+
392
+ declare class TypeConvert {
393
+ static card<T extends Card | CardInput>(card: T): Card;
394
+ static rating(value: unknown): Rating;
395
+ static state(value: unknown): State;
396
+ static time(value: unknown): Date;
397
+ static review_log(log: ReviewLogInput | ReviewLog): ReviewLog;
478
398
  }
479
- type TSeedStrategy = (this: AbstractScheduler) => string;
480
- type TSchedulerStrategy<T extends CardInput | Card = CardInput | Card> = new (card: T, now: DateInput, algorithm: FSRSAlgorithm, strategies: Map<StrategyMode, TStrategyHandler>) => IScheduler;
399
+
400
+ declare const clipParameters: (parameters: number[], numRelearningSteps: number, enableShortTerm?: boolean) => number[];
481
401
  /**
482
- * When enable_short_term = false, the learning steps strategy will not take effect.
402
+ * @returns The input if the parameters are valid, throws if they are invalid
403
+ * @example
404
+ * try {
405
+ * generatorParameters({
406
+ * w: checkParameters([0.40255])
407
+ * });
408
+ * } catch (e: any) {
409
+ * alert(e);
410
+ * }
483
411
  */
484
- type TLearningStepsStrategy = (params: FSRSParameters, state: State, cur_step: number) => {
485
- [K in Grade]?: {
486
- scheduled_minutes: number;
487
- next_step: number;
488
- };
489
- };
490
- type StrategyMap = {
491
- [StrategyMode.SCHEDULER]: TSchedulerStrategy;
492
- [StrategyMode.SEED]: TSeedStrategy;
493
- [StrategyMode.LEARNING_STEPS]: TLearningStepsStrategy;
494
- };
495
- type TStrategyHandler<E = StrategyMode> = E extends StrategyMode ? StrategyMap[E] : never;
412
+ declare const checkParameters: (parameters: number[] | readonly number[]) => readonly number[] | number[];
413
+ declare const migrateParameters: (parameters?: number[] | readonly number[], numRelearningSteps?: number, enableShortTerm?: boolean) => number[];
414
+ declare const generatorParameters: (props?: Partial<FSRSParameters>) => FSRSParameters;
415
+ /**
416
+ * Create an empty card
417
+ * @param now Current time
418
+ * @param afterHandler Convert the result to another type. (Optional)
419
+ * @example
420
+ * ```typescript
421
+ * const card: Card = createEmptyCard(new Date());
422
+ * ```
423
+ * @example
424
+ * ```typescript
425
+ * interface CardUnChecked
426
+ * extends Omit<Card, "due" | "last_review" | "state"> {
427
+ * cid: string;
428
+ * due: Date | number;
429
+ * last_review: Date | null | number;
430
+ * state: StateType;
431
+ * }
432
+ *
433
+ * function cardAfterHandler(card: Card) {
434
+ * return {
435
+ * ...card,
436
+ * cid: "test001",
437
+ * state: State[card.state],
438
+ * last_review: card.last_review ?? null,
439
+ * } as CardUnChecked;
440
+ * }
441
+ *
442
+ * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);
443
+ * ```
444
+ */
445
+ declare function createEmptyCard<R = Card>(now?: DateInput, afterHandler?: (card: Card) => R): R;
496
446
 
497
447
  type RequireOnly<A, K extends keyof A> = {
498
448
  [P in K]-?: A[P];
@@ -553,13 +503,67 @@ declare class FSRS extends FSRSAlgorithm implements IFSRS {
553
503
  */
554
504
  declare const fsrs: (params?: Partial<FSRSParameters>) => FSRS;
555
505
 
556
- declare class TypeConvert {
557
- static card<T extends Card | CardInput>(card: T): Card;
558
- static rating(value: unknown): Rating;
559
- static state(value: unknown): State;
560
- static time(value: unknown): Date;
561
- static review_log(log: ReviewLogInput | ReviewLog): ReviewLog;
506
+ declare global {
507
+ export interface Date {
508
+ /**
509
+ * @deprecated This method will be removed in version 6.0.0.
510
+ *
511
+ */
512
+ scheduler(t: int, isDay?: boolean): Date;
513
+ /**
514
+ * @deprecated This method will be removed in version 6.0.0.
515
+ *
516
+ */
517
+ diff(pre: Date, unit: unit): int;
518
+ /**
519
+ * @deprecated This method will be removed in version 6.0.0.
520
+ *
521
+ */
522
+ format(): string;
523
+ /**
524
+ * @deprecated This method will be removed in version 6.0.0.
525
+ *
526
+ */
527
+ dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string;
528
+ }
562
529
  }
530
+ /**
531
+ * 计算日期和时间的偏移,并返回一个新的日期对象。
532
+ * @param now 当前日期和时间
533
+ * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟
534
+ * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移
535
+ * @returns 偏移后的日期和时间对象
536
+ */
537
+ declare function date_scheduler(now: DateInput, t: number, isDay?: boolean): Date;
538
+ declare function date_diff(now: DateInput, pre: DateInput, unit: unit): number;
539
+ declare function formatDate(dateInput: DateInput): string;
540
+ declare function show_diff_message(due: DateInput, last_review: DateInput, unit?: boolean, timeUnit?: string[]): string;
541
+ /**
542
+ *
543
+ * @deprecated Use TypeConvert.time instead
544
+ * @deprecated This function will be removed in version 6.0.0.
545
+ */
546
+ declare function fixDate(value: unknown): Date;
547
+ /**
548
+ * @deprecated Use TypeConvert.state instead
549
+ * @deprecated This function will be removed in version 6.0.0.
550
+ */
551
+ declare function fixState(value: unknown): State;
552
+ /**
553
+ * @deprecated Use TypeConvert.rating instead
554
+ * @deprecated This function will be removed in version 6.0.0.
555
+ */
556
+ declare function fixRating(value: unknown): Rating;
557
+ declare const Grades: Readonly<Grade[]>;
558
+ declare function get_fuzz_range(interval: number, elapsed_days: number, maximum_interval: number): {
559
+ min_ivl: number;
560
+ max_ivl: number;
561
+ };
562
+ declare function clamp(value: number, min: number, max: number): number;
563
+ declare function dateDiffInDays(last: Date, cur: Date): number;
564
+
565
+ declare const ConvertStepUnitToMinutes: (step: StepUnit) => number;
566
+ declare const BasicLearningStepsStrategy: TLearningStepsStrategy;
563
567
 
564
568
  declare function DefaultInitSeedStrategy(this: AbstractScheduler): string;
565
569
  /**
@@ -583,8 +587,5 @@ declare function DefaultInitSeedStrategy(this: AbstractScheduler): string;
583
587
  */
584
588
  declare function GenSeedStrategyWithCardId(card_id_field: string | number): TSeedStrategy;
585
589
 
586
- declare const ConvertStepUnitToMinutes: (step: StepUnit) => number;
587
- declare const BasicLearningStepsStrategy: TLearningStepsStrategy;
588
-
589
590
  export { AbstractScheduler, BasicLearningStepsStrategy, CLAMP_PARAMETERS, ConvertStepUnitToMinutes, DefaultInitSeedStrategy, FSRS, FSRS5_DEFAULT_DECAY, FSRS6_DEFAULT_DECAY, FSRSAlgorithm, FSRSVersion, GenSeedStrategyWithCardId, Grades, INIT_S_MAX, Rating, S_MAX, S_MIN, State, StrategyMode, TypeConvert, W17_W18_Ceiling, checkParameters, clamp, clipParameters, computeDecayFactor, createEmptyCard, dateDiffInDays, date_diff, date_scheduler, default_enable_fuzz, default_enable_short_term, default_learning_steps, default_maximum_interval, default_relearning_steps, default_request_retention, default_w, fixDate, fixRating, fixState, forgetting_curve, formatDate, fsrs, generatorParameters, get_fuzz_range, migrateParameters, show_diff_message };
590
591
  export type { Card, CardInput, DateInput, FSRSHistory, FSRSParameters, FSRSReview, FSRSState, Grade, GradeType, IFSRS, IPreview, IReschedule, IScheduler, RatingType, RecordLog, RecordLogItem, RescheduleOptions, ReviewLog, ReviewLogInput, StateType, StepUnit, Steps, TLearningStepsStrategy, TSchedulerStrategy, TSeedStrategy, TStrategyHandler, TimeUnit, double, int, unit };