]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/atom-space-pen-views/node_modules/fuzzaldrin/README.md
a50867b0c5c600fb37af69a258de7c86d849aa8a
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / atom-space-pen-views / node_modules / fuzzaldrin / README.md
1 # fuzzaldrin
2
3 [![Build Status](https://travis-ci.org/atom/fuzzaldrin.svg?branch=master)](https://travis-ci.org/atom/fuzzaldrin)
4 [![Build status](https://ci.appveyor.com/api/projects/status/0ig71rjdgfm7y9c1/branch/master)](https://ci.appveyor.com/project/kevinsawicki/fuzzaldrin/branch/master)
5
6 Fuzzy filtering and string scoring.
7
8 This library is used by [Atom](http://atom.io) and so its focus will be on
9 scoring and filtering paths, methods, and other things common when writing code.
10 It therefore will specialize in handling common patterns in these types of
11 strings such as characters like `/`, `-`, and `_`, and also handling of
12 camel cased text.
13
14 ## Using
15
16 ```sh
17 npm install fuzzaldrin
18 ```
19
20 ### filter(candidates, query, [options])
21
22 Sort and filter the given candidates by matching them against the given query.
23
24 * `candidates` - An array of strings or objects.
25 * `query` - A string query to match each candidate against.
26 * `options` - An optional object with the following keys:
27 * `key` - The property to use for scoring if the candidates are objects.
28 * `maxResults` - The maximum numbers of results to return.
29
30 Returns an array of candidates sorted by best match against the query.
31
32 ```coffee
33 {filter} = require 'fuzzaldrin'
34
35 # With an array of strings
36 candidates = ['Call', 'Me', 'Maybe']
37 results = filter(candidates, 'me')
38 console.log(results) # ['Me', 'Maybe']
39
40 # With an array of objects
41 candidates = [
42 {name: 'Call', id: 1}
43 {name: 'Me', id: 2}
44 {name: 'Maybe', id: 3}
45 ]
46 results = filter(candidates, 'me', key: 'name')
47 console.log(results) # [{name: 'Me', id: 2}, {name: 'Maybe', id: 3}]
48 ```
49
50 ### score(string, query)
51
52 Score the given string against the given query.
53
54 * `string` - The string the score.
55 * `query` - The query to score the string against.
56
57 ```coffee
58 {score} = require 'fuzzaldrin'
59
60 score('Me', 'me') # 0.17099999999999999
61 score('Maybe', 'me') # 0.0693
62 ```
63
64 ## Developing
65
66 ```sh
67 git clone https://github.com/atom/fuzzaldrin.git
68 cd fuzzaldrin
69 npm install
70 npm test
71 ```
72
73 You can run the benchmarks using:
74
75 ```sh
76 npm run benchmark
77 ```