@_redsocs/spam-warden 0.68.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/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # SpamWarden.js
2
+
3
+ Lightweight, client-side JavaScript library for detecting spam and sentence hijacking in real-time. Trained on the model from [RedSocs/spam-labeler](https://github.com/RedSocs/spam-labeler), bundled for zero-dependency browser usage.
4
+
5
+ ![CI](https://github.com/RedSocs/spam-warden/actions/workflows/ci.yml/badge.svg)
6
+ ![npm](https://img.shields.io/npm/v/spamwarden.svg)
7
+ ![Version](https://img.shields.io/github/v/tag/RedSocs/spam-warden?label=version&color=blue)
8
+
9
+ ## Quick Start
10
+
11
+ ### Install
12
+
13
+ ```bash
14
+ # npm
15
+ npm install spamwarden
16
+
17
+ # Or download from CDN / GitHub releases
18
+ ```
19
+
20
+ ### In the Browser
21
+
22
+ ```html
23
+ <!-- Option 1: From RedSocs CDN -->
24
+ <script src="https://redsocs.com/js/spam-warden.js"></script>
25
+
26
+ <!-- Option 2: Self-hosted -->
27
+ <script src="dist/spamwarden.min.js"></script>
28
+
29
+ <script>
30
+ const result = window.spamwarden.spamcheck("สมัครสมาชิกวันนี้ รับโบนัส ฟรี!");
31
+ console.log(result.isSpam); // true
32
+ console.log(result.prob); // 1.0
33
+ console.log(result.version); // "v0.68"
34
+ </script>
35
+ ```
36
+
37
+ ### As ES Module
38
+
39
+ ```js
40
+ import SpamWarden from './dist/spamwarden.min.js';
41
+ SpamWarden.spamcheck("Welcome bonus! Deposit now");
42
+ ```
43
+
44
+ ### Quick Boolean Check
45
+
46
+ ```js
47
+ if (spamwarden.isSpam(userInput)) {
48
+ // block or flag
49
+ }
50
+ ```
51
+
52
+ ### In Node.js
53
+
54
+ ```js
55
+ const spamwarden = require("./dist/spamwarden.min.js");
56
+ const r = spamwarden.spamcheck("Welcome bonus! Deposit now get 200% match");
57
+ console.log(r.isSpam); // true
58
+ ```
59
+
60
+ ## API
61
+
62
+ ### `spamwarden.spamcheck(text) → object`
63
+
64
+ | Field | Type | Description |
65
+ |-------|------|-------------|
66
+ | `isSpam` | `boolean` | `true` if detected as spam |
67
+ | `prob` | `number` | Spam probability (0.0–1.0) |
68
+ | `reason` | `string?` | Present if hard-rule triggered: `"currency_symbol"` or `"spam_link"` |
69
+ | `version` | `string` | Model version (e.g., `"v0.68"`) |
70
+
71
+ ### `spamwarden.isSpam(text) → boolean`
72
+
73
+ Convenience wrapper — returns only the boolean result.
74
+
75
+ ### `spamwarden.version → string`
76
+
77
+ Current model version string.
78
+
79
+ ## Build
80
+
81
+ ```bash
82
+ # 1. Copy model from spam-labeler
83
+ cp ../spam-labeler/extension/model.json .
84
+
85
+ # 2. Build (bundles model into JS)
86
+ node build.js
87
+ # or: ./build.sh
88
+ ```
89
+
90
+ Output:
91
+
92
+ | File | Size |
93
+ |------|------|
94
+ | `dist/spamwarden.js` | 3.5 MB (uncompressed) |
95
+ | `dist/spamwarden.min.js` | 61 KB (minified) |
96
+ | `dist/spamwarden.min.js` (gzipped) | **27 KB** |
97
+
98
+ ### Optional: Better Minification
99
+
100
+ ```bash
101
+ npm install terser
102
+ node build.js # now uses terser instead of simple minification
103
+ ```
104
+
105
+ ## How It Works
106
+
107
+ ```
108
+ User posts text
109
+
110
+ spamwarden.spamcheck(text)
111
+
112
+ Hard rules check (currency symbols, spam links)
113
+
114
+ Vectorizer: whitespace tokens + trigrams + quadgrams
115
+
116
+ Bernoulli Naive Bayes prediction (class 0 = safe, 1 = spam)
117
+
118
+ Softmax → probability
119
+
120
+ { isSpam, prob, version }
121
+ ```
122
+
123
+ ### Model
124
+
125
+ | Property | Value |
126
+ |----------|-------|
127
+ | **Origin** | [RedSocs/spam-labeler](https://github.com/RedSocs/spam-labeler) (Rust, Bernoulli NB) |
128
+ | **Features** | ~63,000 tokens (whitespace + trigrams + quadgrams) |
129
+ | **Version** | v0.68 (680 training samples) |
130
+ | **Hard Rules** | Currency symbols (`$€£฿`) → auto-spam; Spam links (`line.me`, `@line`, `lin.ee`) → auto-spam |
131
+
132
+ ### Train Your Own Model
133
+
134
+ The model in this repo was trained by [RedSocs/spam-labeler](https://github.com/RedSocs/spam-labeler). To customize for your own use case:
135
+
136
+ ```bash
137
+ # 1. Clone the training repo
138
+ git clone https://github.com/RedSocs/spam-labeler.git
139
+
140
+ # 2. Add your own training data
141
+ cp your-spam.txt spam-labeler/data/spam.txt
142
+ cp your-safe.txt spam-labeler/data/safe.txt
143
+
144
+ # 3. Retrain and export
145
+ cd spam-labeler
146
+ cargo run --release --bin export_model
147
+ cp extension/model.json ../spam-warden/model.json
148
+
149
+ # 4. Rebuild SpamWarden
150
+ cd ../spam-warden
151
+ node build.js
152
+ ```
153
+
154
+ See the [spam-labeler README](https://github.com/RedSocs/spam-labeler) for the full training pipeline.
155
+
156
+ ## Privacy
157
+
158
+ All processing happens **in-memory in the browser**. No data is sent to any server.
159
+
160
+ ## Related
161
+
162
+ - [**RedSocs/spam-labeler**](https://github.com/RedSocs/spam-labeler) — Rust-based training pipeline, TUI app, and Firefox extension for collecting and training the spam detection model.
163
+
164
+ ## Project Structure
165
+
166
+ ```
167
+ spam-warden/
168
+ ├── src/
169
+ │ └── spamwarden.js # Library source (MODEL_DATA_PLACEHOLDER)
170
+ ├── dist/
171
+ │ ├── spamwarden.js # Bundled (model inlined, ~3.5 MB)
172
+ │ └── spamwarden.min.js # Minified for production (~61 KB, 27 KB gzipped)
173
+ ├── model.json # Trained model from spam-labeler
174
+ ├── build.js # Node.js build script
175
+ ├── build.sh # Shell wrapper
176
+ ├── SPEC.md # Technical specification
177
+ └── README.md # This file
178
+ ```
179
+
180
+ ## CI/CD & Releases
181
+
182
+ ### Versioning
183
+
184
+ ```bash
185
+ # Show current version
186
+ ./version.sh
187
+
188
+ # Create release tag
189
+ ./version.sh v0.70
190
+
191
+ # Push tag to trigger release
192
+ git push origin main --tags
193
+ ```
194
+
195
+ ### npm
196
+
197
+ ```bash
198
+ # Build, then publish
199
+ npm run build
200
+ npm publish --access public
201
+ ```
202
+
203
+ ### GitHub Actions
204
+
205
+ - **CI** — Runs on every push/PR: builds, smoke tests, uploads dist artifacts
206
+ - **Release** — Triggered by `v*` tags: packages dist, creates GitHub Release