ts-fsrs 2.0.2 → 2.1.1

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/package.json CHANGED
@@ -1,43 +1,54 @@
1
- {
2
- "name": "ts-fsrs",
3
- "version": "2.0.2",
4
- "description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "keywords": [
8
- "SuperMemo",
9
- "Anki",
10
- "FSRS"
11
- ],
12
- "dependencies": {
13
- "seedrandom": "^3.0.5"
14
- },
15
- "devDependencies": {
16
- "@types/seedrandom": "^3.0.5",
17
- "eslint": "^8.34.0",
18
- "typescript": "^4.9.5"
19
- },
20
- "scripts": {
21
- "test": "ts-node test/index.ts",
22
- "build": "tsc",
23
- "test_publish": "yalc publish",
24
- "major": "npm version major",
25
- "minor": "npm version minor",
26
- "patch": "npm version patch"
27
- },
28
- "author": "ishiko",
29
- "license": "MIT",
30
- "files": [
31
- "lib/**/*",
32
- "README.md",
33
- "LICENSE"
34
- ],
35
- "repository": {
36
- "type": "git",
37
- "url": "git+https://github.com/ishiko732/ts-fsrs.git"
38
- },
39
- "bugs": {
40
- "url": "https://github.com/ishiko732/ts-fsrs/issues"
41
- },
42
- "homepage": "https://github.com/ishiko732/ts-fsrs#readme"
43
- }
1
+ {
2
+ "name": "ts-fsrs",
3
+ "version": "2.1.1",
4
+ "description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [
8
+ "SuperMemo",
9
+ "Anki",
10
+ "FSRS"
11
+ ],
12
+ "dependencies": {
13
+ "seedrandom": "^3.0.5"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^20.6.2",
17
+ "@types/jest": "^29.5.5",
18
+ "@types/seedrandom": "^3.0.5",
19
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
20
+ "@typescript-eslint/parser": "^6.7.0",
21
+ "eslint": "^8.44.0",
22
+ "eslint-config-prettier": "^9.0.0",
23
+ "jest": "^29.7.0",
24
+ "prettier": "^3.0.3",
25
+ "ts-jest": "^29.1.1",
26
+ "ts-node": "^10.9.1",
27
+ "typescript": "^5.1.6"
28
+ },
29
+ "scripts": {
30
+ "lint": "eslint --fix src/ && prettier --write src/",
31
+ "dev": "ts-node src/fsrs/index.ts",
32
+ "test": "jest --passWithNoTests",
33
+ "build": "tsc --project ./tsconfig.json",
34
+ "major": "npm version major",
35
+ "minor": "npm version minor",
36
+ "patch": "npm version patch",
37
+ "test_publish": "yalc publish"
38
+ },
39
+ "author": "ishiko",
40
+ "license": "MIT",
41
+ "files": [
42
+ "dist/**/*",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/ishiko732/ts-fsrs.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/ishiko732/ts-fsrs/issues"
52
+ },
53
+ "homepage": "https://github.com/ishiko732/ts-fsrs#readme"
54
+ }
package/lib/help.js DELETED
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.show_diff_message = exports.formatDate = exports.date_diff = exports.date_scheduler = void 0;
4
- Date.prototype.scheduler = function (t, isDay) {
5
- return date_scheduler(this, t, isDay);
6
- };
7
- /**
8
- * 当前时间与之前的时间差值
9
- * @param pre 比当前时间还要之前
10
- * @param unit 单位: days | minutes
11
- */
12
- Date.prototype.diff = function (pre, unit) {
13
- return date_diff(this, pre, unit);
14
- };
15
- Date.prototype.format = function () {
16
- return formatDate(this);
17
- };
18
- Date.prototype.dueFormat = function (last_review, unit) {
19
- return show_diff_message(this, last_review, unit);
20
- };
21
- function date_scheduler(now, t, isDay) {
22
- return new Date(isDay ? now.getTime() + t * 24 * 60 * 60 * 1000 : now.getTime() + t * 60 * 1000);
23
- }
24
- exports.date_scheduler = date_scheduler;
25
- function date_diff(now, pre, unit) {
26
- const diff = now.getTime() - pre.getTime();
27
- let r = 0;
28
- switch (unit) {
29
- case 'days':
30
- r = Math.floor((diff) / (24 * 60 * 60 * 1000));
31
- break;
32
- case 'minutes':
33
- r = Math.floor((diff) / (60 * 1000));
34
- break;
35
- }
36
- return r;
37
- }
38
- exports.date_diff = date_diff;
39
- function formatDate(date) {
40
- const year = date.getFullYear();
41
- const month = date.getMonth() + 1;
42
- const day = date.getDate();
43
- const hours = date.getHours();
44
- const minutes = date.getMinutes();
45
- const seconds = date.getSeconds();
46
- return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
47
- }
48
- exports.formatDate = formatDate;
49
- function padZero(num) {
50
- return num < 10 ? `0${num}` : `${num}`;
51
- }
52
- function show_diff_message(due, last_review, unit) {
53
- const diff = due.getTime() - last_review.getTime();
54
- if (diff < 1000 * 60 * 60) { // 小于1小时
55
- return unit ? Math.floor((diff) / (60 * 1000)) + 'min' : String(Math.floor((diff) / (60 * 1000)));
56
- }
57
- else if (diff >= 1000 * 60 * 60 && diff < 1000 * 60 * 60 * 24) { // 大于1小时,小于1天
58
- return unit ? Math.floor((diff) / (60 * 60 * 1000)) + 'hour' : String(Math.floor((diff) / (60 * 60 * 1000)));
59
- }
60
- else if (diff >= 1000 * 60 * 60 * 24 && diff < 1000 * 60 * 60 * 24 * 31) { // 大于1天,小于31天
61
- return unit ? Math.floor((diff) / (24 * 60 * 60 * 1000)) + 'day' : String(Math.floor((diff) / (24 * 60 * 60 * 1000 * 1000)));
62
- }
63
- else if (diff >= 1000 * 60 * 60 * 24 * 31 && diff < 1000 * 60 * 60 * 24 * 365) { // 大于31天,小于365天
64
- return unit ? ((diff) / (30 * 24 * 60 * 60 * 1000)).toFixed(2) + 'month' : ((diff) / (30 * 24 * 60 * 60 * 1000)).toFixed(2);
65
- }
66
- else { // 大于365天
67
- return unit ? ((diff) / (365 * 24 * 60 * 60 * 1000)).toFixed(2) + 'year' : ((diff) / (365 * 24 * 60 * 60 * 1000)).toFixed(2);
68
- }
69
- }
70
- exports.show_diff_message = show_diff_message;