source: frontend/node_modules/didyoumean/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.4 KB
Line 
1didYouMean.js - A simple JavaScript matching engine
2===================================================
3
4[Available on GitHub](https://github.com/dcporter/didyoumean.js).
5
6A super-simple, highly optimized JS library for matching human-quality input to a list of potential
7matches. You can use it to suggest a misspelled command-line utility option to a user, or to offer
8links to nearby valid URLs on your 404 page. (The examples below are taken from a personal project,
9my [HTML5 business card](http://dcporter.aws.af.cm/me), which uses didYouMean.js to suggest correct
10URLs from misspelled ones, such as [dcporter.aws.af.cm/me/instagarm](http://dcporter.aws.af.cm/me/instagarm).)
11Uses the [Levenshtein distance algorithm](https://en.wikipedia.org/wiki/Levenshtein_distance).
12
13didYouMean.js works in the browser as well as in node.js. To install it for use in node:
14
15```
16npm install didyoumean
17```
18
19
20Examples
21--------
22
23Matching against a list of strings:
24```
25var input = 'insargrm'
26var list = ['facebook', 'twitter', 'instagram', 'linkedin'];
27console.log(didYouMean(input, list));
28> 'instagram'
29// The method matches 'insargrm' to 'instagram'.
30
31input = 'google plus';
32console.log(didYouMean(input, list));
33> null
34// The method was unable to find 'google plus' in the list of options.
35```
36
37Matching against a list of objects:
38```
39var input = 'insargrm';
40var list = [ { id: 'facebook' }, { id: 'twitter' }, { id: 'instagram' }, { id: 'linkedin' } ];
41var key = 'id';
42console.log(didYouMean(input, list, key));
43> 'instagram'
44// The method returns the matching value.
45
46didYouMean.returnWinningObject = true;
47console.log(didYouMean(input, list, key));
48> { id: 'instagram' }
49// The method returns the matching object.
50```
51
52
53didYouMean(str, list, [key])
54----------------------------
55
56- str: The string input to match.
57- list: An array of strings or objects to match against.
58- key (OPTIONAL): If your list array contains objects, you must specify the key which contains the string
59 to match against.
60
61Returns: the closest matching string, or null if no strings exceed the threshold.
62
63
64Options
65-------
66
67Options are set on the didYouMean function object. You may change them at any time.
68
69### threshold
70
71 By default, the method will only return strings whose edit distance is less than 40% (0.4x) of their length.
72 For example, if a ten-letter string is five edits away from its nearest match, the method will return null.
73
74 You can control this by setting the "threshold" value on the didYouMean function. For example, to set the
75 edit distance threshold to 50% of the input string's length:
76
77 ```
78 didYouMean.threshold = 0.5;
79 ```
80
81 To return the nearest match no matter the threshold, set this value to null.
82
83### thresholdAbsolute
84
85 This option behaves the same as threshold, but instead takes an integer number of edit steps. For example,
86 if thresholdAbsolute is set to 20 (the default), then the method will only return strings whose edit distance
87 is less than 20. Both options apply.
88
89### caseSensitive
90
91 By default, the method will perform case-insensitive comparisons. If you wish to force case sensitivity, set
92 the "caseSensitive" value to true:
93
94 ```
95 didYouMean.caseSensitive = true;
96 ```
97
98### nullResultValue
99
100 By default, the method will return null if there is no sufficiently close match. You can change this value here.
101
102### returnWinningObject
103
104 By default, the method will return the winning string value (if any). If your list contains objects rather
105 than strings, you may set returnWinningObject to true.
106
107 ```
108 didYouMean.returnWinningObject = true;
109 ```
110
111 This option has no effect on lists of strings.
112
113### returnFirstMatch
114
115 By default, the method will search all values and return the closest match. If you're simply looking for a "good-
116 enough" match, you can set your thresholds appropriately and set returnFirstMatch to true to substantially speed
117 things up.
118
119
120License
121-------
122
123didYouMean copyright (c) 2013-2014 Dave Porter.
124
125Licensed under the Apache License, Version 2.0 (the "License");
126you may not use this file except in compliance with the License.
127You may obtain a copy of the License
128[here](http://www.apache.org/licenses/LICENSE-2.0).
129
130Unless required by applicable law or agreed to in writing, software
131distributed under the License is distributed on an "AS IS" BASIS,
132WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133See the License for the specific language governing permissions and
134limitations under the License.
Note: See TracBrowser for help on using the repository browser.