krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.89k stars 759 forks source link

How to use it in node.js? #520

Closed xuchunyang closed 3 years ago

xuchunyang commented 3 years ago

I want to use this library in node.js. I have installed it via npm i fuse. However, this does not work

const { Fuse } = require("fuse/lib/fuse");

const fuse = new Fuse(["foo", "bar"], { includeScore: true });
const result = fuse.search("foo");
console.log(result);
const result = fuse.search("foo");
                    ^

TypeError: fuse.search is not a function
    at Object.<anonymous> (/Users/xcy/src/pkgs/x.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:4

I initially tried require("fuse") which does not provide the Fuse class.

krisk commented 3 years ago

The answer can be found in the documentation 😃