{"id":19574689,"url":"https://github.com/stringparser/parth","last_synced_at":"2025-02-26T11:20:54.599Z","repository":{"id":23189632,"uuid":"26545943","full_name":"stringparser/parth","owner":"stringparser","description":"Path to RegExp madness not only for an url","archived":false,"fork":false,"pushed_at":"2018-03-03T10:06:29.000Z","size":287,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T23:48:24.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stringparser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-12T16:51:21.000Z","updated_at":"2018-09-19T02:18:33.000Z","dependencies_parsed_at":"2022-08-21T21:30:33.289Z","dependency_job_id":null,"html_url":"https://github.com/stringparser/parth","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stringparser%2Fparth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stringparser%2Fparth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stringparser%2Fparth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stringparser%2Fparth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stringparser","download_url":"https://codeload.github.com/stringparser/parth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240840904,"owners_count":19866290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T06:43:26.704Z","updated_at":"2025-02-26T11:20:54.541Z","avatar_url":"https://github.com/stringparser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parth [![NPM version][badge-version]][x-npm] [![downloads][badge-downloads]][x-npm]\n\n[documentation](#documentation) -\n[examples](#examples) -\n[install](#install) -\n[todo](#todo) -\n[why](#why)\n\n[![build][badge-build]][x-travis]\n\n## sample\n\n```js\nvar Parth = require('parth');\n\nvar parth = new Parth();\nvar props = {handle: function(){}};\n\nparth.set('(get|post) /:page/:view', props)\n     .get('get /weekend/baby?query=string#hash user.10.beers now')\n// =\u003e\n{\n  path: 'get /:page/:view',\n  stem: ':0(get|post) /:page/:view:qs(?:\\\\/?)?([?#][^\\\\/\\s]*)?',\n  depth: 2,\n  regex: /^(get|post) \\/([^?#.\\/\\s]+)\\/([^?#.\\/\\s]+)(?:\\/?)?([?#][^\\/\\s]*)?/,\n  match: 'get /weekend/baby?query=string#hash',\n  handle: [Function],\n  notFound: ' user.10.beers now',\n  params: {\n    page: 'weekend',\n    view: 'baby',\n    qs: '?query=string#hash'\n  }\n}\n```\n\n## documentation\n\nThe `module.exports` a `Parth` constructor\n\n````js\nvar Parth = require('parth');\n````\n\nwhich can take the options below\n\n```js\nvar parth = new Parth(options);\n```\n\n_options_ type `object`, can be\n - `options.defaultRE` default `regex` used if none is given after the params\n\nexample:\n\n```js\nvar parth = new Parth({ defaultRE: /[^\\s\\/?#]+/ });\n\nparth.set('/page/:view') // no regex given after \":view\"\n     .get('/page/10/?query=here')\n// =\u003e\n{\n  path: '/page/:view/',\n  stem: '/page/:view:qs(?:\\\\/?)([?#][^\\\\/\\\\s]*)?',\n  depth: 2,\n  regex: /^\\/page\\/([^\\s\\/?#]+)(?:\\/?)([?#][^\\/\\s]*)?/,\n  match: '/page/10/?query=here',\n  params: {\n    view: '10',\n    qs: '?query=here'\n  },\n  notFound: ''\n}\n```\n\n\u003e NOTE: the query string is separated by default and assigned to `qs`.\n\u003e This will only happen if the path given to `parth.set` has no query string\n\n## parth.set\n\n```js\nfunction set(string path[, object options])\n```\nThis method job is to sanitize `path` and order it with those previously stored.\n\n_arguments_\n - `path`, type `string`, path to be set\n - `options`, type `object`, to merge with this path properties\n\n_returns_ `this`\n\n\u003e NOTE: `options` is deep cloned beforehand to avoid mutation\n\n`path` can contain any number of parameters(regexes) in the form\n```js\n :param-label(\\\\regexp(?:here))\n```\nAny string matching the regular expression below qualifies as a parameter\n\n````js\n/:([-\\w]+)(\\([^\\s]+?[)][?)]*)?/g;\n````\n\n[Go to http://regexr.com/](http://regexr.com/3cuqq) and test it out.\n\n## parth.get\n```js\nfunction get(string path)\n```\n\nTake a string and return a clone of the store object properties\n\n_arguments_\n - `path`, type `string` to match stored paths with\n\n_return_\n - null for non-supported types or not matching paths\n - object with all the information stored in `parth.set`\n\n\u003e All matches are partial i.e. /^regex baby/.\n\u003e Not being strict is useful for `notFound` paths.\n\u003e\n\u003e NOTE: the returned object is a deep copy of the original `options`\n\u003e given in `parth.set` to avoid mutation\n\n### parth properties\n\n - `parth.store`: all paths set for match are here\n - `parth.regex`: array of carefully ordered regexes\n - `parth.regex.master`: regex aggregating all learned\n\n## why\n\nI need it for the [gulp-runtime](https://github.com/stringparser/gulp-runtime) module.\n\n## install\n\nWith [npm](http://npmjs.org)\n\n    npm install --save parth\n\n### examples\n\nRun the [`example.js`](example.js) file.\n\n### test\n\n    npm test\n\n```\n➜  parth (master) ✓ npm t\nparth\n  paths\n    ✓ object\n    ✓ raw object paths\n    ✓ unix paths\n    ✓ raw unix paths\n    ✓ urls\n    ✓ raw urls\n    ✓ urls: querystring is stripped\n    ✓ urls: hash is stripped\n    ✓ urls: parameters are not mistaken as querystrings\n    ✓ space separated paths\n    ✓ raw, space separated paths\n    ✓ unix, object and url paths together\n    ✓ raw: unix, object and urls paths together\n  params\n    ✓ can be given as a string regex\n    ✓ will contain all parameter keys at _\n    ✓ parameter values should be at params\n  notFound\n    ✓ should be false for perfect match\n    ✓ should have what is left of the path\n\n\n18 passing (16ms)\n```\n\n### todo\n\n - [ ] set support for regexp input\n\n### license\n\nThe MIT License (MIT)\n\nCopyright (c) 2014-present Javier Carrillo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[x-npm]: https://npmjs.org/package/parth\n[x-travis]: https://travis-ci.org/stringparser/parth/builds\n[badge-build]: http://img.shields.io/travis/stringparser/parth/master.svg?style=flat-square\n[badge-version]: http://img.shields.io/npm/v/parth.svg?style=flat-square\n[badge-downloads]: http://img.shields.io/npm/dm/parth.svg?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstringparser%2Fparth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstringparser%2Fparth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstringparser%2Fparth/lists"}