0

Detect profanity in a given text

by
Published Apr 8, 2025

This method helps safeguard your website or app by detecting offensive or inappropriate language in user inputs. By screening for profanity and other harmful content before it’s made public, you can maintain a positive user environment, protect your brand, and prevent abusive behavior on your platform.

Script greip Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Greip = {
3
  apiKey: string;
4
};
5
/**
6
 * Detect profanity in a given text
7
 * This method helps safeguard your website or app by detecting offensive or inappropriate language in user inputs. By screening for profanity and other harmful content before it’s made public, you can maintain a positive user environment, protect your brand, and prevent abusive behavior on your platform.
8
 */
9
export async function main(
10
  auth: Greip,
11
  text: string,
12
  listBadWords: string | undefined,
13
  scoreOnly: string | undefined,
14
  format: string | undefined,
15
  userID: string | undefined,
16
  mode: string | undefined,
17
  callback: string | undefined,
18
) {
19
  const url = new URL(`https://greipapi.com/scoring/profanity`);
20
  for (const [k, v] of [
21
    ["text", text],
22
    ["listBadWords", listBadWords],
23
    ["scoreOnly", scoreOnly],
24
    ["format", format],
25
    ["userID", userID],
26
    ["mode", mode],
27
    ["callback", callback],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.apiKey,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.text();
45
}
46