@zephyr424/wb-sdk 0.1.1 → 0.3.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/bin/wb.js +82 -0
- 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.d.ts +48 -0
- package/index.js +1 -1
- package/package.json +32 -25
- package/scripts/build-wordlist.js +26 -0
- package/src/wordBank.js +19 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Word Management API
|
|
2
|
+
|
|
3
|
+
The `wb.word` module provides methods for managing your word bank — adding, retrieving, searching, and deleting words.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## `wb.word.list()`
|
|
8
|
+
|
|
9
|
+
Returns all words currently stored in the bank.
|
|
10
|
+
|
|
11
|
+
**Returns:** `Word[]` — an array of `Word` objects.
|
|
12
|
+
|
|
13
|
+
**Example:**
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const allWords = wb.word.list();
|
|
17
|
+
console.log(allWords);
|
|
18
|
+
// [
|
|
19
|
+
// Word { id: '1', word: 'apple', definition: 'a fruit', ... },
|
|
20
|
+
// Word { id: '2', word: 'book', definition: 'a set of pages', ... }
|
|
21
|
+
// ]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## `wb.word.get(id)`
|
|
27
|
+
|
|
28
|
+
Retrieves a single word by its unique identifier.
|
|
29
|
+
|
|
30
|
+
**Parameters:**
|
|
31
|
+
|
|
32
|
+
| Parameter | Type | Required | Description |
|
|
33
|
+
| :--- | :--- | :--- | :--- |
|
|
34
|
+
| `id` | `string` | ✅ Yes | The unique ID of the word |
|
|
35
|
+
|
|
36
|
+
**Returns:** `Word | null` — the word object if found, otherwise `null`.
|
|
37
|
+
|
|
38
|
+
**Example:**
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const word = wb.word.get('apple');
|
|
42
|
+
if (word) {
|
|
43
|
+
console.log(word.definition); // "a fruit"
|
|
44
|
+
} else {
|
|
45
|
+
console.log('Word not found');
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## `wb.word.add(data)`
|
|
52
|
+
|
|
53
|
+
Adds a new word to the bank. If a word with the same ID already exists, it will be overwritten.
|
|
54
|
+
|
|
55
|
+
**Parameters:**
|
|
56
|
+
|
|
57
|
+
| Parameter | Type | Required | Description |
|
|
58
|
+
| :--- | :--- | :--- | :--- |
|
|
59
|
+
| `data.id` | `string` | ✅ Yes | Unique identifier |
|
|
60
|
+
| `data.word` | `string` | ✅ Yes | The word itself |
|
|
61
|
+
| `data.definition` | `string` | ✅ Yes | Meaning or translation |
|
|
62
|
+
| `data.repetitions` | `number` | ❌ No | Default: `0` |
|
|
63
|
+
| `data.interval` | `number` | ❌ No | Default: `0` (days) |
|
|
64
|
+
| `data.easeFactor` | `number` | ❌ No | Default: `2.5` (range 1.3–2.5) |
|
|
65
|
+
| `data.lastReviewed` | `string \| Date \| null` | ❌ No | Default: `null` (ISO string or Date object) |
|
|
66
|
+
|
|
67
|
+
**Returns:** `Word` — the newly created (or updated) word object.
|
|
68
|
+
|
|
69
|
+
**Example:**
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// Add a simple word
|
|
73
|
+
wb.word.add({
|
|
74
|
+
id: 'grok',
|
|
75
|
+
word: 'grok',
|
|
76
|
+
definition: 'to understand intuitively'
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Add a word with explicit SM‑2 state (e.g., when importing data)
|
|
80
|
+
wb.word.add({
|
|
81
|
+
id: 'serendipity',
|
|
82
|
+
word: 'serendipity',
|
|
83
|
+
definition: 'the occurrence of events by chance in a happy way',
|
|
84
|
+
repetitions: 3,
|
|
85
|
+
interval: 15,
|
|
86
|
+
easeFactor: 2.3,
|
|
87
|
+
lastReviewed: '2026-08-15T10:00:00.000Z'
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## `wb.word.remove(id)`
|
|
94
|
+
|
|
95
|
+
Permanently deletes a word from the bank by its ID.
|
|
96
|
+
|
|
97
|
+
**Parameters:**
|
|
98
|
+
|
|
99
|
+
| Parameter | Type | Required | Description |
|
|
100
|
+
| :--- | :--- | :--- | :--- |
|
|
101
|
+
| `id` | `string` | ✅ Yes | The unique ID of the word to remove |
|
|
102
|
+
|
|
103
|
+
**Returns:** `void`
|
|
104
|
+
|
|
105
|
+
**Example:**
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
wb.word.remove('grok');
|
|
109
|
+
// Now 'grok' is no longer in the bank
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## `wb.word.search(keyword)`
|
|
115
|
+
|
|
116
|
+
Searches for words whose **word** or **definition** contains the given keyword (case‑insensitive).
|
|
117
|
+
|
|
118
|
+
**Parameters:**
|
|
119
|
+
|
|
120
|
+
| Parameter | Type | Required | Description |
|
|
121
|
+
| :--- | :--- | :--- | :--- |
|
|
122
|
+
| `keyword` | `string` | ✅ Yes | The search term (case‑insensitive) |
|
|
123
|
+
|
|
124
|
+
**Returns:** `Word[]` — an array of matching words (empty if none found).
|
|
125
|
+
|
|
126
|
+
**Example:**
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const results = wb.word.search('bene');
|
|
130
|
+
// Returns words like "benevolent", "beneficial", "benefit"
|
|
131
|
+
results.forEach(w => console.log(`${w.word}: ${w.definition}`));
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## `wb.word.top(n)`
|
|
137
|
+
|
|
138
|
+
Returns the top `n` words with the **highest repetition count** — i.e., the words you have reviewed most often.
|
|
139
|
+
|
|
140
|
+
**Parameters:**
|
|
141
|
+
|
|
142
|
+
| Parameter | Type | Required | Description |
|
|
143
|
+
| :--- | :--- | :--- | :--- |
|
|
144
|
+
| `n` | `number` | ✅ Yes | Number of top words to return |
|
|
145
|
+
|
|
146
|
+
**Returns:** `Word[]` — an array of the top `n` words (sorted descending by repetitions).
|
|
147
|
+
|
|
148
|
+
**Example:**
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
const mostPracticed = wb.word.top(10);
|
|
152
|
+
console.log('Your top 10 most practiced words:');
|
|
153
|
+
mostPracticed.forEach(w => console.log(`${w.word} (${w.repetitions} reviews)`));
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Data Type: `Word`
|
|
159
|
+
|
|
160
|
+
The `Word` object contains the following fields:
|
|
161
|
+
|
|
162
|
+
| Field | Type | Description |
|
|
163
|
+
| :--- | :--- | :--- |
|
|
164
|
+
| `id` | `string` | Unique identifier |
|
|
165
|
+
| `word` | `string` | The word itself |
|
|
166
|
+
| `definition` | `string` | Meaning or translation |
|
|
167
|
+
| `repetitions` | `number` | Number of successful reviews |
|
|
168
|
+
| `interval` | `number` | Current interval in days |
|
|
169
|
+
| `easeFactor` | `number` | Difficulty factor (1.3 – 2.5) |
|
|
170
|
+
| `lastReviewed` | `Date \| null` | Timestamp of the last review (Date object or null) |
|
|
171
|
+
| `isDue(today?: Date)` | `function` | Returns `true` if the word is due for review on the given date (default: today) |
|
|
172
|
+
| `toJSON()` | `function` | Returns a plain object suitable for serialization (e.g., to store in JSON) |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Summary of `wb.word` Methods
|
|
177
|
+
|
|
178
|
+
| Method | Description |
|
|
179
|
+
| :--- | :--- |
|
|
180
|
+
| `list()` | Get all words |
|
|
181
|
+
| `get(id)` | Get a word by ID |
|
|
182
|
+
| `add(data)` | Add or update a word |
|
|
183
|
+
| `remove(id)` | Delete a word |
|
|
184
|
+
| `search(keyword)` | Search words by word or definition |
|
|
185
|
+
| `top(n)` | Get the most frequently reviewed words |
|
|
186
|
+
|
|
187
|
+
For the review‑scheduling methods, see the [Review Scheduling API](/api/review).
|
|
188
|
+
|
|
189
|
+
---
|
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
\\\ash
|
|
6
|
+
npm install @zephyr424/wb-sdk
|
|
7
|
+
\\\
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
\\\javascript
|
|
12
|
+
const { WordBank } = require('@zephyr424/wb-sdk');
|
|
13
|
+
|
|
14
|
+
const wb = new WordBank();
|
|
15
|
+
|
|
16
|
+
// Add words
|
|
17
|
+
wb.word.add({ id: '1', word: 'apple', definition: 'a fruit' });
|
|
18
|
+
wb.word.add({ id: '2', word: 'benevolent', definition: 'kind' });
|
|
19
|
+
|
|
20
|
+
// Get today's review queue
|
|
21
|
+
const due = wb.review.getDue();
|
|
22
|
+
console.log(\📚 \ words due today\);
|
|
23
|
+
\\\
|
|
24
|
+
|
|
25
|
+
## Next Steps
|
|
26
|
+
|
|
27
|
+
- [API Documentation](/en/api/word) — Explore all methods
|
|
28
|
+
- [Blog](/en/blog/) — Read about design decisions
|
package/docs/en/index.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: home
|
|
3
|
+
|
|
4
|
+
hero:
|
|
5
|
+
name: "wb-sdk"
|
|
6
|
+
text: "A spaced repetition engine"
|
|
7
|
+
tagline: Build smarter vocabulary apps with one command
|
|
8
|
+
actions:
|
|
9
|
+
- theme: brand
|
|
10
|
+
text: Get Started
|
|
11
|
+
link: /en/guide/
|
|
12
|
+
- theme: alt
|
|
13
|
+
text: View on GitHub
|
|
14
|
+
link: https://github.com/Zephyr424/wb-sdk
|
|
15
|
+
|
|
16
|
+
features:
|
|
17
|
+
- title: 🧠 SM-2 Algorithm
|
|
18
|
+
details: Industry-standard spaced repetition, proven to optimize memory retention
|
|
19
|
+
- title: 📚 Zero Dependencies
|
|
20
|
+
details: Lightweight and fast — no bloat, just the engine
|
|
21
|
+
- title: 🔁 Intuitive API
|
|
22
|
+
details: Clean, chainable methods — wb.word & wb.review
|
|
23
|
+
- title: 📦 npm Ready
|
|
24
|
+
details: npm install @zephyr424/wb-sdk and start building
|
|
25
|
+
---
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
**wb-sdk** is a lightweight, zero‑dependency JavaScript library that implements the **SM‑2 spaced repetition algorithm** — the same engine behind Anki and many other flashcard apps. It provides a clean, intuitive API (`wb.word` and `wb.review`) so you can easily add intelligent vocabulary review to your own applications without reinventing the wheel.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the package via npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @zephyr424/wb-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or using yarn:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @zephyr424/wb-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Here’s a minimal example to get you up and running in seconds:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
// 1. Import the library
|
|
27
|
+
const { WordBank } = require('@zephyr424/wb-sdk');
|
|
28
|
+
|
|
29
|
+
// 2. Create a word bank instance
|
|
30
|
+
const wb = new WordBank();
|
|
31
|
+
|
|
32
|
+
// 3. Add some words
|
|
33
|
+
wb.word.add({ id: '1', word: 'apple', definition: 'a fruit' });
|
|
34
|
+
wb.word.add({ id: '2', word: 'benevolent', definition: 'kind and generous' });
|
|
35
|
+
wb.word.add({ id: '3', word: 'ephemeral', definition: 'lasting for a short time' });
|
|
36
|
+
|
|
37
|
+
// 4. Get today's review queue (all words are due initially)
|
|
38
|
+
const due = wb.review.getDue();
|
|
39
|
+
console.log(`📚 ${due.length} words due for review today:`);
|
|
40
|
+
due.forEach(w => console.log(` - ${w.word}: ${w.definition}`));
|
|
41
|
+
|
|
42
|
+
// 5. Simulate a review (quality from 0 = forgot to 5 = perfect)
|
|
43
|
+
wb.review.submit('1', 4); // "apple" with quality 4/5
|
|
44
|
+
|
|
45
|
+
// 6. Check progress
|
|
46
|
+
console.log(wb.review.progress());
|
|
47
|
+
// { total: 3, mastered: 0, remaining: 3, daysToMaster: 1 }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Core Concepts
|
|
51
|
+
|
|
52
|
+
### The SM‑2 Algorithm
|
|
53
|
+
|
|
54
|
+
SM‑2 is a **spaced repetition** algorithm that optimizes the interval between reviews based on your performance. Each time you review a word and rate your recall (0–5), the engine:
|
|
55
|
+
|
|
56
|
+
- Adjusts the word’s **ease factor** (difficulty) dynamically
|
|
57
|
+
- Calculates the **next review interval** (in days)
|
|
58
|
+
- Tracks **repetition count** to determine when a word is “mastered”
|
|
59
|
+
|
|
60
|
+
This ensures you spend time on the words you’re most likely to forget — maximizing learning efficiency.
|
|
61
|
+
|
|
62
|
+
### Data Structure
|
|
63
|
+
|
|
64
|
+
Each word is stored as a `Word` object with the following fields:
|
|
65
|
+
|
|
66
|
+
| Field | Type | Description |
|
|
67
|
+
| :--- | :--- | :--- |
|
|
68
|
+
| `id` | `string` | Unique identifier (required) |
|
|
69
|
+
| `word` | `string` | The word itself (required) |
|
|
70
|
+
| `definition` | `string` | Meaning or translation (required) |
|
|
71
|
+
| `repetitions` | `number` | Number of successful reviews (default `0`) |
|
|
72
|
+
| `interval` | `number` | Current interval in days (default `0`) |
|
|
73
|
+
| `easeFactor` | `number` | Difficulty factor between `1.3` and `2.5` (default `2.5`) |
|
|
74
|
+
| `lastReviewed` | `Date \| null` | Timestamp of the last review (default `null`) |
|
|
75
|
+
|
|
76
|
+
### Workflow
|
|
77
|
+
|
|
78
|
+
1. **Add** words to the bank using `wb.word.add()`.
|
|
79
|
+
2. Each day, call `wb.review.getDue()` to get the words that need review.
|
|
80
|
+
3. For each reviewed word, call `wb.review.submit(id, quality)` with your self‑rated quality score.
|
|
81
|
+
4. The engine updates the word’s state automatically — the next review date is calculated for you.
|
|
82
|
+
5. Track overall progress with `wb.review.progress()`.
|
|
83
|
+
|
|
84
|
+
## API Overview
|
|
85
|
+
|
|
86
|
+
The library exposes two main sub‑modules:
|
|
87
|
+
|
|
88
|
+
- **`wb.word`** – manage your word list (`list`, `get`, `add`, `remove`, `search`, `top`)
|
|
89
|
+
- **`wb.review`** – handle review scheduling (`getDue`, `submit`, `forecast`, `progress`)
|
|
90
|
+
|
|
91
|
+
For detailed method signatures and examples, visit the [API Reference](/api/word).
|
|
92
|
+
|
|
93
|
+
## Next Steps
|
|
94
|
+
|
|
95
|
+
- 📖 Read the full [API Documentation](/api/word) to explore every method.
|
|
96
|
+
- 🧪 Run the built‑in example: `node example.js` (in the project root).
|
|
97
|
+
- 💡 Check the [GitHub repository](https://github.com/Zephyr424/wb-sdk) for source code and contributing guidelines.
|
|
98
|
+
- 🌟 If you find this library useful, please give it a star ⭐ on GitHub!
|
|
99
|
+
|
|
100
|
+
---
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: home
|
|
3
|
+
|
|
4
|
+
hero:
|
|
5
|
+
name: "wb-sdk"
|
|
6
|
+
text: "A spaced repetition engine"
|
|
7
|
+
tagline: Build smarter vocabulary apps with one command
|
|
8
|
+
actions:
|
|
9
|
+
- theme: brand
|
|
10
|
+
text: Get Started
|
|
11
|
+
link: /guide/
|
|
12
|
+
- theme: alt
|
|
13
|
+
text: View on GitHub
|
|
14
|
+
link: https://github.com/Zephyr424/wb-sdk
|
|
15
|
+
|
|
16
|
+
features:
|
|
17
|
+
- title: 🧠 SM-2 Algorithm
|
|
18
|
+
details: Industry-standard spaced repetition, proven to optimize memory retention
|
|
19
|
+
- title: 📚 Zero Dependencies
|
|
20
|
+
details: Lightweight and fast — no bloat, just the engine
|
|
21
|
+
- title: 🔁 Intuitive API
|
|
22
|
+
details: Clean, chainable methods — wb.word & wb.review
|
|
23
|
+
- title: 📦 npm Ready
|
|
24
|
+
details: npm install @zephyr424/wb-sdk and start building
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📊 Download Stats
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🚀 Try it online
|
|
36
|
+
|
|
37
|
+
Click the button above to open an interactive demo on CodeSandbox. No installation required!
|
|
38
|
+
|
|
39
|
+
---
|