diff options
Diffstat (limited to 'src/client/react/lib')
-rw-r--r-- | src/client/react/lib/url.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/client/react/lib/url.js b/src/client/react/lib/url.js new file mode 100644 index 0000000..3b7f6b4 --- /dev/null +++ b/src/client/react/lib/url.js @@ -0,0 +1,24 @@ +import moment from 'moment'; +import queryString from 'query-string'; +import users from '../users'; +import purifyWeek from './purifyWeek'; + +export function userFromMatch(match) { + const user = `${match.params.type}/${match.params.value}`; + + if (!users.allIds.includes(user)) { + return null; + } + + return user; +} + +export function weekFromLocation(location) { + const weekStr = queryString.parse(location.search).week; + + if (!weekStr) { + return moment().week(); + } + + return purifyWeek(parseInt(weekStr, 10)); +} |