Skip to content

Commit 80b87a9

Browse files
committed
fix: getFn to FuseOptionKeyObject
fixes #655
1 parent 6afcfaf commit 80b87a9

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

dist/fuse.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ declare class Fuse<T> {
8989
* @returns An indexed list
9090
*/
9191
static createIndex<U>(
92-
keys: Array<Fuse.FuseOptionKey>,
92+
keys: Array<Fuse.FuseOptionKey<U>>,
9393
list: ReadonlyArray<U>,
9494
options?: Fuse.FuseIndexOptions<U>
9595
): Fuse.FuseIndex<U>
@@ -234,12 +234,13 @@ declare namespace Fuse {
234234
// name: 'title',
235235
// weight: 0.7
236236
// }
237-
export type FuseOptionKeyObject = {
237+
export type FuseOptionKeyObject<T> = {
238238
name: string | string[]
239-
weight: number
239+
weight?: number
240+
getFn?: (obj: T) => ReadonlyArray<string> | string
240241
}
241242

242-
export type FuseOptionKey = FuseOptionKeyObject | string | string[]
243+
export type FuseOptionKey<T> = FuseOptionKeyObject<T> | string | string[]
243244

244245
export interface IFuseOptions<T> {
245246
/** Indicates whether comparisons should be case sensitive. */
@@ -255,13 +256,13 @@ declare namespace Fuse {
255256
/** When `true`, the calculation for the relevance score (used for sorting) will ignore the `field-length norm`. */
256257
ignoreFieldNorm?: boolean
257258
/** 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. */
258-
fieldNormWeight: number
259+
fieldNormWeight?: number
259260
/** 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. */
260261
includeMatches?: boolean
261262
/** 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. */
262263
includeScore?: boolean
263264
/** List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of `strings` and `objects`. */
264-
keys?: Array<FuseOptionKey>
265+
keys?: Array<FuseOptionKey<T>>
265266
/** Determines approximately where in the text is the pattern expected to be found. */
266267
location?: number
267268
/** 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`). */
@@ -308,5 +309,5 @@ declare namespace Fuse {
308309
| { $and?: Expression[] }
309310
| { $or?: Expression[] }
310311

311-
export const config: Required<IFuseOptions<any>>;
312+
export const config: Required<IFuseOptions<any>>
312313
}

src/index.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ declare class Fuse<T> {
8686
* @returns An indexed list
8787
*/
8888
static createIndex<U>(
89-
keys: Array<Fuse.FuseOptionKey>,
89+
keys: Array<Fuse.FuseOptionKey<U>>,
9090
list: ReadonlyArray<U>,
9191
options?: Fuse.FuseIndexOptions<U>
9292
): Fuse.FuseIndex<U>
@@ -231,12 +231,13 @@ declare namespace Fuse {
231231
// name: 'title',
232232
// weight: 0.7
233233
// }
234-
export type FuseOptionKeyObject = {
234+
export type FuseOptionKeyObject<T> = {
235235
name: string | string[]
236-
weight: number
236+
weight?: number
237+
getFn?: (obj: T) => ReadonlyArray<string> | string
237238
}
238239

239-
export type FuseOptionKey = FuseOptionKeyObject | string | string[]
240+
export type FuseOptionKey<T> = FuseOptionKeyObject<T> | string | string[]
240241

241242
export interface IFuseOptions<T> {
242243
/** Indicates whether comparisons should be case sensitive. */
@@ -252,13 +253,13 @@ declare namespace Fuse {
252253
/** When `true`, the calculation for the relevance score (used for sorting) will ignore the `field-length norm`. */
253254
ignoreFieldNorm?: boolean
254255
/** 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. */
255-
fieldNormWeight: number
256+
fieldNormWeight?: number
256257
/** 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. */
257258
includeMatches?: boolean
258259
/** 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. */
259260
includeScore?: boolean
260261
/** List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of `strings` and `objects`. */
261-
keys?: Array<FuseOptionKey>
262+
keys?: Array<FuseOptionKey<T>>
262263
/** Determines approximately where in the text is the pattern expected to be found. */
263264
location?: number
264265
/** 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`). */
@@ -305,5 +306,5 @@ declare namespace Fuse {
305306
| { $and?: Expression[] }
306307
| { $or?: Expression[] }
307308

308-
export const config: Required<IFuseOptions<any>>;
309+
export const config: Required<IFuseOptions<any>>
309310
}

0 commit comments

Comments
 (0)