npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-highlight

v3.5.0

Published

Text highlighting plugin for jQuery

Downloads

25,199

Readme

jQuery.Highlight.js

Text highlighting plugin for jQuery.

Original code and documentation.

Install

How to use this plugin.

Note: This plugin requires jQuery to be included, which is left up to you.

First you need to install the module, which can be installed in one of the following ways:

npm install jquery-highlight
bower install jquery-highlight
component install knownasilya/jquery-highlight
# or just download it from Github

API

$.highlight

Function signature: highlight(word, options, callback)

The parameters are:

word string|array (required)

string such as "lorem" or "lorem ipsum" or an array of string such as ["lorem", "ipsum"]

options object (optional)

object with the following available options

  • className -- The CSS class of a highlighted element, defaults to 'highlight'.
  • element -- The element that wraps the highlighted word, defaults to 'span'.
  • caseSensitive -- If the search should be case sensitive, defaults to false.
  • wordsOnly -- If we want to highlight partial sections of a word, e.g. 'ca' from 'cat', defaults to false.
  • wordsBoundary -- If wordsOnly is set to true, this is used to determine these boundaries, defaults to \\b (word boundary).
  • wordsBoundaryStart -- If wordsOnly is set to true, this is used to determine prefix word boundaries, defaults to the value of wordsBoundary.
  • wordsBoundaryEnd -- If wordsOnly is set to true, this is used to determine suffix word boundaries, defaults to the value of wordsBoundary.

callback function (optional)

function that will be called for each DOM node/element highlighted

$.unhighlight

Function signature: unhighlight(options):

The parameters are:

options object (optional)

object with the following available options

  • className -- The highlights to remove based on CSS class, defaults to 'highlight'.
  • element -- The highlights to remove based on HTML element, defaults to 'span'.

Examples

Below are several ways that you can utilize this plugin.

// wrap every occurrence of text 'lorem' in content
// with <span class='highlight'> (default options)
$('#content').highlight('lorem');

// search for and highlight more terms at once
// so you can save some time on traversing DOM
$('#content').highlight(['lorem', 'ipsum']);
$('#content').highlight('lorem ipsum');

// wrap every occurrence of text 'lorem' in content
// with <span class='highlight'> (default options)
// log every word highlighted to the console using the invoked callback
$('#content').highlight('lorem', {}, function(el) {
 console.log('highligting DOM element', el)
});

// search only for entire word 'lorem'
$('#content').highlight('lorem', {
  wordsOnly: true
});

// search only for the entire word 'C#'
// and make sure that the word boundary can also
// be a 'non-word' character, as well as a regex latin1 only boundary:
$('#content').highlight('C#', {
  wordsOnly: true,
  wordsBoundary: '[\\b\\W]'
});

// search only for the entire word 'C++'
// and make sure that the word boundary can also
// be a 'non-word' character, as well as a regex latin1 only boundary:
$('#content').highlight('C++', {
  wordsOnly: true,
  wordsBoundaryEnd: '\\W*\\b'
});


// don't ignore case during search of term 'lorem'
$('#content').highlight('lorem', {
  caseSensitive: true
});

// wrap every occurrance of term 'ipsum' in content
// with <em class='important'>
$('#content').highlight('ipsum', {
  element: 'em',
  className: 'important'
});

// remove default highlight
$('#content').unhighlight();

// remove custom highlight
$('#content').unhighlight({
  element: 'em',
  className: 'important'
});

Attribution

Plugin was originally created by Bartek Szopka (@bartaz).

License

MIT