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

@zero-bits/taro-utils

v1.0.1

Published

Zero-Bits Taro Utils Library

Readme

@zero-bits/taro-utils

Taro 项目通用工具库,目前提供:

  • mathUtil — 基于 number-precision 的精确浮点运算工具
  • getUUID — 生成符合 RFC 4122 v4 规范的 UUID

安装

# npm
npm install @zero-bits/taro-utils

# pnpm
pnpm add @zero-bits/taro-utils

mathUtil

解决 JavaScript 浮点运算精度丢失问题(如 0.1 + 0.2 !== 0.3),所有方法均支持传入 number 或 string,非法值自动视为 0。

import { mathUtil } from '@zero-bits/taro-utils'

mathUtil.add(0.1, 0.2)          // 0.3
mathUtil.sub(1.0, 0.9)          // 0.1
mathUtil.mul(3, 0.3)            // 0.9
mathUtil.div(1.21, 1.1)         // 1.1
mathUtil.floor(3.14159, 2)      // 3.14

// 支持字符串输入(常见于表单、接口返回值场景)
mathUtil.add('0.1', '0.2')      // 0.3
mathUtil.mul('9.99', '100')     // 999

// 链式多参数运算(可变参数)
mathUtil.add(1, 2, 3, 4)        // 10
mathUtil.mul(2, 3, 4)           // 24

API

| 方法 | 参数 | 返回值 | 说明 | |------|------|--------|------| | add(...numbers) | (number \| string)[] | number | 精确加法,支持多个参数 | | sub(...numbers) | (number \| string)[] | number | 精确减法,支持多个参数 | | mul(...numbers) | (number \| string)[] | number | 精确乘法,支持多个参数 | | div(...numbers) | (number \| string)[] | number | 精确除法,支持多个参数 | | floor(value, precision) | number, number | number | 四舍五入保留指定小数位 | | core | — | NP | 原始 number-precision 实例,可调用底层方法 |

非数字字符串(如 ''、'abc'、undefined)会被安全转换为 0,不会抛出异常。

getUUID

生成符合 RFC 4122 v4 规范的 UUID 字符串,格式为 xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx。

import { getUUID } from '@zero-bits/taro-utils'

getUUID() // 'a3bb189e-8bf9-3888-9912-ace4e6543002'
getUUID() // 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

常见用途:

// 列表项的临时 key
const items = data.map(item => ({ ...item, _key: getUUID() }))

// 请求的唯一追踪 ID
const traceId = getUUID()
await http.post('/api/submit', { traceId, ...payload })

// 表单字段唯一标识
const fieldId = getUUID()

License

MIT