5.1.0 • Published 4 years ago

@tadashi/highlight v5.1.0

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

Highlight

Dependency Status devDependency Status

XO code style Greenkeeper badge

Make the words shine

Install

$ npm i -S @tadashi/highlight

Usage

Basic usage

const highlight = require('@tadashi/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('@tadashi/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('@tadashi/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('@tadashi/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
caseSensitivebooleannotrueDefines whether letters are treated as distinct

License

MIT © Thiago Lagden