fconvert 0.1.3 → 0.1.4

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.
package/dist/convert CHANGED
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fconvert",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Fast local CLI conversion tool with graph-based anything-to-anything routing",
5
5
  "type": "module",
6
6
  "main": "src/cli/main.ts",
@@ -9,6 +9,7 @@ import { FormatRegistry } from "../formats/registry.ts";
9
9
  interface PickerPayload {
10
10
  prompt: string;
11
11
  query: string;
12
+ preferred: string;
12
13
  options: Array<{
13
14
  id: string;
14
15
  name: string;
@@ -110,7 +111,8 @@ export async function pickOutputFormatInteractive(
110
111
 
111
112
  const payload: PickerPayload = {
112
113
  prompt: "output format",
113
- query: extname(inputPath).replace(/^\./, ""),
114
+ query: "",
115
+ preferred: extname(inputPath).replace(/^\./, ""),
114
116
  options: registry.all().map((format) => ({
115
117
  id: format.id,
116
118
  name: format.name,
@@ -18,9 +18,10 @@ type option struct {
18
18
  }
19
19
 
20
20
  type payload struct {
21
- Prompt string `json:"prompt"`
22
- Query string `json:"query"`
23
- Options []option `json:"options"`
21
+ Prompt string `json:"prompt"`
22
+ Query string `json:"query"`
23
+ Preferred string `json:"preferred"`
24
+ Options []option `json:"options"`
24
25
  }
25
26
 
26
27
  type scoredOption struct {
@@ -31,6 +32,7 @@ type scoredOption struct {
31
32
  type model struct {
32
33
  prompt string
33
34
  query string
35
+ preferred string
34
36
  all []option
35
37
  filtered []option
36
38
  cursor int
@@ -93,6 +95,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
93
95
  func (m model) View() string {
94
96
  var builder strings.Builder
95
97
  builder.WriteString(fmt.Sprintf("%s > %s\n", m.prompt, m.query))
98
+ if m.query == "" && m.preferred != "" {
99
+ builder.WriteString(fmt.Sprintf(" hint: original extension '.%s' is ranked first\n", m.preferred))
100
+ }
96
101
 
97
102
  if len(m.filtered) == 0 {
98
103
  builder.WriteString(" no matches\n")
@@ -139,7 +144,7 @@ func (m *model) refilter() {
139
144
  scored := make([]scoredOption, 0, len(m.all))
140
145
 
141
146
  for _, item := range m.all {
142
- score := fuzzyScore(query, item)
147
+ score := fuzzyScore(query, item, m.preferred)
143
148
  if score < 0 {
144
149
  continue
145
150
  }
@@ -166,9 +171,19 @@ func (m *model) refilter() {
166
171
  }
167
172
  }
168
173
 
169
- func fuzzyScore(query string, item option) int {
174
+ func fuzzyScore(query string, item option, preferred string) int {
170
175
  if query == "" {
171
- return 1
176
+ score := 1
177
+ if preferred != "" {
178
+ normalizedPreferred := strings.ToLower(preferred)
179
+ if strings.EqualFold(item.Extension, normalizedPreferred) {
180
+ score += 25
181
+ }
182
+ if strings.EqualFold(item.ID, normalizedPreferred) {
183
+ score += 20
184
+ }
185
+ }
186
+ return score
172
187
  }
173
188
 
174
189
  candidate := strings.ToLower(item.ID + " " + item.Extension + " " + item.Name)
@@ -207,6 +222,16 @@ func fuzzyScore(query string, item option) int {
207
222
  if strings.HasPrefix(strings.ToLower(item.ID), query) {
208
223
  score += 15
209
224
  }
225
+ if preferred != "" {
226
+ normalizedPreferred := strings.ToLower(preferred)
227
+ if strings.EqualFold(item.Extension, normalizedPreferred) {
228
+ score += 8
229
+ }
230
+ if strings.EqualFold(item.ID, normalizedPreferred) {
231
+ score += 6
232
+ }
233
+ }
234
+
210
235
  return score
211
236
  }
212
237
 
@@ -244,9 +269,10 @@ func main() {
244
269
  }
245
270
 
246
271
  picker := model{
247
- prompt: data.Prompt,
248
- query: data.Query,
249
- all: data.Options,
272
+ prompt: data.Prompt,
273
+ query: data.Query,
274
+ preferred: strings.TrimSpace(data.Preferred),
275
+ all: data.Options,
250
276
  }
251
277
  picker.refilter()
252
278