A React component library for grammar checking and rectification
npm install grammar-checker-libsA React component library for grammar checking and rectification with real-time suggestions and corrections.
- Real-time grammar checking
- Intelligent error detection and suggestions
- Fast and reliable grammar corrections
- Free and open-source
- Easy integration with existing React applications
``bash`
npm install grammar-checker-libs
or
`bash`
yarn add grammar-checker-libs
`bash
#for npm
npm install grammar-checker-libs
#for yarn
yarn add grammar-checker-libs
`
This library requires a backend server to process grammar checks. Download and setup the server:
Clone the backend repository:
`bash`
git clone https://github.com/Ajay7616/grammar-check-backend.git
cd grammar-check-backend
Start the Java LanguageTool Server (Port 8081):
`bash`
java -cp "LanguageTool-6.3/languagetool-server.jar" org.languagetool.server.HTTPServer --port 8081
Start the Python Server:
`bash`
pip install -r requirements.txt
python app.py
> Note: Run the Java server first, then the Python server. Both must be running for the grammar checker to work.
`javascript
import { GrammarRectifier } from 'grammar-checker-libs';
function MyComponent() {
return (
);
}
`
`javascript
import { GrammarRectifier } from 'grammar-checker-libs';
function MyComponent() {
return (
);
}
`
`javascript
import { GrammarRectifier } from 'grammar-checker-libs';
import * as api from 'grammar-checker-libs';
async function checkGrammar(text) {
try {
const result = await api.checkGrammar(text);
console.log(result);
} catch (error) {
console.error('Grammar check failed:', error);
}
}
`
If you're using Create React App and encounter module resolution errors with http, https, stream, etc., you need to configure webpack polyfills:
1. Install required packages:
`bash`
npm install --save-dev react-app-rewired node-polyfill-webpack-plugin stream-http https-browserify url assert stream-browserify util browserify-zlib
2. Create config-overrides.js in your project root:
`javascript
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = function override(config) {
config.resolve.fallback = {
...config.resolve.fallback,
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
url: require.resolve('url'),
assert: require.resolve('assert'),
stream: require.resolve('stream-browserify'),
util: require.resolve('util'),
zlib: require.resolve('browserify-zlib'),
};
config.plugins.push(new NodePolyfillPlugin());
return config;
};
`
3. Update your package.json scripts:
`json`
{
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
}
}
Note: This is only required for Create React App with Webpack 5. Modern tools like Vite, Next.js, or newer React frameworks handle this automatically.
####
The main component for grammar checking and correction.
Important: This component only works with and
Supported Usage:
`javascript
`
Functions exported from utils/api.js:
#### checkGrammar(text)
Checks the provided text for grammar errors.
Parameters:
- text (string): The text to check
Returns:
- Promise with grammar check results
Example:
`javascript
import { checkGrammar } from 'grammar-checker-libs';
const result = await checkGrammar("This are wrong.");
`
- Java: JDK 8 or higher
- Python: Python 3.7 or higher
- Package Manager: Node.js 14+ / Yarn 1.22.x
Download the backend server files:
`bash`
git clone https://github.com/Ajay7616/grammar-check-backend.git
1. Start Java LanguageTool Server:
`bash`
cd grammar-check-backend
java -cp "LanguageTool-6.3/languagetool-server.jar" org.languagetool.server.HTTPServer --port 8081
Server started on http://localhost:8081
Wait for the message:
2. Start Python Server:
`bash`
pip install -r requirements.txt
python app.py
http://localhost:5555
The server will start on
Test if servers are running:
`bashTest Java server
curl http://localhost:8081/v2/check -d "language=en-US&text=This are wrong"
Why This Approach?
This library uses a free, reliable, and fast approach by leveraging:
- LanguageTool: Industry-standard open-source grammar checker
- Local Processing: No external API calls, complete privacy
- High Performance: Fast response times with local servers
- No Cost: Completely free to use
- Reliable: No rate limits or API restrictions
Development
$3
`bash
npm run build
`$3
`bash
npm test
`Troubleshooting
$3
Make sure both Java and Python servers are running:
`bash
Check if Java server is running (Port 8081)
curl http://localhost:8081Check if Python server is running (Port 5555)
curl http://localhost:5555
`Note: Java server runs on port 8081 and Python server runs on port 5555. If you need to use different ports, update the API endpoint in your component configuration.
$3
Ensure you have Java installed:
`bash
java -version
``MIT
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
- GitHub Issues: [Issues]
- Email: [Email]
- LanguageTool - Open-source grammar checker
- language-tool-python by Jack Morris - Backend support
- React community
---
Made with love for better writing