0.0.5 • Published 9 years ago

tagsearch v0.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

tagsearch

Travis Build Code Coverage npm

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.

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:

const t = tagsearch(['slim', 'shady', 's']);
const h = t.highlight('i am the real slim shady');

expect(h).to.equal('i am the real <strong>slim</strong> <strong>shady</strong>');

You can specify your own wrapping function:

const t = tagsearch(['slim', 'shady', 's']);
const h = t.highlight('i am the real slim shady', match => `<em>${match.original}</em>`);

expect(h).to.equal('i am the real <em>slim</em> <em>shady</em>');