{"_id":"match-path-plus","_rev":"1213856","name":"match-path-plus","description":"match-path","dist-tags":{"latest":"0.0.3"},"maintainers":[{"name":"g120hbq","email":"hbqhbq123@qq.com"}],"time":{"modified":"2021-10-13T05:46:58.000Z","created":"2017-05-30T15:28:08.020Z","0.0.3":"2017-09-16T14:48:00.118Z","0.0.2":"2017-09-16T14:46:29.245Z","0.0.1":"2017-05-30T15:28:08.020Z"},"users":{},"author":{"name":"hubiqing"},"repository":{"type":"git","url":"git+https://github.com/githbq/match-path-plus.git"},"versions":{"0.0.3":{"name":"match-path-plus","version":"0.0.3","description":"match-path","main":"build/index.js","scripts":{"start:build":"npm run tsc && node build","start":"node run","test":"mocha src/**/*.test.ts","clear":"rimraf build","tsc":"npm run clear && tsc","tsc:w":"npm run clear && tsc -w","p":"npm run tsc && npm publish","lint":"tslint \"src/**/*.ts\""},"dependencies":{"path-to-regexp":"^1.7.0","tslib":"^1.6.1"},"devDependencies":{"@types/mocha":"^2.2.41","@types/node":"^6.0.48","@types/should":"^8.3.0","mocha":"^3.3.0","rimraf":"^2.6.1","should":"^11.2.1","ts-node":"^3.0.2","tslint":"^5.1.0","typescript":"^2.3.2"},"keywords":["typescript","match-path"],"author":{"name":"hubiqing"},"repository":{"type":"git","url":"git+https://github.com/githbq/match-path-plus.git"},"engines":{"node":">=7.6"},"license":"MIT","gitHead":"13e8ca8b003a3531b3c65a371bc4a1fcbc3048b6","bugs":{"url":"https://github.com/githbq/match-path-plus/issues"},"homepage":"https://github.com/githbq/match-path-plus#readme","_id":"match-path-plus@0.0.3","_npmVersion":"5.4.1","_nodeVersion":"8.4.0","_npmUser":{"name":"g120hbq","email":"hbqhbq123@qq.com"},"dist":{"shasum":"36c6ef0f21130bb2b22819d0bf2b0b1e5d5d55e0","size":2362,"noattachment":false,"key":"/match-path-plus/-/match-path-plus-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/match-path-plus/download/match-path-plus-0.0.3.tgz"},"maintainers":[{"name":"g120hbq","email":"hbqhbq123@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/match-path-plus-0.0.3.tgz_1505573279512_0.9157807356677949"},"directories":{},"publish_time":1505573280118,"_hasShrinkwrap":false,"_cnpm_publish_time":1505573280118},"0.0.2":{"name":"match-path-plus","version":"0.0.2","description":"match-path","main":"build/index.js","scripts":{"start:build":"npm run tsc && node build","start":"node run","test":"mocha src/**/*.test.ts","clear":"rimraf build","tsc":"npm run clear && tsc","tsc:w":"npm run clear && tsc -w","p":"npm run tsc && npm publish","lint":"tslint \"src/**/*.ts\""},"dependencies":{"path-to-regexp":"^1.7.0","tslib":"^1.6.1"},"devDependencies":{"@types/mocha":"^2.2.41","@types/node":"^6.0.48","@types/should":"^8.3.0","mocha":"^3.3.0","rimraf":"^2.6.1","should":"^11.2.1","ts-node":"^3.0.2","tslint":"^5.1.0","typescript":"^2.3.2"},"keywords":["typescript","match-path"],"author":{"name":"hubiqing"},"repository":{"type":"git","url":"git+https://github.com/githbq/match-path-plus.git"},"engines":{"node":">=7.6"},"license":"MIT","gitHead":"833f9756bdae7801ee743805be62fe3d111150a9","bugs":{"url":"https://github.com/githbq/match-path-plus/issues"},"homepage":"https://github.com/githbq/match-path-plus#readme","_id":"match-path-plus@0.0.2","_npmVersion":"5.4.1","_nodeVersion":"8.4.0","_npmUser":{"name":"g120hbq","email":"hbqhbq123@qq.com"},"dist":{"shasum":"f4de41642169eaf61993567b5e1898bc003646b6","size":2279,"noattachment":false,"key":"/match-path-plus/-/match-path-plus-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/match-path-plus/download/match-path-plus-0.0.2.tgz"},"maintainers":[{"name":"g120hbq","email":"hbqhbq123@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/match-path-plus-0.0.2.tgz_1505573189165_0.9411618576850742"},"directories":{},"publish_time":1505573189245,"_hasShrinkwrap":false,"_cnpm_publish_time":1505573189245},"0.0.1":{"name":"match-path-plus","version":"0.0.1","description":"match-path","main":"build/index.js","scripts":{"start:build":"npm run tsc && node build","start":"node run","test":"mocha src/**/*.test.ts","clear":"rimraf build","tsc":"npm run clear && tsc","tsc:w":"npm run clear && tsc -w","p":"npm run tsc && npm publish","lint":"tslint \"src/**/*.ts\""},"dependencies":{"path-to-regexp":"^1.7.0","tslib":"^1.6.1"},"devDependencies":{"@types/mocha":"^2.2.41","@types/node":"^6.0.48","@types/should":"^8.3.0","mocha":"^3.3.0","rimraf":"^2.6.1","should":"^11.2.1","ts-node":"^3.0.2","tslint":"^5.1.0","typescript":"^2.3.2"},"keywords":["typescript","match-path"],"author":{"name":"hubiqing"},"repository":{"type":"git","url":"git+https://github.com/githbq/match-path-plus.git"},"engines":{"node":">=7.6"},"license":"MIT","gitHead":"42a81ac33e09d9e22082a982f3c3045daa271280","bugs":{"url":"https://github.com/githbq/match-path-plus/issues"},"homepage":"https://github.com/githbq/match-path-plus#readme","_id":"match-path-plus@0.0.1","_shasum":"28d7183a708f39cd0b6a933ed0c80f30fe19116a","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.10.0","_npmUser":{"name":"g120hbq","email":"hbqhbq123@qq.com"},"dist":{"shasum":"28d7183a708f39cd0b6a933ed0c80f30fe19116a","size":2136,"noattachment":false,"key":"/match-path-plus/-/match-path-plus-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/match-path-plus/download/match-path-plus-0.0.1.tgz"},"maintainers":[{"name":"g120hbq","email":"hbqhbq123@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/match-path-plus-0.0.1.tgz_1496158087947_0.1219352085608989"},"directories":{},"publish_time":1496158088020,"_hasShrinkwrap":false,"_cnpm_publish_time":1496158088020}},"readme":"> match-path-plus\r\n\r\nPowered by [`path-to-regexp`](https://github.com/component/path-to-regexp).\r\n\r\n![my love](./logo.png) \r\n \r\n## Install\r\n```\r\nyarn add match-path-plus\r\n```\r\n\r\n## import\r\n```javascript\r\n//es6\r\nimport { matchPath , mapSearchParams } from 'match-path-plus'\r\n//es5\r\nconst { matchPath , mapSearchParams } = require('match-path-plus')\r\n```\r\n\r\n## Usage\r\n```javascript\r\n//typescript\r\n/**\r\n * entry\r\n */\r\nimport * as  pathToRegExp from 'path-to-regexp'\r\n\r\nconst cache = new Map()\r\n\r\n/**\r\n * Converts path to a regex, if a match is found then we extract params from it\r\n * @param routePattern \r\n * @param url \r\n * @param regOptions path-to-regexp options\r\n */\r\nexport function matchPath(routePattern, url, regOptions) {\r\n    const [pathToMatch = '/', search = ''] = url.split('?')\r\n    let regexp = cache.get(routePattern)\r\n\r\n    if (!regexp) {\r\n        const keys = []\r\n        // path-to-regexp options\r\n        regOptions = {\r\n            ...regOptions,\r\n            sensitive: false,\r\n            strict: false,\r\n            end: false\r\n        }\r\n        regexp = { pattern: pathToRegExp(routePattern, keys, regOptions), keys }\r\n        cache.set(routePattern, regexp)\r\n    }\r\n\r\n    const m = regexp.pattern.exec(pathToMatch)\r\n\r\n    if (!m) {\r\n        return null\r\n    }\r\n\r\n    const path = m[0]\r\n    const params = Object.create(null)\r\n\r\n    for (let i = 1; i < m.length; i += 1) {\r\n        params[regexp.keys[i - 1].name] = decodeURIComponent(m[i])\r\n    }\r\n\r\n    // Add querystring params\r\n    Object.assign(params, mapSearchParams(search))\r\n\r\n    return {\r\n        path: path === '' ? '/' : path,\r\n        params\r\n    }\r\n}\r\n\r\n/**\r\n * Maps a querystring to an object\r\n * Supports arrays and utf-8 characters\r\n * @param search\r\n * @returns {any}\r\n */\r\nexport function mapSearchParams(search) {\r\n    let params = {}\r\n    let params_re = /([^?&=]+)=?([^&]*)/g\r\n\r\n    if (search.indexOf('?') !== -1) {\r\n        search = search.split('?')[1]\r\n    }\r\n\r\n    search.replace(params_re, function (m, name, value) {\r\n        params[decodeURIComponent(name)] = decodeURIComponent(value)\r\n    })\r\n\r\n    return params\r\n}\r\n\r\n```\r\n","_attachments":{},"homepage":"https://github.com/githbq/match-path-plus#readme","bugs":{"url":"https://github.com/githbq/match-path-plus/issues"},"license":"MIT"}