{"id":13494910,"url":"https://github.com/bvaughn/react-highlight-words","last_synced_at":"2025-05-14T08:05:07.598Z","repository":{"id":41284434,"uuid":"48126484","full_name":"bvaughn/react-highlight-words","owner":"bvaughn","description":"React component to highlight words within a larger body of text","archived":false,"fork":false,"pushed_at":"2025-01-12T21:39:54.000Z","size":3581,"stargazers_count":2243,"open_issues_count":8,"forks_count":176,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-14T08:03:29.546Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bvaughn.github.io/react-highlight-words/","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/bvaughn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null},"funding":{"github":"bvaughn","patreon":null,"open_collective":"brianvaughn","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"bvaughn","custom":null}},"created_at":"2015-12-16T18:02:09.000Z","updated_at":"2025-05-13T14:04:23.000Z","dependencies_parsed_at":"2024-01-13T16:25:42.368Z","dependency_job_id":"a6d870e1-76bf-4d8b-be26-f865718b7863","html_url":"https://github.com/bvaughn/react-highlight-words","commit_stats":{"total_commits":135,"total_committers":30,"mean_commits":4.5,"dds":0.6962962962962963,"last_synced_commit":"0f030ab7fd5a19d9882ce8410656ba43067d2898"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Freact-highlight-words","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Freact-highlight-words/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Freact-highlight-words/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Freact-highlight-words/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bvaughn","download_url":"https://codeload.github.com/bvaughn/react-highlight-words/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101588,"owners_count":22014907,"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":[],"created_at":"2024-07-31T19:01:29.355Z","updated_at":"2025-05-14T08:05:07.573Z","avatar_url":"https://github.com/bvaughn.png","language":"JavaScript","funding_links":["https://github.com/sponsors/bvaughn","https://opencollective.com/brianvaughn","https://buymeacoffee.com/bvaughn"],"categories":["JavaScript","React"],"sub_categories":["React Components"],"readme":"\u003cimg src=\"https://cloud.githubusercontent.com/assets/29597/11913937/0d2dcd78-a629-11e5-83e7-6a17b6d765a5.png\" width=\"260\" height=\"260\"\u003e\n\nReact component to highlight words within a larger body of text.\n\nCheck out a demo [here](https://bvaughn.github.io/react-highlight-words).\n\n## Usage\n\nTo use it, just provide it with an array of search terms and a body of text to highlight.\n\n[Try this example in Code Sandbox.](https://codesandbox.io/s/5v8yqoxv7k)\n\n```jsx\nimport React from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport Highlighter from \"react-highlight-words\";\n\nconst root = createRoot(document.getElementById(\"root\"));\nroot.render(\n  \u003cHighlighter\n    highlightClassName=\"YourHighlightClass\"\n    searchWords={[\"and\", \"or\", \"the\"]}\n    autoEscape={true}\n    textToHighlight=\"The dog is chasing the cat. Or perhaps they're just playing?\"\n  /\u003e\n);\n```\n\nAnd the `Highlighter` will mark all occurrences of search terms within the text:\n\n\u003cimg width=\"368\" alt=\"screen shot 2015-12-19 at 8 23 43 am\" src=\"https://cloud.githubusercontent.com/assets/29597/11914033/e3c319f6-a629-11e5-896d-1a5ce22c9ea2.png\"\u003e\n\n## Props\n\n| Property               | Type                        | Required? | Description                                                                                                                                                                                                                                                                                                                                                        |\n|------------------------|-----------------------------|:---------:|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `activeClassName`      | String                      |           | The class name to be applied to an active match. Use along with `activeIndex`                                                                                                                                                                                                                                                                                      |\n| `activeIndex`          | Number                      |           | Specify the match index that should be actively highlighted. Use along with `activeClassName`                                                                                                                                                                                                                                                                      |\n| `activeStyle`          | Object                      |           | The inline style to be applied to an active match. Use along with `activeIndex`                                                                                                                                                                                                                                                                                    |\n| `autoEscape`           | Boolean                     |           | Escape characters in `searchWords` which are meaningful in regular expressions                                                                                                                                                                                                                                                                                     |\n| `className`            | String                      |           | CSS class name applied to the outer/wrapper `\u003cspan\u003e`                                                                                                                                                                                                                                                                                                               |\n| `caseSensitive`        | Boolean                     |           | Search should be case sensitive; defaults to `false`                                                                                                                                                                                                                                                                                                               |\n| `findChunks`           | Function                    |           | Use a custom function to search for matching chunks. This makes it possible to use arbitrary logic when looking for matches. See the default `findChunks` function in [highlight-words-core](https://github.com/bvaughn/highlight-words-core) for signature. Have a look at the [custom findChunks example](https://codesandbox.io/s/k20x3ox31o) on how to use it. |\n| `highlightClassName`   | String or Object            |           | CSS class name applied to highlighted text or object mapping search term matches to class names.                                                                                                                                                                                                                                                                   |\n| `highlightStyle`       | Object                      |           | Inline styles applied to highlighted text                                                                                                                                                                                                                                                                                                                          |\n| `highlightTag`         | Node or String              |           | Type of tag to wrap around highlighted matches. Defaults to `mark` but can also be a React component (class or functional)                                                                                                                                                                                                                                         |\n| `sanitize`             | Function                    |           | Process each search word and text to highlight before comparing (eg remove accents); signature `(text: string): string`                                                                                                                                                                                                                                            |\n| `searchWords`          | Array\u003cString \u0026#124; RegExp\u003e |     ✓     | Array of search words. String search terms are automatically cast to RegExps unless `autoEscape` is true.                                                                                                                                                                                                                                                          |\n| `textToHighlight`      | String                      |     ✓     | Text to highlight matches in                                                                                                                                                                                                                                                                                                                                       |\n| `unhighlightClassName` | String                      |           | CSS class name applied to unhighlighted text                                                                                                                                                                                                                                                                                                                       |\n| `unhighlightStyle`     | Object                      |           | Inline styles applied to unhighlighted text                                                                                                                                                                                                                                                                                                                        |\n| `unhighlightTag`       | Node or String              |           | Type of tag applied to unhighlighted parts. Defaults to `span` but can also be a React component (class or functional)                                                                                                                                                                                                                                             |\n| *                      | any                         |           | Any other props (such as `title` or `data-*`) are applied to the outer/wrapper `\u003cspan\u003e`                                                                                                                                                                                                                                                                            |\n\n## Custom highlight tag\n\nBy default, this component uses an HTML Mark Text element (`\u003cmark\u003e`) to wrap matched text, but you can inject a custom\ntag using the `highlightTag` property. This tag should be a React component that accepts the following properties:\n\n| Property         | Type   | Description            |\n|------------------|--------|------------------------|\n| `children`       | String | Text to be highlighted |\n| `highlightIndex` | Number | Index of matched text  |\n\nFor example:\n\n```js\nconst Highlight = ({ children, highlightIndex }) =\u003e (\n  \u003cstrong className=\"highlighted-text\"\u003e{children}\u003c/strong\u003e\n);\n```\n\n## Installation\n\n```\nyarn add react-highlight-words\n```\n\n```\nnpm i react-highlight-words\n```\n\n## License\n\nMIT License - fork, modify and use however you want.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Freact-highlight-words","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbvaughn%2Freact-highlight-words","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Freact-highlight-words/lists"}