Util Package

Shared utility functions across the monorepo

Overview

@zooly/util is a shared utility package that provides common helper functions used across multiple packages and apps in the monorepo.

Package Details

  • Package Name: @zooly/util
  • Location: packages/util
  • Type: Utility library

Key Features

  • Shared utility functions
  • Common constants
  • Helper functions for various operations

Utilities

The package includes utilities for:

  • Constants: Shared constants
  • Currency Utils: Multi-currency support with zero-decimal currency handling
  • Extract Inline Scripts: Extract inline scripts from HTML
  • Extract Inline Styles: Extract inline styles from HTML
  • Fetch Location: Location-related utilities
  • Log Event: Event logging utilities
  • Stripe Utils: Stripe payment and currency formatting utilities
  • General Utils: Common utility functions

Currency Utilities

File: packages/util/src/utils/currency.ts

Centralized utilities for handling multi-currency amounts, including zero-decimal currencies (e.g. JPY, KRW where 1 minor unit = 1 whole unit):

FunctionDescription
isZeroDecimalCurrency(currency)Returns true for currencies with no decimal places (JPY, KRW, etc.)
getMinorUnitMultiplier(currency)Returns 100 for normal currencies, 1 for zero-decimal
getDecimalPlaces(currency)Returns 2 for normal currencies, 0 for zero-decimal
minorUnitToMajor(amount, currency)Converts minor units to major: 1000 USD → 10.00, 1000 JPY → 1000
majorToMinorUnit(amount, currency)Converts major to minor units: 10.00 USD → 1000, 1000 JPY → 1000

Stripe Utilities

File: packages/util/src/utils/stripe-utils.ts

FunctionDescription
formatMinorUnitToDisplay(amountMinorUnit, currency?)Formats an amount for display using Intl.NumberFormat with the correct currency symbol and decimal places. Defaults to "USD".
calculateStripeFees(amountMinorUnit, currency?)Calculates Stripe processing fees. The fixed fee ($0.30) is set to 0 for zero-decimal currencies.

Dependencies

  • @zooly/types for shared types
  • AI SDK providers (Anthropic, Google, OpenAI)
  • Date-fns for date manipulation
  • Zod for validation
  • Parse5 for HTML parsing

Usage

This package provides reusable utility functions that can be imported by any package or app in the monorepo, reducing code duplication and ensuring consistency.