4.0.2 • Published 1 year ago

string-lookup-manager v4.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
1 year ago

An easy way to collect regular expressions search results.

It you need to get an array of search results from several regular expressions. But search results may overlap and duplicate. This package will help you get clean results of this search.

Install

npm install string-lookup-manager

Usage

import LookupManager from 'string-lookup-manager';

const text = 'foo bar foobar bar foo';
const expressions = [/foo/gi, /bar/gi, /foobar/gi];
const manager = new LookupManager();
let match;

expressions.forEach(expression => {
  // Regex finds this:
  // { value: 'foo', start: 0 }
  // { value: 'foo', start: 8 }
  // { value: 'foo', start: 19 }
  // { value: 'bar', start: 4 }
  // { value: 'bar', start: 11 }
  // { value: 'bar', start: 15 }
  // { value: 'foobar', start: 8 }
  while ((match = expression.exec(text))) {
    console.log({ value: match[0], start: match.index });
    manager.add(match[0], match.index);
  }
});

// Lookup manager items:
//  LookupItem { value: 'foo', start: 0, end: 2 },
//  LookupItem { value: 'bar', start: 4, end: 6 },
//  LookupItem { value: 'foobar', start: 8, end: 13 },
//  LookupItem { value: 'bar', start: 15, end: 17 },
//  LookupItem { value: 'foo', start: 19, end: 21 }
console.log(manager.items);
4.0.2

1 year ago

4.0.0

2 years ago

3.0.9

2 years ago

3.0.8

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago