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

@longzai-intelligence-utils/core

v0.0.1

Published

Readme

@longzai-intelligence-utils/core

通用工具函数库,提供 CSS 类名处理、ID 生成、字符串处理、日期格式化、平台检测等基础能力。

概述

本包提供项目通用的工具函数,不包含业务逻辑,可被所有其他包依赖。所有函数均为纯函数,无副作用。

安装

bun add @longzai-intelligence-utils/core

快速开始

import { cn, generateId, formatDate, isMacOS } from '@longzai-intelligence-utils/core';

// CSS 类名合并
const className = cn('base-class', { active: true, disabled: false });
// 结果: 'base-class active'

// 生成唯一 ID
const id = generateId(); // 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
const shortId = generateShortId(); // 'xxxxxxxx'

// 日期格式化
const formatted = formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss');

// 平台检测
if (isMacOS()) {
  // macOS 特定逻辑
}

API 文档

CSS 类名工具

cn(...inputs: ClassValue[]): string

合并 CSS 类名,支持条件类名。

cn('foo', 'bar'); // 'foo bar'
cn('foo', { bar: true, baz: false }); // 'foo bar'
cn('foo', null, undefined, 'bar'); // 'foo bar'

ID 生成工具

generateId(): string

生成 UUID 格式的唯一标识符。

generateShortId(): string

生成 8 位短 ID。

字符串工具

truncate(str: string, length: number): string

截断字符串到指定长度。

capitalize(str: string): string

首字母大写。

camelToKebab(str: string): string

驼峰转短横线。

kebabToCamel(str: string): string

短横线转驼峰。

日期格式化工具

formatDate(date: Date | string | number, format: string): string

格式化日期。

| 格式符 | 说明 | | ------ | ------------ | | YYYY | 四位年份 | | MM | 两位月份 | | DD | 两位日期 | | HH | 24小时制小时 | | mm | 分钟 | | ss | 秒 |

formatRelativeTime(date: Date | string | number): string

格式化为相对时间(如"3 分钟前")。

formatFileSize(bytes: number): string

格式化文件大小。

平台检测工具

| 函数 | 返回值 | 说明 | | -------------- | ------- | -------------------- | | isMacOS() | boolean | 是否为 macOS | | isWindows() | boolean | 是否为 Windows | | isLinux() | boolean | 是否为 Linux | | isMobile() | boolean | 是否为移动设备 | | isElectron() | boolean | 是否为 Electron 环境 | | isBrowser() | boolean | 是否为浏览器环境 | | isNode() | boolean | 是否为 Node.js 环境 |

类型守卫

| 函数 | 说明 | | ------------------------------------------------------------ | ------------ | ----------------------- | -------- | | isNonNull<T>(value: T | null | undefined): value is T | 检查非空 | | isString(value: unknown): value is string | 检查字符串 | | isNumber(value: unknown): value is number | 检查数字 | | isObject(value: unknown): value is Record<string, unknown> | 检查对象 | | isArray(value: unknown): value is unknown[] | 检查数组 | | isFunction(value: unknown): value is Function | 检查函数 | | isPromise(value: unknown): value is Promise<unknown> | 检查 Promise | | isErrorResult<T>(result: Result<T>): result is ErrorResult | 检查错误结果 |

相关链接