JSPM

@sharpapi/sharpapi-node-detect-profanities

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q35340F
  • License MIT

SharpAPI.com Node.js SDK for detecting profanities in text

Package Exports

  • @sharpapi/sharpapi-node-detect-profanities
  • @sharpapi/sharpapi-node-detect-profanities/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sharpapi/sharpapi-node-detect-profanities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SharpAPI GitHub cover

Profanity Detection API for Node.js

πŸ›‘οΈ Detect profanities and inappropriate content with AI β€” powered by SharpAPI.

npm version License

SharpAPI Profanity Detection analyzes text content for profanities, offensive language, and inappropriate content using AI. Essential for content moderation, community guidelines enforcement, and maintaining safe user environments.


πŸ“‹ Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. API Documentation
  5. Response Format
  6. Examples
  7. License

Requirements

  • Node.js >= 16.x
  • npm or yarn

Installation

Step 1. Install the package via npm:

npm install @sharpapi/sharpapi-node-detect-profanities

Step 2. Get your API key

Visit SharpAPI.com to get your API key.


Usage

const { SharpApiDetectProfanitiesService } = require('@sharpapi/sharpapi-node-detect-profanities');

const apiKey = process.env.SHARP_API_KEY;
const service = new SharpApiDetectProfanitiesService(apiKey);

const userComment = `
This is a sample comment that might contain inappropriate language.
Checking for profanities and offensive content.
`;

async function checkContent() {
  try {
    const statusUrl = await service.detectProfanities(userComment);
    console.log('Job submitted. Status URL:', statusUrl);

    const result = await service.fetchResults(statusUrl);
    const detection = result.getResultJson();

    if (!detection.result.pass) {
      console.log('⚠️ Profanity detected!');
      console.log('Confidence:', detection.result.score + '%');
      console.log('Reason:', detection.result.reason);
    } else {
      console.log('βœ… Content is clean');
    }
  } catch (error) {
    console.error('Error:', error.message);
  }
}

checkContent();

API Documentation

Methods

detectProfanities(text: string): Promise<string>

Analyzes text content for profanities and inappropriate language.

Parameters:

  • text (string, required): The text content to analyze

Returns:

  • Promise: Status URL for polling the job result

Response Format

The API returns a detection result with confidence score:

{
  "data": {
    "type": "api_job_result",
    "id": "a8f2c1b5-9e4d-4a3b-8c7f-6d5e4f3a2b1c",
    "attributes": {
      "status": "success",
      "type": "content_detect_profanities",
      "result": {
        "pass": false,
        "score": 92,
        "reason": "The text contains explicit profanity and offensive language that violates community guidelines."
      }
    }
  }
}

Result Fields:

  • pass (boolean): true if content is clean, false if profanities detected
  • score (integer, 0-100): Confidence score of the detection
    • 90-100: Very high confidence
    • 75-89: High confidence
    • 60-74: Moderate confidence
    • Below 60: Low confidence (may need human review)
  • reason (string): Explanation of why content was flagged or cleared

Examples

Basic Profanity Detection

const { SharpApiDetectProfanitiesService } = require('@sharpapi/sharpapi-node-detect-profanities');

const service = new SharpApiDetectProfanitiesService(process.env.SHARP_API_KEY);

const content = 'This is a sample user comment to check for inappropriate content.';

service.detectProfanities(content)
  .then(statusUrl => service.fetchResults(statusUrl))
  .then(result => {
    const detection = result.getResultJson().result;

    if (detection.pass) {
      console.log('βœ… Content approved');
    } else {
      console.log(`⚠️ Content flagged (${detection.score}% confidence)`);
      console.log(`Reason: ${detection.reason}`);
    }
  })
  .catch(error => console.error('Detection failed:', error));

Batch Content Moderation

const service = new SharpApiDetectProfanitiesService(process.env.SHARP_API_KEY);

const userComments = [
  { id: 1, text: 'Great product! Really helpful.' },
  { id: 2, text: 'Terrible service, very disappointed.' },
  { id: 3, text: 'Amazing quality, highly recommend!' }
];

async function moderateComments(comments) {
  const moderated = await Promise.all(
    comments.map(async (comment) => {
      try {
        const statusUrl = await service.detectProfanities(comment.text);
        const result = await service.fetchResults(statusUrl);
        const detection = result.getResultJson().result;

        return {
          ...comment,
          approved: detection.pass,
          confidence: detection.score,
          reason: detection.reason,
          requiresReview: !detection.pass && detection.score < 75
        };
      } catch (error) {
        return {
          ...comment,
          approved: false,
          error: error.message,
          requiresReview: true
        };
      }
    })
  );

  return moderated;
}

const results = await moderateComments(userComments);

const approved = results.filter(r => r.approved).length;
const flagged = results.filter(r => !r.approved).length;
const needsReview = results.filter(r => r.requiresReview).length;

console.log(`πŸ“Š Moderation Summary:`);
console.log(`Total: ${results.length}`);
console.log(`βœ… Approved: ${approved}`);
console.log(`⚠️ Flagged: ${flagged}`);
console.log(`πŸ‘€ Needs Human Review: ${needsReview}`);

Real-time Comment Filtering

const service = new SharpApiDetectProfanitiesService(process.env.SHARP_API_KEY);

