Last active
May 31, 2024 19:32
-
-
Save dinocarl/429961cc263dac33541a38bdf7555867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const strongOrPlain = (bool, str) => bool | |
? `<strong>${str}</strong>` | |
: str; | |
const RangeItemComp = ({header, start, end, highlighted}) => `<li>${ | |
strongOrPlain( | |
highlighted, | |
`${header}: ${start} - ${end}` | |
)}</li>`; | |
const RangeListComp = (rl) => [ | |
'<ol>', | |
...rl.map(RangeItemComp), | |
'</ol>' | |
]; | |
// --- | |
const data = [ | |
{ date: '2024-05-30', open: { from: '08:00am', to: '08:00pm' } }, | |
{ date: '2024-05-31', open: { from: '08:00am', to: '08:00pm' } }, | |
{ date: '2024-06-01', open: { from: '08:00am', to: '08:00pm' } } | |
]; | |
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; | |
// mapping the data | |
const hours2RangeList = (arr) => arr.map( | |
({ date, open: { from: start, to: end } }) => ({ | |
header: dayNames[new Date(date).getDay()], | |
start, | |
end, | |
highlighted: date === '2024-05-31' | |
}) | |
); | |
// printing the html | |
RangeListComp( | |
hours2RangeList(data) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment