-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
30 lines (26 loc) · 919 Bytes
/
Copy pathcommon.js
File metadata and controls
30 lines (26 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Imports:
const fs = require('fs');
const axios = require('axios');
const puppeteer = require('puppeteer');
// Funcs:
// Adds "." before 2 numbers from end [example: 10799 -> 107.99]:
const formatPrice = priceInt => {
var priceArr = String(priceInt).split('');
return parseFloat(priceArr.slice(0, priceArr.length - 2).join('') + '.' + priceArr.slice(priceArr.length - 2, priceArr.length).join(''));
}
// Changes "," in price str to "." and formats it to a float:
const formatPriceToFloat = price => {
return parseFloat(String(price).replace(',', '.'));
};
// Calculates percent of discount:
const calculateDiscountPercent = (basePrice, discountPrice) => {
return Math.round(100 - (discountPrice * 100) / basePrice);
};
module.exports = {
fs: fs,
axios: axios,
puppeteer: puppeteer,
formatPrice: formatPrice,
formatPriceToFloat: formatPriceToFloat,
calculateDiscountPercent: calculateDiscountPercent,
};