This package has been deprecated

Author message:

lagden-highlight > 4.3.1 is now @tadashi/highlight

lagden-highlight

4.3.1 • Public • Published

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])

Name Type Required Default Description
source string yes - Your text
q string yes - The term that will be shine
options object no see below Options

options

Name Type Required Default Description
tpl string no <mark>$&</mark> Custom template
split boolean no true Break the term in many words
caseSensitive boolean no true The words can differ in meaning

License

MIT © Thiago Lagden

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i lagden-highlight

    Weekly Downloads

    8

    Version

    4.3.1

    License

    MIT

    Unpacked Size

    8.94 kB

    Total Files

    7

    Last publish

    Collaborators

    • lagden