Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swizec/bigmac-index-price-calculator
Pricing based on Big Mac Index purchasing power parity 🍔
https://github.com/swizec/bigmac-index-price-calculator
Last synced: 3 days ago
JSON representation
Pricing based on Big Mac Index purchasing power parity 🍔
- Host: GitHub
- URL: https://github.com/swizec/bigmac-index-price-calculator
- Owner: Swizec
- Created: 2019-08-21T05:34:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T23:38:10.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T09:20:46.155Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 1.05 MB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Big Mac Index Price Calculator 🍔
The Big Mac Index is a purchasing power parity index published by The Economist. It aims to compare purchasing power across the world using the price of a Big Mac.
This library makes it easy to use big mac purchasing power parity in your projects.
You'll need an [ipstack](https://ipstack.com/) API key. Free tier will do just fine. The library uses it to geolocate your users and calculate a fair price based on your American price.
By default there is no currency conversion. Prices come back in USD, adjusted for purchasing power.
The library is designed so it doesn't break server-side rendering. ✌️
## How to use 🍔
```bash
yarn add bigmac-index-price-calculator
```Install `bigmac-index-price-calculator`
```javascript
import { ParityPrice } from "./index";const parity = new ParityPrice(``);
const fairPrice = await parity.price(149)
````fairPrice` now contains the fair price for your product.
### Displaying location
You might want to tell your users that prices have been adjusted for purchasing power parity. Set the meta flag to include the full response from ipstack.
```javascript
import { ParityPrice } from "./index";const parity = new ParityPrice(``);
const { fairPrice, location } = await parity.priceWithLocation(149)
```This includes currency information, if you have a paid ipstack API key.
### Using on the backend
You can optionally provide an IP argument to use a custom IP. Useful on a server where you see the user's IP in your request handler and don't want to fetch pricing info in the name of your server.
```javascript
import { ParityPrice} from "./index";const parity = new ParityPrice(``);
const { fairPrice, location } = await parity.price(149, '68.188.8.242')
```### SSL requests
If your ipstack API key supports it, you can enable SSL.
```javascript
import { ParityPrice} from "./index";const parity = new ParityPrice(``, true);
```# License
MIT