npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

you-need-suggest

v0.1.1

Published

本地动态筛选功能

Readme

you need suggest

这是一个本地搜索建议的插件。适用场景是,数据量只有固定的几百条数据但后端实现模糊搜索又显得大才小用的场景。

这种场景下,前端如果展示会让用户很难找到自己想要的数据,有了这个插件,用户可以根据模糊的记忆找到自己想要的数据,尤其适合应用于类似下拉列表/搜索选择的场景中。例如下面的场景:

模糊搜索 模糊搜索

这里配置了用于匹配的字段 (字符串类型的任意字段)。底层通过 编辑距离算法,计算出相似值,并根据相似度大小顺序返回结果。可以设置 相似度阔值,以减少不必要的返回数据量;可以设置 大小写区分(仅支持英文)

安装

npm install you-need-suggest -S

使用

基本使用

import { YouNeedSuggestion } from "you-need-suggest";

const data = [
  {
    text: "test1"
  },
  {
    text: "test2"
  },
  {
    text: "test3"
  }
];
const suggestion = new YouNeedSuggestion(data);
const result = suggestion.get("t2");

// search value: [
//   { data: { text: 'test2' }, similarity: 0.5 },
//   { data: { text: 'test1' }, similarity: 0.25 },
//   { data: { text: 'test3' }, similarity: 0.25 }
// ]
console.log('search value: ', result);

自定义

const data = [
  {
    value: "test1"
  },
  {
    value: "test2"
  },
  {
    value: "test3"
  }
];
const suggestion = new YouNeedSuggestion(data, {
  keyNameList: ["value"],
  minSimilarity: 0.3
});
const result = suggestion.get("t2");

// search value: [
//   { data: { text: 'test2' }, similarity: 0.5 },
// ]
console.log('search value: ', result);

配置项

export interface YouNeedSuggestionOptions {
  // 进行匹配的字段,默认:["text"]
  keyNameList: string | string[];
  // 是否过滤空值,默认:true
  filterEmptyValue: boolean;
  // 是否区分大小写,默认:false
  caseSensitive: boolean;
  // 最小相似度,默认:0
  minSimilarity: number;
  // 计算算法适配器,默认使用编辑距离算法
  compare: (sourceStr: string, targetStr: string) => number;
}