{"id":13518511,"url":"https://github.com/Haroenv/holmes","last_synced_at":"2025-03-31T10:31:56.708Z","repository":{"id":8975981,"uuid":"59898828","full_name":"Haroenv/holmes","owner":"Haroenv","description":"Fast and easy searching inside a page","archived":false,"fork":false,"pushed_at":"2022-03-24T09:11:34.000Z","size":2258,"stargazers_count":1703,"open_issues_count":4,"forks_count":71,"subscribers_count":24,"default_branch":"gh-pages","last_synced_at":"2025-03-26T04:06:06.619Z","etag":null,"topics":["dom","filter","holmes","innertext","minimal","search"],"latest_commit_sha":null,"homepage":"https://haroen.me/holmes/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Haroenv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-28T14:38:05.000Z","updated_at":"2024-12-16T10:11:42.000Z","dependencies_parsed_at":"2022-08-25T02:21:11.380Z","dependency_job_id":null,"html_url":"https://github.com/Haroenv/holmes","commit_stats":null,"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haroenv%2Fholmes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haroenv%2Fholmes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haroenv%2Fholmes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haroenv%2Fholmes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Haroenv","download_url":"https://codeload.github.com/Haroenv/holmes/tar.gz/refs/heads/gh-pages","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246399798,"owners_count":20770908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","filter","holmes","innertext","minimal","search"],"created_at":"2024-08-01T05:01:45.670Z","updated_at":"2025-03-31T10:31:56.678Z","avatar_url":"https://github.com/Haroenv.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized","JavaScript"],"sub_categories":["Uncategorized"],"readme":"# [\u003cimg alt=\"Holmes.js\" src=\"https://haroen.me/holmes/images/logo.png\" height=\"50px\"\u003e\u003c/img\u003e](https://www.npmjs.com/package/holmes.js)\n\n\u003e Fast and easy searching inside a page.\n\n[![Build Status](https://travis-ci.org/Haroenv/holmes.svg?branch=gh-pages)](https://travis-ci.org/Haroenv/holmes)\n[![Coverage Status](https://coveralls.io/repos/github/Haroenv/holmes/badge.svg)](https://coveralls.io/github/Haroenv/holmes)\n[![npm version](https://badge.fury.io/js/holmes.js.svg)](https://yarnpkg.com/en/package/holmes.js)\n[![Bower version](https://badge.fury.io/bo/holmes.js.svg)](https://badge.fury.io/bo/holmes.js)\n[![CDNJS version](https://img.shields.io/cdnjs/v/holmes.js.svg?colorB=green)](https://cdnjs.com/libraries/holmes.js)\n[![Join the chat at https://gitter.im/Haroenv/holmes](https://badges.gitter.im/Haroenv/holmes.svg)](https://gitter.im/Haroenv/holmes?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![gzipped size](http://img.badgesize.io/https://unpkg.com/holmes.js/js/holmes.js?compression=gzip)](https://unpkg.com/holmes.js)\n\nHolmes filters a list of elements based on the value of a `input` in just ~2KB.\n\n## Installation\n\nYou can install Holmes with either `npm` or `bower` under the package name `holmes.js`. For `npm` that looks like this:\n\n```sh\n$ yarn add holmes.js # or via npm\n```\n\nAfter which you can add it in your page with i.e. webpack, rollup, browserify or loading the module in a different script tag.\n\nYou have to make sure that you have a `css` rule for the class `.hidden` that hides elements however you want. One option is to have this:\n\n```css\n.hidden {\n  display: none;\n}\n```\n\nbut this could be any `css` you want.\n\n## Usage\n\n[demo](https://haroen.me/holmes/)\n\n### When should I use it?\n\nYou should use Holmes when \n\n- you have a limited amount of items\n- you don't need typo-tolerance\n- you only want to add a really small library\n- all items are already visible on the page\n\nIn cases where you have a more complicated expectation, I'd suggest using a service like [Algolia](https://github.com/algolia/instantsearch.js).\n\n\u003e Fair disclosure: I currently work at Algolia, does it seem interesting? [Join us!](https://algolia.com/careers)\n\n### Simple example\n\n```js\nholmes({\n  input: '.search input', // default: input[type=search]\n  find: '.results div' // querySelectorAll that matches each of the results individually\n})\n```\n\n## Options\n\n[full documentation](https://haroen.me/holmes/doc)\n\n### `input`\n**default**: `input[type=search]`\n\nquerySelector for the input\n\n**examples**: `input`, `.search input`\n\n### `find` **required**\n\nquerySelectorAll for elements to search in\n\n**examples**: `blockquote p`, `.result`, `.results div`\n\n### `class`\n\n#### `class.hidden`\n**default**: `hidden`\n\nClass to add when the a `.find` doesn't contain the search query.\n\n**examples**: `hidden`, `dn`, `none`\n\n#### `class.visible`\n**default**: `false`\n\nClass to add to visible items if they contain the search query.\n\n**examples**: `visible`, `vis`, `nohidden`\n\n### `placeholder`\n**default**: `false`\n\nhtml to show when no results.\n\n**examples**: `\u003cp\u003e No results \u003c/p\u003e`, `Didn't find anything.`\n\n### `dynamic`\n**default**: `false`\n\nEnable this option if you want Holmes to query the value of the `.find` at every input.\n\n**examples**: `true`, `false`\n\n### `instant` :warning: DEPRECATED\n**default**: `false`\n\nThis option is deprecated. To use Holmes in an async environment, initialise it with:\n\n```js\nholmes(options).start();\n// or\nconst h = new holmes(options);\nh.start();\n```\n\nThis way it'll start immediately, just like it used to do with `instant: true`. Sorry for the inconvenience.\n\nBy default Holmes will wait on a `DOMContentLoaded` event to start searching. If you're loading the elements by `AJAX` for example this event comes too early. In that case you can enable `instant`, and start Holmes when your content is ready.\n\n**examples**: `true`, `false`\n\n### `minCharacters`\n**default**: `0`\n\nA minimum amount of characters need to be typed before Holmes starts filtering.\n\n**examples**: `2`, `5`\n\n### `mark`\n**default**: `false`\n\nTo start showing the result in a `\u003cmark\u003e` tag inside the `.find`, you should enable this. To change the colour this `match` is shown in, you should style the [`mark`](https://developer.mozilla.org/en/docs/Web/HTML/Element/mark) background-color.\n\n\u003e:exclamation: this will break event listeners on nested content\n\n\u003e:exclamation: this won't work if the character after the match is a literal `\u003e`.\n\n\u003e:speaking_head: If you really have to use this character, you can replace all occurences of `\u003e` by `\u0026gt;`\n\n\n**examples**: `true`, `false`\n\n### `hiddenAttr`\n**default**: `true`\n\nAdds `hidden=\"true\"` to hidden elements. [Interesting link](https://www.paciellogroup.com/blog/2012/05/html5-accessibility-chops-hidden-and-aria-hidden/) explaining its use.\n\n### `shouldShow`\n\ndefault match judgment is a partial match of the input value.\n\n```js\nfunction(htmlText, search) {\n  return htmlText.indexOf(search) !== -1;\n}\n```\n\nA custom matching function to be called with as first argument the text of an element,\nand as second argument the current input text. This should return true if you want the\nelement to show, and false if it needs to be hidden.\n\n```js\nvar customMatching = function(htmlText, search) {\n  return search.split(/\\s+/).every(function(v, i) {\n    if (htmlText.indexOf(v) === -1) {\n      return false;\n    }\n    return true;\n  });\n}\nholmes({\n  shouldShow: customMatching\n})\n```\n\n### `onHidden`\n\nCallback for when an item is hidden.\n\n```js\nfunction(el) {\n  console.log('hide',el);\n}\n```\n\n### `onVisible`\n\nCallback for when an item is visible again.\n\n```js\nfunction(el) {\n  console.log('show',el);\n}\n```\n\n### `onEmpty`\n\nCallback for when no items were found.\n\n```js\nfunction(placeholder) {\n  console.log('nothing found',placeholder);\n}\n```\n\n### `onFound`\n\nCallback for when items are found after being empty.\n\n```js\nfunction(placeholder) {\n  console.log('something found',placeholder);\n}\n```\n\n### `onInput`\n\nCallback for every input.\n\n```js\nfunction(input) {\n  console.log('current input',input);\n}\n```\n\n## Methods and members\n\nFor all of the methods you should initialise a new instance of Holmes like this:\n\n```js\nvar h = new holmes(options);\n```\n\nThen you can use the following methods:\n\n### `.clear()`\n\nYou can clear a holmes input programmatically, by using:\n\n```js\nh.clear();\n```\n\n### `.count()`\n\nYou can receive informations on what elements are visible, hidden and in total at any point:\n\n```js\nh.count(); // {all: 41, hidden: 34, visible: 7}\n```\n\n### `.start()`\n\nStart an even listener for the specified options. Holmes **always** has `.start()` running on initialisation.\n\n```js\nh.start();\n```\n\n### `.stop()`\n\nStops the current running event listener. Resolves a Promise when this has been completed.\n\n```js\nh.stop();\nh.start(); // could accidentally start too soon\n\nh.stop().then(h.start); // might take a small time\n```\n\n### `.hidden`\n\nThere's also a member `.hidden` that gives the count without a function call:\n\n```js\nconsole.log(h.hidden); // 34\n```\n\n### `.elements`\n\nA `NodeList` of all of the elements that holmes considers. There's also `.elementsLength` for the amount of elements and `.elementsArray` with an array of the elements.\n\n### `.input`\n\nThe input that holmes looks in. There's also the last search string as `.searchString`\n\n### `.placeholder`\n\nThe current placeholder (DOM Node).\n\n### `.running`\n\nWhether or not this instance is running.\n\n### `.options`\n\nShows the options chosen chosen for this instance of holmes. You can also set options like this after initialisation.\n\n```js\nconsole.log(h.options); // specified options\n```\n\n\u003e note: setting options after it's running might require `h.stop().then(h.start)`\n\n### Showcase\n\nWhat|who|image\n---|---|---\n[bullg.it](https://bullg.it)|[@haroenv](https://github.com/haroenv)|\u003cimg alt=\"screenshot of bullg.it\" src=\"https://haroen.me/holmes/images/screen-bullgit.gif\" width=\"100%\" /\u003e\n[family.scss](https://lukyvj.github.io/family.scss)|[@lukyvj](https://github.com/lukyvj)|\u003cimg alt=\"screenshot of family.scss\" src=\"https://haroen.me/holmes/images/screen-family.gif\" width=\"100%\" /\u003e\n[wikeo.be](https://wikeo.be)|[@bistory](https://github.com/bistory)|\u003cimg src=\"https://haroen.me/holmes/images/screen-wikeo.gif\" alt=\"searching on wikeo.be for pages\" width=\"100%\"\u003e\n[lunchbreakapp.be](https://www.lunchbreakapp.be)|[@AndreasBackx](https://github.com/AndreasBackx)|\u003cimg src=\"https://thumbs.gfycat.com/FancyDependentGiraffe-size_restricted.gif\" alt=\"searching on lunchbreak for items\" width=\"100%\"\u003e\n\nI'd love to find out how people use my project, [let me know](https://github.com/Haroenv/holmes/issues/new?title=add+my+project+to+usages\u0026body=who%7Cwhat%0D%0A---%7C---%0D%0A%40myusername%7C%5Bmy+project%5D%28https%3A%2F%2Flink-to-project.com%29%0D%0A%0D%0ASome+explanation+what+it+is) if you want to be featured!\n\n### Questions?\n\nCompatible up to IE11. For support of older browsers you'll need to polyfill `classList`, `addEventListener` and the `input` event with for example [remy/polyfills](https://github.com/remy/polyfills). I haven't tried this myself yet, so let me know what you used if you support older browsers!\n\nFor IE11 you need to polyfill `Object.assign` and `String.includes`, you can do that as described in [#90](https://github.com/Haroenv/holmes/issues/90)\n\nLet me know on twitter: [@haroenv](https://twitter.com/haroenv), or in an issue.\n\n## Contributing\n\nContributions are always welcome! Here are some loose guidelines:\n\n* use `feature branches`\n* don't make it slower\n* explain why you want a feature\n* `npm run doc` to recreate the documentation\n\nBuilding to a UMD is done via rollup (`npm run build`).\n\nBut I don't bite, if you have any questions or insecurities, hit me up for example on [gitter](https://gitter.im/Haroenv/holmes?utm_source=readme\u0026utm_medium=link\u0026utm_content=link).\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHaroenv%2Fholmes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHaroenv%2Fholmes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHaroenv%2Fholmes/lists"}