alfred-spell 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +23 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -22,21 +22,36 @@ async function main() {
22
22
  return;
23
23
  }
24
24
 
25
- const topScore = Math.max(...data.map((x) => x.score));
25
+ const sortedData = data.toSorted((a, b) => b.score - a.score);
26
+ const topScore = sortedData[0].score;
27
+
28
+ const hasExactMatch = sortedData.findIndex((x) => x.word === input) !== -1;
29
+
30
+ if (!hasExactMatch) {
31
+ sortedData.unshift({
32
+ word: input,
33
+ score: -1,
34
+ });
35
+ }
26
36
 
27
37
  alfy.output(
28
- data.map((x) => {
29
- const isScoreTop = x.score === topScore;
30
- let prefix = "";
31
- if (isScoreTop) {
32
- const isTypo = x.word.toLocaleLowerCase() !== input.toLocaleLowerCase();
38
+ sortedData.map((x) => {
39
+ const isShowingTopScoreCandidate = x.score === topScore;
40
+ const isShowingExactMatch = x.word === input;
41
+ const isShowingRawInputAsIs = x.score < 0;
33
42
 
34
- prefix = isTypo ? "✍️ " : "✅ ";
43
+ let prefix = "";
44
+ if (isShowingTopScoreCandidate) {
45
+ prefix = isShowingExactMatch ? "✅ " : "✍️ ";
35
46
  }
36
47
 
48
+ const displayScore = (x.score / topScore).toFixed(3);
49
+
37
50
  return {
38
51
  title: x.word,
39
- subtitle: `${prefix}Match score: ${x.score}`,
52
+ subtitle: isShowingRawInputAsIs
53
+ ? "💬 Raw input"
54
+ : `${prefix}Match score: ${displayScore}`,
40
55
  text: {
41
56
  copy: x.word,
42
57
  largetype: x.word,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alfred-spell",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "postinstall": "alfy-init",