opengrammar-server 2.0.189663

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 (53) hide show
  1. package/README.npm.md +95 -0
  2. package/bin/opengrammar-server.js +111 -0
  3. package/dist/server.js +48639 -0
  4. package/package.json +80 -0
  5. package/server-node.ts +159 -0
  6. package/server.ts +15 -0
  7. package/src/analyzer.ts +542 -0
  8. package/src/dictionary.ts +1973 -0
  9. package/src/index.ts +978 -0
  10. package/src/nlp/nlp-engine.ts +17 -0
  11. package/src/nlp/tone-analyzer.ts +269 -0
  12. package/src/rephraser.ts +146 -0
  13. package/src/rules/categories/academic-writing.ts +182 -0
  14. package/src/rules/categories/adjectives-adverbs.ts +152 -0
  15. package/src/rules/categories/articles.ts +160 -0
  16. package/src/rules/categories/business-writing.ts +250 -0
  17. package/src/rules/categories/capitalization.ts +79 -0
  18. package/src/rules/categories/clarity.ts +117 -0
  19. package/src/rules/categories/common-errors.ts +601 -0
  20. package/src/rules/categories/confused-words.ts +219 -0
  21. package/src/rules/categories/conjunctions.ts +176 -0
  22. package/src/rules/categories/dangling-modifiers.ts +123 -0
  23. package/src/rules/categories/formality.ts +274 -0
  24. package/src/rules/categories/formatting-idioms.ts +323 -0
  25. package/src/rules/categories/gerund-infinitive.ts +274 -0
  26. package/src/rules/categories/grammar-advanced.ts +294 -0
  27. package/src/rules/categories/grammar.ts +286 -0
  28. package/src/rules/categories/inclusive-language.ts +280 -0
  29. package/src/rules/categories/nouns-pronouns.ts +233 -0
  30. package/src/rules/categories/prepositions-extended.ts +217 -0
  31. package/src/rules/categories/prepositions.ts +159 -0
  32. package/src/rules/categories/punctuation.ts +347 -0
  33. package/src/rules/categories/quantity-agreement.ts +200 -0
  34. package/src/rules/categories/readability.ts +293 -0
  35. package/src/rules/categories/sentence-structure.ts +100 -0
  36. package/src/rules/categories/spelling-advanced.ts +164 -0
  37. package/src/rules/categories/spelling.ts +119 -0
  38. package/src/rules/categories/style-tone.ts +511 -0
  39. package/src/rules/categories/style.ts +78 -0
  40. package/src/rules/categories/subject-verb-agreement.ts +201 -0
  41. package/src/rules/categories/tone-rules.ts +206 -0
  42. package/src/rules/categories/verb-tense.ts +582 -0
  43. package/src/rules/context-filter.ts +446 -0
  44. package/src/rules/index.ts +96 -0
  45. package/src/rules/ruleset-part1-cj-pu-sp.json +657 -0
  46. package/src/rules/ruleset-part1-np-ad-aa-pr.json +831 -0
  47. package/src/rules/ruleset-part1-ss-vt.json +907 -0
  48. package/src/rules/ruleset-part2-cw-st-nf.json +318 -0
  49. package/src/rules/ruleset-part3-aw-bw-il-rd.json +161 -0
  50. package/src/rules/types.ts +79 -0
  51. package/src/shared-types.ts +152 -0
  52. package/src/spellchecker.ts +418 -0
  53. package/tsconfig.json +25 -0
