{"_id":"url-matcher","_rev":"4-dc10723d5e4af93cd69f6c2d2ffc268e","name":"url-matcher","description":"A pattern matcher library for routes with typed parameters","dist-tags":{"latest":"0.2.2"},"versions":{"0.2.1":{"name":"url-matcher","version":"0.2.1","description":"A pattern matcher library for routes with typed parameters","main":"lib/index","repository":{"type":"git","url":"git+https://github.com/itajaja/url-matcher.git"},"homepage":"https://github.com/itajaja/url-matcher","bugs":{"url":"https://github.com/itajaja/url-matcher/issues"},"scripts":{"build":"webpack","lint":"eslint modules","test":"npm run lint && karma start"},"authors":["Giacomo Tagliabue"],"license":"MIT","dependencies":{"invariant":"^2.0.0"},"devDependencies":{"babel":"^5.4.7","babel-core":"^5.4.7","babel-eslint":"^3.1.23","babel-loader":"^5.0.0","eslint":"^1.7.3","eslint-config-rackt":"^1.1.1","expect":"^1.12.0","karma":"^0.13.13","karma-chrome-launcher":"^0.2.0","karma-mocha":"^0.2.0","karma-mocha-reporter":"^1.1.1","karma-sourcemap-loader":"^0.3.5","karma-webpack":"^1.7.0","mocha":"^2.0.1","webpack":"^1.4.13"},"tags":["route","url"],"keywords":["routing","route","routes","router","url","matcher"],"gitHead":"9759e966176acb1c637dae1ad80c95257b287431","_id":"url-matcher@0.2.1","_shasum":"5d9d6b1e17a60a31619d1df9d841484b8d17386c","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"itajaja","email":"giacomo.tag@gmail.com"},"dist":{"shasum":"5d9d6b1e17a60a31619d1df9d841484b8d17386c","tarball":"https://registry.npmjs.org/url-matcher/-/url-matcher-0.2.1.tgz","integrity":"sha512-B66CxJCMzHmFMiao4159Gz2aFzGH0eocGB3eO9cJIMM+MeKb8W7qkOz3qlhvfRr07RGFffWt7iHnkvC4oGDaag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF2QuzrfM7lfYPRNm0v/Zl8mPb7VMPw/N+0x0qtKfJjZAiBx2t2MBPLPde3GPDBOCx9v5zZk+cA9C9qBYCDqsITtEw=="}]},"maintainers":[{"name":"itajaja","email":"giacomo.tag@gmail.com"}]},"0.2.2":{"name":"url-matcher","version":"0.2.2","description":"A pattern matcher library for routes with typed parameters","main":"lib/index","repository":{"type":"git","url":"git+https://github.com/itajaja/url-matcher.git"},"homepage":"https://github.com/itajaja/url-matcher","bugs":{"url":"https://github.com/itajaja/url-matcher/issues"},"scripts":{"build":"babel src -d lib","lint":"eslint src","test":"npm run lint && karma start"},"authors":["Giacomo Tagliabue"],"license":"MIT","dependencies":{"invariant":"^2.0.0"},"devDependencies":{"babel":"^5.4.7","babel-core":"^5.4.7","babel-eslint":"^3.1.23","babel-loader":"^5.0.0","eslint":"^1.7.3","eslint-config-rackt":"^1.1.1","expect":"^1.12.0","karma":"^0.13.13","karma-chrome-launcher":"^0.2.0","karma-mocha":"^0.2.0","karma-mocha-reporter":"^1.1.1","karma-sourcemap-loader":"^0.3.5","mocha":"^2.0.1"},"tags":["route","url"],"keywords":["routing","route","routes","router","url","matcher"],"gitHead":"0031115f7de0a245ebd11ab2f7d54e6d3eaa4dc2","_id":"url-matcher@0.2.2","_shasum":"702670150569063d4ba39abd7ecad0ad4dc3da93","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"itajaja","email":"giacomo.tag@gmail.com"},"dist":{"shasum":"702670150569063d4ba39abd7ecad0ad4dc3da93","tarball":"https://registry.npmjs.org/url-matcher/-/url-matcher-0.2.2.tgz","integrity":"sha512-5ATRLevACsAE9JLQ/64Q32dh8NtU2A85zChqBQlNvHF1+FbnqlGXBwzXa6ulvozjVID7o5SrIHvteENmlmIyqA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHWz0HJePGoZVvw/NGcdTLFfRYjijPor3NilQ6OwEBjAAiBgsDPdD+UgoZwmMplhD/LAgYRriXU+7PJ0jmFe3TSsxw=="}]},"maintainers":[{"name":"itajaja","email":"giacomo.tag@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/url-matcher-0.2.2.tgz_1493326818480_0.32696213060989976"}}},"readme":"# url-matcher\n\n[![NPM](https://nodei.co/npm/url-matcher.png?downloads=true)](https://nodei.co/npm/url-matcher/)\n\nA pattern matcher library for route URLs with typed parameters.\n\n## Usage\n\n### Path Syntax\n\nA route path is a string that is used to match a URL (or a portion of one). Route paths are interpreted literally, except for the following special symbols:\n\n  - `:paramName` Matches a URL segment and captures a param. The matched segment depends on the **[parameter rule](#parameter-rules)**. If no rule is provided, it defaults to the string matcher (`[^/?#]+`). The matched string is called a **param**\n  - `()` Wraps a portion of the URL that is optional\n  - `*` Matches all characters (non-greedy) up to the next character in the pattern, or to the end of the URL if there is none, and creates a `splat` param\n  - `**` Matches all characters (greedy) until the next `/`, `?`, or `#` and creates a `splat` param\n\n```js\nimport { matchPattern } from 'url-matcher'\n\nmatchPattern('/hello/:name', '/hello/michael')          // WILL MATCH\nmatchPattern('/hello/:name', '/hello')                  // WILL NOT MATCH\n\nmatchPattern('/hello(/:name)', '/hello')                // WILL MATCH\nmatchPattern('/hello(/:name)', '/hello/ryan')           // WILL MATCH\n\nmatchPattern('/files/*.*', '/files/hello.jpg')          // WILL MATCH\n\nmatchPattern('/files/**/*.jpg', '/files/path/to/file')  // WILL MATCH\n```\n\n### Parameter Rules\n\nIf a parameter is defined in the form of `:parameterName` in the path, you might want to use specific parsing rules for it. You can achieve that by specifying parameter rules. If for example you want to match only integers for a specific parameter, you can declare your route like this:\n\n````js\nimport { matchPattern } from 'url-matcher'\nimport { int } from 'url-matcher/rules'\n\nvar route = {\n  pattern: 'users/:userId',\n  rules: {\n    userId: int()\n  }\n}\n\nmatchPattern(route, '/100') //WILL MATCH\nmatchPattern(route, '/abc') //WILL NOT MATCH\n````\n\nNot only the Route will match only the desired input, but the corresponding value in the `paramValues` list will be converted to an integer.\n\n#### Existing rules\n\n- `int({ max, min, fixedLength })`:  This rule matches non negative integers and returns the parsed string as a number. The following arguments can be specified to further refine the parameter matching:\n  - `fixedLength` specifies the precise length of the argument\n  - `max` specifies the minimum value assignable\n  - `min` specifies the maximum value assignable\n- `string({ maxLength, minLength, length })`: This rule matches any character except the forward slashes. This is the default rule when nothing else is specified. you can use the following arguments:\n  - `length` specifies the precise length of the argument\n  - `minLength` specifies the minimum length for the argument\n  - `maxLength` specifies the maximum length for the argument\n- `greedySplat()`: This rule behaves exactly like `**`. You might want to use this definition instead of `**` when you want to specify a different parameter name other than the default `splat` that is used with `**`\n- `splat()` This rule behaves exactly like `*`\n- `any(...values)`: This rule matches only if the parameter value is specified in the values list passed as argument\n- `uuid()`: This rule matches only values that are valid UUIDs\n\n#### Creating a custom rule\n\nYou can create your custom rules to validate parameters. Here is an example on how to do so:\n\n````js\nimport { createRule } from 'url-matcher/rules'\n\nvar arrayRule = createRule({\n  regex: '(\\\\[(?:\\\\w+,)*\\\\w*\\\\])',\n  convert: (v) => {\n    let result = []\n    let matcher = /(\\w+)/g\n    let match\n    while((match = matcher.exec(v))) result.push(match[1])\n    return match\n  }\n})\n````\n\nThe following rule will match paths that are specified as list of comma-separated values and it will return a list of values in the corresponding item of paramValues. Here is an example of how is used:\n\n````js\nimport { matchPattern } from 'url-matcher'\n\nvar route = {\n  pattern: 'images/:tags',\n  rules: {\n    'tags': arrayRule\n  }  \n}\n\nmatchPattern(route, '/images/[top, funny]') // WILL MATCH\n// {\n//  remainingPathname: '',\n//  paramNames: [ 'tags' ],\n//  paramValues: [ [ 'top', 'funny' ] ]\n// }\n````\n\n`createRule` is a utility method that helps defining rules. if the object passed as parameter doesn't contain one of the following properties, a default will be used:\n\n- `regex` defaults to `([^/?#]+)` (the string matcher)\n- `validate` defaults to `(() => true)`\n- `convert` defaults to `((val) => val)` (the identity function)\n\n### APIs\n\n#### `matchPattern(route, pathname)`\n\n- `route`: The route can either be the string pattern or an object with the following types:\n  - `pattern`: A string representing the [path syntax](#path-syntax) \n  - `rules`: A dictionary of [parameter rules](#parameter-rules) where the key is the parameter name and the value is the rule used\n- `pathname` The string path to match against the route\n- **Returns** If the pathname is matched, returns an object with the following properties, otherwise undefined:\n  - `remainingPathname`: The remaining part of the path left outside of the match\n  - `paramNames`: A list of parameter names in order of appearance\n  - `paramValues`: A list of parameter values in order of appearance\n\n#### `getRoute(route)`\n- **Returns** an object with the following properties:\n  - `tokens`: the list of tokens in which the route pattern is divided\n  - `regexpSource`: the regular expression used to match the pathnames\n  - `params`: a list of parameter objects containing `paramName` and `paramRule` in order of appearance.\n  - `paramNames`: the list of parameter names in order of appearance\n\n#### `formatPattern(route, params)`\n\n- `params` a dictionary of `paramName: paramValue`\n- **Returns** a version of the given pattern with params interpolated. Throws if there is a dynamic segment of the pattern for which there is no param\n\n#### `getParams(route, pathname)`\n\n- **Returns** a dictionary of `paramName: paramValue` if the pathname matches the route, otherwise null\n","maintainers":[{"name":"itajaja","email":"giacomo.tag@gmail.com"}],"time":{"modified":"2022-06-28T06:16:01.249Z","created":"2015-11-06T20:42:03.178Z","0.2.1":"2015-11-06T20:42:03.178Z","0.2.2":"2017-04-27T21:00:19.231Z"},"homepage":"https://github.com/itajaja/url-matcher","keywords":["routing","route","routes","router","url","matcher"],"repository":{"type":"git","url":"git+https://github.com/itajaja/url-matcher.git"},"bugs":{"url":"https://github.com/itajaja/url-matcher/issues"},"license":"MIT","readmeFilename":"README.md"}