JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 84
  • Score
    100M100P100Q72581F
  • License MIT

A simple matcher with regex cache.

Package Exports

  • easy-match

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (easy-match) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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.