Skip to main content

gentleduck/libs

A collection of tiny, framework-agnostic utility functions. Each utility lives in its own folder and can be imported individually or all together.

Philosophy

UI components use a handful of helpers - cn for class merging, formatters, assertion functions. gentleduck/libs collects them in one typed package so you do not pull in lodash for three functions.


Installation


npm install @gentleduck/libs

npm install @gentleduck/libs

Loading diagram...

Available Utilities

  • cn - Utility for conditional className merging.
  • cnMemo - Memoized cn for primitive string inputs; for hot-path callers (LRU cache, bounded to 256 entries).
  • filtered-object - Create a new object by excluding specified keys.
  • chunkByCounts - Split an array into consecutive groups whose sizes are given by a sizes array.
  • group-array, group-data-by-numbers - Deprecated aliases for chunkByCounts with different parameter orders; use chunkByCounts instead.
  • parse-date - Parse strings or values into valid Date objects.
  • generateArabicSlug - Convert text to URL slugs preserving Arabic characters.
  • getTodayDate - Return today's date as a YYYY-MM-DD string.
  • index.ts - Barrel file that re-exports utilities.

Usage

import { cn } from '@gentleduck/libs'

function MyComponent({ active }: { active: boolean }) {
  return (
    <div className={cn('rounded-md border p-4', active && 'bg-primary text-primary-foreground')}>
      Hello
    </div>
  )
}