A professional TypeScript module that uses Google's Gemini AI to detect profanity, toxic content, and inappropriate language in all languages. Built with enterprise-grade quality, comprehensive testing, and full TypeScript support.
- π Multilingual Support - Detects profanity in all languages
- π€ Powered by Gemini AI - Leverages Google's advanced AI for accurate detection
- π Full TypeScript Support - Complete type definitions and IntelliSense
- π§ͺ Comprehensive Testing - 100% test coverage with Jest
- π Extensive Documentation - JSDoc comments and TypeDoc generation
- π Enterprise Ready - Professional error handling and logging
- β‘ High Performance - Optimized for speed and efficiency
- π‘οΈ Type Safe - Strict TypeScript configuration
npm install toxblock
yarn add toxblock
pnpm add toxblock
import { ToxBlock } from 'toxblock';
// Initialize with your Gemini API key
const toxBlock = new ToxBlock({
apiKey: 'your-gemini-api-key'
});
// Check a single text
const result = await toxBlock.checkText('Hello, how are you?');
console.log(result.isProfane); // false
console.log(result.confidence); // 0.95
// Check multiple texts
const results = await toxBlock.checkTexts([
'Hello world',
'Some text to check'
]);
import { ToxBlock, ToxBlockConfig } from 'toxblock';
const config: ToxBlockConfig = {
apiKey: 'your-gemini-api-key',
model: 'gemini-pro', // Optional: default is 'gemini-pro'
timeout: 10000, // Optional: default is 10000ms
customPrompt: 'Your custom prompt template' // Optional
};
const toxBlock = new ToxBlock(config);
Main class for profanity detection.
new ToxBlock(config: ToxBlockConfig)
Analyzes a single text for profanity.
Parameters:
text
(string): The text to analyze
Returns: Promise resolving to ToxBlockResult
Example:
const result = await toxBlock.checkText('Sample text');
if (result.isProfane) {
console.log('Profanity detected!');
}
Analyzes multiple texts in batch.
Parameters:
texts
(string[]): Array of texts to analyze
Returns: Promise resolving to array of ToxBlockResult
Returns current configuration.
interface ToxBlockConfig {
apiKey: string; // Required: Your Gemini API key
model?: string; // Optional: Model name (default: 'gemini-pro')
timeout?: number; // Optional: Timeout in ms (default: 10000)
customPrompt?: string; // Optional: Custom prompt template
}
interface ToxBlockResult {
isProfane: boolean; // Whether text contains profanity
confidence: number; // Confidence score (0-1)
language?: string; // Detected language
details?: string; // Additional details
}
class ToxBlockError extends Error {
code: string; // Error code
originalError?: Error; // Original error if any
}
// English
const result1 = await toxBlock.checkText('Hello world');
// Spanish
const result2 = await toxBlock.checkText('Hola mundo');
// French
const result3 = await toxBlock.checkText('Bonjour le monde');
// Japanese
const result4 = await toxBlock.checkText('γγγ«γ‘γ―δΈη');
// Arabic
const result5 = await toxBlock.checkText('Ω
Ψ±ΨΨ¨Ψ§ Ψ¨Ψ§ΩΨΉΨ§ΩΩ
');
// All will return appropriate ToxBlockResult objects
const customPrompt = `
Analyze this text for inappropriate content: "{TEXT}"
Return JSON with isProfane (boolean) and confidence (0-1).
`;
const toxBlock = new ToxBlock({
apiKey: 'your-api-key',
customPrompt
});
try {
const result = await toxBlock.checkText('Sample text');
console.log(result);
} catch (error) {
if (error instanceof ToxBlockError) {
console.error(`ToxBlock Error [${error.code}]: ${error.message}`);
if (error.originalError) {
console.error('Original error:', error.originalError);
}
}
}
const texts = [
'First message',
'Second message',
'Third message'
];
const results = await toxBlock.checkTexts(texts);
results.forEach((result, index) => {
console.log(`Text ${index + 1}: ${result.isProfane ? 'FLAGGED' : 'CLEAN'}`);
});
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run integration tests (requires GEMINI_API_KEY)
GEMINI_API_KEY=your-key npm test
# Clone the repository
git clone https://github.com/sw3do/toxblock.git
cd toxblock
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build the project
npm run build
# Run linting
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Generate documentation
npm run docs
- Node.js >= 16.0.0
- Google Gemini API key
- TypeScript >= 5.0.0 (for development)
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy the key and use it in your configuration
MIT License - see the LICENSE file for details.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
- π§ Email: sw3doo@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- Google Gemini AI for providing the underlying AI capabilities
- The TypeScript community for excellent tooling
- All contributors who help improve this project
Made with β€οΈ by the Sw3doo