import ppp from '@sachithrrra/ppp';// Calculate a fair price for a $10 product in Sri Lankaconst fairPrice = ppp(10, 'LK');console.log(fairPrice); // Output: 4.3108...
The function returns null for invalid country codes and throws errors for invalid parameters:
import ppp from '@sachithrrra/ppp';// Invalid country code returns nullconst result = ppp(10, 'INVALID');console.log(result); // null// Invalid parameters throw errorstry { ppp(-10, 'US'); // Negative price} catch (error) { console.error(error.message); // "Original price must be a non-negative number."}try { ppp(10, 'US', 2); // Smoothing out of range (0-1)} catch (error) { console.error(error.message); // "Smoothing must be a number between 0 and 1."}try { ppp(10, 'US', 0.2, 'invalid'); // Invalid rounding strategy} catch (error) { console.error(error.message); // "Rounding must be one of: 'none', 'currency', 'pretty'."}
Always validate country codes and handle null returns gracefully in production code. Consider using a fallback to your standard pricing when PPP data is unavailable.