UNPKG

@revenuecat/purchases-ui-js

Version:

Web components for Paywalls. Powered by RevenueCat

61 lines (60 loc) 3.26 kB
import type { ComponentLocalizations } from "../data/entities"; export declare const VARIABLE_NAMES: string[]; export type VariableDictionary = { product_name: string | number | undefined; price: string | number | undefined; price_per_period: string | number | undefined; price_per_period_full: string | number | undefined; total_price_and_per_month: string | number | undefined; total_price_and_per_month_full: string | number | undefined; sub_price_per_month: string | number | undefined; sub_price_per_week: string | number | undefined; sub_duration: string | number | undefined; sub_duration_in_months: string | number | undefined; sub_period: string | number | undefined; sub_period_length: string | number | undefined; sub_period_abbreviated: string | number | undefined; sub_offer_duration: string | number | undefined; sub_offer_duration_2: string | number | undefined; sub_offer_price: string | number | undefined; sub_offer_price_2: string | number | undefined; sub_relative_discount: string | number | undefined; [key: string]: string | number | undefined; }; export type ReplaceVariablesProps = { value?: string; variableDictionary?: VariableDictionary; }; /** * Returns a string with the variables replaced by values from the dictionary * @param value A string like "Try {{ product_name }} for only {{ total_price_and_per_month }}" * @param dictionary Dictionary containing the values for the variables * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)" */ export declare const replaceVariables: ({ value, variableDictionary: dictionary, }: ReplaceVariablesProps) => string | undefined; /** * Given a ComponentLocalizations object and a locale returns the label with label_id in the chosen locale, if any. Falls * back to the label with the same label_id in the fallbackLocale, if any. Finally returns undefined if no label can be * found for the requested label_id. * @param label_id - The id of the label to be returned * @param locale - The preferred locale to return the label * @param fallbackLocale - The locale to fall back to in case no label is found in the preferred one * @param labels - A ComponentLocalizations instance * @returns The label in the preferred or fallback locale, or undefined. */ export declare function getLabelById(label_id: string | null | undefined, locale: string, fallbackLocale: string, labels: ComponentLocalizations): string | undefined; /** * Gets a label by ID and replaces any variables in it with values from the dictionary * @param text_lid - The ID of the text label to retrieve * @param purchaseState - Object containing locale and defaultLocale * @param labels - ComponentLocalizations containing the labels * @param variableDictionary - Dictionary of variables to replace in the label text * @returns The label with variables replaced, or undefined if label not found */ export declare function getLabelAndReplaceVariables({ text_lid, locale, defaultLocale, labels, variableDictionary, }: { text_lid?: string; locale: string; defaultLocale: string; labels: ComponentLocalizations; variableDictionary?: VariableDictionary; }): string | undefined;