-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
48 lines (42 loc) · 1.19 KB
/
helpers.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import slugify from "slugify";
export function formatAndScaleValue(value, oblastKey, oblastScales) {
// Get the proper scale for this oblast name
const scale = oblastScales ? oblastScales[oblastKey] : 1;
// If the scale is undefined, set it to 1
const sliderScale = (scale >= 0 ? scale : 1);
// Return the value scaled by the sliderScale
return formatValue(value * sliderScale);
}
export function formatValue(value) {
return (+value).toFixed(1);
}
// We use the spelling from the data set - NOT the map property data
function standardizeOblastSpelling(oblastName) {
switch (oblastName) {
// TODO crimea / sevastopal are missing due to russian occupation.
case "khmelnytskyy":
return "khmelnytskiy";
case "kiev":
return "kyiv";
case "kiev-city":
return "kyiv";
case "odessa":
return "odesa";
case "mykolayiv":
return "mikolayiv";
case "transcarpathia":
return "zakarpattya";
default:
return oblastName
}
}
// Normalize our oblast name using slugify
export function normalizeOblastName(key) {
if (!key) return key;
return standardizeOblastSpelling(
slugify(key, {
strict: true,
lower: true,
})
);
}