]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/atom-space-pen-views/node_modules/fuzzaldrin/lib/fuzzaldrin.js
41755d2f8da6e83f43bf34b9598197b17efd23de
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / atom-space-pen-views / node_modules / fuzzaldrin / lib / fuzzaldrin.js
1 (function() {
2 var PathSeparator, SpaceRegex, filter, matcher, scorer;
3
4 scorer = require('./scorer');
5
6 filter = require('./filter');
7
8 matcher = require('./matcher');
9
10 PathSeparator = require('path').sep;
11
12 SpaceRegex = /\ /g;
13
14 module.exports = {
15 filter: function(candidates, query, options) {
16 var queryHasSlashes;
17 if (query) {
18 queryHasSlashes = query.indexOf(PathSeparator) !== -1;
19 query = query.replace(SpaceRegex, '');
20 }
21 return filter(candidates, query, queryHasSlashes, options);
22 },
23 score: function(string, query) {
24 var queryHasSlashes, score;
25 if (!string) {
26 return 0;
27 }
28 if (!query) {
29 return 0;
30 }
31 if (string === query) {
32 return 2;
33 }
34 queryHasSlashes = query.indexOf(PathSeparator) !== -1;
35 query = query.replace(SpaceRegex, '');
36 score = scorer.score(string, query);
37 if (!queryHasSlashes) {
38 score = scorer.basenameScore(string, query, score);
39 }
40 return score;
41 },
42 match: function(string, query) {
43 var baseMatches, index, matches, queryHasSlashes, seen, _i, _ref, _results;
44 if (!string) {
45 return [];
46 }
47 if (!query) {
48 return [];
49 }
50 if (string === query) {
51 return (function() {
52 _results = [];
53 for (var _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
54 return _results;
55 }).apply(this);
56 }
57 queryHasSlashes = query.indexOf(PathSeparator) !== -1;
58 query = query.replace(SpaceRegex, '');
59 matches = matcher.match(string, query);
60 if (!queryHasSlashes) {
61 baseMatches = matcher.basenameMatch(string, query);
62 matches = matches.concat(baseMatches).sort(function(a, b) {
63 return a - b;
64 });
65 seen = null;
66 index = 0;
67 while (index < matches.length) {
68 if (index && seen === matches[index]) {
69 matches.splice(index, 1);
70 } else {
71 seen = matches[index];
72 index++;
73 }
74 }
75 }
76 return matches;
77 }
78 };
79
80 }).call(this);