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

@via-cli/utils-core

v0.0.2

Published

Utility functions for core

Readme

@via-cli/core

通用工具函数集合,用于 FundComponents 项目的轻量工具库,包含数字格式化、深拷贝、防抖等常用方法,方便在组件或服务中复用。

目录

  • 简介
  • 安装
  • 快速开始
  • API
  • 开发与测试
  • 贡献

简介

此包导出一个命名空间 Core,在其中包含若干实用函数:

  • formatNumber(num: number): string — 将数字格式化为千分位显示。示例

包信息(来自 package.json):

  • 名称:@via-cli/core
  • 版本:0.0.1

安装

推荐使用 pnpm(本仓库使用 pnpm workspace):

cd <your-project>
pnpm add @via-cli/core

使用 npm/yarn 同样适用:

npm install @via-cli/core
# 或
# yarn add @via-cli/core

在 monorepo 或本地开发时,可在根目录使用 workspace 连接或直接在本包中运行构建/开发脚本。

快速开始

示例(TypeScript / ESM):

import { Core } from '@via-cli/core'

// 千分位
console.log(Core.formatNumber(1234567.89)) // "1,234,567.89"

// 深拷贝
const a = { x: 1, y: { z: [1, 2] } }
const b = Core.deepClone(a)
console.log(b)

// 防抖
const fn = (v: string) => console.log('called', v)
const debounced = Core.debounce(fn, 200)
debounced('a')
debounced('b')

API

所有导出都位于 Core 命名空间内:

  • formatNumber(num: number): string

    • 描述:使用浏览器/运行时的本地化规则将数字格式为包含千分位的字符串。
    • 参数:num 要格式化的数字。
    • 返回:格式化后的字符串。
  • deepClone(obj: T): T

    • 描述:对对象或数组进行深拷贝。会处理 Date、数组与普通对象,基础类型直接返回。
    • 参数:obj 要克隆的对象或数组。
    • 返回:克隆后的对象。
  • debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters) => void

    • 描述:返回一个防抖函数;在连续调用时会延迟执行,直到最后一次调用后经过 delay 毫秒才运行。
    • 参数:func 目标函数,delay 延迟毫秒数。
    • 返回:防抖包装后的函数(返回值被忽略,回调以异步方式触发)。

开发与测试

仓库使用 TypeScript + tsup 构建,测试框架为 Vitest。常用命令(在包目录运行或通过 workspace 转发):

# 安装依赖(在仓库根目录运行)
pnpm install

# 本包:开发(watch)
cd playground/utils; pnpm run dev

# 构建
cd playground/utils; pnpm run build

# 运行测试
cd playground/utils; pnpm run test

# 以 UI 模式运行 Vitest
cd playground/utils; pnpm run test:ui

# 生成覆盖率
cd playground/utils; pnpm run coverage

贡献

欢迎提交 issue/PR。贡献流程请参考仓库根目录的 CONTRIBUTINGDEVELOPMENT_GUIDE.md

提交变更建议遵循:

  • 小而清晰的 PR,每个 PR 包含变更说明与测试(如适用)。
  • 运行 pnpm run buildpnpm run test 确保没有回归。