metonym / format-fuse.js Goto Github PK
View Code? Open in Web Editor NEWUtility to format matching fuse.js results for easier text highlighting
License: MIT License
Utility to format matching fuse.js results for easier text highlighting
License: MIT License
Slightly modifying the example from the readme like so:
const results = format([
{
item: {
titles: ["Monster 1959", "Second Title"],
author: { firstName: "David", lastName: "Maine" },
},
matches: [
{
indices: [[1, 2]],
value: "Monster 1959",
key: "title",
arrayIndex: 0,
},
],
},
]);
I think the code doesn't follow the refIndex
property from fuse on title
.
Performing a Fuse extended search for 'sao paulo' on an item that contains the text 'SAO PAULO' yields matches for [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ], and format-fuse returns them as SAO, AO an PAULO. Rendering those as shown in the readme causes the UI to show "SAOAO PAULO". Ideally, the resulting value would eliminate overlapping matches.
Example:
const Fuse = require('fuse.js');
const formatFuseJs = require('format-fuse.js').default;
const util = require('util');
const r = new Fuse([{ name: 'SAO PAULO' }], {
keys: ['name'],
includeMatches: true,
includeScore: true,
useExtendedSearch: true,
})
.search('sao paulo')
.map(s => ({ ...s, formatted: formatFuseJs([s])[0] }));
console.log(util.inspect(r, { showHidden: false, depth: null, colors: true }));
Actual:
[
{
item: { name: 'SAO PAULO' },
refIndex: 0,
matches: [
{
indices: [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ],
value: 'SAO PAULO',
key: 'name'
}
],
score: 0.06403390388180329,
formatted: {
name: [
{ text: 'SAO', matches: true },
{ text: 'AO', matches: true },
{ text: ' ', matches: false },
{ text: 'PAULO', matches: true }
]
}
}
]
Expected:
[
{
item: { name: 'SAO PAULO' },
refIndex: 0,
matches: [
{
indices: [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ],
value: 'SAO PAULO',
key: 'name'
}
],
score: 0.06403390388180329,
formatted: {
name: [
{ text: 'SAO', matches: true },
{ text: ' ', matches: false },
{ text: 'PAULO', matches: true }
]
}
}
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.