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

tools-common

v1.0.21

Published

common functions

Readme

常用方法工具

common.js

1.1 时间相关

1.1.1 sortByTime

 sortByTime ({ data, key, order }) // 对数组按时间排序
 data:数据数组
 key:数组对象时间参数对应的键名
 order:默认顺序,false:倒序

1.1.2 randomNumber

 randomNumber (length) // 生成指定长度随机数,默认长度为10
 length:随机数长度

1.1.3 returnNowTime

returnNowTime () // 返回当前时间点,格式为YYYY-MM-DD HH-MM-SS

1.2 下载、防抖相关

1.2.1 downloadResult

 downloadResult (data, docName) // 构造a标签下载后销毁
 data:返回的文件流
 docName:下载文件名称

1.2.2 debounce

 debounce (fn, time) // 防抖
 fn:防抖回调
 time:防抖周期时长
<script>
import toolsCommon from 'tools-common'
export default {
  created () {
     // 初始化防抖方法,fn为防抖回调
    this.inputDebounce = toolsCommon.debounce(this.fn, 1000)
  },
  watch: {
     searchText () { // searchText为input对应value
          this.inputDebounce('test') //'test'为回调函数需要携带的参数
    }
  },
  methods: {
     fn(params){ // 防抖回调函数,params为 inputDebounce调用传参
          console.log('防抖回调', params) // --->  防抖回调test
     }
  }
}
</script>

1.3 操作tree相关

1.3.1 getTreeNodeByKey

 getTreeNodeByKey ({data, key, value}) // 通过指定tree内键及其值找到对应node
 data:tree数组
 key:数组对象value对应的键名
 value: 过滤参数

1.3.2 getNodeParentIds

 getNodeParentIds (data, key, value, parentIds) // 通过指定唯一标识找到tree内所有父级唯一标识
 data:tree数组
 key:数组对象value对应的键名
 value: 过滤参数
 parentIds:返回所有唯一标识的数组,外部传入接收

1.3.3 filterNode

 filterNode (key, idKey, value, tree, filterNodes) // 关键字过滤目录树
 key:节点名称对应键名
 idKey:唯一标识对应键名
 value:搜索关键字
 tree:待过滤树
 filterNodes:接收过滤后树节点,外部传入
const data = [
  {
    title: 'parent 1',
    key: '0-0',
    children: [
      {
        title: 'parent 1-0',
        key: '0-0-0',
        disabled: true,
        children: [
          { title: 'leaf', key: '0-0-0-0', disableCheckbox: true },
          { title: 'leaf', key: '0-0-0-1' },
        ],
      },
      {
        title: 'parent 1-1',
        key: '0-0-1',
        children: [{ key: '0-0-1-0', title: 'sss' }],
      },
    ],
  },
];
const filterNodes = []
filterNode ('title', 'key', 'parent 1-0', data, filterNodes)
console.log('filterNodes', filterNodes)

未完待续