async function filterComment(comment, autoReject = true) {
  const statusUrl = await service.detectProfanities(comment.text);
  const result = await service.fetchResults(statusUrl);
  const detection = result.getResultJson().result;

  const action = {
    commentId: comment.id,
    userId: comment.userId,
    text: comment.text,
    pass: detection.pass,
    confidence: detection.score,
    reason: detection.reason,
    status: '',
    action: ''
  };

  if (detection.pass) {
    action.status = 'approved';
    action.action = 'publish';
  } else if (detection.score >= 85 && autoReject) {
    action.status = 'rejected';
    action.action = 'auto_reject';
  } else if (detection.score >= 60) {
    action.status = 'flagged';
    action.action = 'hold_for_review';
  } else {
    action.status = 'uncertain';
    action.action = 'manual_review';
  }

  return action;
}

const newComment = {
  id: 'CMT-12345',
  userId: 'USER-789',
  text: 'What a fantastic experience! Absolutely loved it!'
};

const moderation = await filterComment(newComment);

console.log(`Comment Status: ${moderation.status}`);
console.log(`Action: ${moderation.action}`);
console.log(`Confidence: ${moderation.confidence}%`);

if (moderation.action === 'publish') {
  console.log('βœ… Comment published successfully');
} else if (moderation.action === 'auto_reject') {
  console.log('🚫 Comment automatically rejected');
  console.log(`Reason: ${moderation.reason}`);
} else {
  console.log('⏸️ Comment held for manual review');
}

Forum Moderation Dashboard

const service = new SharpApiDetectProfanitiesService(process.env.SHARP_API_KEY);

async function generateModerationReport(posts) {
  const analyzed = await Promise.all(
    posts.map(async (post) => {
      const statusUrl = await service.detectProfanities(post.content);
      const result = await service.fetchResults(statusUrl);
      const detection = result.getResultJson().result;

      return {
        postId: post.id,
        author: post.author,
        timestamp: post.timestamp,
        pass: detection.pass,
        score: detection.score,
        reason: detection.reason,
        severity: detection.score >= 90 ? 'high' :
                 detection.score >= 75 ? 'medium' :
                 detection.score >= 60 ? 'low' : 'uncertain'
      };
    })
  );

  const report = {
    totalPosts: posts.length,
    clean: analyzed.filter(a => a.pass).length,
    flagged: analyzed.filter(a => !a.pass).length,
    highSeverity: analyzed.filter(a => a.severity === 'high').length,
    mediumSeverity: analyzed.filter(a => a.severity === 'medium').length,
    lowSeverity: analyzed.filter(a => a.severity === 'low').length,
    needsReview: analyzed.filter(a => a.severity === 'uncertain').length,
    posts: analyzed.filter(a => !a.pass).map(a => ({
      postId: a.postId,
      author: a.author,
      severity: a.severity,
      score: a.score,
      reason: a.reason
    }))
  };

  return report;
}

const forumPosts = [
  { id: 'POST-1', author: 'user123', content: 'Great discussion!', timestamp: new Date() },
  { id: 'POST-2', author: 'user456', content: 'Thanks for sharing!', timestamp: new Date() },
  { id: 'POST-3', author: 'user789', content: 'Very helpful post.', timestamp: new Date() }
];

const report = await generateModerationReport(forumPosts);

console.log('πŸ“‹ Moderation Report:');
console.log(`Total Posts: ${report.totalPosts}`);
console.log(`Clean: ${report.clean}`);
console.log(`Flagged: ${report.flagged}`);
console.log(`  - High Severity: ${report.highSeverity}`);
console.log(`  - Medium Severity: ${report.mediumSeverity}`);
console.log(`  - Low Severity: ${report.lowSeverity}`);
console.log(`  - Needs Review: ${report.needsReview}`);

if (report.posts.length > 0) {
  console.log('\n🚨 Flagged Posts:');
  report.posts.forEach(p => {
    console.log(`  - ${p.postId} by ${p.author} (${p.severity} severity, ${p.score}%)`);
    console.log(`    Reason: ${p.reason}`);
  });
}

Use Cases

  • Social Media Platforms: Moderate user comments and posts
  • Community Forums: Enforce community guidelines automatically
  • Gaming Platforms: Filter chat messages and usernames
  • E-commerce: Screen product reviews and seller messages
  • Educational Platforms: Maintain safe learning environments
  • Dating Apps: Screen user profiles and messages
  • Customer Support: Filter support tickets and feedback
  • Live Chat: Real-time message filtering

Detection Capabilities

The AI analyzes content for:

  • Explicit Profanity: Curse words and vulgar language
  • Offensive Slurs: Discriminatory or hate speech
  • Sexual Content: Inappropriate sexual references
  • Harassment: Threatening or bullying language
  • Toxic Behavior: Generally harmful or abusive content
  • Masked Profanity: Attempts to bypass filters with symbols or misspellings

Integration Tips

Confidence Thresholds

Recommended confidence score thresholds:

  • β‰₯ 90%: Auto-reject/block (very high confidence)
  • 75-89%: Flag for priority review (high confidence)
  • 60-74%: Queue for review (moderate confidence)
  • < 60%: Manual review required (low confidence)

Performance Optimization

  • Use batch processing for bulk moderation
  • Cache results for repeated content checks
  • Implement queue systems for high-volume scenarios
  • Combine with other moderation tools for comprehensive coverage

API Endpoint

POST /content/detect_profanities

For detailed API specifications, refer to:



License

This project is licensed under the MIT License. See the LICENSE.md file for details.


Support


Powered by SharpAPI - AI-Powered API Workflow Automation