Skip to main content

modules

@epilot/pricing / Exports

@epilot/pricing

Table of contents​

Enumerations​

Interfaces​

Type Aliases​

Variables​

Functions​

Type Aliases​

AmountFormatter​

Ζ¬ AmountFormatter: ({ amount, currency, format, locale, }: { amount: number | string ; currency?: Currency ; enableSubunitDisplay?: boolean ; format?: string ; locale?: string }) => string

Type declaration​

β–Έ ({ amount, currency, format, locale, }): string

Parameters​
NameType

| { amount, currency, format, locale, } | Object | | { amount, currency, format, locale, }.amount | number | string | | { amount, currency, format, locale, }.currency? | Currency | | { amount, currency, format, locale, }.enableSubunitDisplay? | boolean | | { amount, currency, format, locale, }.format? | string | | { amount, currency, format, locale, }.locale? | string |

Returns​

string

Defined in​

src/formatters/index.ts:23


ComputeAggregatedAndPriceTotals​

Ζ¬ ComputeAggregatedAndPriceTotals: (priceItems: PriceItemsDto) => PricingDetails

Type declaration​

β–Έ (priceItems): PricingDetails

Parameters​
NameType
priceItemsPriceItemsDto
Returns​

PricingDetails

Defined in​

src/pricing.ts:43


Currency​

Ζ¬ Currency: "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SVC" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL"

ISO 4217 CURRENCY CODES as specified in the documentation Taken from https://www.iso.org/iso-4217-currency-codes.html sorted and parsed

Defined in​

node_modules/@types/dinero.js/index.d.ts:96


DineroConvertor​

Ζ¬ DineroConvertor: (unitAmountDecimal: string, currency?: Currency) => dinero.Dinero

Type declaration​

β–Έ (unitAmountDecimal, currency?): dinero.Dinero

Parameters​
NameType
unitAmountDecimalstring
currency?Currency
Returns​

dinero.Dinero

Defined in​

src/formatters/index.ts:53


PriceTierDisplayMode​

Ζ¬ PriceTierDisplayMode: Components.Schemas.PriceTierDisplayMode

Defined in​

src/types/index.d.ts:27


PricingDetails​

Ζ¬ PricingDetails: Components.Schemas.PricingDetails

Defined in​

src/types/index.d.ts:8


RelationAttributeValue​

Ζ¬ RelationAttributeValue: Object

Type declaration​

NameType
$relation{ _schema: string ; _tags: string[] ; entity_id: string }[]

Defined in​

src/pricing.ts:60


Tax​

Ζ¬ Tax: Components.Schemas.Tax

Defined in​

src/types/index.d.ts:11


TaxAmountBreakdown​

Ζ¬ TaxAmountBreakdown: Components.Schemas.TaxAmountBreakdown

Defined in​

src/types/index.d.ts:21


TimeFrequency​

Ζ¬ TimeFrequency: Exclude<BillingPeriod, "one_time">

Defined in​

src/types/index.d.ts:25


TimeFrequencyNormalizerMatrix​

Ζ¬ TimeFrequencyNormalizerMatrix: { [outputFrequency in TimeFrequency]: { [inputFrequency in TimeFrequency]: Object } }

A interface for a normalized time frequencies transformation matrix

Eg. Output must be monthly, input was yearly

timeFrequencyNormalizerMatrix.yearly.monthly

Defined in​

src/normalizers/constants.ts:15

Variables​

BillingPeriods​

β€’ Const BillingPeriods: Set<string>

Defined in​

src/pricing.ts:28


DECIMAL_PRECISION​

β€’ Const DECIMAL_PRECISION: 12

Defined in​

src/formatters/constants.ts:1


DEFAULT_CURRENCY​

β€’ Const DEFAULT_CURRENCY: "EUR"

Defined in​

src/currencies/index.ts:26


GENERIC_UNIT_DISPLAY_LABEL​

β€’ Const GENERIC_UNIT_DISPLAY_LABEL: "unit"

Defined in​

src/formatters/constants.ts:6


TaxRates​

β€’ Const TaxRates: Readonly<{ nontaxable: number = 0; reduced: number = 0.07; standard: number = 0.19 }>

Defined in​

src/pricing.ts:30


timeFrequencyNormalizerMatrix​

β€’ Const timeFrequencyNormalizerMatrix: TimeFrequencyNormalizerMatrix

A normalized time frequencies transformation matrix

See also TimeFrequencyNormalizerMatrix

