4.0.2 • Published 3 months ago
string-lookup-manager v4.0.2
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
3 months ago
4.0.0
9 months ago
3.0.9
10 months ago
3.0.8
1 year ago
3.0.7
2 years ago
3.0.6
2 years ago
3.0.5
2 years ago
3.0.3
2 years ago
3.0.2
2 years ago
3.0.1
2 years ago
3.0.0
2 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.1.2
3 years ago
1.1.1
4 years ago
1.1.0
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago