Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximilianschmitt/tagsearch
Search a string with a set of tags.
https://github.com/maximilianschmitt/tagsearch
Last synced: about 1 month ago
JSON representation
Search a string with a set of tags.
- Host: GitHub
- URL: https://github.com/maximilianschmitt/tagsearch
- Owner: maximilianschmitt
- Created: 2015-06-22T20:20:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-26T13:56:07.000Z (over 9 years ago)
- Last Synced: 2024-11-19T18:16:13.033Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/tagsearch
- Size: 129 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# tagsearch
[![Travis Build](http://img.shields.io/travis/maximilianschmitt/tagsearch.svg?style=flat)](https://travis-ci.org/maximilianschmitt/tagsearch) [![Code Coverage](https://img.shields.io/coveralls/maximilianschmitt/tagsearch.svg)](https://coveralls.io/r/maximilianschmitt/tagsearch) [![npm](https://img.shields.io/npm/dm/tagsearch.svg)](https://www.npmjs.com/package/tagsearch)
Search a string with a set of tags.
## Installation
```
$ npm i tagsearch -S
```## Usage
### t.matches(string)
`matches` is not case-sensitive and finds all matches within a string.
```js
const t = tagsearch(['slim', 's', 'shady']);
const matches = t.matches('slim shady');expect(matches).to.deep.equal([
{ start: 0, end: 4, tag: 'slim', original: 'slim' }
{ start: 5, end: 10, tag: 'shady', original: 'shady' },
{ start: 0, end: 1, tag: 's', original: 's' },
{ start: 5, end: 6, tag: 's', original: 's' }
]);
```### t.highlight(string[, wrappingFunction])
`highlight` wraps every match in `strong`-tags by default:
```js
const t = tagsearch(['slim', 'shady', 's']);
const h = t.highlight('i am the real slim shady');expect(h).to.equal('i am the real slim shady');
```You can specify your own wrapping function:
```js
const t = tagsearch(['slim', 'shady', 's']);
const h = t.highlight('i am the real slim shady', match => `${match.original}`);expect(h).to.equal('i am the real slim shady');
```