-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
38 lines (34 loc) · 869 Bytes
/
library.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
const menu = {
menuActions: {
Search: function () {
return []
},
Borrow: null,
Return: null
}
}
const libraryObject = {
start: function () {
return 'Welcome to our library'
}
}
export function library (libraryReader) {
const bookList = libraryReader()
menu.menuActions.Search = function (titlePart) {
return bookList.filter((book) => book.title.indexOf(titlePart) !== -1)
}
menu.menuActions.Borrow = function (book) {
const msSecs = Date.now() + 1000 * 60 * 60 * 24 * 21
book.returnDate = new Date(msSecs)
return book
}
menu.menuActions.Return = function (book) {
delete book.returnDate
}
libraryObject.menu = menu
return libraryObject
}
// if run as node index.js then say hello to the console
if (import.meta.url === `file://${process.argv[1]}`) {
console.log(library(() => []).start())
}