wlistfilter
v1.0.0
Published
A simple JavaScript utility for managing and checking whitelisted IPs from a file.
Readme
WhitelistFilter
A simple JavaScript utility for managing and checking whitelisted IPs from a file.
Installation
Clone the repository and install dependencies if required:
git clone https://github.com/dev-juri/wlistfilter.git
cd wlistfilterUsage
1. Create an instance of WhitelistFilter
const WhitelistFilter = require("./WhitelistFilter");
let wlFilter = new WhitelistFilter();2. Load the whitelist from a .txt file
Use the asynchronous method to read and store the whitelist:
await wlFilter.fetchWhitelist("path/to/whitelist.txt");- Parameters:
filePath(string) – Path to the.txtfile.
- Returns:
- A
Setcontaining the loaded content.
- A
3. Check if an IP is whitelisted
Verify if an IP address exists in the loaded whitelist:
wlFilter.isWhitelisted("192.168.1.1");- Parameters:
ip(string) – The IP address to check.
- Returns:
trueif the IP exists in the whitelist, otherwisefalse.
Example
(async () => {
const wlFilter = new WhitelistFilter();
await wlFilter.fetchWhitelist("whitelist.txt");
console.log(wlFilter.isWhitelisted("192.168.1.1")); // true or false
})();