-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (64 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import alfy from 'alfy';
import Recognizer from 'climbing-grade-recognizer';
import ClimbingGrade from 'climbing-grade';
const sportFormats = ['kurtyki', 'french', 'uiaa', 'yds', 'australian', 'british'];
const boulderFormats = ['font', 'hueco'];
const getTypeFormats = (system) => {
if (boulderFormats.indexOf(system) >= 0) {
return boulderFormats;
}
return sportFormats;
};
const formatting = {
kurtyki: "Polish",
french: "French",
uiaa: "UIAA",
yds: "YDS (United States)",
australian: "Australian",
british: "British",
font: "Fontainebleau",
hueco: "Hueco (United States)"
};
const formatGrade = (gr, system) => {
const output = [];
const grade = new ClimbingGrade(gr, system);
getTypeFormats(system).filter((format) => format !== system).forEach((format) => {
output.push({
title: grade.format(format),
subtitle: formatting[format],
arg: "open",
valid: true,
icon: {
"path": "./workout.png"
}
});
});
return output;
};
let system;
let [inputGrade, inputSystem] = alfy.input.split(" ");
try {
let output = [];
if (!inputSystem) {
system = Recognizer.recognize(inputGrade);
if (system.length > 1) {
system.forEach((system) => {
output.push({
title: `Did you mean ${inputGrade} in ${system} system?`,
arg: `climb ${inputGrade} ${system}`,
valid: true
});
});
} else {
output = formatGrade(inputGrade, system[0]);
}
} else {
output = formatGrade(inputGrade, inputSystem);
}
alfy.output(output);
} catch (e) {
alfy.output([{
title: 'Grade cannot be converted. ' + system,
subtitle: e.message
}]);
}