-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
206 lines (175 loc) · 4.85 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"use strict";
const sn = require("./dataset/senegal.json");
const rg = require("./dataset/regions.json");
const dp = require("./dataset/departments.json");
const { lowerCase, findItem, departmentItem } = require("./libs/utils");
const { RegionReferenceError, DepartmentReferenceError } = require("./libs/exceptions.js");
module.exports = {
/**
* Get all data about the regions
*
* @typedef Region
* @property {string} nom
* @property {string} code
* @property {number} population
* @property {number} superficie
* @property {string[]} departments
*
* @returns {Region[]} The regions
*/
rg: () => rg,
/**
* Get all regions name.
*
* @returns {string[]} The region names
*/
regions: () => {
return rg.map((region) => region.nom);
},
/**
* Get all regions code.
*
* @returns {string[]} The region codes
*/
codes: () => {
return rg.map((region) => region.code);
},
/**
* Get departments by region.
*
* @param {string} regionName The name of the region
*
* @throws {RegionReferenceError} Argument regionName should not be empty
*
* @returns {string[]} The departments for a region
*/
departments: (regionName) => {
regionName = lowerCase(regionName);
if (regionName?.length == 0) {
throw new RegionReferenceError();
}
const { departments } = findItem(regionName);
return departments;
},
/**
* Get the population count by region.
*
* @param{string} regionName - The name of the region
*
* @throws {RegionReferenceError} Argument regionName should not be empty
*
* @returns {number} The population of a region
*/
population: (regionName) => {
regionName = lowerCase(regionName);
if (regionName?.length == 0) {
throw new RegionReferenceError();
}
const { population } = findItem(regionName);
return population;
},
/**
* Get area by region.
*
* @param{string} regionName - The name of the region
*
* @throws {RegionReferenceError} Argument regionName should not be empty
*
* @returns {number} The area of a region
*/
superficie: (regionName) => {
regionName = lowerCase(regionName);
if (regionName?.length == 0) {
throw new RegionReferenceError();
}
const { superficie } = findItem(regionName);
return superficie;
},
// Get Data from different departments
/**
* Get all departments names
*
* @returns {string[]} The department names
*/
allDepartments: () => {
return dp.map((department) => department.nom);
},
/**
* Get the arrondissements by departments.
*
* @param {string} departmentName - The name of the department
*
* @throws {DepartmentReferenceError} Argument departmentName should not be empty
*
* @returns {string[]} The arrondissements for a department
*/
arrondissements: (departmentName) => {
departmentName = lowerCase(departmentName);
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}
const { arrondissements } = departmentItem(departmentName);
return arrondissements;
},
/**
* Get the population count by departments.
*
* @param {string} departmentName - The name of the department
*
* @throws {DepartmentReferenceError} Argument departmentName should not be empty
*
* @returns {int} The population count for a department
*/
populationDepartment: (departmentName) => {
departmentName = lowerCase(departmentName);
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}
const { population } = departmentItem(departmentName);
return population;
},
/**
* Get area by departments.
*
* @param {string} departmentName - The name of the department
*
* @throws {DepartmentReferenceError} Argument departmentName should not be empty
*
* @returns {int} The area for a department
*/
superficieDepartment: (departmentName) => {
departmentName = lowerCase(departmentName);
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}
const { superficie } = departmentItem(departmentName);
return superficie;
},
/**
* Get all data about Senegal.
*
* @typedef Country
* @property {string} pays
* @property {string} capital
* @property {string} langueOfficielle
* @property {string} languesNationales
* @property {string} monnaie
* @property {string} devise
* @property {string} drapeau
* @property {string} codeIso
* @property {number} indicatif
* @property {number} habitants
* @property {number} surface
* @property {number} regions
* @property {number} departments
*
* @returns {Country} The infos about a country
*/
sn: () => sn,
/**
* Get all national language
*
* @returns {string[]} The national languages
*/
languesNationales: () => sn.languesNationales,
};