@bigdreamsweb3/wordbin 1.1.7 → 1.1.8

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.
Files changed (2) hide show
  1. package/CONTRIBUTING.md +156 -67
  2. package/package.json +1 -1
package/CONTRIBUTING.md CHANGED
@@ -1,15 +1,12 @@
1
- Here's the **CONTRIBUTING.md** file ready for you to download and use in your project.
2
-
3
- You can copy the content below and save it as `CONTRIBUTING.md` in the root of your repository.
4
-
5
- ```markdown
6
1
  # Contributing to WordBin
7
2
 
8
3
  Thank you for your interest in contributing to WordBin!
9
- We welcome all kinds of help — bug reports, documentation improvements, new features, dictionary variants, tests, or even small fixes.
4
+ We welcome all kinds of help — bug reports, documentation improvements, new features, dictionary variants, tests, or small fixes.
10
5
 
11
6
  This guide explains how to contribute effectively and what would be most valuable to the project right now.
12
7
 
8
+ ---
9
+
13
10
  ## Table of Contents
14
11
 
15
12
  - [Code of Conduct](#code-of-conduct)
@@ -19,15 +16,22 @@ This guide explains how to contribute effectively and what would be most valuabl
19
16
  - [Submitting Pull Requests](#submitting-pull-requests)
20
17
  - [Good First Issues](#good-first-issues)
21
18
  - [Development Setup](#development-setup)
19
+ - [Project Layout](#project-layout)
20
+ - [Running Tests](#running-tests)
21
+ - [Where Things Live](#where-things-live)
22
22
  - [Current Priorities (2026)](#current-priorities-2026)
23
23
  - [Code Style & Conventions](#code-style--conventions)
24
24
  - [License](#license)
25
25
 
26
+ ---
27
+
26
28
  ## Code of Conduct
27
29
 
28
30
  This project follows the [Contributor Covenant Code of Conduct v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
29
31
  Be respectful, inclusive, and constructive in all interactions.
30
32
 
33
+ ---
34
+
31
35
  ## How to Contribute
32
36
 
33
37
  ### Reporting Bugs
@@ -36,66 +40,72 @@ If you find a bug:
36
40
 
37
41
  1. Check if it's already reported in [existing issues](https://github.com/bigdreamsweb3/wordbin/issues).
38
42
  2. If not, open a new issue and include:
39
- - Clear, descriptive title
43
+ - A clear, descriptive title
40
44
  - Steps to reproduce
41
- - Expected vs actual behavior
42
- - Node.js / browser version
43
- - Dictionary version used (v1/v2/custom)
44
- - Minimal code snippet or test case
45
-
46
- Use the **Bug report** template when available.
45
+ - Expected vs actual behaviour
46
+ - Node.js version (`node -v`)
47
+ - Dictionary version used (v1 / v2 / custom)
48
+ - The payload format involved (hex / base58 / base64 / bin21 / bytes)
49
+ - A minimal code snippet or failing test case
47
50
 
48
51
  ### Suggesting Features or Improvements
49
52
 
50
- Have an idea for a new feature, better performance, UX improvement, or new dictionary type?
51
-
52
53
  Open an issue with:
53
- - Problem or opportunity you're addressing
54
- - Proposed solution (as detailed as you want)
55
- - Any alternatives you've considered
56
- - Rough estimate of impact/benefit
57
54
 
58
- Use the **Feature request** template if it exists.
55
+ - The problem or opportunity you're addressing
56
+ - Your proposed solution (as detailed as you like)
57
+ - Any alternatives you considered
58
+ - Rough estimate of impact
59
59
 
60
- ### Submitting Pull Requests
60
+ For larger architectural changes — new payload formats, new dictionary structures, changes to the encode/decode pipeline — please open an issue to discuss before writing code.
61
61
 
62
- Want to submit code? Awesome!
62
+ ### Submitting Pull Requests
63
63
 
64
64
  1. **Fork** the repository and **clone** your fork
65
- 2. Create a new branch:
66
- `git checkout -b fix/lowercase-normalization`
67
- or `feat/add-top-20k-dictionary`
65
+ 2. Create a focused branch:
66
+ ```bash
67
+ git checkout -b fix/decode-bin21-format
68
+ # or
69
+ git checkout -b feat/add-top-20k-dictionary
70
+ ```
68
71
  3. Make your changes
69
- 4. Add or update tests if applicable
70
- 5. Run the test suite:
71
- `npm test` or `npm run vitest`
72
- 6. Commit with clear messages (semantic style preferred):
73
- `fix: normalize words to lowercase in buildDictionary`
74
- `feat: add CLI flag for lowercase normalization`
75
- `docs: improve contributing guide`
76
- `test: add cases for empty input and literals`
72
+ 4. Add or update tests in `test/test.spec.ts` for any new behaviour
73
+ 5. Run the full test suite and confirm everything passes:
74
+ ```bash
75
+ npm test
76
+ ```
77
+ 6. Commit with clear, semantic messages:
78
+ ```
79
+ fix: correct bin21 format detection in detectAndConvert
80
+ feat: add partialScan fallback for non-WordBin payloads
81
+ docs: update decode API in README
82
+ test: add round-trip cases for base58 and bin21 formats
83
+ ```
77
84
  7. Push your branch and open a pull request against `main`
78
85
 
79
- Small, focused PRs are usually merged quickly.
80
- Larger changes might be reviewed in stages — feel free to open a draft PR early to discuss.
86
+ Small, focused PRs are merged quickly. For larger changes, open a draft PR early — it's easier to align on approach before a lot of code is written.
81
87
 
82
88
  ### Good First Issues
83
89
 
84
- Looking for an easy entry point? These tasks are beginner-friendly:
90
+ Looking for an easy entry point? These are beginner-friendly:
85
91
 
86
- - Improve/fix documentation or README examples
87
- - Add case normalization (lowercase) to dictionary building
92
+ - Fix documentation or README examples
93
+ - Add case normalisation (lowercase) to dictionary building
88
94
  - Create a smaller curated dictionary (e.g. top 10k–50k English words)
89
95
  - Add more helpful messages or progress indicators to the CLI
90
- - Write tests for edge cases (empty strings, very long phrases, invalid base64)
91
- - Create a simple browser demo (CodeSandbox, StackBlitz, or static HTML)
96
+ - Write tests for edge cases (empty strings, very long phrases, single-word inputs)
97
+ - Build a simple browser demo (CodeSandbox, StackBlitz, or a static HTML page)
98
+
99
+ Look for issues labelled **[good first issue]** on GitHub.
92
100
 
93
- Look for issues labeled **[good first issue]** on GitHub.
101
+ ---
94
102
 
95
103
  ## Development Setup
96
104
 
105
+ **Prerequisites:** Node.js ≥ 18, npm ≥ 9
106
+
97
107
  ```bash
