Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created July 7, 2016 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdreyno/ab5431caabaddc907e1dbbec4ec141a6 to your computer and use it in GitHub Desktop.
Save tdreyno/ab5431caabaddc907e1dbbec4ec141a6 to your computer and use it in GitHub Desktop.
Code Router
const country = (seg) => /^[a-z]{2}$/.test(seg);
const midPrefix = (seg) => /^m|g$/.test(seg);
const midValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const coMidPrefix = (seg) => /^m|g$/.test(seg);
const coMidValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const darkNews = (seg) => seg === DARK_LABEL;
const year = (seg) => /^[0-9]{4}/.test(seg);
const month = (seg) => /^[0-9]{2}/.test(seg);
const day = (seg) => /^[0-9]{2}/.test(seg);
const dateSegment = [year, month, day];
const midSegment = [midPrefix, midValue];
const coMidSegment = [coMidPrefix, coMidValue];
/**
* Route definitions.
*/
const homepage = [];
const homepageWithoutDateWithCountry = [...homepage, country];
const homepageWithDate = [...homepage, ...dateSegment];
const homepageWithDateWithCountry = [...homepage, ...dateSegment, country];
const midWithoutDate = [...midSegment];
const midWithoutDateWithCountry = [...midWithoutDate, country];
const midWithDate = [...dateSegment, ...midWithoutDate];
const midWithDateWithCountry = [...midWithDate, country];
const darkWithoutDate = [country, darkNews];
const darkWithDate = [...dateSegment, ...darkWithoutDate];
const comentionWithoutDate = [...midSegment, ...coMidSegment];
const comentionWithoutDateWithCountry = [...comentionWithoutDate, country];
const comentionWithDate = [...dateSegment, ...comentionWithoutDate];
const comentionWithDateWithCountry = [...comentionWithDate, country];
export const homepageRoutes = [homepage, homepageWithoutDateWithCountry, homepageWithDate, homepageWithDateWithCountry];
export const midRoutes = [midWithoutDate, midWithoutDateWithCountry, midWithDate, midWithDateWithCountry];
export const darkRoutes = [darkWithoutDate, darkWithDate];
export const comentionRoutes = [comentionWithoutDate, comentionWithoutDateWithCountry, comentionWithDate, comentionWithDateWithCountry];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment