Socket
Socket
Sign inDemoInstall

antibot

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antibot

A simple auto-training spamfilter


Version published
Maintainers
1
Created
Source

antibot

A simple spamfilter with autotraining

Install

npm i --save antibot

Example

const spamfilter = require("antibot");

const instance = spamfilter.create(["spam"], {
  onFiltered: (spam) =>
    spam.split(" ").flatMap((word) => [`_${word}_`, `-${word}-`]),
  skipOnFilteredOnInit: true,
});

const isSpam = instance.test("SPAM filter"); // true
const isSpamToo = instance.test("_FILTER_"); // true, because it trained from onFiltered call

API

const instance = instance.create();

Creates a new Spamfilter instance

instance.test(content);

Returns true if spam detected, otherwise false.

By default will split words and lowercase them, banning those too. You might want to override the tactic with onFiltered second parameter of the .create method:

const instance = spamfilter.create(["spam"], {
  onFiltered: (spam) =>
    spam.split(" ").flatMap((word) => [`_${word}_`, `-${word}-`]),
  skipOnFilteredOnInit: true,
});

onFiltered - function that predicts the new banned words derived from detected content

skipOnFilteredOnInit - the words passed in .create() method will not be transformed through onFiltered and leave intact

onDetection - overrides detection behavior

const filter = spamfilter.create(["123"], {
  onDetection: (text, dict) => Object.keys(dict).length === text.length,
});

filter.test("3"); // true
const tree = instance.explain();

Explains the reason of detection as a tree, e.g.

{
  spam: {
    filter: {},
    test: {},
  },
  filter: {
    word: {},
  },
};

Plugins

const spamfilter = require("antibot");

class CustomPlugin extends spamfilter.Plugin {
  beforeFiltered(content: string) {
    // ... preprocessing returning string
    return content;
  }

  afterFiltered(contents: string[]) {
    // ... postprocessing returning string array
    return contents;
  }
}

const filter = spamfilter.create(...);

filter.inject(new CustomPlugin())

beforeFiltered fires before main intermediate processing as asserted in Spamfilter params onFiltered

afterFiltered fires after main intermediate processing as asserted in Spamfilter params onFiltered

onDetection of params takes precedence over onDetection of plugin(s)

Predefined plugins

Levenshtein

const LevenshteinPlugin = require("antibot/plugins/LevenshteinPlugin");

const filter = spamfilter.create(["abcd"]);
filter.inject(new LevenshteinPlugin({ sensitivity: 1 }));

filter.test("abced");

Nilsimsa

const NilsimsaPlugin = require("antibot/plugins/NilsimsaPlugin");

const expected = true;

const filter = spamfilter.create(["1234 abcde"], {
  onFiltered: (exact) => [exact],
});
filter.inject(new NilsimsaPlugin({ from: 128, to: 128 }));

filter.test("1234 abcde");

Test

npm test

Keywords

FAQs

Package last updated on 20 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc