Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify input to Fuse.parseIndex #782

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/api/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Fuse will automatically index the table if one isn't provided during instantiati

### `Fuse.parseIndex`

Parses a serialized Fuse index.
Parses a serialized Fuse index from a json object representation.

**Example**

Expand All @@ -69,6 +69,9 @@ fs.writeFile('fuse-index.json', JSON.stringify(myIndex.toJSON()))
// (2) When app starts
// Load and deserialize index
const fuseIndex = await require('fuse-index.json')
// Alternatively, if fetching the index, convert to json before parsing.
const fuseIndex = await fetch('./fuse-index.json').then(r => r.json())

const myIndex = Fuse.parseIndex(fuseIndex)
// initialize Fuse with the index
const fuse = new Fuse(books, options, myIndex)
Expand Down
5 changes: 4 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ declare class Fuse<T> {
): FuseIndex<U>

public static parseIndex<U>(
index: any,
index: {
keys: ReadonlyArray<string>
records: FuseIndexRecords
},
options?: FuseIndexOptions<U>
): FuseIndex<U>

Expand Down