98
- # 1. Fork & clone the repo
108
+ # 1. Fork and clone
99
109
  git clone https://github.com/bigdreamsweb3/wordbin.git
100
110
  cd wordbin
101
111
 
@@ -105,51 +115,130 @@ npm install
105
115
  # 3. Build the library
106
116
  npm run build
107
117
 
108
- # 4. Run tests
118
+ # 4. Run the tests
109
119
  npm test
110
- # or watch mode:
111
- npm run vitest
120
+ ```
121
+
122
+ ---
112
123
 
113
- # 5. Build dictionaries (optional)
114
- npx wordbin build --version 2
115
- # or interactive mode:
116
- npx wordbin build
124
+ ## Project Layout
125
+
126
+ ```
127
+ wordbin/
128
+ ├── src/
129
+ │ ├── core/
130
+ │ │ └── wordbin.ts # WordBin class — encode(), decode(), format detection
131
+ │ ├── dict/
132
+ │ │ ├── dictionary-loader.ts # loadLatestDictionary, loadDictionaryByVersion
133
+ │ │ ├── builder.ts # buildDictionary() — constructs dict from a wordlist
134
+ │ │ └── data/ # Bundled v1 (BIP-39) dictionary JSON
135
+ │ ├── utils/
136
+ │ │ └── buffer.ts # toHex, toBase64, encodeVarint, decodeVarint, utf8*
137
+ │ └── constants.ts # LITERAL token value and other shared constants
138
+ ├── test/
139
+ │ └── test.spec.ts # Vitest suites — encode, decode, round-trip, non-WordBin
140
+ ├── data/ # Built dictionary files — generated, gitignored
141
+ └── dist/ # Compiled output — generated on build, not committed
117
142
  ```
118
143
 
119
- Main source code lives in `src/`.
120
- Generated dictionaries appear in `data/`.
144
+ ---
145
+
146
+ ## Running Tests
147
+
148
+ The test suite is organised into four independently-controllable suites.
149
+
150
+ ```bash
151
+ npm test # run everything once
152
+ npm run test:watch # watch mode — re-runs on save
153
+ ```
154
+
155
+ ### Run a single suite via CLI
156
+
157
+ ```bash
158
+ npx vitest -t "Encode only"
159
+ npx vitest -t "Decode only"
160
+ npx vitest -t "Encode then decode"
161
+ npx vitest -t "Non-WordBin decode"
162
+ ```
163
+
164
+ ### Toggle suites without touching the CLI
165
+
166
+ At the top of `test/test.spec.ts`:
167
+
168
+ ```ts
169
+ const RUN = {
170
+ ENCODE_ONLY: true, // encode text → verify all payload representations
171
+ DECODE_ONLY: true, // decode a pre-built payload → verify result
172
+ ENCODE_THEN_DECODE: true, // full round-trip across all 5 formats
173
+ NON_WORDBIN_DECODE: true, // arbitrary payloads → graceful fallback behaviour
174
+ };
175
+ ```
176
+
177
+ Set any flag to `false` to skip that suite entirely. Skipped suites are reported as skipped — they are never silently removed.
178
+
179
+ ### What each suite covers
180
+
181
+ | Suite | What it tests |
182
+ | ---------------------- | -------------------------------------------------------------------------------------------- |
183
+ | **Encode only** | All payload formats (hex, base58, base64, bin21), compression ratio, format validity |
184
+ | **Decode only** | Known hex payload, known base64 payload, non-WordBin fallback |
185
+ | **Encode then decode** | Full round-trip for hex, base58, base64, bin21, and raw `Uint8Array` |
186
+ | **Non-WordBin decode** | 4 foreign payloads — verifies `isWordBin: false`, `notice` is set, `text` is always a string |
187
+
188
+ ---
189
+
190
+ ## Where Things Live
191
+
192
+ | What you want to change | File |
193
+ | -------------------------------------------------------- | ------------------------------------ |
194
+ | Encode / decode logic | `src/core/wordbin.ts` |
195
+ | Payload format detection (hex / base58 / base64 / bin21) | `detectAndConvert()` in `wordbin.ts` |
196
+ | `DecodeResult` type or `PayloadFormat` union | top of `wordbin.ts` |
197
+ | Partial scan / best-effort fallback | `partialScan()` in `wordbin.ts` |
198
+ | Dictionary loading and versioning | `src/dict/dictionary-loader.ts` |
199
+ | Building a dictionary from a wordlist | `src/dict/builder.ts` |
200
+ | Buffer utilities (varint, hex, utf8) | `src/utils/buffer.ts` |
201
+ | Shared constants (LITERAL byte value) | `src/constants.ts` |
202
+ | Tests | `test/test.spec.ts` |
203
+
204
+ ---
121
205
 
122
206
  ## Current Priorities (2026)
123
207
 
124
208
  These improvements would have the biggest impact right now:
125
209
 
126
- - Case-insensitive dictionaries (normalize to lowercase during build)
127
- - Smaller curated dictionaries (top 10k–50k words, programming keywords, domain-specific lists)
128
- - Performance & compression benchmarks across dictionaries and phrase lengths
129
- - Interactive browser demo (CodeSandbox / StackBlitz / simple HTML page)
130
- - CLI enhancements (progress bars, `--lowercase`, `--output-dir`, better help)
131
- - Better error handling & messages (missing dictionary, invalid input, etc.)
210
+ - **Case-insensitive dictionaries** normalise to lowercase during dictionary building so `"Hello"` and `"hello"` encode identically
211
+ - **Smaller curated dictionaries** top 10k–50k common English words, programming keywords, domain-specific lists (DeFi, medical, etc.)
212
+ - **Bin21 safety** audit which Latin-1 characters survive common transports (databases, JSON fields) without corruption; document safe subsets
213
+ - **Performance benchmarks** encode/decode throughput across dictionary sizes and phrase lengths
214
+ - **Browser demo** a minimal CodeSandbox or static HTML page showing encode/decode live
215
+ - **CLI enhancements** progress bars, `--lowercase` flag, `--output-dir`, improved help text
216
+ - **Error messages** — clearer messages when a dictionary is missing, input is invalid, or a version mismatch is detected
132
217
 
133
- If you're unsure where to begin — feel free to ask in an issue or draft PR!
218
+ If you're unsure where to begin, open an issue or a draft PR we're happy to help you find a good starting point.
219
+
220
+ ---
134
221
 
135
222
  ## Code Style & Conventions
136
223
 
137
- - ESM syntax (`import` / `export`)
138
- - TypeScript where possible
139
- - Vitest for testing
140
- - Prefer async/await
141
- - Small, focused functions
142
- - JSDoc comments for public APIs
224
+ - **ESM** `import` / `export` throughout, no CommonJS
225
+ - **TypeScript** all source files, strict mode preferred
226
+ - **Vitest** for all tests; no Jest
227
+ - **async/await** — preferred over `.then()` chains
228
+ - **Small, focused functions** — each function does one thing
229
+ - **JSDoc** on all public methods and exported types
143
230
 
144
- We use **Prettier** + **ESLint** — run these before committing:
231
+ Run these before committing:
145
232
 
146
233
  ```bash
147
234
  npm run lint
148
235
  npm run format
149
236
  ```
150
237
 
238
+ ---
239
+
151
240
  ## License
152
241
 
153
- By contributing your code to this project, you agree that it will be licensed under the same [MIT License](./LICENSE) as the rest of the project.
242
+ By contributing code to this project, you agree that your contribution will be licensed under the same [MIT License](./LICENSE) as the rest of the project.
154
243
 
155
- Thank you for helping make WordBin better!
244
+ Thank you for helping make WordBin better — we up 🚀
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigdreamsweb3/wordbin",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "WordBin – Encode words & short text into tiny, reversible binary for storage, URLs, IoT, QR codes, metadata, blockchain, or Web3 apps.",
5
5
  "author": "Agbaka Daniel Ugonna <99cratson@gmail.com>",
6
6
  "license": "MIT",