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

c-js-utils

v1.0.8

Published

自用的js的方法库

Readme

简介

在公司工作的过程中, 由于公司业务的问题, 出现了很多类似的逻辑功能, 由此出现了很多相似的方法, 于是把他封装出来供自己以后使用, 也方便公司代码的维护.
目前封装出来的方法不多, 以后也会继续维护添加新的方法.

现有的方法

  • 节流
  • 防抖
  • 深度拷贝
  • 深度合并
  • 数组洗牌
  • 时间戳转时间格式
  • 判断数据类型

如何使用

目前兼容了Vue2 与 Vue3

// 首先安装
npm install --save c-js-utils 
or
cnpm install --save c-js-utils 

// Vue2 
    // main.js中添加代码
    import func from c-js-utils
    Vue.use(func)

    // 然后再页面中就可以使用了
    this.$debounce(func)

// Vue3
    // main.js中添加代码
    import func from c-js-utils

    const app = createApp()
    app.use(func).mount("#app")

    // 由于vue3 与 vue2 的方法不同, 这里只介绍 composition Api 的用法
    import { getCurrentInstance } from "vue"
    export default {
        setup(){
            const { proxy } = getCurrentInstance()  // 将proxy解构出来   关键代码!!!
            proxy.$debounce(func)  // 使用方法
        }
    }

方法文档

  • 节流
    this.$debounce(function, dalay)
    
    // function 是要执行的函数
    // dalay 是延时时间,默认500
  • 防抖
    this.$throttle(function, dalay, first)
    
    // function 是要执行的函数
    // dalay 是延时时间,默认500
    // first 是否一开始就执行一次, 默认 true
  • 深度拷贝
    let data = this.$deepClone(data)
    
    // data 是要克隆的数据
  • 深度合并
    let data = this.$deepMerge(target, source)
    
    // target 是目标数据
    // source 是要合并进去的数据
  • 数组洗牌
    let newArray = this.$arrayShuffle(array)
    
    // array 是处理的数组
  • 时间戳转时间格式
    let time = this.$timeFormat(timeDate, "yyyy-mm-dd")
    
    // timeDate 时间戳
    // "yyyy-mm-dd" 是转化的时间格式
    yyyy => 年
    mm => 月
    dd => 日
    hh => 时
    MM => 分
    ss => 秒
    // 可以自由组合
  • 判断数据类型
    let type = this.$checkType(obj)
    
    // obj 是要判断的数据
    /**
     * 可供判断的数据类型
     * 'boolean',
     * 'number',
     * 'string',
     * 'function',
     * 'array',
     * 'date',
     * 'regExp',
     * 'undefined',
     * 'null',
     * 'object'
     */