# keyword-highlighter

> Highlight a set of keywords in the body of text in your search results

Latest version **1.0.6** (published 2015-12-26) · GPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install keyword-highlighter
pnpm add keyword-highlighter
yarn add keyword-highlighter
bun add keyword-highlighter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2015-12-26 |
| First published | 2015-11-11 |
| Weekly downloads | 0 |
| License | GPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Rafe @rjmk + Friends |
| Maintainers | nelsonic |
| Keywords | highlight, keywords, search, results, fast, browser, server, node.js |

## Links

- npm: https://www.npmjs.com/package/keyword-highlighter
- Repository: https://github.com/dwyl/search-result-keyword-highlighter
- Homepage: https://github.com/dwyl/search-result-keyword-highlighter#readme
- Issues: https://github.com/dwyl/search-result-keyword-highlighter/issues
- npm.io page: https://npm.io/package/keyword-highlighter

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2015-12-26
- 1.0.5 — 2015-12-19
- 1.0.4 — 2015-11-27
- 1.0.3 — 2015-11-12
- 1.0.2 — 2015-11-12
- 1.0.1 — 2015-11-12
- 1.0.0 — 2015-11-11

## README

# Search Result Keyword Highlighter

[![Build Status](https://travis-ci.org/dwyl/search-result-keyword-highlighter.svg)](https://travis-ci.org/dwyl/search-result-keyword-highlighter)
[![codecov.io](https://codecov.io/github/dwyl/search-result-keyword-highlighter/coverage.svg?branch=master)](https://codecov.io/github/dwyl/search-result-keyword-highlighter?branch=master)
[![Code Climate](https://codeclimate.com/github/dwyl/search-result-keyword-highlighter/badges/gpa.svg)](https://codeclimate.com/github/dwyl/search-result-keyword-highlighter)
[![Dependency Status](https://david-dm.org/dwyl/search-result-keyword-highlighter.svg)](https://david-dm.org/dwyl/search-result-keyword-highlighter)
[![devDependency Status](https://david-dm.org/dwyl/search-result-keyword-highlighter/dev-status.svg)](https://david-dm.org/dwyl/search-result-keyword-highlighter#info=devDependencies)

Highlight a keyword in the body of text for a given search result.

## Why?

People who use search want to have the word(s) they searched for
highlighted in the results. We *know* this. (*because Google does it*)

![google-search-result-keyword-bold](https://cloud.githubusercontent.com/assets/194400/11105849/a2a2b008-88c9-11e5-9462-77f6c4577233.png)

Google have *user-tested every feature* of their site/experience...


## What?

For a given set of keywords that a person is searching for,
we highlight all occurrences of the word in the text of the search results.

## Features?

### *Case-insentive* Keyword Highlighting

a search for `Java`, `javA` or `java` will highlight `JAVA` or `JaVa` in the search result.

### Finds *Multiple Occurrences* of the *Same* Keyword in Text

Example:

```js
var text = 'London Bridge is Falling Down FALLING down, fALLiNG Down!';
var highlighted = h('falling', text);
console.log(highlighted);
```
The resulting `highlighted`
```html
London Bridge is <b class='highlight'>Falling</b> Down
<b class='highlight'>FALLING</b> down,
<b class='highlight'>fALLiNG</b> Down!
```

### *Partial* match for Keyword in Text

Imagine you are looking for `PHP` and someone has
listed `phpunit` in their recent experience,
this would be highliged as:
```html
We used <b class='highlight'>php</b>unit for our TDD.
```

### Match *Several Distinct* Keywords

If you pass in a `String` which contains multiple keywords,
it will be `split()` into an `Array` and then each
word will be highlighted in the `text`:



## How?

#### Install the module from NPM:

```sh
npm install keyword-highlighter --save
```

#### Use it in your code:

```js
var highlighter = require('keyword-highlighter');
var text   = 'I write JavaScript Code in Lovely London!';
var result = highlighter('javascript london', text);
console.log(result);
```

This will output:
```html
I write <b class='highlight'>JavaScript</b>
Code in Lovely <b class='highlight'>London</b>!
```

# Done.

<br />
<br />
<hr />

## Discussion:

### Is it *Fast*?

> Try it! And Judge for yourself!

### Should we only sub complete words...?

Consider the following example:

```js
var highlighter = require('keyword-highlighter');
var text = 'She sells sea shells on the sea shore.';
var result = highlighter('she sea', text);
console.log(result);
```
This will output:
```html
<b class='highlight'>She</b> sells
<b class='highlight'>sea</b> <b class='highlight'>she</b>lls
on the <b class='highlight'>sea</b> shore.
```

I'm not *convinced* its *useful* to *highlight* `she`
in the string `shell` ... you? *Please* [***discuss***](https://github.com/dwyl/search-result-keyword-highlighter/issues)

---
_Source: https://npm.io/package/keyword-highlighter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
