{"id":25028078,"url":"https://github.com/alex7kom/easy-location","last_synced_at":"2026-04-24T16:39:25.608Z","repository":{"id":57218523,"uuid":"106572096","full_name":"alex7kom/easy-location","owner":"alex7kom","description":"A thin layer above window.history and window.location APIs for easier URL manipulation.","archived":false,"fork":false,"pushed_at":"2020-01-26T15:57:56.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T08:19:11.105Z","etag":null,"topics":["browser","javascript","query-string","redux","url"],"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/alex7kom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T15:24:21.000Z","updated_at":"2020-01-28T15:32:35.000Z","dependencies_parsed_at":"2022-08-28T21:01:06.825Z","dependency_job_id":null,"html_url":"https://github.com/alex7kom/easy-location","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex7kom%2Feasy-location","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex7kom%2Feasy-location/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex7kom%2Feasy-location/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex7kom%2Feasy-location/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex7kom","download_url":"https://codeload.github.com/alex7kom/easy-location/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246358337,"owners_count":20764366,"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":["browser","javascript","query-string","redux","url"],"created_at":"2025-02-05T19:56:16.377Z","updated_at":"2026-04-24T16:39:25.575Z","avatar_url":"https://github.com/alex7kom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Easy Location\n\n[![Build Status](https://travis-ci.org/Alex7Kom/easy-location.svg?branch=master)](https://travis-ci.org/Alex7Kom/easy-location)\n\nA thin layer above window.history and window.location APIs for easier URL manipulation.\n\n## Motivation\n\nI didn't like other libraries, because they want to own route state, which goes against the Redux principle of 'single source of truth'. Easy Location instead is a thin layer that works with Redux store directly and constructs URL from the store data.\n\nThat said, Easy Location knows nothing about React or Redux and you can use it with anything else.\n\n## Installation\n\n```sh\nnpm install easy-location\n```\n\nor\n\n```sh\nyarn add easy-location\n```\n\n## Usage\n\nThe library exposes `initEasyLocation` function which returns `easyLocation` object and accepts an object with two callbacks:\n\n* `onChange(data)` is called first on init and then on `window`'s `popstate` event. `data` is an object with data extracted from URL, for example, for `https://example.com/apps/hello/?name=John` the data will be:\n\n```json\n{\n  \"path\": [\"apps\", \"hello\"],\n  \"search\": {\n    \"name\": \"John\"\n  }\n}\n```\n\n`path` is an array with `window.location.pathname` parts.\n\n`search` is an object with `window.location.search` pairs.\n\n* `onNewUrl(url)` is called when URL is changed, with `popstate` or `reflect()`. `url` is a full URL which you can feed to some analytics system.\n\n### `easyLocation#reflect(data)`\n\nConstructs a new URL from the provided `data`. `data` is an object with `path` and `search` properties, in fact, it's format is the same with the object with which `onChange(data)` is called. Both `path` and `search` are optional, and if not provided those parts of URL will not be changed.\n\n### `easyLocation#unmount()`\n\nRemove Easy Location listeners from window. `onChange` and `onNewUrl` will not be called after calling this function.\n\n## Redux Example\n\n```js\nimport { createStore, combineReducers } from 'redux';\nimport initEasyLocation from 'easy-location';\n\n// Create a Redux store with reducers that handle URL_CHANGE action\nconst store = createStore(combineReducers({\n  searchQuery: (state = '', action) =\u003e {\n    switch (action.type) {\n      case 'URL_CHANGE':\n        return action.data.search.query;\n      default:\n        return state;\n    }\n  },\n  deepSearch: (state = false, action) =\u003e {\n    switch (action.type) {\n      case 'URL_CHANGE':\n        return action.data.search.deep === '1';\n      default:\n        return state;\n    }\n  }\n}));\n\nconst easyLocation = initEasyLocation({\n  // dispatch an action on URL change\n  onChange: (data) =\u003e {\n    store.dispatch({\n      type: 'URL_CHANGE',\n      data: data\n    });\n  }\n});\n\n// transform state\nconst callReflect = () =\u003e {\n  const state = store.getState();\n\n  easyLocation.reflect({\n    search: {\n      query: state.searchQuery,\n      deep: Number(state.deepSearch)\n    }\n  });\n};\n\n// subscribe on store updates so we can update URL on store changes\nstore.subscribe(callReflect);\n\n// If you want to reflect default state\ncallReflect();\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017-present Alexey Komarov \u003calex7kom@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex7kom%2Feasy-location","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex7kom%2Feasy-location","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex7kom%2Feasy-location/lists"}