Getting Started
Quick examples of the most commonly used utilities.
Filter nulls from arrays
import { notNull } from '@repo/utils'
const items = ['a', null, 'b', undefined, 'c']
const clean = items.filter(notNull)
// ['a', 'b', 'c'] -- typed as string[]
Filter object entries
import { objectFilter } from '@repo/utils'
const scores = { alice: 90, bob: 45, carol: 78 }
const passing = objectFilter(scores, (score) => score >= 50)
// { alice: 90, carol: 78 }
Format dates
import { format, parseISO, dateFormat } from '@repo/utils'
const date = parseISO('2024-06-15T10:30:00Z')
format(date, dateFormat)
// '2024-06-15'
Slugify strings
import { slugify } from '@repo/utils'
slugify('Hello World! 123')
// 'hello-world-123'
Resolve named promises
import { promiseMap } from '@repo/utils'
const result = await promiseMap({
user: fetchUser(id),
posts: fetchPosts(id),
})
// result.user, result.posts -- fully typed