Js工具庫之Shape-filter
類似效果就像Mybatis-plus裏的QueryWrapper
Github:github.com/ame-yu/shape-filter
主要目的
簡化對象數組的查詢
Object based array filter
Install
npm i shape-filter
QuickStart
import sf from "shape-filter"
let arr = [
{id:1, name:"Jackel", email:"[email protected]"},
{id:2, name:"Mira", email:"[email protected]"},
{id:3, name:"Ela", email:"[email protected]"},
//...
]
let list = sf(arr)
//查詢所有gmail郵箱的用戶 Get user list that using gmail
list.match({email:"@gmail.com"})//[{id:3, name:"ela",...
//精確搜索 Accurate search
list.match({name:"ira",email:"@gmail.com"})//[]
list.match({name:"blue com"})//[{id:2, name:"Mira"...
//結合搜索 Combine search
sf(arr,{combine:["name","email"]}).match("blue")//[{id:2, name:"Mira"...
//如果不定義結合的字段將默認結合所有數字和字符串 If you not define combine field,Default will combine all number and string
list.match("jackel")//[{id:1, name:"Jackel"...
限制 limit
過濾對象必須是個對象數組
source must be a object array
使用場景
大量數據離線查找
Deal with a massive of data, quick search.
默認配置
大小寫敏感 開
多單詞查詢邏輯 與
參數對象屬性邏輯 與
預計開發功能
有什麼需求請留個言或Issue,如果已有類似的庫請告知
If you have any suggestions please leave a issue.