-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) 路 1.1 KB
/
Copy pathindex.js
File metadata and controls
44 lines (39 loc) 路 1.1 KB
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
const data = require("./data.json");
/**
* Check if provided code is a valid country code
* @param {string} code
*/
function isValidCode(code) {
return data.find((country) => country.country_code === code.toLowerCase()) ? true : false;
}
/**
* Check if provided emoji is a valid country emoji
* @param {string} emoji
*/
function isValidEmoji(emoji) {
return data.find((country) => country.flag_emoji === emoji) ? true : false;
}
/**
* Get languages from country code
* @param {string} code
*/
function getLanguagesFromCode(code) {
if (!code) throw new Error("Country Code is required");
const value = data.find((country) => country.country_code === code.toLowerCase());
return value ? value.languages : [];
}
/**
* Get languages from country emoji
* @param {string} emoji
*/
function getLanguagesFromEmoji(emoji) {
if (!emoji) throw new Error("Emoji is required");
const value = data.find((country) => country.flag_emoji === emoji);
return value ? value.languages : [];
}
module.exports = {
isValidCode,
isValidEmoji,
getLanguagesFromCode,
getLanguagesFromEmoji,
};