···11+// Type definitions for Fuse.js v6.6.2
22+// TypeScript v4.5.4
33+declare module 'fuse.js' {
44+ export default class Fuse<T> {
55+ constructor(list: ReadonlyArray<T>, options?: Fuse.IFuseOptions<T>, index?: Fuse.FuseIndex<T>);
66+ /**
77+ * Search function for the Fuse instance.
88+ *
99+ * ```typescript
1010+ * const list: MyType[] = [myType1, myType2, etc...]
1111+1212+ * const options: Fuse.IFuseOptions<MyType> = {
1313+ * keys: ['key1', 'key2']
1414+ * }
1515+ *
1616+ * const myFuse = new Fuse(list, options)
1717+ * let result = myFuse.search('pattern')
1818+ * ```
1919+ *
2020+ * @param pattern The pattern to search
2121+ * @param options `Fuse.FuseSearchOptions`
2222+ * @returns An array of search results
2323+ */
2424+ search<R = T>(pattern: string | Fuse.Expression, options?: Fuse.FuseSearchOptions): Fuse.FuseResult<R>[];
2525+2626+ setCollection(docs: ReadonlyArray<T>, index?: Fuse.FuseIndex<T>): void;
2727+2828+ /**
2929+ * Adds a doc to the end the list.
3030+ */
3131+ add(doc: T): void;
3232+3333+ /**
3434+ * Removes all documents from the list which the predicate returns truthy for,
3535+ * and returns an array of the removed docs.
3636+ * The predicate is invoked with two arguments: (doc, index).
3737+ */
3838+ remove(predicate: (doc: T, idx: number) => boolean): T[];
3939+4040+ /**
4141+ * Removes the doc at the specified index.
4242+ */
4343+ removeAt(idx: number): void;
4444+4545+ /**
4646+ * Returns the generated Fuse index
4747+ */
4848+ getIndex(): Fuse.FuseIndex<T>;
4949+5050+ /**
5151+ * Return the current version.
5252+ */
5353+ static version: string;
5454+5555+ /**
5656+ * Use this method to pre-generate the index from the list, and pass it
5757+ * directly into the Fuse instance.
5858+ *
5959+ * _Note that Fuse will automatically index the table if one isn't provided
6060+ * during instantiation._
6161+ *
6262+ * ```typescript
6363+ * const list: MyType[] = [myType1, myType2, etc...]
6464+ *
6565+ * const index = Fuse.createIndex<MyType>(
6666+ * keys: ['key1', 'key2']
6767+ * list: list
6868+ * )
6969+ *
7070+ * const options: Fuse.IFuseOptions<MyType> = {
7171+ * keys: ['key1', 'key2']
7272+ * }
7373+ *
7474+ * const myFuse = new Fuse(list, options, index)
7575+ * ```
7676+ * @param keys The keys to index
7777+ * @param list The list from which to create an index
7878+ * @param options?
7979+ * @returns An indexed list
8080+ */
8181+ static createIndex<U>(
8282+ keys: Array<Fuse.FuseOptionKey<U>>,
8383+ list: ReadonlyArray<U>,
8484+ options?: Fuse.FuseIndexOptions<U>,
8585+ ): Fuse.FuseIndex<U>;
8686+8787+ static parseIndex<U>(index: any, options?: Fuse.FuseIndexOptions<U>): Fuse.FuseIndex<U>;
8888+ }
8989+9090+ export class FuseIndex<T> {
9191+ constructor(options?: FuseIndexOptions<T>);
9292+ setSources(docs: ReadonlyArray<T>): void;
9393+ setKeys(keys: ReadonlyArray<string>): void;
9494+ setIndexRecords(records: FuseIndexRecords): void;
9595+ create(): void;
9696+ add(doc: T): void;
9797+ toJSON(): {
9898+ keys: ReadonlyArray<string>;
9999+ records: FuseIndexRecords;
100100+ };
101101+ }
102102+103103+ type FuseGetFunction<T> = (obj: T, path: string | string[]) => ReadonlyArray<string> | string;
104104+105105+ export type FuseIndexOptions<T> = {
106106+ getFn: FuseGetFunction<T>;
107107+ };
108108+109109+ // {
110110+ // title: { '$': "Old Man's War" },
111111+ // 'author.firstName': { '$': 'Codenar' }
112112+ // }
113113+ //
114114+ // OR
115115+ //
116116+ // {
117117+ // tags: [
118118+ // { $: 'nonfiction', idx: 0 },
119119+ // { $: 'web development', idx: 1 },
120120+ // ]
121121+ // }
122122+ export type FuseSortFunctionItem = {
123123+ [key: string]: { $: string } | { $: string; idx: number }[];
124124+ };
125125+126126+ // {
127127+ // score: 0.001,
128128+ // key: 'author.firstName',
129129+ // value: 'Codenar',
130130+ // indices: [ [ 0, 3 ] ]
131131+ // }
132132+ export type FuseSortFunctionMatch = {
133133+ score: number;
134134+ key: string;
135135+ value: string;
136136+ indices: ReadonlyArray<number>[];
137137+ };
138138+139139+ // {
140140+ // score: 0,
141141+ // key: 'tags',
142142+ // value: 'nonfiction',
143143+ // idx: 1,
144144+ // indices: [ [ 0, 9 ] ]
145145+ // }
146146+ export type FuseSortFunctionMatchList = FuseSortFunctionMatch & {
147147+ idx: number;
148148+ };
149149+150150+ export type FuseSortFunctionArg = {
151151+ idx: number;
152152+ item: FuseSortFunctionItem;
153153+ score: number;
154154+ matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[];
155155+ };
156156+157157+ export type FuseSortFunction = (a: FuseSortFunctionArg, b: FuseSortFunctionArg) => number;
158158+159159+ // title: {
160160+ // '$': "Old Man's War",
161161+ // 'n': 0.5773502691896258
162162+ // }
163163+ type RecordEntryObject = {
164164+ v: string; // The text value
165165+ n: number; // The field-length norm
166166+ };
167167+168168+ // 'author.tags.name': [{
169169+ // 'v': 'pizza lover',
170170+ // 'i': 2,
171171+ // 'n: 0.7071067811865475
172172+ // }
173173+ type RecordEntryArrayItem = ReadonlyArray<RecordEntryObject & { i: number }>;
174174+175175+ // TODO: this makes it difficult to infer the type. Need to think more about this
176176+ type RecordEntry = {
177177+ [key: string]: RecordEntryObject | RecordEntryArrayItem;
178178+ };
179179+180180+ // {
181181+ // i: 0,
182182+ // '$': {
183183+ // '0': { v: "Old Man's War", n: 0.5773502691896258 },
184184+ // '1': { v: 'Codenar', n: 1 },
185185+ // '2': [
186186+ // { v: 'pizza lover', i: 2, n: 0.7071067811865475 },
187187+ // { v: 'helo wold', i: 1, n: 0.7071067811865475 },
188188+ // { v: 'hello world', i: 0, n: 0.7071067811865475 }
189189+ // ]
190190+ // }
191191+ // }
192192+ type FuseIndexObjectRecord = {
193193+ i: number; // The index of the record in the source list
194194+ $: RecordEntry;
195195+ };
196196+197197+ // {
198198+ // keys: null,
199199+ // list: [
200200+ // { v: 'one', i: 0, n: 1 },
201201+ // { v: 'two', i: 1, n: 1 },
202202+ // { v: 'three', i: 2, n: 1 }
203203+ // ]
204204+ // }
205205+ type FuseIndexStringRecord = {
206206+ i: number; // The index of the record in the source list
207207+ v: string; // The text value
208208+ n: number; // The field-length norm
209209+ };
210210+211211+ type FuseIndexRecords = ReadonlyArray<FuseIndexObjectRecord> | ReadonlyArray<FuseIndexStringRecord>;
212212+213213+ // {
214214+ // name: 'title',
215215+ // weight: 0.7
216216+ // }
217217+ export type FuseOptionKeyObject<T> = {
218218+ name: string | string[];
219219+ weight?: number;
220220+ getFn?: (obj: T) => ReadonlyArray<string> | string;
221221+ };
222222+223223+ export type FuseOptionKey<T> = FuseOptionKeyObject<T> | string | string[];
224224+225225+ export interface IFuseOptions<T> {
226226+ /** Indicates whether comparisons should be case sensitive. */
227227+ isCaseSensitive?: boolean;
228228+ /** Determines how close the match must be to the fuzzy location (specified by `location`). An exact letter match which is `distance` characters away from the fuzzy location would score as a complete mismatch. A `distance` of `0` requires the match be at the exact `location` specified. A distance of `1000` would require a perfect match to be within `800` characters of the `location` to be found using a `threshold` of `0.8`. */
229229+ distance?: number;
230230+ /** When true, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string. */
231231+ findAllMatches?: boolean;
232232+ /** The function to use to retrieve an object's value at the provided path. The default will also search nested paths. */
233233+ getFn?: FuseGetFunction<T>;
234234+ /** When `true`, search will ignore `location` and `distance`, so it won't matter where in the string the pattern appears. */
235235+ ignoreLocation?: boolean;
236236+ /** When `true`, the calculation for the relevance score (used for sorting) will ignore the `field-length norm`. */
237237+ ignoreFieldNorm?: boolean;
238238+ /** Determines how much the `field-length norm` affects scoring. A value of `0` is equivalent to ignoring the field-length norm. A value of `0.5` will greatly reduce the effect of field-length norm, while a value of `2.0` will greatly increase it. */
239239+ fieldNormWeight?: number;
240240+ /** Whether the matches should be included in the result set. When `true`, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes. */
241241+ includeMatches?: boolean;
242242+ /** Whether the score should be included in the result set. A score of `0`indicates a perfect match, while a score of `1` indicates a complete mismatch. */
243243+ includeScore?: boolean;
244244+ /** List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of `strings` and `objects`. */
245245+ keys?: Array<FuseOptionKey<T>>;
246246+ /** Determines approximately where in the text is the pattern expected to be found. */
247247+ location?: number;
248248+ /** Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to `2`). */
249249+ minMatchCharLength?: number;
250250+ /** Whether to sort the result list, by score. */
251251+ shouldSort?: boolean;
252252+ /** The function to use to sort all the results. The default will sort by ascending relevance score, ascending index. */
253253+ sortFn?: FuseSortFunction;
254254+ /** At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. */
255255+ threshold?: number;
256256+ /** When `true`, it enables the use of unix-like search commands. See [example](/examples.html#extended-search). */
257257+ useExtendedSearch?: boolean;
258258+ }
259259+260260+ // Denotes the start/end indices of a match
261261+ // start end
262262+ // ↓ ↓
263263+ type RangeTuple = [number, number];
264264+265265+ export type FuseResultMatch = {
266266+ indices: ReadonlyArray<RangeTuple>;
267267+ key?: string;
268268+ refIndex?: number;
269269+ value?: string;
270270+ };
271271+272272+ export type FuseSearchOptions = {
273273+ limit: number;
274274+ };
275275+276276+ export type FuseResult<T> = {
277277+ item: T;
278278+ refIndex: number;
279279+ score?: number;
280280+ matches?: ReadonlyArray<FuseResultMatch>;
281281+ };
282282+283283+ export type Expression =
284284+ | { [key: string]: string }
285285+ | {
286286+ $path: ReadonlyArray<string>;
287287+ $val: string;
288288+ }
289289+ | { $and?: Expression[] }
290290+ | { $or?: Expression[] };
291291+292292+ export const config: Required<IFuseOptions<any>>;
293293+}
···11+{
22+ "compilerOptions": {
33+ /* Visit https://aka.ms/tsconfig to read more about this file */
44+55+ /* Projects */
66+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
77+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
88+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
99+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
1010+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1111+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212+1313+ /* Language and Environment */
1414+ "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1515+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616+ // "jsx": "preserve", /* Specify what JSX code is generated. */
1717+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1818+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1919+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
2020+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
2121+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
2222+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
2323+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2424+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2525+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2626+2727+ /* Modules */
2828+ "module": "esnext" /* Specify what module code is generated. */,
2929+ // "rootDir": "./", /* Specify the root folder within your source files. */
3030+ "moduleResolution": "nodenext" /* Specify how TypeScript looks up a file from a given module specifier. */,
3131+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3434+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
3535+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
3636+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
3737+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
3838+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
3939+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
4242+ // "resolveJsonModule": true, /* Enable importing .json files. */
4343+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4444+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
4545+4646+ /* JavaScript Support */
4747+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
4848+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
4949+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
5050+5151+ /* Emit */
5252+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
5353+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
5454+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
5555+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5656+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
5757+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
5858+ // "outDir": "./", /* Specify an output folder for all emitted files. */
5959+ // "removeComments": true, /* Disable emitting comments. */
6060+ // "noEmit": true, /* Disable emitting files from a compilation. */
6161+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
6262+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
6363+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
6464+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
6565+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
6666+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
6767+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
6868+ // "newLine": "crlf", /* Set the newline character for emitting files. */
6969+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
7070+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
7171+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7272+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7373+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
7474+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7575+7676+ /* Interop Constraints */
7777+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
7878+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
7979+ "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
8080+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
8181+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
8282+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
8383+8484+ /* Type Checking */
8585+ "strict": true /* Enable all strict type-checking options. */,
8686+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
8787+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
8888+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
8989+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
9090+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
9191+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
9292+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
9393+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
9494+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
9595+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
9696+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
9797+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
9898+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
9999+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100100+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101101+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102102+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103103+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104104+105105+ /* Completeness */
106106+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107107+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108108+ }
109109+}