New version needs docs + examples
Was surprised to see a new release of this. I love this package but the changes to the API in the new version are fairly confusing and the documentation is missing a lot of details (I had to roll back to 2.0.4 because the new highlight API seems more complex than the previous).
Happy to work with you on the docs if you'd like/it would help. Send me an email and we can figure it out: [email protected].
fuzzysort.highlight(result) changed to result.highlight()
the readme shows that. what's confusing?
It does, but it doesn't work as described. If I loop over the results returned by fuzzysort.go() and then call result.highlight() on a result I get "result.highlight() is undefined." There seems to be some connection/usage of fuzzysort.single() required but it's not immediately clear from the docs.
This happens locally in an app as well as in the replit env in the screenshot below.
Writing tutorials for stuff like this is my bread and butter—happy to collab and help come up with some solid examples. This is a really great library.
@rglover I took a quick look by logging result to console, and it seems that the actual "object" is instead stored with the key 0 when you have custom keys (i.e. what you are searching over are objects). result[0].highlight() seems to work as desired.
This behavior is consistent with the older versions as well (the only difference is that you are now made aware of this "quirk" due to the highlight method being directly on the object).
I got this error too. My workaround is to call result[0].highlight() before mapping it into a new object, like this:
const formatted_result = results.map((result={}) => {
let result0 = result[0].highlight();
let result1 = result[1].highlight();
return {
...(result?.obj || {}),
hilighted_result0: result0,
hilighted_result1: result1
};
});
Thanks @JJCUBER and @JomMarn, I'll take a look.
Hey @rglover, I just updated to version 3.0.1, which was released two weeks ago, and it is working fine now. There's no need to call result.highlight() before mapping to new object anymore for me.
@rglover Can this be closed?
Yes 👍