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 🙏

© 2024 – Pkg Stats / Ryan Hefner

colin-util

v1.0.3

Published

工具包分别已压缩或者分包. 可支持全引入和按需引入两种方式

Downloads

7

Readme

工具库函数开发

工具包分别已压缩或者分包. 可支持全引入和按需引入两种方式

import { debounce, throttle } from "colin-util";   //全引入
import deepClone from "colin-util/dist";           //按需引入

// debounce用法
debounce(() => {
    console.log('fn 防抖执行了')
}, 1000)

// throttle用法
function handle(){
    console.log('节流函数降低调用频率');
}
window.addEventListener("mousemove",throttle(handle, 1000));

// deepClone用法
const liLei = {
    name: 'lilei',
    age: 28,
    habits: ['coding', 'hiking', 'running']
}
// 深拷贝:实现一
const liLeiStr = JSON.stringify(liLei)
const liLeiCopy = JSON.parse(liLeiStr)
console.log(liLeiStr === liLeiCopy) // false

// 深拷贝: 实现二
const liLeiCopy1 = deepClone(liLei);
console.log(liLeiStr === liLeiCopy1) // false

// recursionTree 分析树结构用法
const tree = [
    {
        id: 0,
        title: '节点0',
        children: [
            { 
                id: 1, 
                title: '节点1',
                children: [
                    {
                        id: 3,
                        title: '节点3'
                    },
                    {
                        id: 4,
                        title: '节点4'
                    }
                ]
            },
            { 
                id: 2, 
                title: '节点2'
            }
        ]
    }
]

const allId = {};   // allId会拿到节点及其所有上下关系的详细信息
recursionTree(tree, { step: 1, allId, pIdList: [] })
console.log(allId)
// {
//  0: {
//     childList: (4) [1, 3, 4, 2]
//     item: {id: 0, title: '节点0', children: Array(2)}
//     pId: undefined
//     pIdList: []
//     step: 1
//  },
//  1: {
//     childList: (2) [3, 4]
//     item: {id: 1, title: '节点1', children: Array(2)}
//     pId: 0
//     pIdList: [0]
//     step: 2
//   },
//   ...
// }

// arrayToTree  将带有引用关系的数组转换为树结构
const array = [
    {id: 0},
    {id: 1, pid: 0},
    {id: 2, pid: 0},
    {id: 3, pid: 1},
    {id: 4, pid: 1},
    {id: 5, pid: 2}
]

const newTree =  arrayToTree(array);
console.log(newTree);
// [
//     {
//         id: 0,
//         children: [
//             { 
//                 id: 1, 
//                 pid: 0,
//                 children: [
//                     { id: 3, pid: 1},
//                     { id: 4, pid: 1},
//                 ]
//             },
//             { 
//                 id: 2, 
//                 pid: 0,
//                 children: [
//                     { id: 5, pid: 2}
//                 ]
//             }
//         ]
//     }
// ]