@zephyr424/wb-sdk 0.1.1 → 0.2.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/.github/workflows/deploy.yml +41 -0
- package/README.md +2 -2
- package/data/top5000.json +55002 -0
- package/docs/.vitepress/config.mjs +112 -0
- package/docs/api/review.md +155 -0
- package/docs/api/types.md +0 -0
- package/docs/api/word.md +189 -0
- package/docs/blog/designing-api.md +30 -0
- package/docs/blog/index.md +19 -0
- package/docs/blog/publishing-to-npm.md +36 -0
- package/docs/blog/why-sm2.md +26 -0
- package/docs/contributors.md +16 -0
- package/docs/en/api/word.md +189 -0
- package/docs/en/blog/index.md +0 -0
- package/docs/en/guide/index.md +28 -0
- package/docs/en/index.md +25 -0
- package/docs/guide/index.md +100 -0
- package/docs/index.md +39 -0
- package/docs/package-lock.json +2564 -0
- package/docs/package.json +19 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/scripts/build-wordlist.js +26 -0
- package/src/wordBank.js +19 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "docs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"docs:dev": "vitepress dev",
|
|
9
|
+
"docs:build": "vitepress build",
|
|
10
|
+
"docs:preview": "vitepress preview"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"vitepress": "^1.6.4"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const WordBank = require('./src/wordBank');
|
|
2
|
-
module.exports = WordBank;
|
|
2
|
+
module.exports = { WordBank };
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const rawData = fs.readFileSync(path.join(__dirname, '../data/wordfreq-en-25000-log.json'), 'utf8');
|
|
5
|
+
const wordList = JSON.parse(rawData);
|
|
6
|
+
|
|
7
|
+
const top5000 = wordList.slice(0, 5000);
|
|
8
|
+
|
|
9
|
+
const vocab = top5000.map(([word, logFreq], index) => ({
|
|
10
|
+
id: String(index + 1),
|
|
11
|
+
word: word,
|
|
12
|
+
frequency: Math.exp(logFreq),
|
|
13
|
+
phonetic: null,
|
|
14
|
+
definitions: [],
|
|
15
|
+
repetitions: 0,
|
|
16
|
+
interval: 0,
|
|
17
|
+
easeFactor: 2.5,
|
|
18
|
+
lastReviewed: null
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(
|
|
22
|
+
path.join(__dirname, '../data/top5000.json'),
|
|
23
|
+
JSON.stringify(vocab, null, 2)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
console.log(`✅ 已生成 ${vocab.length} 个高频词`);
|
package/src/wordBank.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const WordManager = require('./wordManager');
|
|
2
2
|
const ReviewManager = require('./reviewManager');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
3
5
|
|
|
4
6
|
class WordBank {
|
|
5
7
|
constructor(initialWords = []) {
|
|
@@ -20,10 +22,26 @@ class WordBank {
|
|
|
20
22
|
{ id: '3', word: 'cat', definition: 'a small animal' }
|
|
21
23
|
]
|
|
22
24
|
};
|
|
25
|
+
|
|
26
|
+
// 加载 top5000 高频词
|
|
27
|
+
if (name === 'top5000') {
|
|
28
|
+
const dataPath = path.join(__dirname, '../data/top5000.json');
|
|
29
|
+
try {
|
|
30
|
+
const rawData = fs.readFileSync(dataPath, 'utf8');
|
|
31
|
+
const words = JSON.parse(rawData);
|
|
32
|
+
words.forEach(w => this.word.add(w));
|
|
33
|
+
console.log(`✅ 已加载 ${words.length} 个高频词`);
|
|
34
|
+
return;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('❌ 加载 top5000 词库失败:', err.message);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
23
41
|
const words = presets[name];
|
|
24
42
|
if (!words) throw new Error(`Preset ${name} not found`);
|
|
25
43
|
words.forEach(w => this.word.add(w));
|
|
26
44
|
}
|
|
27
45
|
}
|
|
28
46
|
|
|
29
|
-
module.exports = WordBank;
|
|
47
|
+
module.exports = WordBank;
|