@gentleduck/libs

中文文档
1.0.0发布于 2026/05/30MITTypeScriptES Module零依赖近 30 天下载 3075

Tiny, framework-agnostic utility functions for gentleduck/ui.

原始使用文档
文档目录5 节
  1. Quick Start
  2. Utilities
  3. Performance notes
  4. Deprecations
  5. License

@gentleduck/libs

@gentleduck/libs

Tiny, framework-agnostic utility functions for gentleduck/ui.

MIT - Changelog - Contributing - Docs

npm downloads MIT


Shared utilities for the gentleduck ecosystem.

Quick Start

bun add @gentleduck/libs
import { cn } from '@gentleduck/libs/cn'

<div className={cn('base', active && 'bg-blue-500')} />

Utilities

UtilityImportDescription
cn@gentleduck/libs/cnConditional className merging (clsx + tailwind-merge)
cnMemo@gentleduck/libs/cnMemoized cn for stable class-string inputs
chunkByCounts@gentleduck/libs/chunk-by-countsPartition an array into consecutive groups by given sizes
filteredObject@gentleduck/libs/filtered-objectType-safe shallow Omit<T, K>
generateArabicSlug@gentleduck/libs/generate-arabic-slugURL-safe slug retaining Arabic script + Latin + digits
getTodayDate@gentleduck/libs/get-today-dateToday as YYYY-MM-DD in the local timezone
groupArrays@gentleduck/libs/group-arrayDeprecated. Alias for chunkByCounts (reversed params)
groupDataByNumbers@gentleduck/libs/group-data-by-numbersDeprecated. Alias for chunkByCounts
parseDate@gentleduck/libs/parse-dateParse "today", "in N days", ISO-8601, or long-form date to Date

Each utility is tree-shakeable via its own subpath export. Zero framework dependencies.

Performance notes

  • cn() allocates a fresh array on every call and walks the tailwind-merge trie on every invocation. With 1000+ import sites monorepo-wide this is the hottest className path. Hoist stable class strings out of render bodies, or use cnMemo when the inputs are stable primitive strings.
  • cnMemo keys its cache by the joined input. Do not feed it dynamic booleans / arrays / objects — that leaks memory without payoff.

Deprecations

groupArrays and groupDataByNumbers were byte-identical implementations with reversed parameter order. Both are now thin aliases over chunkByCounts and will be removed in the next major. Migrate to:

import { chunkByCounts } from '@gentleduck/libs/chunk-by-counts'

chunkByCounts(['a', 'b', 'c', 'd', 'e'], [2, 3])
// => [['a', 'b'], ['c', 'd', 'e']]

License

MIT

版本与发布记录

@gentleduck/libs 共发布 16 个版本,首次发布于 2025/09/02;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.0.0latest2026/05/305 个月前
0.2.22026/05/205 个月前
0.2.12026/05/066 个月前
0.2.02026/04/196 个月前
0.1.162026/03/158 个月前
0.1.152026/03/108 个月前

关于 @gentleduck/libs 的常见问题

@gentleduck/libs 是什么?

Tiny, framework-agnostic utility functions for gentleduck/ui.

如何安装 @gentleduck/libs?

在项目目录运行 npm install @gentleduck/libs,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:clsx(^2.1.1)、tailwind-merge(^3.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gentleduck/libs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gentleduck/libs 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gentleduck/libs 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gentleduck/libs 可以商用吗?

@gentleduck/libs 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gentleduck/libs 的下载量有多少?

根据 npm 官方下载统计,@gentleduck/libs 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,075 次,日均约 103 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gentleduck/libs 还在维护吗?

最新版本 1.0.0 发布于 2026/05/30(5 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 8 个;首次发布于 2025/09/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。