simple-folder-search 2.2.0 → 2.3.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.
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ searchCandidates: () => searchCandidates,
33
34
  simpleFolderSearch: () => simpleFolderSearch
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
@@ -90,13 +91,16 @@ async function simpleFolderSearch(filepath, fileExtensions, search, options = {}
90
91
  }
91
92
  if (!search || Array.isArray(search) && search.length === 0)
92
93
  return filesForFuse.map((file) => file.path);
94
+ return await searchCandidates(filesForFuse, search, minimumScore);
95
+ }
96
+ async function searchCandidates(candidates, search, minimumScore) {
93
97
  const fuseOptions = {
94
98
  includeScore: true,
95
99
  threshold: 1 - minimumScore,
96
100
  // Convert our score to Fuse threshold
97
101
  keys: ["name", "artist"]
98
102
  };
99
- const fuse = new import_fuse.default(filesForFuse, fuseOptions);
103
+ const fuse = new import_fuse.default(candidates, fuseOptions);
100
104
  const searchQueries = Array.isArray(search) ? [{ name: search[0], artist: search[1] }] : [search];
101
105
  const searchPromises = searchQueries.map((query) => fuse.search(query));
102
106
  const results = await Promise.all(searchPromises);
@@ -105,5 +109,6 @@ async function simpleFolderSearch(filepath, fileExtensions, search, options = {}
105
109
  }
106
110
  // Annotate the CommonJS export names for ESM import in node:
107
111
  0 && (module.exports = {
112
+ searchCandidates,
108
113
  simpleFolderSearch
109
114
  });
package/dist/index.d.cts CHANGED
@@ -15,5 +15,18 @@ interface SearchOptions {
15
15
  * @returns {Promise<string[]>} A promise that resolves to an array of file paths that match the search query.
16
16
  */
17
17
  declare function simpleFolderSearch(filepath: string, fileExtensions: string[], search: string | string[], options?: SearchOptions, cacheCallback?: CacheCallback): Promise<string[]>;
18
+ /**
19
+ * Search for candidates based on a search query and minimum score.
20
+ *
21
+ * @param {Array<{name: string; artist?: string; path: string;}>} candidates - An array of candidate objects to search through.
22
+ * @param {string | string[]} search - The search query, either a string or an array of [name, artist].
23
+ * @param {number} minimumScore - The minimum score required for a candidate to be considered a match.
24
+ * @returns {Promise<string[]>} A promise that resolves to an array of file paths that match the search query.
25
+ */
26
+ declare function searchCandidates(candidates: {
27
+ name: string;
28
+ artist?: string;
29
+ path: string;
30
+ }[], search: string | string[], minimumScore: number): Promise<string[]>;
18
31
 
19
- export { simpleFolderSearch };
32
+ export { searchCandidates, simpleFolderSearch };
package/dist/index.d.ts CHANGED
@@ -15,5 +15,18 @@ interface SearchOptions {
15
15
  * @returns {Promise<string[]>} A promise that resolves to an array of file paths that match the search query.
16
16
  */
17
17
  declare function simpleFolderSearch(filepath: string, fileExtensions: string[], search: string | string[], options?: SearchOptions, cacheCallback?: CacheCallback): Promise<string[]>;
18
+ /**
19
+ * Search for candidates based on a search query and minimum score.
20
+ *
21
+ * @param {Array<{name: string; artist?: string; path: string;}>} candidates - An array of candidate objects to search through.
22
+ * @param {string | string[]} search - The search query, either a string or an array of [name, artist].
23
+ * @param {number} minimumScore - The minimum score required for a candidate to be considered a match.
24
+ * @returns {Promise<string[]>} A promise that resolves to an array of file paths that match the search query.
25
+ */
26
+ declare function searchCandidates(candidates: {
27
+ name: string;
28
+ artist?: string;
29
+ path: string;
30
+ }[], search: string | string[], minimumScore: number): Promise<string[]>;
18
31
 
19
- export { simpleFolderSearch };
32
+ export { searchCandidates, simpleFolderSearch };
package/dist/index.js CHANGED
@@ -54,13 +54,16 @@ async function simpleFolderSearch(filepath, fileExtensions, search, options = {}
54
54
  }
55
55
  if (!search || Array.isArray(search) && search.length === 0)
56
56
  return filesForFuse.map((file) => file.path);
57
+ return await searchCandidates(filesForFuse, search, minimumScore);
58
+ }
59
+ async function searchCandidates(candidates, search, minimumScore) {
57
60
  const fuseOptions = {
58
61
  includeScore: true,
59
62
  threshold: 1 - minimumScore,
60
63
  // Convert our score to Fuse threshold
61
64
  keys: ["name", "artist"]
62
65
  };
63
- const fuse = new Fuse(filesForFuse, fuseOptions);
66
+ const fuse = new Fuse(candidates, fuseOptions);
64
67
  const searchQueries = Array.isArray(search) ? [{ name: search[0], artist: search[1] }] : [search];
65
68
  const searchPromises = searchQueries.map((query) => fuse.search(query));
66
69
  const results = await Promise.all(searchPromises);
@@ -68,5 +71,6 @@ async function simpleFolderSearch(filepath, fileExtensions, search, options = {}
68
71
  return flattenedResults.filter((result) => result.score ? result.score <= 1 - minimumScore : false).map((result) => result.item.path);
69
72
  }
70
73
  export {
74
+ searchCandidates,
71
75
  simpleFolderSearch
72
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-folder-search",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "A simple folder search package",
5
5
  "main": "dist/index.cjs",
6
6
  "exports": {
@@ -91,14 +91,25 @@ export async function simpleFolderSearch(
91
91
  if (!search || (Array.isArray(search) && search.length === 0))
92
92
  return filesForFuse.map(file => file.path);
93
93
 
94
+ return await searchCandidates(filesForFuse, search, minimumScore);
95
+ }
96
+
97
+ /**
98
+ * Search for candidates based on a search query and minimum score.
99
+ *
100
+ * @param {Array<{name: string; artist?: string; path: string;}>} candidates - An array of candidate objects to search through.
101
+ * @param {string | string[]} search - The search query, either a string or an array of [name, artist].
102
+ * @param {number} minimumScore - The minimum score required for a candidate to be considered a match.
103
+ * @returns {Promise<string[]>} A promise that resolves to an array of file paths that match the search query.
104
+ */
105
+ export async function searchCandidates(candidates: {name: string; artist?: string; path: string;}[], search: string|string[], minimumScore: number): Promise<string[]> {
94
106
  // Setup Fuse with options
95
107
  const fuseOptions = {
96
108
  includeScore: true,
97
109
  threshold: 1 - minimumScore, // Convert our score to Fuse threshold
98
110
  keys: ["name", "artist"],
99
111
  };
100
-
101
- const fuse = new Fuse(filesForFuse, fuseOptions);
112
+ const fuse = new Fuse(candidates, fuseOptions);
102
113
 
103
114
  // Perform search and filter results
104
115
  const searchQueries = Array.isArray(search) ? [{ name: search[0], artist: search[1] }] : [search];