package/README.npm.md ADDED
@@ -0,0 +1,95 @@
1
+ # opengrammar-server
2
+
3
+ > Privacy-first, open-source grammar intelligence server — run it on **any device**.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/opengrammar-server)](https://www.npmjs.com/package/opengrammar-server)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ Turn **any device** into a local OpenGrammar API server — your old Android phone via Termux, a Raspberry Pi, an old laptop, or any VPS.
9
+
10
+ ## Quick Start
11
+
12
+ ```bash
13
+ # Run instantly (no install needed)
14
+ npx opengrammar-server
15
+
16
+ # Or install globally
17
+ npm install -g opengrammar-server
18
+ opengrammar-server
19
+ ```
20
+
21
+ That's it. Your server is live at `http://localhost:8787` 🎉
22
+
23
+ ## Options
24
+
25
+ ```bash
26
+ opengrammar-server --port 3000 # Custom port
27
+ opengrammar-server --host 127.0.0.1 # Localhost only (more secure)
28
+ opengrammar-server --help # Show all options
29
+ opengrammar-server --version # Show version
30
+ ```
31
+
32
+ ## API Endpoints
33
+
34
+ | Method | Endpoint | Description |
35
+ |--------|----------|-------------|
36
+ | `GET` | `/` | Status dashboard |
37
+ | `GET` | `/health` | Health check |
38
+ | `POST` | `/analyze` | Grammar analysis |
39
+ | `POST` | `/autocomplete`| Text completion |
40
+ | `GET` | `/providers` | List AI providers |
41
+
42
+ ### Example
43
+
44
+ ```bash
45
+ # Check health
46
+ curl http://localhost:8787/health
47
+
48
+ # Analyze text
49
+ curl -X POST http://localhost:8787/analyze \
50
+ -H "Content-Type: application/json" \
51
+ -d '{"text": "Me and him went to store yesterday"}'
52
+ ```
53
+
54
+ ## 🤖 Run on Android (Termux)
55
+
56
+ Turn your old Android phone into a grammar server!
57
+
58
+ ```bash
59
+ # 1. Install Termux from F-Droid (not Play Store)
60
+ # 2. Inside Termux:
61
+ pkg update && pkg install nodejs
62
+ npx opengrammar-server --port 8787
63
+ ```
64
+
65
+ Your phone is now a grammar server accessible on your local network at `http://<phone-ip>:8787`.
66
+
67
+ ## 🍓 Run on Raspberry Pi
68
+
69
+ ```bash
70
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
71
+ sudo apt-get install -y nodejs
72
+ npx opengrammar-server
73
+ ```
74
+
75
+ ## 🐳 Docker
76
+
77
+ ```bash
78
+ docker run -p 8787:8787 swadhinbiswas/opengrammar-backend:latest
79
+ ```
80
+
81
+ ## Environment Variables
82
+
83
+ | Variable | Description |
84
+ |----------|-------------|
85
+ | `PORT` | Server port (default: `8787`) |
86
+ | `HOST` | Bind host (default: `0.0.0.0`) |
87
+ | `GROQ_API_KEY` | Groq API key for AI features (optional) |
88
+ | `OPENAI_API_KEY` | OpenAI API key (optional) |
89
+
90
+ ## Links
91
+
92
+ - 🌐 **Website:** https://opengrammer.eu.cc
93
+ - 📦 **GitHub:** https://github.com/swadhinbiswas/opengrammar
94
+ - 🐛 **Issues:** https://github.com/swadhinbiswas/opengrammar/issues
95
+ - ☁️ **Hosted API:** https://opengrammar-backend-production.thelabrats-dev.workers.dev
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * OpenGrammar Server — CLI Entry Point
5
+ *
6
+ * Usage:
7
+ * npx opengrammar-server
8
+ * npx opengrammar-server --port 3000
9
+ * npx opengrammar-server --help
10
+ */
11
+
12
+ import { createRequire } from 'module';
13
+ import { fileURLToPath } from 'url';
14
+ import { dirname, join } from 'path';
15
+ import { parseArgs } from 'util';
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+
19
+ // Parse CLI args
20
+ let args;
21
+ try {
22
+ const parsed = parseArgs({
23
+ args: process.argv.slice(2),
24
+ options: {
25
+ port: { type: 'string', short: 'p', default: '8787' },
26
+ host: { type: 'string', short: 'h', default: '0.0.0.0' },
27
+ help: { type: 'boolean', short: '?', default: false },
28
+ version: { type: 'boolean', short: 'v', default: false },
29
+ },
30
+ strict: false,
31
+ });
32
+ args = parsed.values;
33
+ } catch {
34
+ args = { port: '8787', host: '0.0.0.0', help: false, version: false };
35
+ }
36
+
37
+ if (args.version) {
38
+ const pkg = createRequire(import.meta.url)(join(__dirname, '../package.json'));
39
+ console.log(`opengrammar-server v${pkg.version}`);
40
+ process.exit(0);
41
+ }
42
+
43
+ if (args.help) {
44
+ console.log(`
45
+ ┌─────────────────────────────────────────────────────┐
46
+ │ OpenGrammar Server v2.0.0 │
47
+ │ Privacy-first grammar intelligence on your device │
48
+ └─────────────────────────────────────────────────────┘
49
+
50
+ Usage:
51
+ npx opengrammar-server [options]
52
+
53
+ Options:
54
+ -p, --port <port> Port to listen on (default: 8787)
55
+ -h, --host <host> Host to bind to (default: 0.0.0.0)
56
+ -v, --version Show version
57
+ -?, --help Show this help
58
+
59
+ Examples:
60
+ npx opengrammar-server
61
+ npx opengrammar-server --port 3000
62
+ npx opengrammar-server --port 8080 --host 127.0.0.1
63
+
64
+ API Endpoints:
65
+ GET / Status dashboard
66
+ GET /health Health check
67
+ POST /analyze Grammar analysis
68
+ POST /autocomplete Text completion
69
+ GET /providers List AI providers
70
+
71
+ Docs: https://opengrammer.eu.cc
72
+ `);
73
+ process.exit(0);
74
+ }
75
+
76
+ // Set port before importing server
77
+ const port = parseInt(args.port, 10) || 8787;
78
+ const host = args.host || '0.0.0.0';
79
+
80
+ process.env.PORT = String(port);
81
+ process.env.HOST = host;
82
+
83
+ // Banner
84
+ console.log(`
85
+ ┌─────────────────────────────────────────────────────┐
86
+ │ OpenGrammar Server v2.0.0 │
87
+ │ Privacy-first grammar intelligence on your device │
88
+ └─────────────────────────────────────────────────────┘
89
+ `);
90
+ console.log(` Starting server on http://${host}:${port}`);
91
+ console.log(` Press Ctrl+C to stop\n`);
92
+
93
+ // Start the Hono server
94
+ try {
95
+ await import(join(__dirname, '../dist/server.js'));
96
+ } catch {
97
+ // Fallback: use tsx at runtime if dist/ doesn't exist (dev mode / npx)
98
+ const { spawn } = await import('child_process');
99
+ const child = spawn(
100
+ 'node',
101
+ ['--import', 'tsx/esm', join(__dirname, '../server-node.ts')],
102
+ {
103
+ stdio: 'inherit',
104
+ env: { ...process.env, PORT: String(port), HOST: host },
105
+ }
106
+ );
107
+ child.on('error', () => {
108
+ console.error('\n ❌ Failed to start. Try: npm install -g tsx\n');
109
+ process.exit(1);
110
+ });
111
+ }