Skip to main content

Helpers — the "filters" of a React theme

In a pipe-based template language you'd write {{ product.price | money }}. In a Tanqory theme the same transforms are plain functions imported from @tanqory/theme-kit:

import { formatMoney, formatDate, imageUrl } from '@tanqory/theme-kit'

<span>{formatMoney(product.price)}</span>
<time>{formatDate(article.publishedAt, { dateStyle: 'medium' })}</time>
<img src={imageUrl(product.featuredImage, { width: 800 })} />

Commerce formatters​

HelperClassic filterExample
formatMoney(money)money฿1,290
formatMoneyWithCurrency(money)money_with_currency฿1,290 THB
formatMoneyWithoutCurrency(money)money_without_currency1,290
formatMoneyWithoutTrailingZeros(money)money_without_trailing_zeros฿1,290 (never .00)
formatWeight(weight)weight_with_unit1.2 kg

All money helpers take the Money shape ({ amount, currencyCode }) that every price field already uses, and format with the store's currency — not a hardcoded one.

Dates​

HelperClassic filterNotes
formatDate(input, options?, locale?)date / time_tagIntl.DateTimeFormat-style options; UTC-stable so SSR and client render identically (no hydration mismatch)

Media​

HelperClassic filterNotes
imageUrl(src, { width, height, crop })image_urlAppends CDN transform params for resized/cropped variants
—image_tagNot needed — write <img>/<picture> in JSX

Translation​

HelperClassic filterNotes
useT() → t(key)t / translateReads the theme's locale files; falls back to the key

String · array · math — just use JavaScript​

The large classic filter families are intentionally not re-implemented, because a React theme has the full language available:

Classic filterJavaScript equivalent
upcase / downcases.toUpperCase() / s.toLowerCase()
truncate: 80s.slice(0, 80) + '…'
split: ','s.split(',')
replace / removes.replaceAll(a, b)
where: 'available'items.filter(i => i.available)
map: 'title'items.map(i => i.title)
sort / reverse / uniqtoSorted() / toReversed() / [...new Set()]
first / last / sizeitems[0] / items.at(-1) / items.length
plus / ceil / modulo+ / Math.ceil() / %
jsonJSON.stringify(v)
default: 'x'v ?? 'x'
link_to, url_forJSX <a href={…}> — URLs come pre-built on objects

Current gaps​

  • Color helpers (color_lighten, color_mix, contrast checks) have no built-in equivalent yet — use CSS color-mix() / your own utilities.
  • handleize (slugify) has no exported helper — handles arrive already-built on every object, so you rarely need it.