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

@wang-weilin/tools

v1.0.2

Published

木木的npm包,公用方法库

Readme

常用方法库

木木的工具库,后续继续添加常用方法库

简介

工具库会覆盖常用的方法,目前比较少,待后续继续添加

前序准备

啦啦啦啦

开发

# 安装
npm i @wang-weilin/tools

#使用
const tools = require('@wang-weilin/tools')

方法使用

常用方法

# getQueryObject-url解析的使用方法
const parmas = tools.getQueryObject('https://www.baidu.com?&name=百度&time=123')
parmas = {
    name: 百度,
    time: 123
}

# debounce-防抖的使用方法
tools.debounce(function(){},1000)

# deepClone-深克隆的使用方法
let proObj = {}
const obj = tools.deepClone(proObj)

# ShiftObjKeyValue-对象key-value交换的使用方法
let proObj = {
    1:男,
    2:女
}
const obj = tools.deeShiftObjKeyValuepClone(proObj)
obj = {
    男: 1,
    女: 2
}

# formatTenThousand-格式转换11000,使用1.10万表示
const num = tools.formatTenThousand(11000)

# formatThousand-格式转换11000,使用1.10k表示
const num = tools.formatThousand(1100)

# intervalNum-格式转换第一种方式: 1234567,使用123,456,7表示
const num = tools.intervalNum(1234567)

# intervalNum2-格式转换第二种方式
// intervalNum2:接收俩个参数,第一个是数字,第二个是保留的小数,默认是俩位
// intervalNum2(12345.1,2); // "12,345.10
const num = tools.intervalNum2(1234567)

# format-格式化时间
// format:接收俩个参数,第一个是毫秒级时间戳,第二个返回的时间格式,默认:YYYY-MM-DD HH:mm:ss
// 自定义格式:例如: YYYY/MM/DD HH:mm:ss 等
// format(1656748807581); // 2022-07-02 16:00:07
const num = tools.format(1656748807581, 'YYYY-MM-DD HH:mm:ss')

# remainTime-获取倒计时剩余时间,相对于当前时间
// remainTime:接收一个毫秒级时间戳,返回数据格式{dd: '天', hh: '时', mm: '分', ss: '秒'}
// remainTime(165674807581); // { dd: '02', hh: 10, mm: 19, ss: 25 }
const num = tools.remainTime(1656959182583)

# secondToFormatDuration-将秒数转化为时长
// secondToFormatDuration:接收一个秒级时间戳,返回数据格式1h:3m:30s
// secondToFormatDuration(3810); // 1h:3m:30s
const num = tools.secondToFormatDuration(3810)

# desensitizationString-字符串脱敏处理,常用于电话,身份证,银行卡号脱敏站在展示
// desensitizationString:接收三个参数:第一个是需要脱敏的字符串,第二个:前面展示的字符串长度默认是3,第三个是:后面展示的字符串长度默认是4
// desensitizationString(15588881234,3,4); // 155****1234
const num = tools.secondToFormatDuration(15588881234)

正则表达式规则

# isCardId-身份证校验
onnst carId = ****;
const bool =  tools.isCardId(carId)

# isPhoneNo-手机号校验
onnst phone = 15539991111;
const bool =  tools.isPhoneNo(phone)

# isEmail-邮箱校验
onnst qq = [email protected];
const bool =  tools.isEmail(qq)

# checkPassword-验证码校验
onnst code = 123456;
const bool =  tools.checkPassword(code)