Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80621 views
1
// Generated by LiveScript 1.2.0
2
(function(){
3
var prelude, map, sortBy, fl, closestString, nameToRaw, dasherize;
4
prelude = require('prelude-ls'), map = prelude.map, sortBy = prelude.sortBy;
5
fl = require('fast-levenshtein');
6
closestString = function(possibilities, input){
7
var distances, ref$, string, distance;
8
if (!possibilities.length) {
9
return;
10
}
11
distances = map(function(it){
12
var ref$, longer, shorter;
13
ref$ = input.length > it.length
14
? [input, it]
15
: [it, input], longer = ref$[0], shorter = ref$[1];
16
return {
17
string: it,
18
distance: fl.get(longer, shorter)
19
};
20
})(
21
possibilities);
22
ref$ = sortBy(function(it){
23
return it.distance;
24
}, distances)[0], string = ref$.string, distance = ref$.distance;
25
return string;
26
};
27
nameToRaw = function(name){
28
if (name.length === 1 || name === 'NUM') {
29
return "-" + name;
30
} else {
31
return "--" + name;
32
}
33
};
34
dasherize = function(string){
35
if (/^[A-Z]/.test(string)) {
36
return string;
37
} else {
38
return prelude.dasherize(string);
39
}
40
};
41
module.exports = {
42
closestString: closestString,
43
nameToRaw: nameToRaw,
44
dasherize: dasherize
45
};
46
}).call(this);
47
48