You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

easy-match

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-match

A simple matcher with regex cache.

1.1.5
latest
Source
npmnpm
Version published
Weekly downloads
166
64.36%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

match

FAQs

Package last updated on 15 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts