Core Utilities and Helpers
This page focuses on core utilities and helpers that are used across various aspects of Limio development. These tools are designed to simplify common tasks and provide consistent functionality.
LimioAppSettings
LimioAppSettings is an object that provides access to global application settings. It offers getter methods for retrieving configured settings within components.
Available Methods
getDateFormat(): Retrieves the configured date format.
Usage
import { LimioAppSettings } from "@limio/sdk";
const dateFormat = LimioAppSettings.getDateFormat();Limio Component Props
Limio provides a hook and a helper function for managing component props.
useComponentProps
A hook that takes an object of optional default props and makes them available throughout the component.
getPropsFromPackageJson
A helper function that retrieves default values from the package.json file.
Usage
External Libraries
Limio exports some external libraries for common tasks:
DateTimefrom Luxon: For date handling
If you need additional exports, please contact Limio support.
sanitiseHTML
An HTML sanitisation function that should be used whenever injecting content from offers into the DOM. It uses DOMPurify under the hood with an HTML profile and automatically adds security attributes to links (e.g. rel="noopener noreferrer" on target="_blank" links).
Important: Always use
sanitiseHTMLwhen rendering user-controlled or offer-sourced HTML content withdangerouslySetInnerHTMLor similar patterns. This prevents XSS attacks from malicious content in offer attributes.
Function Signature
Parameters
dirty(optional):string- The HTML string to sanitise. Defaults to"".
Returns
string- The sanitised HTML string, safe for DOM insertion.
Usage
Behaviour Notes
Strips all non-HTML-safe tags and attributes.
Preserves the
targetattribute on links.Automatically adds
rel="noopener noreferrer"to links withtarget="_blank", andrel="noopener"to links with other target values.Throws an error if called in a non-browser environment without DOM support (a Node.js version is available internally for SSR).
ErrorBoundary
A React error boundary component that catches JavaScript errors in its child component tree and displays a fallback UI. Errors are automatically reported to Sentry.
Limio wraps individual components in an error boundary as part of the build step, so it is not necessary to use at the top level. However, ErrorBoundary is useful for wrapping specific children that may error where the parent component should remain functional.
Props
children:React.ReactNode- The component tree to wrap.ErrorUI(optional):React.ComponentType<{ error: Error }>- A custom component to render when an error is caught. Defaults to a built-in error display.
Usage
With a custom error UI:
Behaviour Notes
Catches errors during rendering, in lifecycle methods, and in constructors of child components.
Does not catch errors in event handlers — use try/catch for those.
Logs all caught errors to Sentry with component stack info.
A HOC version is also available:
withErrorBoundary(Component, ErrorUI).
Formatters
Limio provides utility functions for formatting data:
formatDate
Formats an ISO date string into a human-readable date format based on the specified format type or the default Limio app locale settings.
Parameters:
date: string An ISO 8601 date string (e.g.,
"2023-12-14T11:19:29.442Z") that represents the date and time to be formatted.format (optional): string A string representing the desired date format. Supported formats include:
"DATE_EN":"14 Dec 2023""DATE_FULL":"December 14, 2023""DATE_SHORT":"14/12/2023""DATE_MED":"Dec 14, 2023"
If not provided, the function defaults to the Limio app locale settings.
formatDisplayPrice
Formats a string by replacing placeholders with corresponding values from a given price object, allowing dynamic price information to be displayed in a consistent and customisable format.
Parameters:
string: string A template string containing placeholders (e.g., {{currencyCode}}, {{amount}}) to be replaced with values from the offerPrice object.
offerPrice: Array<LimioPrice> An array of price objects, with the first element being used to extract pricing information.
formatCurrency
Formats a currency amount with the specified currency code.
Parameters:
amount: string The amount to formatcurrencyCode: string The currency code (e.g., 'USD', 'EUR')locality(optional): string Specifies the locale for formatting
formatCurrencyForCurrentLocale
Formats a currency amount using the user's current locale, determined from the limio-country cookie. This is a convenience wrapper around formatCurrency that automatically resolves the locale — use this when you want locale-aware formatting without manually specifying a locale.
Parameters:
amount:number | stringThe amount to format.currency:stringThe ISO 4217 currency code (e.g.,"GBP","USD","EUR").
Returns:
A formatted currency string using the browser's
Intl.NumberFormatAPI.
Use
formatCurrency(documented above) if you need to specify a locale explicitly.
formatCountry
Converts an alpha-2 country code into the full name of the corresponding country. Useful for displaying country information in a user interface.
Parameters:
country: string (required) An alpha-2 country code (e.g., "GB" for the United Kingdom).
Returns:
A string of the full name of the country corresponding to the provided alpha-2 country code. If the country code is not found, the return value might be undefined or an empty string.
addressSummary
Takes a Limio address object and returns a string consisting of the populated values. If no address values are found, the helper returns N/A.
Parameters:
address: LimioAddressObject An object containing the address details.
Returns:
A string representation of the address (e.g., "123 John Street, London, EC1 25X"), or "N/A" if no address values are found.
Address Helpers
Limio provides address helpers functions for retrieving address specific data, for all countries in the Limio Country list.
getAddressMetadata
Retrieves address metadata based on the provided alpha-2 country code, determining which address fields are required and which fields should be rendered in a form. Useful for creating dynamic forms that adjust input fields according to the selected country.
Parameters:
country: string An alpha-2 country code (e.g., "CA" for Canada). This code is used to look up country-specific address metadata.
Returns:
AddressMetadata An object containing:
requiredAddressFields: string[]: Required fields (e.g., "address1", "city", "postalCode", "state", "country").
addressFieldsToRender: string[]: Fields to render in the form (e.g., "address1", "address2", "city", "state", "postalCode", "country").
getCountryMetadata
Retrieves and returns metadata related to a specific country based on the provided alpha-2 country code. Useful for accessing country-specific information such as the full country name, telephone country code, and more.
Parameters:
country: string An alpha-2 country code (e.g., "GB" for the United Kingdom).
Returns:
CountryMetadataType An object containing metadata such as:
name: string: The full name of the country (e.g.,
"United Kingdom").alpha-2: string: The alpha-2 country code (e.g.,
"GB").alpha-3: string: The alpha-3 country code (e.g.,
"GBR").country-code: string: The numeric country code (e.g.,
"826").
Example Output:
Offer Helpers
useOfferInfo
A small utility hook that extracts a few commonly needed fields from an offer object into a flat structure. Useful for avoiding repetitive deep property access on offer attributes.
Function Signature
Parameters
offer:LimioObject<Offer>- The offer object to extract info from.
Returns
An OfferInfo object with the following fields:
allowMultibuy
boolean
allow_multibuy__limio attribute
offerDescription
string
mma_description__limio attribute
hasRecurringCharge
boolean
true if any price has type: "recurring"
isDelivery
boolean
true if any product has has_delivery__limio
productNames
string[]
Array of product names
isAutoRenew
boolean
autoRenew__limio attribute
offerImage
Attachment
First image attachment
usesExternalPrice
boolean
use_external_price from first price
isGift
boolean
is_redeem_gift__limio attribute
displayName
string
Product display name, or offer group label as fallback
Usage
checkActiveOffers
Filters an array of offers to return only those that are currently active based on their start and end dates. Offers are sorted by start date.
Function Signature
Parameters
offers(optional):LimioObject<Offer>[]- Array of offers to filter. Defaults to[].includeFuture(optional):boolean- Whentrue, includes offers with a future start date. Defaults tofalse.
Returns
LimioObject<Offer>[]- Filtered array of currently active offers, sorted by start date.
Filtering Logic
An offer is considered active when:
It has no end date, OR its end date is on or after the current date.
If
includeFutureisfalse(default), the offer's start date must also be on or before the current date.
Usage
Including future-dated offers (e.g. for showing upcoming subscription terms):
Fetchers
Limio provides wrapper functions for fetching data from external services.
LimioFetchers.invoiceFetch
Fetches invoice data from Zuora.
Last updated
Was this helpful?

