forked from HenrikJoreteg/feather-route-matcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeather-route-matcher.js.map
1 lines (1 loc) · 5.25 KB
/
feather-route-matcher.js.map
1
{"version":3,"file":"feather-route-matcher.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":[],"mappings":";;;;;;EAAA;EACA,IAAI,aAAa,GAAG,aAAY;EAChC,IAAI,UAAU,GAAG,eAAc;EAC/B;EACA,IAAI,YAAY,GAAG,2BAA0B;EAC7C,IAAI,UAAU,GAAG,MAAK;AACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAI,YAAY,GAAG,UAAU,OAAO,EAAE;EACtC,EAAE,IAAI,KAAK,GAAG,GAAE;EAChB,EAAE,OAAO,GAAG,OAAO;EACnB,KAAK,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;EAClC,KAAK,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC;EACtC,KAAK,OAAO,CAAC,UAAU,EAAE,UAAU,KAAK,EAAE,QAAQ,EAAE;EACpD,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAC;EAChC,MAAM,OAAO,QAAQ,GAAG,KAAK,GAAG,UAAU;EAC1C,KAAK,CAAC;EACN,KAAK,OAAO,CAAC,UAAU,EAAE,YAAY;EACrC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAC;EACxB,MAAM,OAAO,UAAU;EACvB,KAAK,EAAC;AACN;EACA,EAAE,OAAO;EACT,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,GAAG,GAAG,OAAO,GAAG,sBAAsB,CAAC;EAC9D,IAAI,WAAW,EAAE,KAAK;EACtB,GAAG;EACH,EAAC;AACD;EACe,cAAQ,EAAE,MAAM,E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