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

magnify-count

v1.0.2

Published

边界闭合的平滑数值放大算法,用于冷启动阶段优雅地虚增统计数字。

Readme

magnify-count

边界闭合的平滑虚构人数算法 —— 在展示统计数时,针对冷启动数字较小的情况进行虚增放大,使数据看起来更"漂亮"。

🤖 本项目完全由 AI 生成,包括代码、文档、构建配置等。

特性

  • 平滑过渡:从冷启动到真实值之间,虚增部分自动平滑衰减
  • 边界闭合:达到设定阈值后自动显示真实数值,不会出现跳变
  • 零依赖:纯函数实现,无外部依赖
  • ESM + CJS:同时支持 importrequire

安装

npm install magnify-count

使用

import magnifyCount from 'magnify-count';
// 或
const magnifyCount = require('magnify-count');

API

magnifyCount(actualCount, maxRealValue, initialMultiplier?)

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | actualCount | number | ✅ | - | 实际人数 | | maxRealValue | number | ✅ | - | 达到此真实人数后不再虚增 | | initialMultiplier | number | ❌ | 3 | 初始起步倍数 |

返回值number - 最终展示的人数(向下取整)

示例

import magnifyCount from 'magnify-count';

// 实际只有 5 人,设定 100 为上限,默认 3 倍起步
magnifyCount(5, 100);    // => 18

// 实际有 50 人,接近上限时虚增逐渐减少
magnifyCount(50, 100);   // => 81

// 达到或超过上限,直接返回真实人数
magnifyCount(100, 100);  // => 100
magnifyCount(150, 100);  // => 150

// 自定义初始倍数
magnifyCount(10, 200, 5); // => 48

算法原理

核心公式:

展示值 = x + ((M - 1) × x × (L - x)) / (L + (M - 1) × x)

其中 x 为实际人数,L 为上限阈值,M 为初始放大倍数。

虚增部分 ((M - 1) × x × (L - x)) / (L + (M - 1) × x) 会随着 x 趋近 L 而自动衰减至 0,保证在阈值处与真实值无缝衔接。

License

MIT