Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxvien authored and Maxvien committed Jul 10, 2020
0 parents commit 34e0cde
Show file tree
Hide file tree
Showing 9 changed files with 6,429 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.log
.DS_Store
node_modules
dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Vien Dinh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SuperMemo

A JavaScript/TypeScript implementation of the [SuperMemo 2](https://super-memory.com/english/ol/sm2.htm) (SM2) algorithm for spaced based repetition flashcards.

## Installation

```
npm install --save supermemo
```

## Usage

```
import { supermemo, SuperMemoItem } from 'supermemo';
let item: SuperMemoItem = {
interval: 0,
repetition: 0,
efactor: 2.5,
};
console.log(item);
item = supermemo(item, 5);
console.log(item);
item = supermemo(item, 4);
console.log(item);
```

## References

- [The SuperMemo 2 Algorithm explanation.](https://super-memory.com/english/ol/sm2.htm)
- [The Delphi implementation of SuperMemo 2.](https://super-memory.com/english/ol/sm2source.htm)
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "supermemo",
"description": "A JavaScript/TypeScript implementation of the SuperMemo 2 (SM2) algorithm for spaced based repetition flashcards.",
"keywords": [
"sm2",
"supermemo",
"flashcard",
"supermemo-2",
"spaced-repetition"
],
"author": "Vien Dinh",
"version": "2.0.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"test": "tsdx test",
"build": "npx rimraf dist && tsc",
"prepare": "npm run build",
"lint": "tsdx lint"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "^25.1.1",
"husky": "^4.2.1",
"tsdx": "^0.12.3",
"tslib": "^1.10.0",
"typescript": "^3.7.5"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 120,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Maxvien/supermemo.git"
},
"bugs": {
"url": "https://github.com/Maxvien/supermemo/issues"
},
"homepage": "https://github.com/Maxvien/supermemo#readme"
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './supermemo';
3 changes: 3 additions & 0 deletions src/supermemo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { supermemo, SuperMemoItem } from './supermemo';

describe('supermemo', () => {});
39 changes: 39 additions & 0 deletions src/supermemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export interface SuperMemoItem {
interval: number;
repetition: number;
efactor: number;
}

export type SuperMemoGrade = 0 | 1 | 2 | 3 | 4 | 5;

export function supermemo(item: SuperMemoItem, grade: SuperMemoGrade): SuperMemoItem {
let nextInterval: number;
let nextRepetition: number;
let nextEfactor: number;

if (grade >= 3) {
if (item.repetition === 0) {
nextInterval = 1;
nextRepetition = 1;
} else if (item.repetition === 1) {
nextInterval = 6;
nextRepetition = 2;
} else {
nextInterval = Math.round(item.interval * item.efactor);
nextRepetition = item.repetition + 1;
}
} else {
nextInterval = 1;
nextRepetition = 0;
}

nextEfactor = item.efactor + (0.1 - (5 - grade) * (0.08 + (5 - grade) * 0.02));

if (nextEfactor < 1.3) nextEfactor = 1.3;

return {
interval: nextInterval,
repetition: nextRepetition,
efactor: nextEfactor,
};
}
27 changes: 27 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "es5",
"module": "CommonJS",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true,
"sourceMap": false,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["examples", "node_modules", "src/**/*.test.ts"]
}
Loading

0 comments on commit 34e0cde

Please sign in to comment.