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

dhc-tool

v1.0.6

Published

js工具代码

Downloads

19

Readme

dhc-tool

js工具代码

使用方式:
  1. 使用方式一:通过 npm 导入使用
import utils from 'dhc-tool';

utils.trim("......");
utils.format("2022-12-18 12:00:00")
  1. 使用方式二:通过编译后在浏览器中使用。链接地址:

集成有:
校验类:
  • isNull:是否是一个null
  • isUndefined:是否是一个undefined
  • isString:是否是一个字符串
  • isNumber:是否是一个数字
  • isArray:是否是一个数组
  • isObject:是否是一个对象
  • isPromise:是否是一个promise
  • isPhoneNumber:是否是一个手机号
  • isEmail:是否是一个邮箱
  • isAndroid:是否是安卓设备
  • isiOS:是否是ios设备
  • isWeixin:是否是微信浏览器
工具类:
  • trim:去除首尾空字符

  • concatString:字符串拼接

  • debounce:防抖

  • throttle:节流

  • Log:日志收集

  • Interval:倒计时

    const interval = new dhcTool.Interval(function(){
        // 倒计时每次触发执行函数
    }, 1000)
    
    // 清除倒计时
    interval.$clear()
  • Online:网络状态监控

    const NW = new dhcTool.Online({
        //正常网络
        online: ()=>{ ... },
        //弱网
        lowline: ()=>{ ... },
        //断网
        offline: ()=>{ ... }
    })
    // 设置弱网判断阀值,默认400
    NW.defaults.rtt = 100;
  • loadScript:脚本读取

    // 回调写法
    dhcTool.loadScript(url, function(){
    	// 加载成功
    }, function(){
    	// 加载失败
    })
    
    // promise写法
    dhcTool.loadScript(url).then(function(){
    	// 加载成功
    }).catch(function(){
    	// 加载失败
    })
  • loadCss:样式读取

    // 回调写法
    dhcTool.loadCss(url, function(){
    	// 加载成功
    }, function(){
    	// 加载失败
    })
    
    // promise写法
    dhcTool.loadCss(url).then(function(){
    	// 加载成功
    }).catch(function(){
    	// 加载失败
    })
时间日期:
  • format:时间日期转换

    dhcTool.format('2022-12-01', 'YYYY-MM-DD hh:mm:ss'); // 2022-12-01 00:00:00
    
    dhcTool.format('2022/12/01 13:33:00', 'YY-MM-DD hh:mm:ss') // 22-12-01 13:33:00
    
    dhcTool.format(1670061437001, 'YYYY/MM/DD hh:mm:ss') // 2022/12/03 17:57:17
  • getDate:转换为 *分钟前、*天前、*月前

    dhcTool.getDate(1670061437001) // 20分钟前
    
    // 可传入服务器当前时间(1670063374674),更精确!!!跨时区时建议使用
    dhcTool.getDate(1670061437001, 1670063374674) // 32分钟前
存储类:
  • cookie:cookie操作

  • storage:storage操作,不需要处理转换数据类型,存入什么,取出来就是什么!!!

    // 设置 localstroage
    dhcTool.stroage.set(key, value)
    // 读取 localstroage
    dhcTool.stroage.get(key)
    
    // 设置 sessionstroage
    dhcTool.stroage.set(key, value, true)
    // 读取 sessionstroage
    dhcTool.stroage.get(key, true)
计算类:
  • toFixed:四舍五入

    dhcTool.toFixed('44.5678', 2) //保留2位小数
    dhcTool.toFixed(44.555, 2) //保留2位小数
  • math:四则运算对象(add 加法、subtract 减法、multiply 乘法、divide 除法)

    dhcTool.math.add(0.1, 0.2) // 0.3
    dhcTool.math.add(0.1, '0.2') // 0.3