Censorly is a Node.js SDK for interacting with the Censorly API, a powerful AI-powered text moderation service. This package simplifies integration by providing easy-to-use methods for analyzing text.
Install the package using npm:
npm install censorly
First, import the Censorly
SDK and create an instance with your API token.
To use this SDK, you must sign up for an account on Censorly and obtain an API token in Dashboard.
import Censorly from 'censorly';
// Initialize the SDK with your API token
const censorly = new Censorly('your_api_token');
// Analyze a message
async function analyzeText() {
try {
const result = await censorly.analyzeMessage('This is the text to analyze.');
console.log('Analysis result:', result);
} catch (error) {
console.error('Error analyzing text:', error.message);
}
}
analyzeText();
import Censorly from 'censorly';
Censorly.analyzeMessage({ apiToken: 'your_api_token', text: "Text to analyze" }) // Must be a valid Object
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
If your project uses CommonJS instead of ES Modules, you can use the following syntax to import the package:
const { Censorly, analyzeMessage } = require('censorly');
The rest of the usage remains the same.
Analyzes a given text for flagged topics.
-
text
(string): The text to be analyzed.
A Promise
resolving to the analysis result(JSON)
{
"flagged": boolean, // Whether the content was flagged as inappropriate
"topics": string[], // Array of main topics identified in the text
"confidence": number, // Number from 0 to 1.0 indicating AI's certainty
"language": string // Two-letter language code (e.g., "en", "es") or "Unknown"
}
This project is licensed under the MIT License.