- Notifications
You must be signed in to change notification settings - Fork0
A fully-typed class for filtering a list of domain names in various ways
License
NotificationsYou must be signed in to change notification settings
crock/DomainFilter
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A fully-typed class for filtering a list of domain names in various ways
npm i domainfilter
or
yarn add domainfilter
I've automatically generated basic documentation usingTypeDoc. Some basic usage examples are below.
https://crock.github.io/DomainFilter/
I have included a Node script in the bundle that will download a JSON list of adult terms for theIFilterConfig.adult
option or you can pass in your own list of terms like so...
constdf=newDomainFilter({adult:false},{adultTerms:["badword","anotherbadword"]})
To run the Node script, you can do the following in your project directory...
node node_modules/domainfilter/scripts/downloadAdultTerms.js
importDomainFilter,{KeywordPosition}from'domainfilter';constdf=newDomainFilter({keywords:[{value:"example",selected:true,position:KeywordPosition.anywhere},{value:"admin",selected:true,position:KeywordPosition.end},{value:"foobar",selected:false,position:KeywordPosition.anywhere},]});constresults=df.filter(["admintuts.com","example.com","sysadmin.com","foobar.org"]);print(results);// Logs ["sysadmin.com", "example.com"]
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Dropfilter - Browser Usage Example</title></head><body><divid="results"></div><scriptsrc="/dist/DomainFilter.umd.js"></script><script>constDomainFilter=window["DomainFilter"].defaultconstresultsEl=document.getElementById("results");document.addEventListener("DOMContentLoaded",function(){constdf=newDomainFilter({keywords:[{value:'admin',selected:true,position:"start"}]});constresults=df.filter(['admintuts.com','google.com','sysadmin.com'])resultsEl.innerText=results.join("\n");})</script></body></html>
A complete set of unit tests are implemented usingJest.To run the tests, simply runnpm run test
in the root directory.
Let me know of any issues or feature requests by opening an issue onGitHub.
Completed | Feature |
---|---|
✅ | IFilterConfig.domainLength |
✅ | IFilterConfig.domainHacks |
✅ | IFilterConfig.hyphens |
✅ | IFilterConfig.numbers |
✅ | IFilterConfig.keywords |
✅ | IFilterConfig.extensions |
✅ | IFilterConfig.adult - Added in 1.0.4 |
✅ | IFilterConfig.idn - Added in 1.0.5 |