@gentleduck/libs
v1.0.0
Published
Tiny, framework-agnostic utility functions for gentleduck/ui.
Downloads
217
Maintainers
Readme
Shared utilities for the gentleduck ecosystem.
Quick Start
bun add @gentleduck/libsimport { cn } from '@gentleduck/libs/cn'
<div className={cn('base', active && 'bg-blue-500')} />Utilities
| Utility | Import | Description |
| --- | --- | --- |
| cn | @gentleduck/libs/cn | Conditional className merging (clsx + tailwind-merge) |
| cnMemo | @gentleduck/libs/cn | Memoized cn for stable class-string inputs |
| chunkByCounts | @gentleduck/libs/chunk-by-counts | Partition an array into consecutive groups by given sizes |
| filteredObject | @gentleduck/libs/filtered-object | Type-safe shallow Omit<T, K> |
| generateArabicSlug | @gentleduck/libs/generate-arabic-slug | URL-safe slug retaining Arabic script + Latin + digits |
| getTodayDate | @gentleduck/libs/get-today-date | Today as YYYY-MM-DD in the local timezone |
| groupArrays | @gentleduck/libs/group-array | Deprecated. Alias for chunkByCounts (reversed params) |
| groupDataByNumbers | @gentleduck/libs/group-data-by-numbers | Deprecated. Alias for chunkByCounts |
| parseDate | @gentleduck/libs/parse-date | Parse "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 thetailwind-mergetrie on every invocation. With 1000+ import sites monorepo-wide this is the hottest className path. Hoist stable class strings out of render bodies, or usecnMemowhen the inputs are stable primitive strings.cnMemokeys 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
