text-finder
Version:
Searching word in string, faster and flexible.
77 lines (51 loc) • 1.63 kB
Markdown
text-finder Search "registered words" in string.
Word registering is easy, and search is fast.
```
npm install text-finder
```
```
const textfinder = require('text-finder');
(async () => {
// setup is async. (return Promise<void>)
await textfinder.setup(['apple', 'orange', 'remon']);
const result = textfinder.findOne('I like orange');
// result: {string: 'orange', start: 7, end: 13}
})();
```
"character mapping" means Translate as a other character.
ex) lower/upper case(A => a)
```
const {TextFinder} = require('./');
const textfinder = new TextFinder({A: 'a', O: 'o', R: 'r'});
(async () => {
await textfinder.setup(['apple', 'orange', 'remon']);
const result = textfinder.findOne('I like Remon');
// result: {string: 'Remon', start: 7, end: 12}
})();
```
Returns the first word found.
```
const result = textfinder.findOne('I like orange and remon.');
// result: {string: 'orange', start: 7, end: 13}
```
Return the all word found as an array.
```
const result = textfinder.find('I like orange and remon.');
// result: [{string: 'orange', start: 7, end: 13}, {string: 'remon', start, 18, end: 23}]
```
| function | 100words | 1000words | 10000words |
|----------|----------|-----------|------------|
| Array
| TextFinder
| TextFinder
MIT LICENSE [LICENSE](LICENSE)