更新版本号至 0.0.6,添加 queryFilter 函数以支持基于 Fuse.js 的查询过滤
This commit is contained in:
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/js-filter",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"description": "用于 JavaScript 数组的 SQL LIKE 过滤器函数",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@@ -10,20 +10,19 @@
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.26.0",
|
||||
"packageManager": "pnpm@10.32.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
".": "./dist/index.js",
|
||||
"./query-filter": "./dist/query-filter.js"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
"fuse.js": "^7.1.0",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
16
src/query-filter.ts
Normal file
16
src/query-filter.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import Fuse from 'fuse.js';
|
||||
import { filter } from './index';
|
||||
export const queryFilter = (opts?: { query?: string, routes?: any[] }) => {
|
||||
const query = opts?.query || '';
|
||||
const routes = opts?.routes || [];
|
||||
if (query.toLocaleUpperCase().startsWith('WHERE')) {
|
||||
return filter(routes, query);
|
||||
}
|
||||
const fuse = new Fuse(routes, {
|
||||
keys: ['path', 'key', 'description'],
|
||||
threshold: 0.4,
|
||||
});
|
||||
let findsRoutes = fuse.search(query);
|
||||
const resultRoutes = findsRoutes.map(r => r.item);
|
||||
return resultRoutes;
|
||||
}
|
||||
Reference in New Issue
Block a user