-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.js
More file actions
135 lines (129 loc) · 4.48 KB
/
Copy pathformat.js
File metadata and controls
135 lines (129 loc) · 4.48 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
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
export const format = {
getMaxLengths: async function (headers, items) {
const max_lengths = [];
const headers_length = headers.length;
for (let i = 0; i < headers_length; i++) {
max_lengths.push(headers[i].length);
}
const total_items = items.length;
for (let i = 0; i < total_items; i++) {
for (let j = 0; j < headers_length; j++) {
const attribute_length = items[i][j].length;
if (attribute_length > max_lengths[j]) {
max_lengths[j] = attribute_length;
}
}
}
return max_lengths;
},
createStrings: async function (headers, items, max_lengths) {
const choice_strings = [];
const headers_length = headers.length;
const total_items = items.length;
let headers_string = '';
for (let i = 0; i < headers_length; i++) {
headers_string += headers[i] + ' '.repeat(max_lengths[i] - headers[i].length) + ' | ';
}
choice_strings.push(headers_string);
choice_strings.push('-'.repeat(headers_string.length));
for (let i = 0; i < total_items; i++) {
let item_string = '';
for (let j = 0; j < headers_length; j++) {
item_string += items[i][j] + ' '.repeat(max_lengths[j] - items[i][j].length) + ' | ';
}
choice_strings.push(item_string);
}
return choice_strings;
},
table: async function (headers, items) {
const max_lengths = await this.getMaxLengths(headers, items);
const choice_strings = await this.createStrings(headers, items, max_lengths);
return choice_strings;
},
playlists: async function (playlists) {
const headers = ['', 'Title', 'Owner', 'Num Songs']
const items = [];
const total_playlists = playlists.length;
for (let i = 0; i < total_playlists; i++) {
const current_playlist = playlists[i];
items.push(
[(i + 1).toString(), current_playlist.name, current_playlist.display_name, current_playlist.num_songs.toString()]
);
}
return await this.table(headers, items);
},
playlistTracks: async function (tracks) {
const headers = ['', 'Title', 'Artist', 'Album', 'Date Added', 'Duration'];
const items = [];
const total_tracks = tracks.length;
for (let i = 0; i < total_tracks; i++) {
const current_track = tracks[i];
items.push(
[(i + 1).toString(), current_track.name, current_track.display_name, current_track.album,
current_track.date_added.substr(0, 10), current_track.duration_ms.toString()]
);
}
return await this.table(headers, items);
},
albums: async function (albums) {
const headers = ['', 'Title', 'Artist', 'Type', 'Released', 'Num Songs', 'Label'];
const items = [];
const total_albums = albums.length;
for (let i = 0; i < total_albums; i++) {
const current_album = albums[i];
items.push(
[(i + 1).toString(), current_album.name, current_album.display_name,
current_album.album_type.charAt(0).toUpperCase() + current_album.album_type.slice(1),
current_album.release_year, current_album.num_songs.toString(), current_album.label]
);
}
return await this.table(headers, items);
},
albumTracks: async function (tracks) {
const headers = ['', 'Title', 'Artist', 'Duration'];
const items = [];
const total_tracks = tracks.length;
for (let i = 0; i < total_tracks; i++) {
const current_track = tracks[i];
items.push(
[(i + 1).toString(), current_track.name, current_track.display_name, current_track.duration_ms]
);
}
return await this.table(headers, items);
},
artists: async function (artists) {
const headers = ['', 'Artist',];
const items = [];
const total_artists = artists.length;
for (let i = 0; i < total_artists; i++) {
const current_artist = artists[i];
items.push(
[(i + 1).toString(), current_artist.name]
);
}
return await this.table(headers, items);
},
items: async function (items, type) {
if (type === 'playlists') {
return await this.playlists(items);
}
else if (type === 'playlistTracks') {
return await this.playlistTracks(items);
}
else if (type === 'albums') {
return await this.albums(items);
}
else if (type === 'albumTracks') {
return await this.albumTracks(items);
}
else if (type === 'artists') {
return await this.artists(items);
}
else {
console.log('Something went wrong... format type does not exist');
}
},
defaultDescription: async function (item) {
return '';
}
}