@quenty/fzy 5.9.0 → 5.9.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.9.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/fzy@5.9.0...@quenty/fzy@5.9.1) (2025-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
12
+
13
+
14
+
15
+
16
+
6
17
  # [5.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/fzy@5.8.0...@quenty/fzy@5.9.0) (2025-04-02)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/fzy",
3
- "version": "5.9.0",
3
+ "version": "5.9.1",
4
4
  "description": "Lua implementation of fzy string search algorithm",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -24,10 +24,10 @@
24
24
  "Quenty"
25
25
  ],
26
26
  "dependencies": {
27
- "@quenty/loader": "^10.8.0"
27
+ "@quenty/loader": "^10.8.1"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "e8ea56930e65322fcffc05a1556d5df988068f0b"
32
+ "gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
33
33
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  The lua implementation of the fzy string matching algorithm. This algorithm
3
4
  is optimized for matching stuff on the terminal, but should serve well as a
@@ -69,6 +70,18 @@ local Fzy = {}
69
70
  .maxMatchLength number
70
71
  @within Fzy
71
72
  ]=]
73
+ export type FzyConfig = {
74
+ caseSensitive: boolean,
75
+ gapLeadingScore: number,
76
+ gapTrailingScore: number,
77
+ gapInnerScore: number,
78
+ consecutiveMatchScore: number,
79
+ slashMatchScore: number,
80
+ wordMatchScore: number,
81
+ capitalMatchScore: number,
82
+ dotMatchScore: number,
83
+ maxMatchLength: number,
84
+ }
72
85
 
73
86
  --[=[
74
87
  Creates a new configuration for Fzy.
@@ -76,7 +89,7 @@ local Fzy = {}
76
89
  @param config table
77
90
  @return FzyConfig
78
91
  ]=]
79
- function Fzy.createConfig(config)
92
+ function Fzy.createConfig(config: any): FzyConfig
80
93
  assert(type(config) == "table" or config == nil, "Bad config")
81
94
 
82
95
  config = config or {}
@@ -107,7 +120,7 @@ end
107
120
  @param config any
108
121
  @return boolean
109
122
  ]=]
110
- function Fzy.isFzyConfig(config)
123
+ function Fzy.isFzyConfig(config: any): boolean
111
124
  return type(config) == "table"
112
125
  and type(config.gapLeadingScore) == "number"
113
126
  and type(config.gapTrailingScore) == "number"
@@ -131,13 +144,13 @@ end
131
144
  @param haystack string
132
145
  @return boolean
133
146
  ]=]
134
- function Fzy.hasMatch(config, needle: string, haystack: string)
147
+ function Fzy.hasMatch(config: FzyConfig, needle: string, haystack: string): boolean
135
148
  if not config.caseSensitive then
136
149
  needle = string.lower(needle)
137
150
  haystack = string.lower(haystack)
138
151
  end
139
152
 
140
- local j = 1
153
+ local j: number? = 1
141
154
  for i = 1, string.len(needle) do
142
155
  j = string.find(haystack, string.sub(needle, i, i), j, true)
143
156
  if not j then
@@ -150,15 +163,15 @@ function Fzy.hasMatch(config, needle: string, haystack: string)
150
163
  return true
151
164
  end
152
165
 
153
- local function is_lower(c)
154
- return string.match(c, "%l")
166
+ local function is_lower(c: string): boolean
167
+ return string.match(c, "%l") ~= nil
155
168
  end
156
169
 
157
- local function is_upper(c)
158
- return string.match(c, "%u")
170
+ local function is_upper(c: string): boolean
171
+ return string.match(c, "%u") ~= nil
159
172
  end
160
173
 
161
- local function precomputeBonus(config, haystack: string)
174
+ local function precomputeBonus(config: FzyConfig, haystack: string)
162
175
  local matchBonus = {}
163
176
 
164
177
  local last_char = "/"
@@ -182,7 +195,7 @@ local function precomputeBonus(config, haystack: string)
182
195
  return matchBonus
183
196
  end
184
197
 
185
- local function compute(config, needle: string, haystack: string, D, M)
198
+ local function compute(config: FzyConfig, needle: string, haystack: string, D: { { number } }, M)
186
199
  -- Note that the match bonuses must be computed before the arguments are
