easy-match
v1.1.5
Published
A simple matcher with regex cache.
Downloads
1,666
Maintainers
Readme
easy-match
A simple matcher with regex cache, zero dependency.
Installation
npm install easy-match
Usage
Contains
const EasyMatch = require('easy-match');
let res = EasyMatch(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@'], ['it@']);
console.log(res.matches.length);//4
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('abcit@'));//true
Left Wildcard
const EasyMatch = require('easy-match');
let res = EasyMatch(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@',"it@","itit@"], ['*it@']);
console.log(res.matches.length);//3
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//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(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@',"it@"], ['it@*']);
console.log(res.matches.length);//2
console.log(res.matches.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//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(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@',"it@"], ['*it@*']);
console.log(res.matches.length);//5
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//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(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@',"it@"], ['*it*@*']);
console.log(res.matches.length);//6
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('[email protected]'));//true
console.log(res.matches.includes('abcit@'));//true
console.log(res.matches.includes('it@'));//true
Regex
const EasyMatch = require('easy-match');
let res = EasyMatch(['[email protected]','[email protected]','[email protected]', '[email protected]','abcit@',"it@"], ['/^it@.*$/']);
console.log(res.matches.length);//2
console.log(res.matches.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//true
console.log(res.others.includes('[email protected]'));//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.