numbeo-helpers
Helpers for translation data in Numbeo API.
The most basic purpose is getting russian translations of categories names used in API. These categories used in this API methods:
Prices:
- /api/price_items
- /api/city_prices
- /api/country_prices
- /api/historical_city_prices
- /api/historical_country_prices
- /api/city_prices_raw
- /api/city_prices_archive_raw
Example:
"monthLastUpdate":4 "contributors":91 "name":"Belgrade, Serbia" "prices": "average_price":5443478260869566 "item_name":"Meal, Inexpensive Restaurant, Restaurants" "highest_price":7 "item_id":1 "lowest_price":4 "average_price":18523809523809522 "item_name":"Imported Beer (0.33 liter bottle), Restaurants" "highest_price":23 "item_id":5 "lowest_price":15 "average_price":03611111111111111 "item_name":"Lettuce (1 head), Markets" "highest_price":05 "item_id":113 "lowest_price":025 "average_price":13 "item_name":"Cappuccino (regular), Restaurants" "highest_price":15 "item_id":114 "lowest_price":12 "yearLastUpdate":2012 "currency":"EUR"
Here you see array of objects named prices, and every object have item_id
. So, numbeo-helpers
working with this IDs.
Also there is one small method for getting textual version of crime and safety indices used by this API methods:
Indices:
- /api/indices
- /api/country_indices
- /api/city_crime
- /api/country_crime
Example:
"health_care_index":6675925925925927 "crime_index":3884500915750915 "traffic_time_index":17 "purchasing_power_incl_rent_index":10448707062276117 "cpi_index":7732543080858119 "pollution_index":693103448275862 "traffic_index":9360606499265447 "quality_of_life_index":1414787210994602 "cpi_and_rent_index":5815013366824719 "groceries_index":718735218572076 "safety_index":61154990842490825 "name":"Kuwait" "rent_index":3749969632054832 "traffic_co2_index":4256 "restaurant_price_index":7545173244741275 "traffic_inefficiency_index":5248906353257302 "property_price_to_income_ratio":6989395647748136
Install
$ npm install numbeo-helpers
$ yarn add numbeo-helpers
Usage
Basic:
const numbeo = ;
Debug:
const numbeo = "debug": true;
You can pass {"debug": true}
in function, so it console.log
messages, if you pass something wrong to method. If you don't pass - debug is false
by default.
API
numbeo.categoryObjectById(category_id)
Returns object of category by ID.
category_id
Type: number
, string
Example:
numbeo;
Result:
"id": 1 "category_name": "en": "Restaurants" "ru": "Рестораны" "item_name": "en": "Meal, Inexpensive Restaurant" "ru": "Порция, недорогой ресторан" "payment_type": "oneoff" "slug": "restaurants"
numbeo.nameById(category_id, [locale])
Get name of category by ID on specified language.
category_id
Type: number
, string
locale
Type: string
Default: ru
Supported: ru
, en
If locale not specified, then ru
will be used.
Example:
numbeo
Result:
Порция на двоих ресторан среднего класса три блюда
numbeo.allCategoriesByType(category)
Returns array of objects with categories of this type.
category
Type: string
Supported: restaurants
, markets
, transportation
, utilities
, sportsleisure
, childcare
, fashion
, rent
, apartments
, finance
Example:
numbeo
Result:
id: 105 category_name: en: 'Salaries And Financing' ru: 'Зарплата и финансирование' item_name: en: 'Average Monthly Net Salary (After Tax)' ru: 'Месячная (после уплаты налогов)' payment_type: 'monthly' slug: 'finance' id: 106 category_name: en: 'Salaries And Financing' ru: 'Зарплата и финансирование' item_name: en: 'Mortgage Interest Rate in Percentages (%), Yearly' ru: 'Ипотека (%, год)' payment_type: 'yearly' slug: 'finance'
numbeo.allCategoriesByPaymentType(payment_type)
Returns array of objects with categories of this payment type.
payment_type
Type: string
Supported: oneoff
, monthly
, yearly
(oneoff
means one-time payments, e.g. market purchases, taxi payments and suchlike)
Example:
numbeo
Results in:
id: 228 category_name: en: 'Childcare' ru: 'Дети' item_name: en: 'International Primary School, Yearly for 1 Child' ru: '' payment_type: 'yearly' slug: 'childcare' id: 106 category_name: en: 'Salaries And Financing' ru: 'Зарплата и финансирование' item_name: en: 'Mortgage Interest Rate in Percentages (%), Yearly' ru: 'Ипотека (%, год)' payment_type: 'yearly' slug: 'finance'
numbeo.crimeAndSafetyIndex(index, [locale])
Get text description of crime and safety index.
Returns object with text descriptions of crime and safety indices by passing crime index. In Numbeo API safety index is a number opposite to crime index, so it's decriptions is opposite too (high level of crime means low level of safety).
index
Type: number
locale
Type: string
Default: ru
Supported: ru
, en
If locale not specified, then ru
will be used.
Example:
numbeo
Results in:
"crime": "Очень низкий" "safety": "Очень высокий"
Testing
$ npm run test
License
MIT © Alexander Sharabarov