Utility to format matching fuse.js results for easier text highlighting
npm install format-fuse.js[![NPM][npm]][npm-url]
> Utility to format matching fuse.js results for easier text highlighting.
``bash`
yarn add format-fuse.js
The utility expects fuse.js search results as an array and outputs matching text based on matching indices.
`js
import format from "format-fuse.js";
const results = format([
{
item: {
title: "Monster 1959",
author: { firstName: "David", lastName: "Maine" },
},
matches: [
{
indices: [[1, 2]],
value: "Monster 1959",
key: "title",
arrayIndex: 0,
},
],
},
]);
console.log(results);
/**
* [
{
author: { firstName: 'David', lastName: 'Maine' },
title: [
{ matches: false, text: 'M' },
{ matches: true, text: 'on' },
{ matches: false, text: 'ster 1959' }
]
}
]
*/
`
Matching and unmatching text become easier to iterate through.
`jsx
import * as React from "react";
export function Highlighter(results) {
return (
return title;
})}
[npm]: https://img.shields.io/npm/v/format-fuse.js.svg?color=blue
[npm-url]: https://npmjs.com/package/format-fuse.js