‘Holmes’ lets developers include an easy way to search inside a Web page

holmesIf you include & invoke this neat open source Node.js library you can easily & efficiently search & match text inside any Web page. You don’t have to be a sleuth, like its name suggests, you can just whip out this bit of freely available JavaScript code & you can get your Sherlock cap on when it comes to finding & displaying text inside any Web page.

Holmes solves the often encountered problem of finding text very elegantly & since it’s written under an Apache 2.0 license, it can be freely used & modified to your heart’s Content.  It’s easy to install with either npm or bower. With the npm package manager you just invoke it like this:

$ npm install –save holmes.js

After installing it, you add it to your page with a bundler like browserfy or load the module in a different script tag.  Also, you need to assure that you have a css rule for the class .hidden that hides elements. You then just go ahead & include a call to the library in your code.

Here’s the example from the product page:

holmes({

input: ‘input’,

find: ‘.results blockquote’,

placeholder: ‘no results’, //optional

class: {

visible: ‘visible’, //optional

hidden: ‘hidden’ //optional

},

dynamic: false //optional

});

You can try out a demo on the product page that implements the sample code. You can also check out the project’s source code on its GitHub page here or contribute if you’re so inclined.

It’s being developed by Haroen Viaene, a young Belgian computer science student & member of the bullgit development community. As some people point out on GitHub & in other places, Holmes does not technically implement a search algorithm, being instead a ‘highlighter of DOM elements which match a simple criteria’, although for all practical purposes this translates as search.

 
Image Credit: Holmes

 

 

 

•Share This•

Save

Save

Save

Save

Save

Click here to opt-out of Google Analytics