Skip to main content

Function Signature

function ppp(
    originalPrice: number,
    countryCode: string,
    smoothing?: number,
    rounding?: RoundingStrategy
): number | null

Description

Calculates the Purchasing Power Parity (PPP) adjusted fair price in USD for a given country. This function applies a country-specific price level ratio to adjust your pricing based on local purchasing power, with optional smoothing and rounding strategies.

Parameters

originalPrice
number
required
The base price in USD (International Dollars). Must be a non-negative number.Validation: Throws an error if not a number or if negative.
countryCode
string
required
The ISO country code (2-letter or 3-letter). Case-insensitive.Examples: "US", "GB", "IND", "br" (automatically converted to uppercase)Validation: Throws an error if not a string.
smoothing
number
default:"0.2"
A value between 0 and 1 to normalize the price discount.
  • 0 = Raw PPP (Theoretical / Maximum Discount)
  • 0.2 = Default (Balanced Discount)
  • 1 = No adjustment (Original Price)
Validation: Must be a number between 0 and 1 (inclusive). Throws an error if outside this range.
rounding
RoundingStrategy
default:"'none'"
Rounding strategy for the final price. Must be one of:
  • 'none' = Full precision (no rounding)
  • 'currency' = Standard currency rounding (2 decimal places)
  • 'pretty' = Marketing-friendly rounding:
    • < $10: Round to x.99 or x.49 (e.g., 4.31 → 4.49, 7.89 → 7.99)
    • 1010 - 100: Round to nearest whole number (e.g., 43.2 → 45, 48.7 → 49)
    • > $100: Round to nearest 5 (e.g., 132 → 130, 138 → 140)
Validation: Throws an error if not one of the valid strategies.

Return Value

return
number | null
The PPP-adjusted price in USD.Returns null if:
  • The country code is not found in the database
  • The country code is invalid (though validation errors are thrown first)

How It Works

The function applies the following formula:
adjustedFactor = factor + (1 - factor) * smoothing
finalPrice = originalPrice * adjustedFactor
Where factor is the country’s Price Level Ratio from the World Bank data.

Examples

import ppp from '@sachithrrra/ppp';

// $29 product for India with default smoothing
const price = ppp(29, 'IN');
console.log(price); // ~9.87 (India has ~0.24 factor)

// Same product for Brazil
const brazilPrice = ppp(29, 'BR');
console.log(brazilPrice); // ~15.95 (Brazil has ~0.51 factor)

Type Definitions

type RoundingStrategy = 'none' | 'currency' | 'pretty';

Build docs developers (and LLMs) love