{"id":13527823,"url":"https://github.com/yahoo/routr","last_synced_at":"2025-05-15T10:03:50.780Z","repository":{"id":18106782,"uuid":"21176004","full_name":"yahoo/routr","owner":"yahoo","description":"A component that provides router related functionalities for both client and server.","archived":false,"fork":false,"pushed_at":"2025-04-07T18:57:16.000Z","size":886,"stargazers_count":248,"open_issues_count":0,"forks_count":32,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-14T16:54:15.495Z","etag":null,"topics":["browserify","javascript","network-infrastructure","web","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yahoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-06-24T18:26:34.000Z","updated_at":"2025-04-07T18:57:19.000Z","dependencies_parsed_at":"2023-11-20T19:32:42.656Z","dependency_job_id":"c0837fc1-bd1d-484a-bd26-71775012c551","html_url":"https://github.com/yahoo/routr","commit_stats":{"total_commits":191,"total_committers":26,"mean_commits":7.346153846153846,"dds":0.774869109947644,"last_synced_commit":"1bc7dc422347402ee27649a474b0de20c1064860"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yahoo%2Froutr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yahoo%2Froutr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yahoo%2Froutr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yahoo%2Froutr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yahoo","download_url":"https://codeload.github.com/yahoo/routr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319716,"owners_count":22051072,"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":["browserify","javascript","network-infrastructure","web","webpack"],"created_at":"2024-08-01T06:02:02.915Z","updated_at":"2025-05-15T10:03:50.649Z","avatar_url":"https://github.com/yahoo.png","language":"JavaScript","readme":"# Routr\n\n[![npm version](https://badge.fury.io/js/routr.svg)](http://badge.fury.io/js/routr)\n![github actions](https://github.com/yahoo/routr/actions/workflows/node.js.yml/badge.svg)\n[![Coverage Status](https://img.shields.io/coveralls/yahoo/routr.svg)](https://coveralls.io/r/yahoo/routr?branch=master)\n\nRoutr library is an implementation of router-related functionalities that can be used for both server and client. It follows the same routing rules as [Express](http://expressjs.com/) by using the same library. This library does not use callbacks for routes, instead just mapping them to string names that can be used as application state and used within your application later. For instance in Flux, the current route would be held as state in a store.\n\n## Usage\n\nFor more detailed examples, please check out [example applications](https://github.com/yahoo/routr/tree/master/examples);\n\n```javascript\nimport Router from 'routr';\n\nconst router = new Router([\n    {\n        name: 'view_user',\n        path: '/user/:id',\n        method: 'get',\n        foo: {\n            bar: 'baz',\n        },\n    },\n    {\n        name: 'view_user_post',\n        path: '/user/:id/post/:post',\n        method: 'get',\n    },\n]);\n\n// match route\nconst route = router.getRoute('/user/garfield?foo=bar');\nif (route) {\n    // this will output:\n    //   - \"view_user\" for route.name\n    //   - \"/user/garfield\" for route.url\n    //   - {id: \"garfield\"} for route.params\n    //   - {path: \"/user/:id\", method: \"get\", foo: { bar: \"baz\"}} for route.config\n    //   - { foo: 'bar' } for route.query\n    console.log('[Route found]:', route);\n}\n\n// generate path name (does not include query string) from route\n// \"path\" will be \"/user/garfield/post/favoriteFood?meal=breakfast\"\nconst path = router.makePath(\n    'view_user_post',\n    { id: 'garfield', post: 'favoriteFood' },\n    { meal: 'breakfast' },\n);\n```\n\n## Object.freeze\n\nWe use `Object.freeze` to freeze the router and route objects for non-production environments to ensure the immutability of these objects.\n\nFor production environments, it is recommended to use tools like [envify](https://github.com/hughsk/envify) along with [uglify](https://github.com/mishoo/UglifyJS) as part of your build process to strip out the production specific code for performance benefits.\n\nWe use `if (process.env.NODE_ENV !== 'production')` to wrap around `Object.freeze()`, so that you can use various tools to build the code for different environments:\n\n### Build with Webpack\n\nTwo main utility plugins:\n\n- use [DefinePlugin](http://webpack.github.io/docs/list-of-plugins.html#defineplugin) to define the value for `process.env`\n- use [UglifyJsPlugin](http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin) to remove dead code.\n\nExample of the webpack configuration:\n\n```js\n    plugins: [\n        new webpack.DefinePlugin({\n            'process.env': {\n                NODE_ENV: JSON.stringify('production')\n            }\n        }),\n        new webpack.optimize.UglifyJsPlugin(),\n        ...\n    ]\n```\n\n### Build with Browserify\n\nSimilar to webpack, you can also use the following two utils with your favorite build system:\n\n- use [envify](https://github.com/hughsk/envify) to set `process.env.NODE_ENV` to the desired environment\n- use [uglifyjs](https://github.com/mishoo/UglifyJS2) to remove dead code.\n\nCommand-line example:\n\n```bash\n$ browserify index.js -t [ envify --NODE_ENV production  ] | uglifyjs -c \u003e bundle.js\n```\n\n## API\n\n- [Routr](https://github.com/yahoo/routr/blob/master/docs/routr.md)\n\n## License\n\nThis software is free to use under the Yahoo! Inc. BSD license.\nSee the [LICENSE file][] for license text and copyright information.\n\n[license file]: https://github.com/yahoo/routr/blob/master/LICENSE.md\n\nThird-pary open source code used are listed in our [package.json file](https://github.com/yahoo/routr/blob/master/package.json).\n","funding_links":[],"categories":["Awesome React","JavaScript"],"sub_categories":["Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyahoo%2Froutr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyahoo%2Froutr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyahoo%2Froutr/lists"}