Defined in​

src/normalizers/constants.ts:29

Functions​

computeAggregatedAndPriceTotals​

β–Έ computeAggregatedAndPriceTotals(priceItems): PricingDetails

Computes all the integer amounts for the price items using the string decimal representation defined on prices unit_amount field. All totals are computed with a decimal precision of DECIMAL_PRECISION. After the calculations the integer amounts are scaled to a precision of 2.

This compute function computes both line items and aggregated totals.

Parameters​

NameType
priceItemsPriceItemsDto

Returns​

PricingDetails

Defined in​

src/pricing.ts:43


computePriceComponent​

β–Έ computePriceComponent(priceItemComponent, priceMappings, parentQuantity): PriceItem

Parameters​

NameType
priceItemComponentPriceItemDto
priceMappingsPriceInputMappings
parentQuantitynumber

Returns​

PriceItem

Defined in​

src/pricing.ts:82


computePriceItemDetails​

β–Έ computePriceItemDetails(priceItem): PricingDetails

Computes the pricing details for a given PriceItem in isolation. The computed price item will be the only entry from the PricingDetails items array.

Parameters​

NameTypeDescription
priceItemPriceItemDto | CompositePriceItemDtothe price item to compute

Returns​

PricingDetails

the pricing details

Defined in​

src/pricing.ts:313


computeQuantities​

β–Έ computeQuantities(price, quantity?, priceMapping?): Object

Parameters​

NameType
pricePrice
quantity?number
priceMapping?PriceInputMapping

Returns​

Object

NameType
isUsingPriceMappingToSelectTierboolean
quantityToSelectTiernumber
safeQuantitynumber
unitAmountMultipliernumber

Defined in​

src/pricing.ts:645


extractPricingEntitiesBySlug​

β–Έ extractPricingEntitiesBySlug(priceItems): PricingEntitiesExtractResult

Extracts the pricing entities from a list of price items.

Parameters​

NameTypeDescription
priceItems(PriceItem | CompositePriceItem)[]a list of price items

Returns​

PricingEntitiesExtractResult

the product and price relations from the price items grouped by their slug.

Defined in​

src/pricing.ts:150


formatAmount​

β–Έ formatAmount(Β«destructuredΒ»): string

Parameters​

NameType
Β«destructuredΒ»Object
β€ΊΒ amountstring | number
β€ΊΒ currency?Currency
β€ΊΒ enableSubunitDisplay?boolean
β€ΊΒ format?string
β€ΊΒ locale?string

Returns​

string

Defined in​

src/formatters/index.ts:23


formatAmountFromString​

β–Έ formatAmountFromString(Β«destructuredΒ»): string

Formats a decimal amount (string) to the desired user-displayable format

Parameters​

NameType
Β«destructuredΒ»Object
β€ΊΒ currency?Currency
β€ΊΒ decimalAmountstring
β€ΊΒ enableSubunitDisplay?boolean
β€ΊΒ format?string
β€ΊΒ locale?string
β€ΊΒ precision?number
β€ΊΒ useRealPrecision?boolean

Returns​

string

  • The user-displayable formatted amount

Defined in​

src/formatters/index.ts:36


formatPriceUnit​

β–Έ formatPriceUnit(unit, hideGenericUnitLabel?): string

Formats built-in price units into a displayable representation. Eg. kw -> kW

Parameters​

NameType
unitstring
hideGenericUnitLabel?boolean

Returns​

string

the formatted unit

Defined in​

src/formatters/index.ts:54


getDisplayTierByQuantity​

β–Έ getDisplayTierByQuantity(tiers, quantity, pricingModel): PriceTier

This function returns the price tier that matches the input quantity.

Parameters​

NameTypeDescription
tiersPriceTier[]The price tiers.
quantitynumberThe quantity.
pricingModel"per_unit" | "tiered_graduated" | "tiered_volume" | "tiered_flatfee" | PricingModelThe pricing model.

Returns​

PriceTier

The selected tier.

Defined in​

src/tiers/index.ts:19


getTierDescription​

β–Έ getTierDescription(pricingModel, tier, unit, locale, currency, t, options?): string

Get the tier description for a tiered price. This function will return a string describing the price, based on the tier and unit.

Parameters​

NameTypeDescription
pricingModelPricingModel-
tierPriceTierThe price tier.
unitstringThe price unit.
localestringThe locale to use when formatting the price.
currencyCurrencyThe currency to use when formatting
t(key: string, options?: { defaultValue?: string ; ns: string }) => string-
optionsObject-
options.enableSubunitDisplay?boolean-
options.showStartsAt?boolean-