187
200
  -- converted to lowercase, since there are bonuses for camelCase.
188
201
 
@@ -240,7 +253,7 @@ end
240
253
  @param haystack string
241
254
  @return boolean
242
255
  ]=]
243
- function Fzy.isPerfectMatch(config, needle, haystack)
256
+ function Fzy.isPerfectMatch(config: FzyConfig, needle: string, haystack: string): boolean
244
257
  if config.caseSensitive then
245
258
  return needle == haystack
246
259
  else
@@ -256,7 +269,7 @@ end
256
269
  @param haystack string
257
270
  @return number -- higher scores indicate better matches. See also [Fzy.getMinScore] and [Fzy.getMaxScore].
258
271
  ]=]
259
- function Fzy.score(config, needle: string, haystack: string): number
272
+ function Fzy.score(config: FzyConfig, needle: string, haystack: string): number
260
273
  local n = string.len(needle)
261
274
  local m = string.len(haystack)
262
275
 
@@ -272,7 +285,6 @@ function Fzy.score(config, needle: string, haystack: string): number
272
285
  end
273
286
  end
274
287
 
275
-
276
288
  --[=[
277
289
  Compute the locations where fzy matches a string.
278
290
 
@@ -285,7 +297,7 @@ end
285
297
  @return { int } -- indices, where `indices[n]` is the location of the `n`th character of `needle` in `haystack`.
286
298
  @return number -- the same matching score returned by `score`
287
299
  ]=]
288
- function Fzy.positions(config, needle: string, haystack: string)
300
+ function Fzy.positions(config: FzyConfig, needle: string, haystack: string): ({ number }, number)
289
301
  local n = string.len(needle)
290
302
  local m = string.len(haystack)
291
303
 
@@ -334,13 +346,13 @@ end
334
346
  @param haystacks { string }
335
347
  @return {{idx, positions, score}, ...}
336
348
  ]=]
337
- function Fzy.filter(config, needle: string, haystacks: { string })
338
- local result = {}
349
+ function Fzy.filter(config: FzyConfig, needle: string, haystacks: { string }): { any }
350
+ local result: { any } = {}
339
351
 
340
352
  for i, line in ipairs(haystacks) do
341
353
  if Fzy.hasMatch(config, needle, line) then
342
354
  local p, s = Fzy.positions(config, needle, line)
343
- table.insert(result, {i, p, s})
355
+ table.insert(result, { i, p, s } :: { any })
344
356
  end
345
357
  end
346
358
 
@@ -378,7 +390,7 @@ end
378
390
  @param config FzyConfig
379
391
  @return number
380
392
  ]=]
381
- function Fzy.getMaxLength(config): number
393
+ function Fzy.getMaxLength(config: FzyConfig): number
382
394
  assert(Fzy.isFzyConfig(config), "Bad config")
383
395
 
384
396
  return config.maxMatchLength
@@ -393,7 +405,7 @@ end
393
405
  @param config FzyConfig
394
406
  @return number
395
407
  ]=]
396
- function Fzy.getScoreFloor(config): number
408
+ function Fzy.getScoreFloor(config: FzyConfig): number
397
409
  assert(Fzy.isFzyConfig(config), "Bad config")
398
410
 
399
411
  return config.maxMatchLength * config.gapInnerScore
@@ -408,7 +420,7 @@ end
408
420
  @param config FzyConfig
409
421
  @return number
410
422
  ]=]
411
- function Fzy.getScoreCeiling(config): number
423
+ function Fzy.getScoreCeiling(config: FzyConfig): number
412
424
  assert(Fzy.isFzyConfig(config), "Bad config")
413
425
 
414
426
  return config.maxMatchLength * config.consecutiveMatchScore
@@ -47,13 +47,13 @@ local MIN_SCORE = Fzy.getMinScore()
47
47
  local MAX_SCORE = Fzy.getMaxScore()
48
48
 
49
49
  local function compareTables(a, b)
50
- for key, value in pairs(a) do
50
+ for key, value in a do
51
51
  if b[key] ~= value then
52
52
  return false
53
53
  end
54
54
  end
55
55
 
56
- for key, value in pairs(b) do
56
+ for key, value in b do
57
57
  if a[key] ~= value then
58
58
  return false
59
59
  end