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-spam

v1.0.1

Published

SharpAPI.com Node.js SDK for detecting spam content in text

Readme

SharpAPI GitHub cover

Spam Detector API for Node.js

🛡️ Detect spam content with AI accuracy — powered by SharpAPI.

npm version License

SharpAPI Spam Detector uses advanced AI to identify spam, malicious content, and unwanted messages. Perfect for content moderation, email filtering, and user-generated content protection.


📋 Table of Contents

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

Requirements

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

Installation

Step 1. Install the package via npm:

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

Step 2. Get your API key

Visit SharpAPI.com to get your API key.


Usage

const { SharpApiDetectSpamService } = require('@sharpapi/sharpapi-node-detect-spam');

const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
const service = new SharpApiDetectSpamService(apiKey);

const suspiciousText = `
URGENT! You have won $1,000,000!!! Click here NOW to claim your prize!
Send your bank details to [email protected] immediately!
Limited time offer!!!
`;

async function checkSpam() {
  try {
    // Submit spam detection job
    const statusUrl = await service.detectSpam(suspiciousText);
    console.log('Job submitted. Status URL:', statusUrl);

    // Fetch results (polls automatically until complete)
    const result = await service.fetchResults(statusUrl);
    const spamResult = result.getResultJson();

    console.log('Is spam:', spamResult.is_spam);
    console.log('Confidence score:', spamResult.score);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

checkSpam();

API Documentation

Methods

detectSpam(text: string): Promise<string>

Analyzes text content to determine if it's spam.

Parameters:

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

Returns:

  • Promise: Status URL for polling the job result

Example:

const statusUrl = await service.detectSpam(userGeneratedContent);
const result = await service.fetchResults(statusUrl);

Response Format

The API returns spam detection results with confidence score:

{
  "is_spam": true,
  "score": 95,
  "confidence": "high",
  "reasons": [
    "Contains urgency language",
    "Requests financial information",
    "Uses excessive punctuation",
    "Contains suspicious URLs"
  ],
  "categories": ["phishing", "financial_scam"]
}

Examples

Basic Spam Detection

const { SharpApiDetectSpamService } = require('@sharpapi/sharpapi-node-detect-spam');

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

const userComment = 'Check out my website for amazing deals!!! Click here now!!!';

service.detectSpam(userComment)
  .then(statusUrl => service.fetchResults(statusUrl))
  .then(result => {
    const spamCheck = result.getResultJson();

    if (spamCheck.is_spam) {
      console.log(`⚠️ SPAM DETECTED (${spamCheck.score}% confidence)`);
      console.log('Reasons:', spamCheck.reasons.join(', '));
    } else {
      console.log('✅ Content is clean');
    }
  })
  .catch(error => console.error('Detection failed:', error));

Content Moderation Pipeline

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

async function moderateContent(content) {
  const statusUrl = await service.detectSpam(content);
  const result = await service.fetchResults(statusUrl);
  const spamCheck = result.getResultJson();

  return {
    approved: !spamCheck.is_spam || spamCheck.score < 70,
    confidence: spamCheck.score,
    reasons: spamCheck.reasons,
    action: spamCheck.score >= 90 ? 'block' :
            spamCheck.score >= 70 ? 'review' :
            'approve'
  };
}

const userPosts = [
  'Great product! Highly recommend.',
  'WIN MONEY NOW!!! CLICK HERE!!!',
  'Thanks for the helpful information.'
];

for (const post of userPosts) {
  const moderation = await moderateContent(post);
  console.log(`Post: "${post}"`);
  console.log(`Action: ${moderation.action} (${moderation.confidence}% spam)`);
  console.log('---');
}

Batch Spam Checking

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

const messages = [
  { id: 1, text: 'Looking forward to our meeting tomorrow.' },
  { id: 2, text: 'URGENT! Update your password immediately!!!' },
  { id: 3, text: 'Could you send me the project files?' }
];

const results = await Promise.all(
  messages.map(async (msg) => {
    const statusUrl = await service.detectSpam(msg.text);
    const result = await service.fetchResults(statusUrl);
    const spamCheck = result.getResultJson();

    return {
      id: msg.id,
      text: msg.text,
      is_spam: spamCheck.is_spam,
      score: spamCheck.score
    };
  })
);

const spamMessages = results.filter(r => r.is_spam);
console.log(`Found ${spamMessages.length} spam messages out of ${messages.length}`);

Use Cases

  • Content Moderation: Filter spam from user comments, reviews, and forums
  • Email Filtering: Identify and block spam emails
  • Form Protection: Prevent spam submissions on contact forms
  • Social Media: Detect and remove spam posts and messages
  • E-commerce: Filter fake reviews and fraudulent listings
  • Community Management: Protect online communities from spam bots
  • API Protection: Block automated spam attacks on your services

Detection Capabilities

The spam detector identifies various types of unwanted content:

  • Phishing attempts: Fake login pages, credential theft
  • Financial scams: Lottery scams, investment fraud, fake prizes
  • Link spam: Malicious URLs, affiliate link spam
  • Advertisement spam: Unsolicited promotional content
  • Bot-generated content: Automated spam messages
  • Social engineering: Manipulative or deceptive content

API Endpoint

POST /content/detect_spam

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