Returns​

string

The tier description.

Defined in​

src/tiers/index.ts:49


isPriceBuiltInUnit​

β–Έ isPriceBuiltInUnit(unit): unit is string

Checks whether a price unit is a built-in unit or not.

Parameters​

NameTypeDescription
unitstringthe built-in unit code or user custom unit

Returns​

unit is string

true if the unit is a built-in unit

Defined in​

src/formatters/index.ts:294


isTaxInclusivePrice​

β–Έ isTaxInclusivePrice(price): boolean

Checks whether a price is tax inclusive or not.

Parameters​

NameTypeDescription
pricePricethe price object

Returns​

boolean

true if the price is tax inclusive, false otherwise. defaults to true.

Defined in​

src/utils/index.ts:39


normalizePriceMappingInput​

β–Έ normalizePriceMappingInput(priceMapping, price): Dinero

This function takes in a quantity, block mapping number, block mapping frequency, price, and parent quantity and returns the normalized quantity. The block mapping number and block mapping frequency are used to calculate the normalized quantity. The normalized quantity is the quantity multiplied by the block mapping number and block mapping frequency. The block mapping number and block mapping frequency are converted to dinero objects and then multiplied with the quantity. The normalized quantity is then multiplied by the parent quantity and returned.

Parameters​

NameTypeDescription
priceMappingPriceInputMapping-
pricePriceThe price to be used to calculate the normalized quantity

Returns​

Dinero

The normalized quantity

Defined in​

src/normalizers/index.ts:16


normalizeTimeFrequency​

β–Έ normalizeTimeFrequency(timeValue, timeValueFrequency, targetTimeFrequency, precision?): number

This function will normalize an inputted value of a specific time frequency to the desired time frequency based on constant values defined here timeFrequencyNormalizerMatrix.

The default precision is set to 4 decimal places.

Parameters​

NameTypeDescription
timeValuenumberthe value in time that will be normalized
timeValueFrequencyTimeFrequencythe current time frequency of the value
targetTimeFrequencyTimeFrequencythe time frequency the value will be normalized to
precision?numberthe precision of the normalized value

Returns​

number

normalizedFrequencyInput

See also TimeFrequency

Defined in​

src/types/index.d.ts:28


normalizeTimeFrequencyToDinero​

β–Έ normalizeTimeFrequencyToDinero(timeValue, timeValueFrequency, targetTimeFrequency, precision?): Dinero

This function will normalize an inputted value of a specific time frequency to the desired time frequency based on constant values defined here timeFrequencyNormalizerMatrix.

The default dinerojs precision is set to 12 decimal places.

Parameters​

NameTypeDescription
timeValuenumberthe value in time that will be normalized
timeValueFrequencyTimeFrequencythe current time frequency of the value
targetTimeFrequencyTimeFrequencythe time frequency the value will be normalized to
precision?number-

Returns​

Dinero

a DineroJS object representing the normalized frequency input

See also TimeFrequency

Defined in​

src/types/index.d.ts:34


parseDecimalValue​

β–Έ parseDecimalValue(value): string

Converts a decimal string value into a valid decimal amount value, without any thousand separators, using dot as the decimal separator.

Parameters​

NameTypeDescription
valuestringThe decimal string value to convert

Returns​

string

A valid decimal amount value

Defined in​

src/formatters/index.ts:377


toDinero​

β–Έ toDinero(unitAmountDecimal, currency?): Dinero

Convert an amount decimal and currency into a dinero object.

Parameters​

NameType
unitAmountDecimalstring
currency?Currency

Returns​

Dinero

Defined in​

src/formatters/index.ts:53


toDineroFromInteger​

β–Έ toDineroFromInteger(integerAmount, currency?): Dinero

Utility mapper from Integer amount into DineroJS object using DECIMAL_PRECISION (12).

Parameters​

NameType
integerAmountnumber
currency?Currency

Returns​

Dinero

Defined in​

src/formatters/index.ts:268


toIntegerAmount​

β–Έ toIntegerAmount(decimalAmount): number

Converts a string decimal amount to an integer amount with 2 digits precision.

Parameters​

NameTypeDescription
decimalAmountstringa string decimal amount

Returns​

number

the decimal amount represent as an integer scaled to 2 decimal places precision.

Defined in​

src/formatters/index.ts:262