mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Merge pull request #2328 from smrq/fuse-js
Add type definitions for Fuse.js
This commit is contained in:
@@ -88,6 +88,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [FPSMeter](http://darsa.in/fpsmeter/) (by [Aaron Lampros](https://github.com/alampros))
|
||||
* [fs-extra](https://github.com/jprichardson/node-fs-extra) (by [midknight41](https://github.com/midknight41))
|
||||
* [FullCalendar](http://arshaw.com/fullcalendar/) (by [Neil Stalker](https://github.com/nestalk))
|
||||
* [Fuse.js](https://github.com/krisk/Fuse) (by [Greg Smith](https://github.com/smrq))
|
||||
* [Gamepad](http://www.w3.org/TR/gamepad/) (by [Kon](http://phyzkit.net/))
|
||||
* [GeoJSON](http://geojson.org/) (by [Jake Bruun](https://github.com/cobster))
|
||||
* [Giraffe](https://github.com/barc/backbone.giraffe) (by [Matt McCray](https://github.com/darthapo))
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/// <reference path="fuse.d.ts" />
|
||||
|
||||
function test_fuse_find_identifiers() {
|
||||
var books = [{
|
||||
id: 1,
|
||||
title: 'The Great Gatsby',
|
||||
author: 'F. Scott Fitzgerald'
|
||||
}, {
|
||||
id: 2,
|
||||
title: 'The DaVinci Code',
|
||||
author: 'Dan Brown'
|
||||
}, {
|
||||
id: 3,
|
||||
title: 'Angels & Demons',
|
||||
author: 'Dan Brown'
|
||||
}];
|
||||
var options = {
|
||||
keys: ['author', 'title'], // keys to search in
|
||||
id: 'id' // return a list of identifiers only
|
||||
};
|
||||
var f = new Fuse(books, options);
|
||||
var result = f.search('brwn'); // Fuzzy-search for pattern 'brwn'
|
||||
}
|
||||
|
||||
function test_fuse_find_records() {
|
||||
var books = [{
|
||||
id: 1,
|
||||
title: 'The Great Gatsby',
|
||||
author: 'F. Scott Fitzgerald'
|
||||
}, {
|
||||
id: 2,
|
||||
title: 'The DaVinci Code',
|
||||
author: 'Dan Brown'
|
||||
}, {
|
||||
id: 3,
|
||||
title: 'Angels & Demons',
|
||||
author: 'Dan Brown'
|
||||
}];
|
||||
var options = {
|
||||
keys: ['author', 'title']
|
||||
};
|
||||
var f = new Fuse(books, options);
|
||||
var result = f.search('brwn');
|
||||
}
|
||||
|
||||
function test_fuse_flat_array() {
|
||||
var books = ["Old Man's War", "The Lock Artist", "HTML5", "Right Ho Jeeves", "The Code of the Wooster", "Thank You Jeeves", "The DaVinci Code", "Angels & Demons", "The Silmarillion", "Syrup", "The Lost Symbol", "The Book of Lies", "Lamb", "Fool", "Incompetence", "Fat", "Colony", "Backwards, Red Dwarf", "The Grand Design", "The Book of Samson", "The Preservationist", "Fallen", "Monster 1959"];
|
||||
var f = new Fuse(books);
|
||||
var result = f.search('Falen');
|
||||
}
|
||||
|
||||
function test_fuse_deep_key_search() {
|
||||
var books = [{
|
||||
id: 1,
|
||||
title: 'The Great Gatsby',
|
||||
author: {
|
||||
firstName: 'F. Scott',
|
||||
lastName: 'Fitzgerald'
|
||||
}
|
||||
}, {
|
||||
title: 'The DaVinci Code',
|
||||
author: {
|
||||
firstName: 'Dan',
|
||||
lastName: 'Brown'
|
||||
}
|
||||
}];
|
||||
|
||||
var options = {
|
||||
keys: ['author.firstName']
|
||||
}
|
||||
var f = new Fuse(books, options);
|
||||
var result = f.search('brwn');
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
// Type definitions for Fuse.js 1.1.5
|
||||
// Project: https://github.com/krisk/Fuse
|
||||
// Definitions by: Greg Smith <https://github.com/smrq/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare class Fuse {
|
||||
constructor(list: any[], options?: fuse.IFuseOptions);
|
||||
search(pattern: string): any[];
|
||||
}
|
||||
|
||||
declare module fuse {
|
||||
interface IFuseOptions extends ISearchOptions {
|
||||
caseSensitive?: boolean;
|
||||
includeScore?: boolean;
|
||||
shouldSort?: boolean;
|
||||
searchFn?: any;
|
||||
sortFn?: (a: {score: number}, b: {score: number}) => number;
|
||||
getFn?: (obj: any, path: string) => any;
|
||||
keys?: string[];
|
||||
}
|
||||
|
||||
interface ISearchOptions {
|
||||
location?: number;
|
||||
distance?: number;
|
||||
threshold?: number;
|
||||
maxPatternLength?: number;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user