-
-
Notifications
You must be signed in to change notification settings - Fork 805
/
play-meta-util.js
98 lines (80 loc) · 1.95 KB
/
play-meta-util.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
import { plays } from './play-meta';
const getAllPlays = () => {
return plays;
};
const getPlayById = id => {
return plays.find(play => play.id === id);
};
const getPlaysOnSearch = searchTerm => {
return plays.filter(play => {
return (play.name.toLowerCase().includes(searchTerm.toLowerCase())
|| play.description.toLowerCase().includes(searchTerm.toLowerCase()));
});
}
const getPlaysByTags = tags => {
return plays.filter(play => {
return play.tags.includes(tags);
});
}
const getPlaysByLevel = level => {
return plays.filter(play => {
return play.level === level;
});
}
const getPlaysByCreator = creator => {
return plays.filter(play => {
return play.github === creator;
});
}
const getPlaysByLanguage = language => {
return plays.filter(play => {
const lang = play.language || 'js';
return lang === language;
});
}
const getAllTags = () => {
const tags = plays.reduce((acc, play) => {
return acc.concat(play.tags.split(','));
}, []);
return Array.from(new Set([...tags]));
}
const getAllCreators = () => {
const creators = plays.reduce((acc, play) => {
play.github && acc.push(play.github);
return acc;
}, []);
return Array.from(new Set([...creators]));
}
const getAllLevels = () => {
const levels = plays.reduce((acc, play) => {
return acc.concat(play.level);
}, []);
return Array.from(new Set([...levels]));
}
const getAllLanguages = () => {
const languages = plays.reduce((acc, play) => {
const lang = play.language || 'js';
return acc.concat(lang);
}, []);
return Array.from(new Set([...languages]));
}
const getFeaturedPlays = () => {
const featuredPlays = plays.filter(play => {
return play.featured;
});
return featuredPlays;
}
export {
getAllPlays,
getPlayById,
getPlaysOnSearch,
getPlaysByLevel,
getPlaysByTags,
getPlaysByLanguage,
getPlaysByCreator,
getAllTags,
getAllCreators,
getAllLevels,
getAllLanguages,
getFeaturedPlays
};