sightengine-js
v0.6.0
Published
A fully-typed TypeScript SDK for the SightEngine content‑moderation API, with streaming support, threshold presets, and helper utilities.
Downloads
28
Maintainers
Readme
🔥 Features
- ✅ Fully‑typed (TypeScript)
- 📡 Stream image moderation
- 🌐 URL image inputs
- ⚙️ Threshold presets + custom thresholds
- 🛠️ Helper utilities:
isNSFW(),listFlaggedCategories()
📦 Installation
npm install sightengine-js
# or
yarn add sightengine-js🚀 Quick Start
import { SightEngineClient, isNSFW, listFlaggedCategories } from "sightengine-js";
const sightengine = new SightEngineClient({
apiSecret: "<your api secret>",
apiUser: "<your api user>",
});
const imageModerationResult = await sightengine.moderateImage(
"<path to your image>",
[
"nudity-2.1",
"gore-2.0",
"offensive-2.0",
],
);
// URL-based
const urlImageModerationResult = await sightengine.moderateImageByUrl(
"<image URL>",
[
"nudity-2.1",
"gore-2.0",
"offensive-2.0",
],
);
console.log(listFlaggedCategories(imageModerationResult));
console.log(isNSFW(imageModerationResult));
📚 API Reference
new SightEngineClient(options)
| Property | Type | Description |
|----------|--------|-------------------------------------------|
| apiUser| string| Your SightEngine API user. |
| apiSecret| string| Your SightEngine API secret. |
client.moderateImage(path, models?)
path– Local file system path to the image.models– Array of model identifiers (default:["nudity-2.1"]).
Returns a promise that resolves to ImageModerationResponse.
client.moderateImageByUrl(url, models?)
url– Direct URL to the image.models– Same as above.
Returns a promise that resolves to ImageModerationResponse.
Types
ImageModerationResponse– Raw response from SightEngine (seesrc/types.ts).NormalizedImageModerationResponse– Internal normalized shape used by helpers.
⚙️ Thresholds & Presets
import { DEFAULT_THRESHOLDS, PRESET_THRESHOLDS } from "sightengine-js";
// Example: use the strict preset
const thresholds = PRESET_THRESHOLDS.strict;| Model | Default |
|------------|---------|
| nudity | 0.85 |
| offensive| 0.5 |
| gore | 0.5 |
| violence | 0.5 |
| self-harm| 0.5 |
🛠️ Helper Utilities
isNSFW(response, threshold?)– Returnstrueif any of the important categories (nudity,gore,violence,self-harm,sexual) exceed the given threshold.listFlaggedCategories(response, thresholds?)– Returns an array of categories (and sub‑scores) that exceed the supplied thresholds.
Both functions accept the raw ImageModerationResponse from the client.
🤝 Contributing
- Fork the repo
- Create a feature branch (
git checkout -b feat/...) - Commit with Commitizen (
npm run commit) - Push & open a PR against
develop - Tests must pass, coverage ≥ 90%
📜 License
MIT © Ali Nazari
