Giter VIP home page Giter VIP logo

listmatch's Introduction

ListMatcher

Library for performing denylist/allowlist matching operations for things like email addresses.

Maven Dependency:

<dependency>
  <groupId>com.giladam</groupId>
  <artifactId>ListMatch</artifactId>
  <version>1.1.0</version>
</dependency>

Example usage for managing single list:

    
    //load some patterns from a text file:
    Set<String> allowListPatterns = ListMatcher.readPatternsFromFile(new File("/tmp/allow.txt"));

    PatternList patternList = new PatternList(allowListPatterns, "@", false);
        
    //do some matching:
    boolean inAllowlist = patternList.matches("[email protected]");

Example usage for managing multiple lists:

    
    //load some patterns from a text file:
    Set<String> allowListPatterns = ListMatcher.readPatternsFromFile(new File("/tmp/someAllowlist.txt"));
    Set<String> denyListPatterns = ListMatcher.readPatternsFromFile(new File("/tmp/someDenylist.txt"));

    //some options
    boolean caseSensitive = false;

    //If you have multiple lists to manage:
    Map<String,PatternList> listByName = new HashMap<>();

    listByName.put("email.allowlist", new PatternList(allowListPatterns, "@", caseSensitive));
    listByName.put("email.denylist", new PatternList(denyListPatterns, "@", caseSensitive));

    ListMatcher listMatcher = new ListMatcher(listByName);
    
    //do some matching:
    boolean inAllowlist = listMatcher.matchesList("email.allowlist", "[email protected]");
    boolean inDenylist = listMatcher.matchesList("email.denylist", "[email protected]");

Matching patterns can look like (example using '@' delimiter for an email patterns list):


# Wildcard as email local part:
*@anylocalpart.com

# Wildcard as email domain part
anydomain@*

# Exact matches are preferred because they are tested against directly:
[email protected]

# Wildcard after some characters:
startswith*@domain.com

# Wildcard before some characters:
*[email protected]

Matching patterns can also look like (example using '.' delimiter for an ip address list, but I think there are probably better libraries out there for IP range handling.):


# Exact match
10.100.0.1

# Wildcards in IP ranges:
10.*.*.*

# Wildcards in IP ranges:
10.100.0.*

Matching patterns can also have no delimiter for components like (example using "" or null for delimiter for an url list):


# Exact match
https://www.example.com/specific.html

# Wildcards in urls:
http://www.example.com/allowed/*

# Wildcards in the middle and end:
http://*.edu/*

listmatch's People

Contributors

dependabot[bot] avatar giladam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

listmatch's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.