Skip to content
cansukaluc.dev

Lab · Library

@cansukaluc/utils

A small, zero-dependency, fully-typed and tree-shakable utility library. The playground below runs the real published package in your browser — edit any call and run it.

$ npm install @cansukaluc/utils

demonstrates: API design · TypeScript · 100% test coverage · npm publishing · tree-shaking

Live playground

Not a mock — your input is evaluated against the actual functions.

chunk<T>(items: readonly T[], size: number): T[][]

Split an array into fixed-size groups. The final chunk may be shorter.

or press ⌘/Ctrl + Enter

API

  • chunk<T>(items: readonly T[], size: number): T[][]

    Split an array into fixed-size groups. The final chunk may be shorter.

  • groupBy<T, K>(items, keyFn): Record<K, T[]>

    Group items by the key returned from a function.

  • uniqueBy<T, K>(items, keyFn): T[]

    Remove duplicates, keeping the first occurrence by key.

  • clamp(value: number, min: number, max: number): number

    Restrict a number to an inclusive range.

  • slugify(input: string): string

    Turn any string into a URL-friendly slug (accents stripped).

  • retry<T>(fn, options?): Promise<T>

    Retry an async function with exponential backoff.