{"id":19714401,"url":"https://github.com/peternaydenov/route-emitter","last_synced_at":"2025-04-29T19:32:53.922Z","repository":{"id":79800624,"uuid":"548872071","full_name":"PeterNaydenov/route-emitter","owner":"PeterNaydenov","description":"Converts route change into event signal.","archived":false,"fork":false,"pushed_at":"2025-04-27T07:33:08.000Z","size":2004,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T08:26:52.211Z","etag":null,"topics":["events","history","js","navigate","router"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeterNaydenov.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","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":"2022-10-10T10:11:27.000Z","updated_at":"2025-04-27T07:33:12.000Z","dependencies_parsed_at":"2023-09-28T01:16:46.299Z","dependency_job_id":"ed5c5165-5adb-4008-803c-ad7189e5898f","html_url":"https://github.com/PeterNaydenov/route-emitter","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"ee9b10cade94f92e5612d42d528f4152b20c8438"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Froute-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Froute-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Froute-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Froute-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeterNaydenov","download_url":"https://codeload.github.com/PeterNaydenov/route-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251569650,"owners_count":21610596,"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":["events","history","js","navigate","router"],"created_at":"2024-11-11T22:31:30.242Z","updated_at":"2025-04-29T19:32:53.915Z","avatar_url":"https://github.com/PeterNaydenov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":" # Route-emitter (@peter.naydenov/route-emitter)\n\n![version](https://img.shields.io/github/package-json/v/peterNaydenov/route-emitter)\n![license](https://img.shields.io/github/license/peterNaydenov/route-emitter)\n![GitHub issues](https://img.shields.io/github/issues-raw/peterNaydenov/route-emitter)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40peter.naydenov%2Froute-emitter)\n\n\n\nProvide an list of \"**application addresses**\"(in brief: *'address list'*) and `route-emitter` can take control over change of the URL, page titles and browser history records.\n\n\n## What route-emitter can do?\n- Every external change of the URL will be measured against the **address list**. Router will generate one of the 3 possible signals(`change`,`refresh`,`error`) and will execute a callback function if any provided;\n- Router can change the URL by calling the method `navigate` with the `address name` and data. `route-emitter` will generate and change the URL, will change page title and will set a browser history record if needed.\n- Update your `address list` at any time. Router will start using the new list immediately;\n\n\n\n## Important Notes\n- Calling method `navigate` will **NOT** generate signal to `change`(prevents infinite loop);\n- Router don't have any route logic build in. Everything is programmable from outside;\n- If url is not recognized, router will signal an `error`;\n- Signal `reload` means that requested url is the same as the current url;\n- Calling navigate with address and wrong set of data will generate signal `error`;\n\n\n\n## Application Address Definition\n\n```js\nconst address = {\n               name: 'about'                 // required\n             , path: '/about/:name'          // required\n             , title: x =\u003e `About ${x.name}` // optional\n             , inHistory: true               // optional\n        }\n// path: string. Path to be matched;\n// name: string. Name of the address used also for event name;\n// title: string|function. Title of the page. ( optional, default value: App title);\n// inHistory: boolean. If true, will add record in the browser history. (optional, default value: false);\n\n// Address can be a redirect address. Then possible fields are:\nconst redirectAddress = {\n               name: 'about'                 // required\n             , path: '/about/:name'          // required\n             , redirect: 'home'              // required\n             , data: { name: 'Peter' }       // optional\n        }\n// redirect: string. Name of the address to be redirected. Address should be in the address list;\n// data: object. Data to be passed to the redirected address;\n```\n\n\n\n## Instalation\nInstall for node.js projects by writing in your terminal:\n\n```\nnpm install @peter.naydenov/route-emitter\n```\n\nOnce it has been installed, it can be used by writing this line in JavaScript project:\n\n```js\nimport routeEmitter from '@peter.naydenov/route-emitter'\n\n// or require it:\nconst routeEmitter = require ( '@peter.naydenov/route-emitter' )\n```\n\n\n## How to use it\n\nRouter has 2 configuration options:\n- appName : string. Used as page title if address don't have title. Default value: 'App title';\n- sessionStorageKey : string. Used to store in sessionStorage the last route. Default value: '_routeEmmiterLastLocation';\n\nConfiguration if needed could be provided to routeEmmiter during initialization:     \n```js\nconst config = { appName: 'My App', sessionStorageKey: 'myAppLastLocation' }\nconst router = routeEmitter ( config )\n```\n\nBefore `run` the router provide at least one address - current address. On `run` the router will start evaluating the URL against the address list. If URL is not recognized, the router will signal an `error`. If URL is recognized, the router will signal `change` and will execute the callback function if any provided.\n\n```js\n// create the router instance:\nconst router = routeEmmiter ()\n// set application title \u0026 addresses:\nrouter.setAddresses ( addressList )\n// listen for 'error' signal \nrouter.onError (({code, message}) =\u003e console.log ( code, message )   )\nrouter.onChange ((name, data) =\u003e console.log ( `Address \"${name}\" was loaded successfully`)   )\n// run the router\nrouter.run ()\n// -\u003e Address \"home\" was loaded successfully\n```\n\n\n\n## Route-emitter Methods\n```js\n// Router Methods\n   setAddresses        : 'Set the address list'\n , removeAddresses     : 'Remove addresses from the list by name'\n , getCurrentAddress   : 'Returns the current address name and data'\n , navigate            : 'Change current address. Will not generate \"change\" signal'\n , createURL           : 'Create URL from address name and data (In version 2.1.0 and above)'\n\n , onChange  : 'Register a callback function for \"change\" signal'\n , onRefresh : 'Register a callback function for \"refresh\" signal'\n , onError   : 'Register a callback function for \"error\" signal'\n\n , run : 'Start the router'\n\n , listActiveAddresses : 'Returns a list of active addresses names'\n , listActiveRoutes    : 'Returns a list of active addresses and their paths. (Mostly used for debugging)'\n , destroy             : 'Destroy the router'\n```\n\n\n\n## External Links\n- [History of changes](https://github.com/PeterNaydenov/route-emitter/blob/master/Changelog.md)\n- [Migration guide](https://github.com/PeterNaydenov/route-emitter/blob/master/Migration.guide.md)\n- [Documentation v.1.x.x](https://github.com/PeterNaydenov/route-emitter/blob/master/README_v.1.x.x.md)\n\n\n\n## Credits\n'@peter.naydenov/route-emitter' was created and supported by Peter Naydenov.\n\n\n\n## License\n'@peter.naydenov/router-emitter' is released under the MIT License.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeternaydenov%2Froute-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeternaydenov%2Froute-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeternaydenov%2Froute-emitter/lists"}