-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (24 loc) · 846 Bytes
/
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
const moment = require('moment');
const filterCampsites = require('./campsiteFilter');
const fs = require('fs');
const fileName = process.argv[2];
fs.readFile(fileName, (error, data) => {
if (error) throw error;
try {
const { search, campsites, reservations } = JSON.parse(data);
if (!search) {
return console.warn('The search key could not be found in the input file.')
}
if (!campsites) {
return console.warn('The campsites key could not be found in the input file.')
}
if (!reservations) {
return console.warn('The reservations key could not be found in the input file.')
}
filterCampsites(search, campsites, reservations).map((campsite) => console.log(campsite.name));
}
catch (error) {
console.warn('The input file must be a valid JSON object');
console.log(error);
}
})