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

xhbn-tools

v1.1.8

Published

提供了常用的工具函数

Downloads

14

Readme

安装

npm install xhbn-tools

使用

import {isMobile} from 'xhbn-tools'

const isMobile = isMobile();

1、金额展示处理

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | priceTofixed | string或者number 比如:1 | 保留两位小数显示 | 例 1.00 | | tenThousandFormatter | 接受3个参数 (需要转换的数字, 小数点后展示几位的数字默认是2,大于多少需要W 的单位,默认是1万) 18992 | 转换为万的 | 例 10.00W | | thousandsdFormatter | 接受1个参数 string或者number 比如19982.82 | 返回千分位逗号的数据 | 例 19,982.82 |

const price = priceTofixed(1)
console.log(price)   // 1.00

const price1 = tenThousandFormatter(100000, 2, 10e3)
console.log(price1)   // 10.00W

const price2 = thousandsdFormatter(19982.82)
console.log(price2)   // 19,982.82

2、数值计算

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | accAdd | 接受2个参数 比如 (10, 2) | 加法函数 | 例 12 | | accSub | 接受2个参数 比如 (10, 2) | 减法函数 | 例 8 | | accMul | 接受2个参数 比如 (10, 2) | 乘法函数 | 例 20 | | accDiv | 接受2个参数 比如 (10, 2) | 除法函数 | 例 5 |

const value = accAdd(10, 2)
console.log(value)   // 12

const value1 = accSub(10, 2)
console.log(value1)   // 8

const value2 = accMul(10, 2)
console.log(value2)   // 20

const value3 = accDiv(10, 2)
console.log(value3)   // 5

3、浏览器环境判断

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | isIOS | 无 | 判断 ios | true 或者false | | isMobile | 无 | 判断 移动端 | true 或者false | | isMiniProgram | 无 | 判断 内嵌的网页 小程序环境 | true 或者false | | isWeixin | 无 | 判断 微信环境 | true 或者false | | isAndroid | 无 | 判断 安卓端 | true 或者false |

const value = isIOS()
console.log(value)   // true || false

4、数据类型判断

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | isArray | 无 | 判断 数组 | true 或者false | | isNaN | 无 | 判断 NaN | true 或者false | | isNull | 无 | 判断 Null | true 或者false |

const value = isArray()
console.log(value)   // true || false

5、日期格式化

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | dateFormat | 接受2个参数 (time, format) | format 格式:{y}-{m}-{d} {h}:{i}:{s}星期{a} | 2024-03-23 09:19:36星期六 |

const value = dateFormat(new Date(), '{y}-{m}-{d} {h}:{i}:{s} 星期{a}')
console.log(value)   // 2024-03-23 09:19:36 星期六

6、其他基础支持

| 名称 | 参数 | 描述 | 返回值 | | -------- | ----------- | ----------- |----------- | | deepCopy | 接受1个参数 | 将参数深拷贝后返回 | 返回拷贝后置值 | | copyText | 接受1个参数 | 复制传入的文案 | 返回一个promise | | debounce | 接受2个参数 (fn, delay) | delay 默认是 200 | | | throttle | 接受2个参数 (fn, delay) | delay 默认是 200 | |

const value = deepCopy(new Date())
console.log(value)   // new Date()

copyText('12222').then(() => {
    <!-- 成功复制 -->
}).catch(err => {
    <!-- err  不支持复制功能 -->
})

debounce(function, 200)