{"id":14155531,"url":"https://github.com/moroshko/autosuggest-highlight","last_synced_at":"2025-04-08T01:35:40.826Z","repository":{"id":31574482,"uuid":"35139240","full_name":"moroshko/autosuggest-highlight","owner":"moroshko","description":"Utilities for highlighting text in autosuggest and autocomplete components","archived":false,"fork":false,"pushed_at":"2023-03-15T02:45:26.000Z","size":1322,"stargazers_count":309,"open_issues_count":6,"forks_count":36,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T00:33:56.934Z","etag":null,"topics":["autocomplete","autosuggest","javascript","typeahead"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moroshko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-06T04:23:10.000Z","updated_at":"2025-03-19T16:07:04.000Z","dependencies_parsed_at":"2024-06-18T12:25:30.996Z","dependency_job_id":"2aee2c4a-3e8f-4aca-b347-a90335e3e568","html_url":"https://github.com/moroshko/autosuggest-highlight","commit_stats":{"total_commits":57,"total_committers":9,"mean_commits":6.333333333333333,"dds":0.5614035087719298,"last_synced_commit":"421036daa7c1145b6ee7ae77a53eb4735caf8c9a"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moroshko%2Fautosuggest-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moroshko%2Fautosuggest-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moroshko%2Fautosuggest-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moroshko%2Fautosuggest-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moroshko","download_url":"https://codeload.github.com/moroshko/autosuggest-highlight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247057008,"owners_count":20876495,"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":["autocomplete","autosuggest","javascript","typeahead"],"created_at":"2024-08-17T08:03:47.143Z","updated_at":"2025-04-08T01:35:40.808Z","avatar_url":"https://github.com/moroshko.png","language":"JavaScript","funding_links":[],"categories":["javascript"],"sub_categories":[],"readme":"[![Build Status](https://img.shields.io/codeship/99ce0dd0-d5d5-0132-ce75-1e0a7d4d648e/master.svg?style=flat-square)](https://codeship.com/projects/78168)\n[![Contributors](https://img.shields.io/github/contributors/moroshko/autosuggest-highlight.svg?style=flat-square)](https://github.com/moroshko/autosuggest-highlight/graphs/contributors)\n[![Coverage Status](https://img.shields.io/codecov/c/github/moroshko/autosuggest-highlight/master.svg?style=flat-square)](https://codecov.io/gh/moroshko/autosuggest-highlight)\n\n[![npm Downloads](https://img.shields.io/npm/dm/autosuggest-highlight.svg?style=flat-square)](https://npmjs.org/package/autosuggest-highlight)\n[![npm Version](https://img.shields.io/npm/v/autosuggest-highlight.svg?style=flat-square)](https://npmjs.org/package/autosuggest-highlight)\n\n# Autosuggest Highlight\n\nUtilities for highlighting text in autosuggest and autocomplete components.\n\n## Installation\n\n```shell\nyarn add autosuggest-highlight\n```\n\nor\n\n```shell\nnpm install autosuggest-highlight --save\n```\n\n## API\n\n| Function | Description |\n| :--- | :--- |\n| [`match(text, query, options)`](#match) | Calculates the characters to highlight in `text` based on `query`. |\n| [`parse(text, matches)`](#parse) | Breaks the given `text` to parts based on `matches`. |\n\n\u003ca name=\"match\"\u003e\u003c/a\u003e\n\n### match(text, query, options)\n\nCalculates the characters to highlight in `text` based on `query`.\n\nIt returns an array of pairs. Every pair `[a, b]` means that `text.slice(a, b)` should be highlighted.\n\nOptions are passed as JSON.\n\n| Option | Description |\n| :--- | :--- |\n| insideWords | `boolean` false by default. Searches inside words |\n| findAllOccurrences | `boolean` false by default. Finds all occurrences of each match |\n| requireMatchAll | `boolean` false by default. Requires each word of `query` to be found in `text` or else returns an empty set |\n\n#### Examples\n\nWe match at the beginning of a word by default:\n\n```js\nvar match = require('autosuggest-highlight/match');\n\n// text indices:     012345678\n// highlighting:          vv\nvar matches = match('some text', 'te'); // [[5, 7]]\n```\n\n```js\n// text indices:     012345678\n// highlighting:\nvar matches = match('some text', 'e'); // []\n```\n\nEnable search inside words:\n\n```js\nvar match = require('autosuggest-highlight/match');\n\n// text indices:     012345678\n// highlighting:       v\nvar matches = match('some text', 'm', { insideWords: true }); // [[2, 3]]\n```\n\nWhen `query` is a single word, only the first match is returned by default:\n\n```js\n// text indices:     012345678901234\n// highlighting:     v\nvar matches = match('some sweet text', 's'); // [[0, 1]]\n```\n\nYou'll get the second match, if `query` contains multiple words:\n\n```js\n// text indices:     012345678901234\n// highlighting:     v    v\nvar matches = match('some sweet text', 's s'); // [[0, 1], [5, 6]]\n```\n\nOr using the findAllOccurrences option:\n\n```js\n// text indices:     012345678901234\n// highlighting:     v    v\nvar matches = match('some sweet text', 's', { findAllOccurrences: true }); // [[0, 1], [5, 6]]\n```\n\nMatches are case insensitive:\n\n```js\n// text indices:     012345678\n// highlighting:          v\nvar matches = match('Some Text', 't'); // [[5, 6]]\n```\n\nand [diacritics](https://en.wikipedia.org/wiki/Diacritic) are removed:\n\n```js\n// text indices:     0123456\n// highlighting:     vvvv\nvar matches = match('Déjà vu', 'deja'); // [[0, 4]]\n```\n\nWhen `query` has multiple words, the order doesn't matter:\n\n```js\n// text indices:     012345678901234\n// highlighting:     v      v\nvar matches = match('Albert Einstein', 'a e'); // [[0, 1], [7, 8]]\n```\n\n```js\n// text indices:     012345678901234\n// highlighting:     v      v\nvar matches = match('Albert Einstein', 'e a'); // [[0, 1], [7, 8]]\n```\n\n\u003ca name=\"parse\"\u003e\u003c/a\u003e\n\n### parse(text, matches)\n\nBreaks the given `text` to parts based on `matches`.\n\nIt returns an array of `text` parts by specifying whether each part should be highlighted or not.\n\nFor example:\n\n```js\nvar parse = require('autosuggest-highlight/parse');\n\n// text indices:   0123456789012345\n// highlighting:          vv   v\nvar parts = parse('Pretty cool text', [[7, 9], [12, 13]]);\n/*\n  [\n    {\n      text: 'Pretty ',\n      highlight: false\n    },\n    {\n      text: 'co',\n      highlight: true\n    },\n    {\n      text: 'ol ',\n      highlight: false\n    },\n    {\n      text: 't',\n      highlight: true\n    },\n    {\n      text: 'ext',\n      highlight: false\n    }\n  ]\n*/\n```\n\n## Usage with old browsers\nFor using this library with old browsers such as IE11 you must change import to\n```js\nvar match = require('autosuggest-highlight/ie11/match');\nvar parse = require('autosuggest-highlight/ie11/parse');\n```\n\n## License\n\n[MIT](http://moroshko.mit-license.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoroshko%2Fautosuggest-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoroshko%2Fautosuggest-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoroshko%2Fautosuggest-highlight/lists"}