contactfilter
v1.0.0
Published
Filters post content to disallow contact information like phone numbers, emails, and disallowed domains.
Maintainers
Readme
contactfilter
Filters post content to disallow contact information like phone numbers, emails, and disallowed domains.
Features
- Disallows Contact Information: Prevents the posting of phone numbers and email addresses.
- Domain Whitelisting: Allows links only to specified domains and their subdomains.
- Configurable: Supports custom disallowed keywords, allowed domains, and regex patterns for phone and email detection.
- Social Handle Permitted: Social handles (e.g.,
@username) are not disallowed by default.
Installation
npm install contactfilterUsage
const filterContactInfo = require('contactfilter');
// Using default configuration:
const result1 = filterContactInfo("This is a normal post.");
console.log(result1); // { allowed: true }
// Using custom configuration:
const customConfig = {
disallowedKeywords: ["dm", "contact"], // Note: Keywords are no longer used for disallowing by default.
allowedDomains: ["example.com", "mycompany.org"],
phoneRegex: /.../, // your custom regex
emailRegex: /.../, // your custom regex
};
const result2 = filterContactInfo("DM me at [email protected]", customConfig);
console.log(result2); // { allowed: false, reason: "Posting contact information is not allowed." }
// Example with a valid link to an allowed domain
const result3 = filterContactInfo("Check out https://example.com/page", customConfig);
console.log(result3); // { allowed: true }
// Example with a disallowed domain
const result4 = filterContactInfo("Check out http://www.google.com", customConfig);
console.log(result4); // { allowed: false, reason: "Posting contact information is not allowed." }
// Example with a social handle (allowed by default)
const result5 = filterContactInfo("You can follow me on social media, I'm @myuser");
console.log(result5); // { allowed: true }API
filterContactInfo(postContent, options)
Filters post content to disallow contact information.
Parameters:
postContent(string): The content to filter.options(object, optional): Optional configuration for filtering.disallowedKeywords(string[]): An array of keywords to disallow. (Note: This is currently not used in the default filtering logic as per user instructions).allowedDomains(string[]): An array of domains that are allowed in links.phoneRegex(RegExp): A regex for detecting phone numbers.emailRegex(RegExp): A regex for detecting email addresses.socialRegex(RegExp): A regex for detecting social handles. (Note: This is currently not used for disallowing).
Returns:
{allowed: boolean, reason?: string}: An object indicating if the content is allowed and a reason if not.
License
MIT
