easy-match

A simple matcher with regex cache.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
easy-match
1.1.55 years ago5 years agoMinified + gzip package size for easy-match in KB

Readme

easy-match
A simple matcher with regex cache, zero dependency.

logo
version downloads node status

Installation

npm install easy-match

Usage

Contains

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@'], ['it@']);
console.log(res.matches.length);//4
console.log(res.matches.includes('it@abc.com'));//true
console.log(res.matches.includes('itit@abc.com'));//true
console.log(res.others.includes('xyz@abc.com'));//true
console.log(res.matches.includes('abcit@domain.com'));//true
console.log(res.matches.includes('abcit@'));//true

Left Wildcard

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@',"it@","itit@"], ['*it@']);
console.log(res.matches.length);//3
console.log(res.others.includes('it@abc.com'));//true
console.log(res.others.includes('itit@abc.com'));//true
console.log(res.others.includes('xyz@abc.com'));//true
console.log(res.others.includes('abcit@domain.com'));//true
console.log(res.matches.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true
console.log(res.matches.includes('itit@'));//true

Right Wildcard

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@',"it@"], ['it@*']);
console.log(res.matches.length);//2
console.log(res.matches.includes('it@abc.com'));//true
console.log(res.others.includes('itit@abc.com'));//true
console.log(res.others.includes('xyz@abc.com'));//true
console.log(res.others.includes('abcit@domain.com'));//true
console.log(res.others.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true

Inner Wildcard

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@',"it@"], ['*it@*']);
console.log(res.matches.length);//5
console.log(res.matches.includes('it@abc.com'));//true
console.log(res.matches.includes('itit@abc.com'));//true
console.log(res.others.includes('xyz@abc.com'));//true
console.log(res.matches.includes('abcit@domain.com'));//true
console.log(res.matches.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true

Full Wildcard

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','itxyz@abc.com', 'abcit@domain.com','abcit@',"it@"], ['*it*@*']);
console.log(res.matches.length);//6
console.log(res.matches.includes('it@abc.com'));//true
console.log(res.matches.includes('itit@abc.com'));//true
console.log(res.matches.includes('itxyz@abc.com'));//true
console.log(res.matches.includes('abcit@domain.com'));//true
console.log(res.matches.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true

Regex

const EasyMatch = require('easy-match');

let res = EasyMatch(['it@abc.com','itit@abc.com','xyz@abc.com', 'abcit@domain.com','abcit@',"it@"], ['/^it@.*$/']);
console.log(res.matches.length);//2
console.log(res.matches.includes('it@abc.com'));//true
console.log(res.others.includes('itit@abc.com'));//true
console.log(res.others.includes('xyz@abc.com'));//true
console.log(res.others.includes('abcit@domain.com'));//true
console.log(res.others.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true

Test

mocha or npm test
check test folder and QUICKSTART.js for extra usage.