4.3.1 • Published 5 years ago

lagden-highlight v4.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Highlight

NPM version Build Status

Dependency Status devDependency Status

XO code style Greenkeeper badge

Make the words shine

Install

$ npm i -S lagden-highlight

Usage

Basic usage

const highlight = require('lagden-highlight')

const source = 'My name is Bond, James Bond...'
const q = 'James Bond'

highlight(source, q)
// My name is <mark>Bond</mark>, <mark>James</mark> <mark>Bond</mark>...

Without breaking the term into small words

const highlight = require('lagden-highlight')

const source = 'My name is Bond, James Bond...'
const q = 'James Bond'
const split = false

highlight(source, q, {split});
// My name is Bond, <mark>James Bond</mark>...

Without breaking the term into small words and changing the template

const highlight = require('lagden-highlight')

const source = 'My name is Bond, James Bond...'
const q = 'James Bond'
const tpl = '<b>$&</b>'
const split = false

highlight(source, q, {tpl, split});
// My name is Bond, <b>James Bond</b>...

Ignoring case sensitive

const highlight = require('lagden-highlight')

const source = 'What a wonderful phrase'
const q = 'w'
const tpl = '<b>$&</b>'
const caseSensitive = false

highlight(source, q, {tpl, caseSensitive});
// <b>W</b>hat a <b>w</b>onderful phrase

API

highlight(source, q [, options])

NameTypeRequiredDefaultDescription
sourcestringyes-Your text
qstringyes-The term that will be shine
optionsobjectnosee belowOptions

options

NameTypeRequiredDefaultDescription
tplstringno\<mark>$\&\</mark>Custom template
splitbooleannotrueBreak the term in many words
caseSensitivebooleannotrueThe words can differ in meaning

License

MIT © Thiago Lagden

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.0

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago