npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sharpapi/sharpapi-node-detect-profanities

v1.0.1

Published

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

Downloads

161

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:


Related Packages


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