
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
ai-text-detector
Advanced tools
A lightweight, fast JavaScript/TypeScript library for detecting AI-generated text using advanced linguistic analysis. Works in Node.js, React, and browser environments with zero dependencies.
A lightweight, fast JavaScript/TypeScript library for detecting AI-generated text using advanced linguistic analysis. Features enhanced human text recognition, modern AI pattern detection, and adaptive thresholding. Works in both Node.js and browser environments with zero dependencies.
npm install ai-text-detector
yarn add ai-text-detector
import {
detectAIText,
isAIGenerated,
getConfidenceScore,
} from "ai-text-detector";
const longText =
"Furthermore, it is important to note that artificial intelligence has significantly enhanced various operational processes across multiple industries.";
const shortText = "Hello world!";
// Get detailed analysis for longer text
const result = detectAIText(longText);
console.log(result);
// {
// isAIGenerated: true,
// confidence: 0.75,
// reasons: [
// "High frequency of transition words typical of AI writing",
// "Elevated formality level characteristic of AI text"
// ],
// score: 0.75
// }
// Handle short text (less than 50 characters)
try {
const shortResult = detectAIText(shortText);
console.log(shortResult);
} catch (error) {
console.log("Error:", error.message);
// Output: "Error: Text too short for reliable analysis (minimum 50 characters)"
}
// Alternative: Check text length before analysis
function safeDetectAI(text) {
if (text.trim().length < 50) {
return {
isAIGenerated: false,
confidence: 0,
reasons: ["Text too short for reliable analysis"],
score: 0,
error: "Minimum 50 characters required",
};
}
return detectAIText(text);
}
const safeResult = safeDetectAI(shortText);
console.log(safeResult);
// {
// isAIGenerated: false,
// confidence: 0,
// reasons: ["Text too short for reliable analysis"],
// score: 0,
// error: "Minimum 50 characters required"
// }
// Quick boolean check (also throws error for short text)
try {
const isAI = isAIGenerated(longText);
console.log(isAI); // true
} catch (error) {
console.log("Error:", error.message);
}
// Get confidence score with error handling
try {
const confidence = getConfidenceScore(longText);
console.log(confidence); // 0.75
} catch (error) {
console.log("Error:", error.message);
}
const { detectAIText } = require("ai-text-detector");
const text = "Your text here...";
const result = detectAIText(text);
console.log(result);
import React, { useState } from "react";
import { detectAIText } from "ai-text-detector";
function AIDetector() {
const [text, setText] = useState("");
const [result, setResult] = useState(null);
const analyzeText = () => {
if (text.trim()) {
const detection = detectAIText(text);
setResult(detection);
}
};
return (
<div>
<textarea
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Enter text to analyze..."
/>
<button onClick={analyzeText}>Analyze Text</button>
{result && (
<div>
<p>AI Generated: {result.isAIGenerated ? "Yes" : "No"}</p>
<p>Confidence: {(result.confidence * 100).toFixed(1)}%</p>
<ul>
{result.reasons.map((reason, index) => (
<li key={index}>{reason}</li>
))}
</ul>
</div>
)}
</div>
);
}
detectAIText(text: string): DetectionResult
Analyzes the provided text and returns a detailed detection result.
Parameters:
text
(string): The text to analyze (minimum 50 characters required)Returns:
DetectionResult
object with the following properties:
isAIGenerated
(boolean): Whether the text is likely AI-generatedconfidence
(number): Confidence score between 0 and 1reasons
(string[]): Array of reasons explaining the detectionscore
(number): Raw detection scoreThrows:
Error
: When text is empty or less than 50 charactersisAIGenerated(text: string): boolean
Quick check to determine if text is likely AI-generated.
Parameters:
text
(string): The text to analyze (minimum 50 characters required)Returns:
boolean
: True if likely AI-generated, false otherwiseThrows:
Error
: When text is empty or less than 50 charactersgetConfidenceScore(text: string): number
Returns just the confidence score for the detection.
Parameters:
text
(string): The text to analyze (minimum 50 characters required)Returns:
number
: Confidence score between 0 and 1Throws:
Error
: When text is empty or less than 50 charactersThis library uses multiple advanced linguistic analysis techniques to detect AI-generated text:
The library analyzes various linguistic patterns commonly found in AI-generated text:
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details.
FAQs
A lightweight, fast JavaScript/TypeScript library for detecting AI-generated text using advanced linguistic analysis. Works in Node.js, React, and browser environments with zero dependencies.
The npm package ai-text-detector receives a total of 0 weekly downloads. As such, ai-text-detector popularity was classified as not popular.
We found that ai-text-detector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.