Skip to main content

Function Signature

function factor(countryCode: string): number | null

Description

Retrieves the raw Price Level Ratio (PLR) for the given country code. This is the underlying PPP conversion factor from the World Bank data, representing how expensive a country is relative to the United States. The factor indicates the relative price level:
  • 1.0 = Same price level as the United States
  • < 1.0 = Lower price level (goods/services are cheaper)
  • > 1.0 = Higher price level (goods/services are more expensive)

Parameters

countryCode
string
required
The ISO country code (2-letter or 3-letter). Case-insensitive.Examples: "US", "GB", "IND", "br" (automatically converted to uppercase)Unlike the main ppp() function, this does not throw an error for invalid types—it returns null instead.

Return Value

return
number | null
The raw Price Level Ratio for the country.Returns null if:
  • The country code is not found in the database
  • The input is not a string

What the Factor Represents

The factor is the Price Level Ratio (PLR) from the World Bank’s International Comparison Program. It represents the ratio of purchasing power parity (PPP) conversion factor to the market exchange rate. Real Examples:
  • United States (US): 1.0 (baseline)
  • Switzerland (CH): ~1.5 (50% more expensive than the US)
  • United Kingdom (GB): ~0.8 (20% cheaper than the US)
  • India (IN): ~0.24 (76% cheaper than the US)
  • Brazil (BR): ~0.51 (49% cheaper than the US)
  • Nigeria (NG): ~0.43 (57% cheaper than the US)

Examples

import ppp from '@sachithrrra/ppp';

// Get factor for India
const indiaFactor = ppp.factor('IN');
console.log(indiaFactor); // 0.24 (approximate)

// Get factor for United States
const usFactor = ppp.factor('US');
console.log(usFactor); // 1.0

// Get factor for Switzerland (more expensive than US)
const switzerlandFactor = ppp.factor('CH');
console.log(switzerlandFactor); // 1.5 (approximate)

Use Cases

1. Check if Country is Supported

const countryCode = getUserCountry();
const factor = ppp.factor(countryCode);

if (factor === null) {
  // Country not in database, use default pricing
  displayPrice(defaultPrice);
} else {
  // Calculate adjusted price
  displayPrice(ppp(defaultPrice, countryCode));
}

2. Display Discount Information

const factor = ppp.factor('IN');
if (factor !== null) {
  const savingsPercent = Math.round((1 - factor) * 100);
  console.log(`Save ${savingsPercent}% with regional pricing!`);
}

3. Build Custom Pricing Logic

// Use the raw factor for completely custom calculations
const factor = ppp.factor(userCountry);
if (factor !== null && factor < 0.5) {
  // Apply special student discount only in low-income countries
  price = applyStudentDiscount(basePrice * factor);
}
  • ppp() - Calculate PPP-adjusted prices with smoothing and rounding

Build docs developers (and LLMs) love