-
Notifications
You must be signed in to change notification settings - Fork 7
/
feather-route-matcher.min.js.map
1 lines (1 loc) · 4.15 KB
/
feather-route-matcher.min.js.map
1
{"version":3,"file":"feather-route-matcher.min.js","sources":["index.js"],"sourcesContent":["// regexes borrowed from backbone\nvar optionalParam = /\\((.*?)\\)/g\nvar namedParam = /(\\(\\?)?:\\w+/g\n// eslint-disable-next-line no-useless-escape\nvar escapeRegExp = /[\\-{}\\[\\]+?.,\\\\\\^$|#\\s]/g\nvar splatParam = /\\*/g\n\n// Parses a URL pattern such as `/users/:id`\n// and builds and returns a regex that can be used to\n// match said pattern. Credit for these\n// regexes belongs to Jeremy Ashkenas and the\n// other maintainers of Backbone.js\n//\n// It has been modified for extraction of\n// named parameters from the URL\nvar parsePattern = function (pattern) {\n var names = []\n pattern = pattern\n .replace(escapeRegExp, '\\\\$&')\n .replace(optionalParam, '(?:$1)?')\n .replace(namedParam, function (match, optional) {\n names.push(match.slice(1))\n return optional ? match : '([^/?]+)'\n })\n .replace(splatParam, function () {\n names.push('path')\n return '([^?]*?)'\n })\n\n return {\n regExp: new RegExp('^' + pattern + '(?:\\\\?([\\\\s\\\\S]*))?$'),\n namedParams: names\n }\n}\n\nexport default function (routes) {\n var keys = Object.keys(routes)\n var routeCache = {}\n\n // loop through each route we're\n // and build the shell of our\n // route cache.\n for (var item in routes) {\n routeCache[item] = {\n value: routes[item]\n }\n }\n\n // main result is a function that can be called\n // with the url\n return function (url) {\n var params\n var route\n\n // start looking for matches\n var matchFound = keys.some(function (key) {\n var parsed\n\n // fetch the route pattern from the cache\n // there will always be one\n route = routeCache[key]\n\n // if the route doesn't already have\n // a regex we never generated one\n // so we do that here lazily.\n // Parse the pattern to generate the\n // regex once, and store the result\n // for next time.\n if (!route.regExp) {\n parsed = parsePattern(key)\n route.regExp = parsed.regExp\n route.namedParams = parsed.namedParams\n route.pattern = key\n }\n\n // run our cached regex\n var result = route.regExp.exec(url)\n\n // if null there was no match\n // returning falsy here continues\n // the `Array.prototype.some` loop\n if (!result) {\n return\n }\n\n // remove other cruft from result\n result = result.slice(1, -1)\n\n // reduce our match to an object of named parameters\n // we've extracted from the url\n params = result.reduce(function (obj, val, index) {\n if (val) {\n obj[route.namedParams[index]] = val\n }\n return obj\n }, {})\n\n // stops the loop\n return true\n })\n\n // no routes matched\n if (!matchFound) {\n return null\n }\n\n return {\n value: route.value,\n params: params,\n url: url,\n pattern: route.pattern\n }\n }\n}\n"],"names":["optionalParam","namedParam","escapeRegExp","splatParam","routes","keys","Object","routeCache","item","value","url","params","route","some","key","parsed","pattern","names","regExp","replace","match","optional","push","slice","RegExp","namedParams","result","exec","reduce","obj","val","index"],"mappings":"mMACA,IAAIA,EAAgB,aAChBC,EAAa,eAEbC,EAAe,2BACfC,EAAa,aA8BF,SAAUC,GACvB,IAAIC,EAAOC,OAAOD,KAAKD,GACnBG,EAAa,GAKjB,IAAK,IAAIC,KAAQJ,EACfG,EAAWC,GAAQ,CACjBC,MAAOL,EAAOI,IAMlB,OAAO,SAAUE,GACf,IAAIC,EACAC,EAkDJ,OA/CiBP,EAAKQ,KAAK,SAAUC,GACnC,IAAIC,EAzCmBC,EACvBC,GA4CAL,EAAQL,EAAWO,IAQRI,SApDXD,EAAQ,GACZD,GAF2BA,EAsDCF,GAnDzBK,QAAQjB,EAAc,QACtBiB,QAAQnB,EAAe,WACvBmB,QAAQlB,EAAY,SAAUmB,EAAOC,GAEpC,OADAJ,EAAMK,KAAKF,EAAMG,MAAM,IAChBF,EAAWD,EAAQ,aAE3BD,QAAQhB,EAAY,WAEnB,OADAc,EAAMK,KAAK,QACJ,aA2CLP,EAxCC,CACLG,OAAQ,IAAIM,OAAO,IAAMR,EAAU,wBACnCS,YAAaR,GAuCTL,EAAMM,OAASH,EAAOG,OACtBN,EAAMa,YAAcV,EAAOU,YAC3Bb,EAAMI,QAAUF,GAIlB,IAAIY,EAASd,EAAMM,OAAOS,KAAKjB,GAK/B,GAAKgB,EAiBL,OAZAA,EAASA,EAAOH,MAAM,GAAI,GAI1BZ,EAASe,EAAOE,OAAO,SAAUC,EAAKC,EAAKC,GAIzC,OAHID,IACFD,EAAIjB,EAAMa,YAAYM,IAAUD,GAE3BD,GACN,KAGI,IAQF,CACLpB,MAAOG,EAAMH,MACbE,OAAQA,EACRD,IAAKA,EACLM,QAASJ,EAAMI,SAPR"}