[
  {
    "path": ".browserslistrc",
    "content": "# Browsers we support\n> 0.5%\nChrome >= 73\nChromeAndroid >= 75\nFirefox >= 67\nEdge >= 17\nIE 11\nSafari >= 12.1\niOS >= 11.3\n"
  },
  {
    "path": ".eslintignore",
    "content": "/build\n/fixtures\n\nnode_modules/\n"
  },
  {
    "path": ".eslintrc",
    "content": "{\n  \"extends\": \"react-app\",\n  \"rules\": {\n    \"import/no-anonymous-default-export\": 0\n  }\n}\n"
  },
  {
    "path": ".github/lock.yml",
    "content": "# Configuration for lock-threads - https://github.com/dessant/lock-threads\n\n# Number of days of inactivity before a closed issue or pull request is locked\ndaysUntilLock: 60\n\n# Issues and pull requests with these labels will not be locked. Set to `[]` to disable\nexemptLabels: []\n\n# Label to add before locking, such as `outdated`. Set to `false` to disable\nlockLabel: false\n\n# Comment to post before locking. Set to `false` to disable\nlockComment: false\n# Limit to only `issues` or `pulls`\n# only: issues\n\n# Optionally, specify configuration settings just for `issues` or `pulls`\n# issues:\n#   exemptLabels:\n#     - help-wanted\n#   lockLabel: outdated\n\n# pulls:\n#   daysUntilLock: 30\n"
  },
  {
    "path": ".github/workflows/format.yml",
    "content": "name: Format\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  format:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Cancel Previous Runs\n        uses: styfle/cancel-workflow-action@0.9.1\n\n      - name: Checkout Repository\n        uses: actions/checkout@v2\n\n      - name: Use Node.js\n        uses: actions/setup-node@v2\n        with:\n          node-version: 14\n\n      - name: Install dependencies\n        run: yarn install --frozen-lockfile\n\n      - name: Format\n        run: npm run format --if-present\n\n      - name: Commit\n        run: |\n          git config --local user.email \"github-actions@remix.run\"\n          git config --local user.name \"Remix Run Bot\"\n\n          git add .\n          if [ -z \"$(git status --porcelain)\" ]; then\n            echo \"💿 no formatting changed\"\n            exit 0\n          fi\n          git commit -m \"chore: format\" -m \"formatted $GITHUB_SHA\"\n          git push\n          echo \"💿 pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)\"\n"
  },
  {
    "path": ".github/workflows/release.yml",
    "content": "name: release\non:\n  release:\n    types: [published]\n\njobs:\n  release:\n    if: github.repository == 'remix-run/history'\n    runs-on: ubuntu-latest\n\n    strategy:\n      matrix:\n        node-version: [14.x]\n\n    steps:\n      - uses: actions/checkout@v2\n\n      - name: Use Node.js ${{ matrix.node-version }}\n        uses: actions/setup-node@v1\n        with:\n          node-version: ${{ matrix.node-version }}\n\n        # https://github.com/actions/setup-node/issues/213#issuecomment-833724757\n      - name: Install npm v7\n        run: npm i -g npm@7 --registry=https://registry.npmjs.org\n\n      - name: Install dependencies\n        run: npm ci\n\n      - name: Build\n        run: npm run build\n\n      - name: Test\n        run: npm run test & npm run size\n\n      - name: Publish\n        env:\n          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}\n        run: |\n          echo \"//registry.npmjs.org/:_authToken=$NPM_TOKEN\" > ~/.npmrc\n          node scripts/publish.js\n"
  },
  {
    "path": ".github/workflows/test.yml",
    "content": "name: test\non: [push, pull_request]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n\n    strategy:\n      matrix:\n        node-version: [14.x]\n\n    steps:\n      - uses: actions/checkout@v2\n\n      - name: Use Node.js ${{ matrix.node-version }}\n        uses: actions/setup-node@v1\n        with:\n          node-version: ${{ matrix.node-version }}\n\n        # https://github.com/actions/setup-node/issues/213#issuecomment-833724757\n      - name: Install npm v7\n        run: npm i -g npm@7 --registry=https://registry.npmjs.org\n\n      - name: Install dependencies\n        run: npm ci\n\n      - name: Build\n        run: npm run build\n\n      - name: Test\n        run: npm run test & npm run size\n"
  },
  {
    "path": ".gitignore",
    "content": "/build/\n/fixtures/*/history.js\n\nnode_modules/\n"
  },
  {
    "path": ".prettierignore",
    "content": "package.json\npackage-lock.json\n"
  },
  {
    "path": ".prettierrc",
    "content": "{}\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "All development happens [on GitHub](https://github.com/remix-run/history). When [creating a pull request](https://help.github.com/articles/creating-a-pull-request/), please make sure that all of the following apply:\n\n- If you're adding a new feature or \"fixing\" a bug, please go into detail about your use case and why you think you need that feature or that bug fixed. This library has lots and lots of dependents, and we can't afford to make changes lightly without understanding why.\n- The tests pass. The test suite will automatically run when you create the PR. All you need to do is wait a few minutes to see the result in the PR.\n- Each commit in your PR should describe a significant piece of work. Work that was done in one commit and then undone later should be squashed into a single commit.\n\nIf your PR fails to meet these guidelines, it may be closed without much of an explanation besides a link to this document.\n\nThank you for your contribution!\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) React Training 2016-2020\nCopyright (c) Remix Software 2020-2021\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject 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,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# history &middot; [![npm package][npm-badge]][npm]\n\n[npm-badge]: https://img.shields.io/npm/v/history.svg?style=flat-square\n[npm]: https://www.npmjs.org/package/history\n\nThe history library lets you easily manage session history anywhere JavaScript runs. A `history` object abstracts away the differences in various environments and provides a minimal API that lets you manage the history stack, navigate, and persist state between sessions.\n\n## Documentation\n\nDocumentation for version 5 can be found in the [docs](docs) directory. This is the current stable release. Version 5 is used in React Router version 6.\n\nDocumentation for version 4 can be found [on the v4 branch](https://github.com/remix-run/history/tree/v4/docs). Version 4 is used in React Router versions 4 and 5.\n\n## Changes\n\nTo see the changes that were made in a given release, please lookup the tag on [the releases page](https://github.com/remix-run/history/releases).\n\nFor changes released in version 4.6.3 and earlier, please see [the `CHANGES.md` file](https://github.com/remix-run/history/blob/845d690c5576c7f55ecbe14babe0092e8e5bc2bb/CHANGES.md).\n\n## Development\n\nDevelopment of the current stable release, version 5, happens on [the `main` branch](https://github.com/remix-run/history/tree/main). Please keep in mind that this branch may include some work that has not yet been published as part of an official release. However, since `main` is always stable, you should feel free to build your own working release straight from `main` at any time.\n\nIf you're interested in helping out, please read [our contributing guidelines](CONTRIBUTING.md).\n\n## About\n\n`history` is developed and maintained by [Remix](https://remix.run). If you're interested in learning more about what React can do for your company, please [get in touch](mailto:hello@remix.run)!\n\n## Thanks\n\nA big thank-you to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to run our build in real browsers.\n\nAlso, thanks to [Dan Shaw](https://www.npmjs.com/~dshaw) for letting us use the `history` npm package name. Thanks, Dan!\n"
  },
  {
    "path": "docs/README.md",
    "content": "Welcome to the history docs!\n\nThe history library lets you easily manage session history anywhere JavaScript\nruns. A `history` object abstracts away the differences in various environments\nand provides a minimal API that lets you manage the history stack, navigate, and\npersist state between sessions.\n\nThe library is very small, so there are really just a few files here for you to\nbrowse.\n\nIf this is your first time here, we'd recommend you start with the [Getting\nStarted](getting-started.md) guide.\n\nYou may also be interested in reading one of the following guides:\n\n- [Installation](installation.md)\n- [Navigation](navigation.md)\n- [Blocking Transitions](blocking-transitions.md)\n\nAn [API Reference](api-reference.md) is also available.\n"
  },
  {
    "path": "docs/api-reference.md",
    "content": "<a name=\"top\"></a>\n\n# history API Reference\n\nThis is the API reference for [the history JavaScript library](https://github.com/remix-run/history).\n\nThe history library provides an API for tracking application history using [location](#location) objects that contain URLs and state. This reference includes type signatures and return values for the interfaces in the library. Please read the [getting started guide](getting-started.md) if you're looking for explanations about how to use the library to accomplish a specific task.\n\n<a name=\"overview\"></a>\n\n## Overview\n\n<a name=\"environments\"></a>\n\n### Environments\n\nThe history library includes support for three different \"environments\", or modes of operation.\n\n- [Browser history](#createbrowserhistory) is used in web apps\n- [Hash history](#createhashhistory) is used in web apps where you don't want to/can't send the URL to the server for some reason\n- [Memory history](#creatememoryhistory) - is used in native apps and testing\n\nJust pick the right mode for your target environment and you're good to go.\n\n<a name=\"listening\"></a>\n\n### Listening\n\nTo read the current location and action, use [`history.location`](#history.location) and [`history.action`](#history.action). Both of these properties are mutable and automatically update as the location changes.\n\nTo be notified when the location changes, setup a listener using [`history.listen`](#history.listen).\n\n<a name=\"navigation\"></a>\n\n### Navigation\n\nTo change the current location, you'll want to use one of the following:\n\n- [`history.push`](#history.push) - Pushes a new location onto the history stack\n- [`history.replace`](#history.replace) - Replaces the current location with another\n- [`history.go`](#history.go) - Changes the current index in the history stack by a given delta\n- [`history.back`](#history.back) - Navigates one entry back in the history stack\n- [`history.forward`](#history.forward) - Navigates one entry forward in the history stack\n\n<a name=\"confirming-navigation\"></a>\n\n### Confirming Navigation\n\nTo prevent the location from changing, use [`history.block`](#history.block). This API allows you to prevent the location from changing so you can prompt the user before retrying the transition.\n\n<a name=\"creating-hrefs\"></a>\n\n### Creating `href` values\n\nIf you're building a link, you'll want to use [`history.createHref`](#history.createhref) to get a URL you can use as the value of `<a href>`.\n\n---\n\n<a name=\"reference\"></a>\n\n## Reference\n\nThe [source code](https://github.com/remix-run/history/tree/main/packages/history) for the history library is written in TypeScript, but it is compiled to JavaScript before publishing. Some of the function signatures in this reference include their TypeScript type annotations, but you can always refer to the original source as well.\n\n<a name=\"action\"></a>\n\n### Action\n\nAn `Action` represents a type of change that occurred in the history stack. `Action` is an `enum` with three members:\n\n- <a name=\"action.pop\"></a> `Action.Pop` - A change to an arbitrary index in the stack, such as a back or forward navigation. This does not describe the direction of the navigation, only that the index changed. This is the default action for newly created history objects.\n- <a name=\"action.push\"></a> `Action.Push` - Indicates a new entry being added to the history stack, such as when a link is clicked and a new page loads. When this happens, all subsequent entries in the stack are lost.\n- <a name=\"action.replace\"></a> `Action.Replace` - Indicates the entry at the current index in the history stack being replaced by a new one.\n\nSee [the Getting Started guide](getting-started.md) for more information.\n\n<a name=\"createbrowserhistory\"></a>\n<a name=\"browserhistory\"></a>\n\n### `History`\n\nA `History` object represents the shared interface for `BrowserHistory`, `HashHistory`, and `MemoryHistory`.\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ninterface History {\n  readonly action: Action;\n  readonly location: Location;\n  createHref(to: To): string;\n  push(to: To, state?: any): void;\n  replace(to: To, state?: any): void;\n  go(delta: number): void;\n  back(): void;\n  forward(): void;\n  listen(listener: Listener): () => void;\n  block(blocker: Blocker): () => void;\n}\n```\n\n</details>\n\n### `createBrowserHistory`\n\n<details>\n  <summary>Type declaration</summary>\n\n```tsx\nfunction createBrowserHistory(options?: { window?: Window }): BrowserHistory;\n\ninterface BrowserHistory extends History {}\n```\n\n</details>\n\nA browser history object keeps track of the browsing history of an application using the browser's built-in history stack. It is designed to run in modern web browsers that support the HTML5 history interface including `pushState`, `replaceState`, and the `popstate` event.\n\n`createBrowserHistory` returns a `BrowserHistory` instance. `window` defaults to [the `defaultView` of the current `document`](https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView).\n\n```ts\nimport { createBrowserHistory } from \"history\";\nlet history = createBrowserHistory();\n```\n\nSee [the Getting Started guide](getting-started.md) for more information.\n\n<a name=\"createpath\"></a>\n<a name=\"parsepath\"></a>\n<a name=\"createpath-and-parsepath\"></a>\n\n### `createPath` and `parsePath`\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\nfunction createPath(partialPath: Partial<Path>): string;\nfunction parsePath(path: string): Partial<Path>;\n\ninterface Path {\n  pathname: string;\n  search: string;\n  hash: string;\n}\n```\n\n</details>\n\nThe `createPath` and `parsePath` functions are useful for creating and parsing URL paths.\n\n```ts\ncreatePath({ pathname: \"/login\", search: \"?next=home\" }); // \"/login?next=home\"\nparsePath(\"/login?next=home\"); // { pathname: '/login', search: '?next=home' }\n```\n\n<a name=\"createhashhistory\"></a>\n<a name=\"hashhistory\"></a>\n\n### `createHashHistory`\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ncreateHashHistory({ window?: Window }): HashHistory;\n\ninterface HashHistory extends History {}\n```\n\n</details>\n\nA hash history object keeps track of the browsing history of an application using the browser's built-in history stack. It is designed to be run in modern web browsers that support the HTML5 history interface including `pushState`, `replaceState`, and the `popstate` event.\n\n`createHashHistory` returns a `HashHistory` instance. `window` defaults to [the `defaultView` of the current `document`](https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView).\n\nThe main difference between this and [browser history](#createbrowserhistory) is that a hash history stores the current location in the [`hash` portion of the URL](https://developer.mozilla.org/en-US/docs/Web/API/Location/hash#:~:text=The%20hash%20property%20of%20the,an%20empty%20string%2C%20%22%22%20.), which means that it is not ever sent to the server. This can be useful if you are hosting your site on a domain where you do not have full control over the server routes, or e.g. in an Electron app where you don't want to configure the \"server\" to serve the same page at different URLs.\n\n```ts\nimport { createHashHistory } from \"history\";\nlet history = createHashHistory();\n```\n\nSee [the Getting Started guide](getting-started.md) for more information.\n\n<a name=\"creatememoryhistory\"></a>\n<a name=\"memoryhistory\"></a>\n\n### `createMemoryHistory`\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\nfunction createMemoryHistory({\n  initialEntries?: InitialEntry[],\n  initialIndex?: number\n}): MemoryHistory;\n\ntype InitialEntry = string | Partial<Location>;\n\ninterface MemoryHistory extends History {\n  readonly index: number;\n}\n```\n\n</details>\n\nA memory history object keeps track of the browsing history of an application using an internal array. This makes it ideal in situations where you need complete control over the history stack, like React Native and tests.\n\n`createMemoryHistory` returns a `MemoryHistory` instance. You can provide initial entries to this history instance through the `initialEntries` property, which defaults to `['/']` (a single location at the root `/` URL). The `initialIndex` defaults to the index of the last item in `initialEntries`.\n\n```ts\nimport { createMemoryHistory } from \"history\";\nlet history = createMemoryHistory();\n// Or, to pre-seed the history instance with some URLs:\nlet history = createMemoryHistory({\n  initialEntries: [\"/home\", \"/profile\", \"/about\"],\n});\n```\n\nSee [the Getting Started guide](getting-started.md) for more information.\n\n<a name=\"history.action\"></a>\n\n### `history.action`\n\nThe current (most recent) [`Action`](#action) that modified the history stack. This property is mutable and automatically updates as the current location changes.\n\nSee also [`history.listen`](#history.listen).\n\n<a name=\"history.back\"></a>\n\n### `history.back()`\n\nGoes back one entry in the history stack. Alias for `history.go(-1)`.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"history.block\"></a>\n\n### `history.block(blocker: Blocker)`\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ninterface Blocker {\n  (tx: Transition): void;\n}\n\ninterface Transition {\n  action: Action;\n  location: Location;\n  retry(): void;\n}\n```\n\n</details>\n\nPrevents changes to the history stack from happening. This is useful when you want to prevent the user navigating away from the current page, for example when they have some unsaved data on the current page.\n\n```ts\n// To start blocking location changes...\nlet unblock = history.block(({ action, location, retry }) => {\n  // A transition was blocked!\n});\n\n// Later, when you want to start allowing transitions again...\nunblock();\n```\n\nSee [the guide on Blocking Transitions](blocking-transitions.md) for more information.\n\n<a name=\"history.createhref\"></a>\n\n### `history.createHref(to: To)`\n\nReturns a string suitable for use as an `<a href>` value that will navigate to\nthe given destination.\n\n<a name=\"history.forward\"></a>\n\n### `history.forward()`\n\nGoes forward one entry in the history stack. Alias for `history.go(1)`.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"history.go\"></a>\n\n### `history.go(delta: number)`\n\nNavigates back/forward by `delta` entries in the stack.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"history.index\"></a>\n\n### `history.index`\n\nThe current index in the history stack.\n\n> [!Note:]\n>\n> This property is available only on [memory history](#memoryhistory) instances.\n\n<a name=\"history.listen\"></a>\n\n### `history.listen(listener: Listener)`\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ninterface Listener {\n  (update: Update): void;\n}\n\ninterface Update {\n  action: Action;\n  location: Location;\n}\n```\n\n</details>\n\nStarts listening for location changes and calls the given callback with an `Update` when it does.\n\n```ts\n// To start listening for location changes...\nlet unlisten = history.listen(({ action, location }) => {\n  // The current location changed.\n});\n\n// Later, when you are done listening for changes...\nunlisten();\n```\n\nSee [the Getting Started guide](getting-started.md#listening) for more information.\n\n<a name=\"history.location\"></a>\n\n### `history.location`\n\nThe current [`Location`](#location). This property is mutable and automatically updates as the current location changes.\n\nAlso see [`history.listen`](#history.listen).\n\n<a name=\"history.push\"></a>\n\n### `history.push(to: To, state?: any)`\n\nPushes a new entry onto the stack.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"history.replace\"></a>\n\n### `history.replace(to: To, state?: any)`\n\nReplaces the current entry in the stack with a new one.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"location\"></a>\n\n### Location\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ninterface Location {\n  pathname: string;\n  search: string;\n  hash: string;\n  state: unknown;\n  key: string;\n}\n```\n\n</details>\n\nA `location` is a particular entry in the history stack, usually analogous to a \"page\" or \"screen\" in your app. As the user clicks on links and moves around the app, the current location changes.\n\n<a name=\"location.pathname\"></a>\n\n### `location.pathname`\n\nThe `location.pathname` property is a string that contains an initial `/` followed by the remainder of the URL up to the `?`.\n\nSee also [`URL.pathname`](https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname).\n\n<a name=\"location.search\"></a>\n\n### `location.search`\n\nThe `location.search` property is a string that contains an initial `?` followed by the `key=value` pairs in the query string. If there are no parameters, this value may be the empty string (i.e. `''`).\n\nSee also [`URL.search`](https://developer.mozilla.org/en-US/docs/Web/API/URL/search).\n\n<a name=\"location.hash\"></a>\n\n### `location.hash`\n\nThe `location.hash` property is a string that contains an initial `#` followed by fragment identifier of the URL. If there is no fragment identifier, this value may be the empty string (i.e. `''`).\n\nSee also [`URL.hash`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash).\n\n<a name=\"location.state\"></a>\n\n### `location.state`\n\nThe `location.state` property is a user-supplied [`State`](#state) object that is associated with this location. This can be a useful place to store any information you do not want to put in the URL, e.g. session-specific data.\n\n> [!Note:]\n>\n> In web browsers, this state is managed using the browser's built-in\n> `pushState`, `replaceState`, and `popstate` APIs. See also\n> [`History.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).\n\n<a name=\"location.key\"></a>\n\n### `location.key`\n\nThe `location.key` property is a unique string associated with this location. On the initial location, this will be the string `default`. On all subsequent locations, this string will be a unique identifier.\n\nThis can be useful in situations where you need to keep track of 2 different states for the same URL. For example, you could use this as the key to some network or device storage API.\n\n<a name=\"state\"></a>\n\n### State\n\nA `State` value is an arbitrary value that holds extra information associated with a [`Location`](#location) but does not appear in the URL. This value is always associated with that location.\n\nSee [the Navigation guide](navigation.md) for more information.\n\n<a name=\"to\"></a>\n\n### To\n\n<details>\n  <summary>Type declaration</summary>\n\n```ts\ntype To = string | Partial<Path>;\n\ninterface Path {\n  pathname: string;\n  search: string;\n  hash: string;\n}\n```\n\n</details>\n\nA [`To`](https://github.com/remix-run/history/blob/main/packages/history/index.ts#L178) value represents a destination location, but doesn't contain all the information that a normal [`location`](#location) object does. It is primarily used as the first argument to [`history.push`](#history.push) and [`history.replace`](#history.replace).\n\nSee [the Navigation guide](navigation.md) for more information.\n"
  },
  {
    "path": "docs/blocking-transitions.md",
    "content": "# Blocking Transitions\n\n`history` lets you block navigation away from the current page using the\n[`history.block(blocker: Blocker)`](api-reference.md#history.block) API. For\nexample, you can make sure the user knows that if they leave the current page\nthey will lose some unsaved changes they've made.\n\n```js\n// Block navigation and register a callback that\n// fires when a navigation attempt is blocked.\nlet unblock = history.block((tx) => {\n  // Navigation was blocked! Let's show a confirmation dialog\n  // so the user can decide if they actually want to navigate\n  // away and discard changes they've made in the current page.\n  let url = tx.location.pathname;\n  if (window.confirm(`Are you sure you want to go to ${url}?`)) {\n    // Unblock the navigation.\n    unblock();\n\n    // Retry the transition.\n    tx.retry();\n  }\n});\n```\n\nThis example uses\n[`window.confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm),\nbut you could also use your own custom confirm dialog if you'd prefer.\n\n## Caveats\n\n`history.block` will call your callback for all in-page navigation attempts, but\nfor navigation that reloads the page (e.g. the refresh button or a link that\ndoesn't use `history.push`) it registers [a `beforeunload`\nhandler](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event)\nto prevent the navigation. In modern browsers you are not able to customize this\ndialog. Instead, you'll see something like this (Chrome):\n\n![Chrome navigation confirm dialog](images/block.png)\n\nOne subtle side effect of registering a `beforeunload` handler is that the page\nwill not be [salvageable](https://html.spec.whatwg.org/#unloading-documents) in\n[the `pagehide`\nevent](https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event).\nThis means the page may not be reused by the browser, so things like timers,\nscroll position, and event sources will not be reused when the user navigates\nback to that page.\n"
  },
  {
    "path": "docs/getting-started.md",
    "content": "<a name=\"top\"></a>\n<a name=\"intro\"></a>\n\n# Intro\n\nThe history library provides history tracking and navigation primitives for JavaScript applications that run in browsers and other stateful environments.\n\nIf you haven't yet, please take a second to read through [the Installation guide](installation.md) to get the library installed and running on your system.\n\nWe provide 3 different methods for working with history, depending on your environment:\n\n- A \"browser history\" is for use in modern web browsers that support the [HTML5 history API](http://diveintohtml5.info/history.html) (see [cross-browser compatibility](http://caniuse.com/#feat=history))\n- A \"hash history\" is for use in web browsers where you want to store the location in the [hash](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/hash) portion of the current URL to avoid sending it to the server when the page reloads\n- A \"memory history\" is used as a reference implementation that may be used in non-browser environments, like [React Native](https://facebook.github.io/react-native/) or tests\n\nThe main bundle exports one method for each environment: [`createBrowserHistory`](api-reference.md#createbrowserhistory) for browsers, [`createHashHistory`](api-reference.md#createhashhistory) for using hash history in browsers, and [`createMemoryHistory`](api-reference.md#creatememoryhistory) for creating an in-memory history.\n\nIn addition to the main bundle, the library also includes `history/browser` and `history/hash` bundles that export singletons you can use to quickly get a history instance for [the current `document`](https://developer.mozilla.org/en-US/docs/Web/API/Window/document) (web page).\n\n## Basic Usage\n\nBasic usage looks like this:\n\n```js\n// Create your own history instance.\nimport { createBrowserHistory } from \"history\";\nlet history = createBrowserHistory();\n\n// ... or just import the browser history singleton instance.\nimport history from \"history/browser\";\n\n// Alternatively, if you're using hash history import\n// the hash history singleton instance.\n// import history from 'history/hash';\n\n// Get the current location.\nlet location = history.location;\n\n// Listen for changes to the current location.\nlet unlisten = history.listen(({ location, action }) => {\n  console.log(action, location.pathname, location.state);\n});\n\n// Use push to push a new entry onto the history stack.\nhistory.push(\"/home\", { some: \"state\" });\n\n// Use replace to replace the current entry in the stack.\nhistory.replace(\"/logged-in\");\n\n// Use back/forward to navigate one entry back or forward.\nhistory.back();\n\n// To stop listening, call the function returned from listen().\nunlisten();\n```\n\nIf you're using memory history you'll need to create your own `history` object\nbefore you can use it.\n\n```js\nimport { createMemoryHistory } from \"history\";\nlet history = createMemoryHistory();\n```\n\nIf you're using browser or hash history with a `window` other than that of the\ncurrent `document` (like an iframe), you'll need to create your own browser/hash\nhistory:\n\n```js\nimport { createBrowserHistory } from \"history\";\nlet history = createBrowserHistory({\n  window: iframe.contentWindow,\n});\n```\n\n<a name=\"properties\"></a>\n\n## Properties\n\nEach `history` object has the following properties:\n\n- [`history.location`](api-reference.md#history.location) - The current location (see below)\n- [`history.action`](api-reference.md#history.action) - The current navigation action (see below)\n\nAdditionally, memory history provides `history.index` that tells you the current index in the history stack.\n\n<a name=\"listening\"></a>\n\n## Listening\n\nYou can listen for changes to the current location using `history.listen`:\n\n```js\nhistory.listen(({ action, location }) => {\n  console.log(\n    `The current URL is ${location.pathname}${location.search}${location.hash}`\n  );\n  console.log(`The last navigation action was ${action}`);\n});\n```\n\nThe [`location`](api-reference.md#location) object implements a subset of [the `window.location` interface](https://developer.mozilla.org/en-US/docs/Web/API/Location), including:\n\n- [`location.pathname`](api-reference.md#location.pathname) - The path of the URL\n- [`location.search`](api-reference.md#location.search) - The URL query string\n- [`location.hash`](api-reference.md#location.hash) - The URL hash fragment\n- [`location.state`](api-reference.md#location.state) - Some extra state for this\n  location that does not reside in the URL (may be `null`)\n- [`location.key`](api-reference.md#location.key) - A unique string representing this location\n\nThe [`action`](api-reference.md#action) is one of `Action.Push`, `Action.Replace`, or `Action.Pop` depending on how the user got to the current location.\n\n- `Action.Push` means one more entry was added to the history stack\n- `Action.Replace` means the current entry in the stack was replaced\n- `Action.Pop` means we went to some other location already in the stack\n\n<a name=\"cleaning-up\"></a>\n\n## Cleaning up\n\nWhen you attach a listener using `history.listen`, it returns a function that can be used to remove the listener, which can then be invoked in cleanup logic:\n\n```js\nlet unlisten = history.listen(myListener);\n\n// Later, when you're done...\nunlisten();\n```\n\n<a name=\"utilities\"></a>\n\n## Utilities\n\nThe main history bundle also contains both `createPath` and `parsePath` methods that may be useful when working with URL paths.\n\n```js\nlet pathPieces = parsePath(\"/the/path?the=query#the-hash\");\n// pathPieces = {\n//   pathname: '/the/path',\n//   search: '?the=query',\n//   hash: '#the-hash'\n// }\n\nlet path = createPath(pathPieces);\n// path = '/the/path?the=query#the-hash'\n```\n"
  },
  {
    "path": "docs/installation.md",
    "content": "# Installation\n\nThe history library is published to the public [npm](https://www.npmjs.com/)\nregistry. You can install it using:\n\n    $ npm install --save history\n\n## Using a Bundler\n\nThe best way to use the `history` library is with a bundler that supports\nJavaScript modules (we recommend [Rollup](https://rollupjs.org)). Recent\nversions of Webpack and Parcel are also good choices.\n\nThen you can write your code using JavaScript `import` statements, like this:\n\n```js\nimport { createBrowserHistory } from \"history\";\n// ...\n```\n\nIf you're using a bundler that doesn't understand JavaScript modules and only\nunderstands CommonJS, you can use `require` as you would with anything else:\n\n```js\nvar createBrowserHistory = require(\"history\").createBrowserHistory;\n```\n\n## Using `<script>` Tags\n\nIf you'd like to load the library in a browser via a `<script>` tag, you can\nload it from [unpkg](https://unpkg.com). If you're in a browser that supports\n[JavaScript\nmodules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules),\njust use the `history.production.min.js` build:\n\n```html\n<script type=\"module\">\n  // Can also use history.development.js in development\n  import { createBrowserHistory } from \"https://unpkg.com/history/history.production.min.js\";\n  // ...\n</script>\n```\n\nThe `history.development.js` build is also available for non-production apps.\n\nIn legacy browsers that do not yet support JavaScript modules, you can use one\nof our UMD (global) builds:\n\n```html\n<!-- Can also use history.development.js in development -->\n<script src=\"https://unpkg.com/history/umd/history.production.min.js\"></script>\n```\n\nYou can find the library on `window.HistoryLibrary`.\n"
  },
  {
    "path": "docs/navigation.md",
    "content": "# Navigation\n\n`history` objects may be used to programmatically change the current location\nusing the following methods:\n\n- [`history.push(to: To, state?: State)`](api-reference.md#history.push)\n- [`history.replace(to: To, state?: State)`](api-reference.md#history.replace)\n- [`history.go(delta: number)`](api-reference.md#history.go)\n- [`history.back()`](api-reference.md#history.back)\n- [`history.forward()`](api-reference.md#history.forward)\n\nAn example:\n\n```js\n// Push a new entry onto the history stack.\nhistory.push(\"/home\");\n\n// Push a new entry onto the history stack with a query string\n// and some state. Location state does not appear in the URL.\nhistory.push(\"/home?the=query\", { some: \"state\" });\n\n// If you prefer, use a location-like object to specify the URL.\n// This is equivalent to the example above.\nhistory.push(\n  {\n    pathname: \"/home\",\n    search: \"?the=query\",\n  },\n  {\n    some: state,\n  }\n);\n\n// Go back to the previous history entry. The following\n// two lines are synonymous.\nhistory.go(-1);\nhistory.back();\n```\n"
  },
  {
    "path": "fixtures/block-library/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <body>\n    <h1>Navigation Blocking (library version)</h1>\n\n    <p>\n      <label><input type=\"checkbox\" id=\"blocker\" /> block</label>\n    </p>\n    <p>\n      <span>back &amp; forward: </span><br />\n      <button onclick=\"goBack()\">back</button>\n      <button onclick=\"goForward()\">forward</button>\n    </p>\n    <p>\n      <span>pushState &amp; replaceState: </span><br />\n      <a href=\"/\" onclick=\"return pushLink(this)\">push /</a>\n      <a href=\"/one\" onclick=\"return pushLink(this)\">push /one</a>\n      <a href=\"/two\" onclick=\"return pushLink(this)\">push /two</a>\n      <a href=\"/three\" onclick=\"return replaceLink(this)\">replace /three</a>\n    </p>\n    <p>\n      <span>regular links: </span><br />\n      <a href=\"/\">/</a>\n      <a href=\"/one\">/one</a>\n    </p>\n\n    <script src=\"history.production.js\"></script>\n    <script>\n      var h = HistoryLibrary.createBrowserHistory();\n\n      // Blocker\n\n      var blocker = document.getElementById('blocker');\n      var unblock;\n\n      blocker.addEventListener('change', () => {\n        if (blocker.checked) {\n          unblock = h.block(onBlock);\n        } else if (unblock) {\n          unblock();\n          unblock = undefined;\n        }\n      });\n\n      function onBlock(tx) {\n        if (\n          window.confirm(\n            `Are you sure you want to go to ${tx.location.pathname +\n              tx.location.hash}?`\n          )\n        ) {\n          // Reset the blocker so the next transition is allowed.\n          blocker.checked = false;\n          unblock();\n          // Retry the transition.\n          tx.retry();\n        }\n      }\n\n      // Navigation\n\n      function pushLink(link) {\n        h.push(link.getAttribute('href'));\n        return false; // preventDefault\n      }\n\n      function replaceLink(link) {\n        h.replace(link.getAttribute('href'));\n        return false; // preventDefault\n      }\n\n      function goBack() {\n        h.back();\n      }\n\n      function goForward() {\n        h.forward();\n      }\n    </script>\n  </body>\n</html>\n"
  },
  {
    "path": "fixtures/block-library/index.js",
    "content": "/* eslint-disable no-console */\nconst express = require('express');\n\nlet port = process.env.PORT || 5000;\nlet app = express();\n\napp.use(express.static(__dirname));\n\napp.get('*', (req, res) => {\n  res.sendFile(__dirname + '/index.html');\n});\n\napp.listen(port, () => {\n  console.log(`Server listening on http://localhost:${port}`);\n});\n"
  },
  {
    "path": "fixtures/block-vanilla/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <body>\n    <h1>Navigation Blocking (vanilla JS version)</h1>\n\n    <p>\n      <label><input type=\"checkbox\" id=\"blocker\" /> block</label>\n    </p>\n    <p>\n      <span>back &amp; forward: </span><br />\n      <button onclick=\"goBack()\">back</button>\n      <button onclick=\"goForward()\">forward</button>\n    </p>\n    <p>\n      <span>pushState &amp; replaceState: </span><br />\n      <a href=\"/\" onclick=\"return pushLink(this)\">push /</a>\n      <a href=\"/one\" onclick=\"return pushLink(this)\">push /one</a>\n      <a href=\"/two\" onclick=\"return pushLink(this)\">push /two</a>\n      <a href=\"/three\" onclick=\"return replaceLink(this)\">replace /three</a>\n    </p>\n    <p>\n      <span>regular links: </span><br />\n      <a href=\"/\">/</a>\n      <a href=\"/one\">/one</a>\n    </p>\n\n    <script>\n      // Blocking\n\n      var blocker = document.getElementById('blocker');\n\n      function isBlocked() {\n        return blocker.checked;\n      }\n\n      function promptBeforeUnload(event) {\n        event.preventDefault();\n        event.returnValue = '';\n      }\n\n      function toggleBeforeUnloadPrompt() {\n        if (isBlocked()) {\n          window.addEventListener('beforeunload', promptBeforeUnload);\n        } else {\n          window.removeEventListener('beforeunload', promptBeforeUnload);\n        }\n      }\n\n      toggleBeforeUnloadPrompt();\n      blocker.addEventListener('change', () => {\n        toggleBeforeUnloadPrompt();\n      });\n\n      function onBlock(tx) {\n        if (confirm(`Are you sure you want to go to ${tx.href}?`)) {\n          blocker.checked = false;\n          toggleBeforeUnloadPrompt();\n          tx.retry();\n        }\n      }\n\n      // Popstate\n\n      var index = window.history.state && window.history.state.index;\n\n      if (index == null) {\n        index = 0;\n        window.history.replaceState(\n          Object.assign({}, window.history.state, { index }),\n          null\n        );\n      }\n\n      var blockedPopTx = null;\n\n      window.addEventListener('popstate', () => {\n        if (blockedPopTx) {\n          onBlock(blockedPopTx);\n          blockedPopTx = null;\n          return;\n        }\n\n        var nextIndex = window.history.state && window.history.state.index;\n\n        if (isBlocked()) {\n          if (nextIndex != null) {\n            var n = index - nextIndex;\n            if (n) {\n              // Revert the POP\n              blockedPopTx = {\n                href: window.location.href,\n                retry: () => {\n                  window.history.go(n * -1);\n                }\n              };\n\n              window.history.go(n);\n            }\n          } else {\n            // We did not generate this location, so we can't revert the POP.\n          }\n        } else {\n          index = nextIndex;\n        }\n      });\n\n      // Navigation\n\n      function pushLink(link) {\n        var href = link.getAttribute('href');\n\n        if (isBlocked()) {\n          onBlock({ href, retry: () => pushLink(link) });\n        } else {\n          index += 1;\n          window.history.pushState({ index }, null, href);\n        }\n\n        return false; // preventDefault\n      }\n\n      function replaceLink(link) {\n        var href = link.getAttribute('href');\n\n        if (isBlocked()) {\n          onBlock({ href, retry: () => replaceLink(link) });\n        } else {\n          window.history.replaceState({ index }, null, href);\n        }\n\n        return false; // preventDefault\n      }\n\n      function goBack() {\n        window.history.go(-1);\n      }\n\n      function goForward() {\n        window.history.go(1);\n      }\n    </script>\n  </body>\n</html>\n"
  },
  {
    "path": "fixtures/block-vanilla/index.js",
    "content": "/* eslint-disable no-console */\nconst express = require('express');\n\nlet port = process.env.PORT || 5000;\nlet app = express();\n\napp.use(express.static(__dirname));\n\napp.get('*', (req, res) => {\n  res.sendFile(__dirname + '/index.html');\n});\n\napp.listen(port, () => {\n  console.log(`Server listening on http://localhost:${port}`);\n});\n"
  },
  {
    "path": "fixtures/hash-click.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <base href=\"/the/base\" />\n    <script>\n      window.addEventListener('hashchange', () => {\n        console.log('hashchange', window.location.hash);\n      });\n\n      function handleClick(link) {\n        const href = link.getAttribute('href');\n        history.pushState(null, null, href);\n        return false; // preventDefault\n      }\n    </script>\n  </head>\n  <body>\n    <a href=\"/hash-click\">home</a>\n    <a href=\"/hash-click#one\">#one</a>\n    <a href=\"/hash-click#one\" onclick=\"return handleClick(this)\"\n      >#one w pushState</a\n    >\n    <a href=\"/hash-click#two\">#two</a>\n    <a href=\"/hash-click#two\" onclick=\"return handleClick(this)\"\n      >#two w pushState</a\n    >\n  </body>\n</html>\n"
  },
  {
    "path": "fixtures/hash-history-length.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <script>\n      console.log(window.history.length);\n    </script>\n  </head>\n  <body>\n    <a href=\"/hash-history-length\">home</a>\n    <a href=\"/hash-history-length#one\">#one</a>\n    <a href=\"/hash-history-length#two\">#two</a>\n  </body>\n</html>\n"
  },
  {
    "path": "fixtures/unpkg-test.html",
    "content": "<!doctype html>\n<html>\n  <body>\n    <script type=\"module\">\n      import { createBrowserHistory } from 'https://unpkg.com/history@next/history.production.min.js';\n      let history = createBrowserHistory();\n      console.log(history);\n    </script>\n  </body>\n</html>\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"private\": true,\n  \"scripts\": {\n    \"build\": \"node ./scripts/build.js\",\n    \"clean\": \"git clean -fdX .\",\n    \"lint\": \"eslint .\",\n    \"format\": \"prettier --ignore-path .eslintignore --write .\",\n    \"publish\": \"node ./scripts/publish.js\",\n    \"size\": \"filesize\",\n    \"test\": \"node ./scripts/test.js\",\n    \"version\": \"node ./scripts/version.js\",\n    \"watch\": \"node ./scripts/watch.js\"\n  },\n  \"dependencies\": {\n    \"@ampproject/filesize\": \"^4.3.0\",\n    \"@ampproject/rollup-plugin-closure-compiler\": \"0.27.0\",\n    \"@babel/core\": \"^7.15.0\",\n    \"@babel/plugin-transform-runtime\": \"^7.15.0\",\n    \"@babel/preset-env\": \"^7.15.0\",\n    \"@babel/preset-modules\": \"0.1.4\",\n    \"@babel/runtime\": \"^7.15.3\",\n    \"@rollup/plugin-babel\": \"^5.3.0\",\n    \"@rollup/plugin-replace\": \"^3.0.0\",\n    \"@typescript-eslint/eslint-plugin\": \"^4.29.1\",\n    \"@typescript-eslint/parser\": \"^4.29.1\",\n    \"babel-core\": \"^7.0.0-bridge.0\",\n    \"babel-eslint\": \"^10.1.0\",\n    \"babel-loader\": \"^8.2.2\",\n    \"babel-plugin-dev-expression\": \"0.2.2\",\n    \"chalk\": \"^4.1.2\",\n    \"eslint\": \"^7.32.0\",\n    \"eslint-config-react-app\": \"^6.0.0\",\n    \"eslint-plugin-flowtype\": \"^5.9.0\",\n    \"eslint-plugin-import\": \"^2.24.0\",\n    \"eslint-plugin-jsx-a11y\": \"^6.4.1\",\n    \"eslint-plugin-react\": \"^7.24.0\",\n    \"eslint-plugin-react-hooks\": \"^4.2.0\",\n    \"expect\": \"^21.0.0\",\n    \"express\": \"^4.17.1\",\n    \"jest-mock\": \"^21.0.6\",\n    \"jsonfile\": \"^6.1.0\",\n    \"karma\": \"^6.3.4\",\n    \"karma-browserstack-launcher\": \"^1.6.0\",\n    \"karma-chrome-launcher\": \"^3.1.0\",\n    \"karma-firefox-launcher\": \"^2.1.1\",\n    \"karma-mocha\": \"^2.0.1\",\n    \"karma-mocha-reporter\": \"^2.2.5\",\n    \"karma-sourcemap-loader\": \"0.3.8\",\n    \"karma-webpack\": \"^3.0.5\",\n    \"mocha\": \"^5.2.0\",\n    \"prettier\": \"^2.5.1\",\n    \"prompt-confirm\": \"^2.0.4\",\n    \"rollup\": \"^2.56.2\",\n    \"rollup-plugin-copy\": \"^3.4.0\",\n    \"rollup-plugin-prettier\": \"^2.1.0\",\n    \"rollup-plugin-terser\": \"^7.0.2\",\n    \"rollup-plugin-typescript2\": \"0.30.0\",\n    \"semver\": \"^7.3.5\",\n    \"typescript\": \"^4.3.5\",\n    \"webpack\": \"^3.12.0\"\n  },\n  \"workspaces\": {\n    \"packages\": [\n      \"packages/history\"\n    ]\n  },\n  \"filesize\": {\n    \"build/history/history.production.min.js\": {\n      \"none\": \"5.06 kB\"\n    },\n    \"build/history/umd/history.production.min.js\": {\n      \"none\": \"6.03 kB\"\n    }\n  }\n}\n"
  },
  {
    "path": "packages/history/.eslintrc",
    "content": "{\n  \"env\": {\n    \"browser\": true,\n    \"es6\": true,\n    \"node\": false\n  },\n  \"globals\": {\n    \"__DEV__\": true\n  }\n}\n"
  },
  {
    "path": "packages/history/__tests__/.eslintrc",
    "content": "{\n  \"env\": {\n    \"mocha\": true\n  },\n  \"rules\": {\n    \"import/no-unresolved\": [2, { \"ignore\": [\"history\"] }]\n  }\n}\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/BackButtonTransitionHook.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let hookWasCalled = false;\n  let unblock;\n\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      unblock = history.block(() => {\n        hookWasCalled = true;\n      });\n\n      window.history.go(-1);\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"POP\");\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      expect(hookWasCalled).toBe(true);\n\n      unblock();\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/BlockEverything.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      let unblock = history.block();\n\n      history.push(\"/home\");\n\n      expect(history.location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      unblock();\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/BlockPopWithoutListening.js",
    "content": "import expect from \"expect\";\n\nexport default (history, done) => {\n  expect(history.location).toMatchObject({\n    pathname: \"/\",\n  });\n\n  history.push(\"/home\");\n\n  let transitionHookWasCalled = false;\n  let unblock = history.block(() => {\n    transitionHookWasCalled = true;\n  });\n\n  // These timeouts are a hack to allow for the time it takes\n  // for histories to reflect the change in the URL. Normally\n  // we could just listen and avoid the waiting time. But this\n  // test is designed to test what happens when we don't listen(),\n  // so that's not an option here.\n\n  // Allow some time for history to detect the PUSH.\n  setTimeout(() => {\n    history.back();\n\n    // Allow some time for history to detect the POP.\n    setTimeout(() => {\n      expect(transitionHookWasCalled).toBe(true);\n      unblock();\n\n      done();\n    }, 100);\n  }, 10);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/EncodedReservedCharacters.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    () => {\n      // encoded string\n      let pathname = \"/view/%23abc\";\n      history.replace(pathname);\n    },\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/view/%23abc\",\n      });\n      // encoded object\n      let pathname = \"/view/%23abc\";\n      history.replace({ pathname });\n    },\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/view/%23abc\",\n      });\n      // unencoded string\n      let pathname = \"/view/#abc\";\n      history.replace(pathname);\n    },\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/view/\",\n        hash: \"#abc\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/GoBack.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toEqual(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      history.back();\n    },\n    ({ action, location }) => {\n      expect(action).toEqual(\"POP\");\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/GoForward.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toEqual(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      history.back();\n    },\n    ({ action, location }) => {\n      expect(action).toEqual(\"POP\");\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.forward();\n    },\n    ({ action, location }) => {\n      expect(action).toEqual(\"POP\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/InitialLocationDefaultKey.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location.key).toBe(\"default\");\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/InitialLocationHasKey.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location.key).toBeTruthy();\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/Listen.js",
    "content": "import expect from \"expect\";\nimport mock from \"jest-mock\";\n\nexport default (history, done) => {\n  let spy = mock.fn();\n  let unlisten = history.listen(spy);\n\n  expect(spy).not.toHaveBeenCalled();\n\n  unlisten();\n  done();\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushMissingPathname.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home?the=query#the-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n      });\n\n      history.push(\"?another=query#another-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?another=query\",\n        hash: \"#another-hash\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushNewLocation.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home?the=query#the-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n        state: null,\n        key: expect.any(String),\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushRelativePathname.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/the/path?the=query#the-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/the/path\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n      });\n\n      history.push(\"../other/path?another=query#another-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/other/path\",\n        search: \"?another=query\",\n        hash: \"#another-hash\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps, spyOn } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/the/path?the=query#the-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/the/path\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n      });\n\n      let { spy, destroy } = spyOn(console, \"warn\");\n\n      history.push(\"../other/path?another=query#another-hash\");\n\n      expect(spy).toHaveBeenCalledWith(\n        expect.stringContaining(\"relative pathnames are not supported\")\n      );\n\n      destroy();\n    },\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"../other/path\",\n        search: \"?another=query\",\n        hash: \"#another-hash\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushSamePath.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      history.push(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      history.back();\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"POP\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/PushState.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.push(\"/home?the=query#the-hash\", { the: \"state\" });\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"PUSH\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n        state: { the: \"state\" },\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/ReplaceNewLocation.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.replace(\"/home?the=query#the-hash\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"REPLACE\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n        state: null,\n        key: expect.any(String),\n      });\n\n      history.replace(\"/\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"REPLACE\");\n      expect(location).toMatchObject({\n        pathname: \"/\",\n        search: \"\",\n        state: null,\n        key: expect.any(String),\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/ReplaceSamePath.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let prevLocation;\n\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.replace(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"REPLACE\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      prevLocation = location;\n\n      history.replace(\"/home\");\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"REPLACE\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n      });\n\n      expect(location).not.toBe(prevLocation);\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/ReplaceState.js",
    "content": "import expect from \"expect\";\n\nimport { execSteps } from \"./utils.js\";\n\nexport default (history, done) => {\n  let steps = [\n    ({ location }) => {\n      expect(location).toMatchObject({\n        pathname: \"/\",\n      });\n\n      history.replace(\"/home?the=query#the-hash\", { the: \"state\" });\n    },\n    ({ action, location }) => {\n      expect(action).toBe(\"REPLACE\");\n      expect(location).toMatchObject({\n        pathname: \"/home\",\n        search: \"?the=query\",\n        hash: \"#the-hash\",\n        state: { the: \"state\" },\n      });\n    },\n  ];\n\n  execSteps(steps, history, done);\n};\n"
  },
  {
    "path": "packages/history/__tests__/TestSequences/utils.js",
    "content": "import mock from \"jest-mock\";\n\nexport function spyOn(object, method) {\n  let original = object[method];\n  let spy = mock.fn();\n\n  object[method] = spy;\n\n  return {\n    spy,\n    destroy() {\n      object[method] = original;\n    },\n  };\n}\n\nexport function execSteps(steps, history, done) {\n  let index = 0,\n    unlisten,\n    cleanedUp = false;\n\n  function cleanup(...args) {\n    if (!cleanedUp) {\n      cleanedUp = true;\n      unlisten();\n      done(...args);\n    }\n  }\n\n  function execNextStep(...args) {\n    try {\n      let nextStep = steps[index++];\n      if (!nextStep) throw new Error(\"Test is missing step \" + index);\n\n      nextStep(...args);\n\n      if (index === steps.length) cleanup();\n    } catch (error) {\n      cleanup(error);\n    }\n  }\n\n  if (steps.length) {\n    unlisten = history.listen(execNextStep);\n\n    execNextStep({\n      action: history.action,\n      location: history.location,\n    });\n  } else {\n    done();\n  }\n}\n"
  },
  {
    "path": "packages/history/__tests__/browser-test.js",
    "content": "import expect from \"expect\";\nimport { createBrowserHistory } from \"history\";\n\nimport InitialLocationDefaultKey from \"./TestSequences/InitialLocationDefaultKey.js\";\nimport Listen from \"./TestSequences/Listen.js\";\nimport PushNewLocation from \"./TestSequences/PushNewLocation.js\";\nimport PushSamePath from \"./TestSequences/PushSamePath.js\";\nimport PushState from \"./TestSequences/PushState.js\";\nimport PushMissingPathname from \"./TestSequences/PushMissingPathname.js\";\nimport PushRelativePathname from \"./TestSequences/PushRelativePathname.js\";\nimport ReplaceNewLocation from \"./TestSequences/ReplaceNewLocation.js\";\nimport ReplaceSamePath from \"./TestSequences/ReplaceSamePath.js\";\nimport ReplaceState from \"./TestSequences/ReplaceState.js\";\nimport EncodedReservedCharacters from \"./TestSequences/EncodedReservedCharacters.js\";\nimport GoBack from \"./TestSequences/GoBack.js\";\nimport GoForward from \"./TestSequences/GoForward.js\";\nimport BlockEverything from \"./TestSequences/BlockEverything.js\";\nimport BlockPopWithoutListening from \"./TestSequences/BlockPopWithoutListening.js\";\n\ndescribe(\"a browser history\", () => {\n  let history;\n  beforeEach(() => {\n    window.history.replaceState(null, null, \"/\");\n    history = createBrowserHistory();\n  });\n\n  it(\"knows how to create hrefs from location objects\", () => {\n    const href = history.createHref({\n      pathname: \"/the/path\",\n      search: \"?the=query\",\n      hash: \"#the-hash\",\n    });\n\n    expect(href).toEqual(\"/the/path?the=query#the-hash\");\n  });\n\n  it(\"knows how to create hrefs from strings\", () => {\n    const href = history.createHref(\"/the/path?the=query#the-hash\");\n    expect(href).toEqual(\"/the/path?the=query#the-hash\");\n  });\n\n  it(\"does not encode the generated path\", () => {\n    const encodedHref = history.createHref({\n      pathname: \"/%23abc\",\n    });\n    expect(encodedHref).toEqual(\"/%23abc\");\n\n    const unencodedHref = history.createHref({\n      pathname: \"/#abc\",\n    });\n    expect(unencodedHref).toEqual(\"/#abc\");\n  });\n\n  describe(\"listen\", () => {\n    it(\"does not immediately call listeners\", (done) => {\n      Listen(history, done);\n    });\n  });\n\n  describe(\"the initial location\", () => {\n    it('has the \"default\" key', (done) => {\n      InitialLocationDefaultKey(history, done);\n    });\n  });\n\n  describe(\"push a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushNewLocation(history, done);\n    });\n  });\n\n  describe(\"push the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushSamePath(history, done);\n    });\n  });\n\n  describe(\"push state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushState(history, done);\n    });\n  });\n\n  describe(\"push with no pathname\", () => {\n    it(\"reuses the current location pathname\", (done) => {\n      PushMissingPathname(history, done);\n    });\n  });\n\n  describe(\"push with a relative pathname\", () => {\n    it(\"normalizes the pathname relative to the current location\", (done) => {\n      PushRelativePathname(history, done);\n    });\n  });\n\n  describe(\"replace a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceNewLocation(history, done);\n    });\n  });\n\n  describe(\"replace the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceSamePath(history, done);\n    });\n  });\n\n  describe(\"replace state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceState(history, done);\n    });\n  });\n\n  describe(\"location created with encoded/unencoded reserved characters\", () => {\n    it(\"produces different location objects\", (done) => {\n      EncodedReservedCharacters(history, done);\n    });\n  });\n\n  describe(\"back\", () => {\n    it(\"calls change listeners with the previous location\", (done) => {\n      GoBack(history, done);\n    });\n  });\n\n  describe(\"forward\", () => {\n    it(\"calls change listeners with the next location\", (done) => {\n      GoForward(history, done);\n    });\n  });\n\n  describe(\"block\", () => {\n    it(\"blocks all transitions\", (done) => {\n      BlockEverything(history, done);\n    });\n  });\n\n  describe(\"block a POP without listening\", () => {\n    it(\"receives the next ({ action, location })\", (done) => {\n      BlockPopWithoutListening(history, done);\n    });\n  });\n});\n"
  },
  {
    "path": "packages/history/__tests__/create-path-test.js",
    "content": "import expect from \"expect\";\nimport { createPath } from \"history\";\n\ndescribe(\"createPath\", () => {\n  describe(\"given only a pathname\", () => {\n    it(\"returns the pathname unchanged\", () => {\n      let path = createPath({ pathname: \"https://google.com\" });\n      expect(path).toBe(\"https://google.com\");\n    });\n  });\n\n  describe(\"given a pathname and a search param\", () => {\n    it(\"returns the constructed pathname\", () => {\n      let path = createPath({\n        pathname: \"https://google.com\",\n        search: \"?something=cool\",\n      });\n      expect(path).toBe(\"https://google.com?something=cool\");\n    });\n  });\n\n  describe(\"given a pathname and a search param without ?\", () => {\n    it(\"returns the constructed pathname\", () => {\n      let path = createPath({\n        pathname: \"https://google.com\",\n        search: \"something=cool\",\n      });\n      expect(path).toBe(\"https://google.com?something=cool\");\n    });\n  });\n\n  describe(\"given a pathname and a hash param\", () => {\n    it(\"returns the constructed pathname\", () => {\n      let path = createPath({\n        pathname: \"https://google.com\",\n        hash: \"#section-1\",\n      });\n      expect(path).toBe(\"https://google.com#section-1\");\n    });\n  });\n\n  describe(\"given a pathname and a hash param without #\", () => {\n    it(\"returns the constructed pathname\", () => {\n      let path = createPath({\n        pathname: \"https://google.com\",\n        hash: \"section-1\",\n      });\n      expect(path).toBe(\"https://google.com#section-1\");\n    });\n  });\n\n  describe(\"given a full location object\", () => {\n    it(\"returns the constructed pathname\", () => {\n      let path = createPath({\n        pathname: \"https://google.com\",\n        search: \"something=cool\",\n        hash: \"#section-1\",\n      });\n      expect(path).toBe(\"https://google.com?something=cool#section-1\");\n    });\n  });\n});\n"
  },
  {
    "path": "packages/history/__tests__/hash-base-test.js",
    "content": "import expect from \"expect\";\nimport { createHashHistory } from \"history\";\n\ndescribe(\"a hash history on a page with a <base> tag\", () => {\n  let history, base;\n  beforeEach(() => {\n    if (window.location.hash !== \"#/\") {\n      window.location.hash = \"/\";\n    }\n\n    base = document.createElement(\"base\");\n    base.setAttribute(\"href\", \"/prefix\");\n\n    document.head.appendChild(base);\n\n    history = createHashHistory();\n  });\n\n  afterEach(() => {\n    document.head.removeChild(base);\n  });\n\n  it(\"knows how to create hrefs\", () => {\n    const hashIndex = window.location.href.indexOf(\"#\");\n    const upToHash =\n      hashIndex === -1\n        ? window.location.href\n        : window.location.href.slice(0, hashIndex);\n\n    const href = history.createHref({\n      pathname: \"/the/path\",\n      search: \"?the=query\",\n      hash: \"#the-hash\",\n    });\n\n    expect(href).toEqual(upToHash + \"#/the/path?the=query#the-hash\");\n  });\n});\n"
  },
  {
    "path": "packages/history/__tests__/hash-test.js",
    "content": "import expect from \"expect\";\nimport { createHashHistory } from \"history\";\n\nimport Listen from \"./TestSequences/Listen.js\";\nimport InitialLocationDefaultKey from \"./TestSequences/InitialLocationDefaultKey.js\";\nimport PushNewLocation from \"./TestSequences/PushNewLocation.js\";\nimport PushSamePath from \"./TestSequences/PushSamePath.js\";\nimport PushState from \"./TestSequences/PushState.js\";\nimport PushMissingPathname from \"./TestSequences/PushMissingPathname.js\";\nimport PushRelativePathnameWarning from \"./TestSequences/PushRelativePathnameWarning.js\";\nimport ReplaceNewLocation from \"./TestSequences/ReplaceNewLocation.js\";\nimport ReplaceSamePath from \"./TestSequences/ReplaceSamePath.js\";\nimport ReplaceState from \"./TestSequences/ReplaceState.js\";\nimport EncodedReservedCharacters from \"./TestSequences/EncodedReservedCharacters.js\";\nimport GoBack from \"./TestSequences/GoBack.js\";\nimport GoForward from \"./TestSequences/GoForward.js\";\nimport BlockEverything from \"./TestSequences/BlockEverything.js\";\nimport BlockPopWithoutListening from \"./TestSequences/BlockPopWithoutListening.js\";\n\n// TODO: Do we still need this?\n// const canGoWithoutReload = window.navigator.userAgent.indexOf('Firefox') === -1;\n// const describeGo = canGoWithoutReload ? describe : describe.skip;\n\ndescribe(\"a hash history\", () => {\n  let history;\n  beforeEach(() => {\n    window.history.replaceState(null, null, \"#/\");\n    history = createHashHistory();\n  });\n\n  it(\"knows how to create hrefs from location objects\", () => {\n    const href = history.createHref({\n      pathname: \"/the/path\",\n      search: \"?the=query\",\n      hash: \"#the-hash\",\n    });\n\n    expect(href).toEqual(\"#/the/path?the=query#the-hash\");\n  });\n\n  it(\"knows how to create hrefs from strings\", () => {\n    const href = history.createHref(\"/the/path?the=query#the-hash\");\n    expect(href).toEqual(\"#/the/path?the=query#the-hash\");\n  });\n\n  it(\"does not encode the generated path\", () => {\n    const encodedHref = history.createHref({\n      pathname: \"/%23abc\",\n    });\n    expect(encodedHref).toEqual(\"#/%23abc\");\n\n    const unencodedHref = history.createHref({\n      pathname: \"/#abc\",\n    });\n    expect(unencodedHref).toEqual(\"#/#abc\");\n  });\n\n  describe(\"listen\", () => {\n    it(\"does not immediately call listeners\", (done) => {\n      Listen(history, done);\n    });\n  });\n\n  describe(\"the initial location\", () => {\n    it('has the \"default\" key', (done) => {\n      InitialLocationDefaultKey(history, done);\n    });\n  });\n\n  describe(\"push a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushNewLocation(history, done);\n    });\n  });\n\n  describe(\"push the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushSamePath(history, done);\n    });\n  });\n\n  describe(\"push state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushState(history, done);\n    });\n  });\n\n  describe(\"push with no pathname\", () => {\n    it(\"reuses the current location pathname\", (done) => {\n      PushMissingPathname(history, done);\n    });\n  });\n\n  describe(\"push with a relative pathname\", () => {\n    it(\"issues a warning\", (done) => {\n      PushRelativePathnameWarning(history, done);\n    });\n  });\n\n  describe(\"replace a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceNewLocation(history, done);\n    });\n  });\n\n  describe(\"replace the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceSamePath(history, done);\n    });\n  });\n\n  describe(\"replace state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceState(history, done);\n    });\n  });\n\n  describe(\"location created with encoded/unencoded reserved characters\", () => {\n    it(\"produces different location objects\", (done) => {\n      EncodedReservedCharacters(history, done);\n    });\n  });\n\n  describe(\"back\", () => {\n    it(\"calls change listeners with the previous location\", (done) => {\n      GoBack(history, done);\n    });\n  });\n\n  describe(\"forward\", () => {\n    it(\"calls change listeners with the next location\", (done) => {\n      GoForward(history, done);\n    });\n  });\n\n  describe(\"block\", () => {\n    it(\"blocks all transitions\", (done) => {\n      BlockEverything(history, done);\n    });\n  });\n\n  describe(\"block a POP without listening\", () => {\n    it(\"receives the next location and action as arguments\", (done) => {\n      BlockPopWithoutListening(history, done);\n    });\n  });\n});\n"
  },
  {
    "path": "packages/history/__tests__/memory-test.js",
    "content": "import expect from \"expect\";\nimport { createMemoryHistory } from \"history\";\n\nimport Listen from \"./TestSequences/Listen.js\";\nimport InitialLocationHasKey from \"./TestSequences/InitialLocationHasKey.js\";\nimport PushNewLocation from \"./TestSequences/PushNewLocation.js\";\nimport PushSamePath from \"./TestSequences/PushSamePath.js\";\nimport PushState from \"./TestSequences/PushState.js\";\nimport PushMissingPathname from \"./TestSequences/PushMissingPathname.js\";\nimport PushRelativePathnameWarning from \"./TestSequences/PushRelativePathnameWarning.js\";\nimport ReplaceNewLocation from \"./TestSequences/ReplaceNewLocation.js\";\nimport ReplaceSamePath from \"./TestSequences/ReplaceSamePath.js\";\nimport ReplaceState from \"./TestSequences/ReplaceState.js\";\nimport EncodedReservedCharacters from \"./TestSequences/EncodedReservedCharacters.js\";\nimport GoBack from \"./TestSequences/GoBack.js\";\nimport GoForward from \"./TestSequences/GoForward.js\";\nimport BlockEverything from \"./TestSequences/BlockEverything.js\";\nimport BlockPopWithoutListening from \"./TestSequences/BlockPopWithoutListening.js\";\n\ndescribe(\"a memory history\", () => {\n  let history;\n  beforeEach(() => {\n    history = createMemoryHistory();\n  });\n\n  it(\"has an index property\", () => {\n    expect(typeof history.index).toBe(\"number\");\n  });\n\n  it(\"knows how to create hrefs\", () => {\n    const href = history.createHref({\n      pathname: \"/the/path\",\n      search: \"?the=query\",\n      hash: \"#the-hash\",\n    });\n\n    expect(href).toEqual(\"/the/path?the=query#the-hash\");\n  });\n\n  it(\"knows how to create hrefs from strings\", () => {\n    const href = history.createHref(\"/the/path?the=query#the-hash\");\n    expect(href).toEqual(\"/the/path?the=query#the-hash\");\n  });\n\n  it(\"does not encode the generated path\", () => {\n    const encodedHref = history.createHref({\n      pathname: \"/%23abc\",\n    });\n    expect(encodedHref).toEqual(\"/%23abc\");\n\n    const unencodedHref = history.createHref({\n      pathname: \"/#abc\",\n    });\n    expect(unencodedHref).toEqual(\"/#abc\");\n  });\n\n  describe(\"listen\", () => {\n    it(\"does not immediately call listeners\", (done) => {\n      Listen(history, done);\n    });\n  });\n\n  describe(\"the initial location\", () => {\n    it(\"has a key\", (done) => {\n      InitialLocationHasKey(history, done);\n    });\n  });\n\n  describe(\"push a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushNewLocation(history, done);\n    });\n  });\n\n  describe(\"push the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushSamePath(history, done);\n    });\n  });\n\n  describe(\"push state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      PushState(history, done);\n    });\n  });\n\n  describe(\"push with no pathname\", () => {\n    it(\"reuses the current location pathname\", (done) => {\n      PushMissingPathname(history, done);\n    });\n  });\n\n  describe(\"push with a relative pathname\", () => {\n    it(\"issues a warning\", (done) => {\n      PushRelativePathnameWarning(history, done);\n    });\n  });\n\n  describe(\"replace a new path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceNewLocation(history, done);\n    });\n  });\n\n  describe(\"replace the same path\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceSamePath(history, done);\n    });\n  });\n\n  describe(\"replace state\", () => {\n    it(\"calls change listeners with the new location\", (done) => {\n      ReplaceState(history, done);\n    });\n  });\n\n  describe(\"location created with encoded/unencoded reserved characters\", () => {\n    it(\"produces different location objects\", (done) => {\n      EncodedReservedCharacters(history, done);\n    });\n  });\n\n  describe(\"back\", () => {\n    it(\"calls change listeners with the previous location\", (done) => {\n      GoBack(history, done);\n    });\n  });\n\n  describe(\"forward\", () => {\n    it(\"calls change listeners with the next location\", (done) => {\n      GoForward(history, done);\n    });\n  });\n\n  describe(\"block\", () => {\n    it(\"blocks all transitions\", (done) => {\n      BlockEverything(history, done);\n    });\n  });\n\n  describe(\"block a POP without listening\", () => {\n    it(\"receives the next location and action as arguments\", (done) => {\n      BlockPopWithoutListening(history, done);\n    });\n  });\n});\n\ndescribe(\"a memory history with some initial entries\", () => {\n  it(\"clamps the initial index to a valid value\", () => {\n    let history = createMemoryHistory({\n      initialEntries: [\"/one\", \"/two\", \"/three\"],\n      initialIndex: 3, // invalid\n    });\n\n    expect(history.index).toBe(2);\n  });\n\n  it(\"starts at the last entry by default\", () => {\n    let history = createMemoryHistory({\n      initialEntries: [\"/one\", \"/two\", \"/three\"],\n    });\n\n    expect(history.index).toBe(2);\n    expect(history.location).toMatchObject({\n      pathname: \"/three\",\n      search: \"\",\n      hash: \"\",\n      state: null,\n      key: expect.any(String),\n    });\n  });\n});\n"
  },
  {
    "path": "packages/history/browser.ts",
    "content": "import { createBrowserHistory } from \"history\";\n\n/**\n * Create a default instance for the current document.\n */\nexport default createBrowserHistory();\n"
  },
  {
    "path": "packages/history/hash.ts",
    "content": "import { createHashHistory } from \"history\";\n\n/**\n * Create a default instance for the current document.\n */\nexport default createHashHistory();\n"
  },
  {
    "path": "packages/history/index.ts",
    "content": "/**\n * Actions represent the type of change to a location value.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action\n */\nexport enum Action {\n  /**\n   * A POP indicates a change to an arbitrary index in the history stack, such\n   * as a back or forward navigation. It does not describe the direction of the\n   * navigation, only that the current index changed.\n   *\n   * Note: This is the default action for newly created history objects.\n   */\n  Pop = \"POP\",\n\n  /**\n   * A PUSH indicates a new entry being added to the history stack, such as when\n   * a link is clicked and a new page loads. When this happens, all subsequent\n   * entries in the stack are lost.\n   */\n  Push = \"PUSH\",\n\n  /**\n   * A REPLACE indicates the entry at the current index in the history stack\n   * being replaced by a new one.\n   */\n  Replace = \"REPLACE\",\n}\n\n/**\n * A URL pathname, beginning with a /.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.pathname\n */\nexport type Pathname = string;\n\n/**\n * A URL search string, beginning with a ?.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.search\n */\nexport type Search = string;\n\n/**\n * A URL fragment identifier, beginning with a #.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.hash\n */\nexport type Hash = string;\n\n/**\n * An object that is used to associate some arbitrary data with a location, but\n * that does not appear in the URL path.\n *\n * @deprecated\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.state\n */\nexport type State = unknown;\n\n/**\n * A unique string associated with a location. May be used to safely store\n * and retrieve data in some other storage API, like `localStorage`.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.key\n */\nexport type Key = string;\n\n/**\n * The pathname, search, and hash values of a URL.\n */\nexport interface Path {\n  /**\n   * A URL pathname, beginning with a /.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.pathname\n   */\n  pathname: Pathname;\n\n  /**\n   * A URL search string, beginning with a ?.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.search\n   */\n  search: Search;\n\n  /**\n   * A URL fragment identifier, beginning with a #.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.hash\n   */\n  hash: Hash;\n}\n\n/**\n * An entry in a history stack. A location contains information about the\n * URL path, as well as possibly some arbitrary state and a key.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location\n */\nexport interface Location extends Path {\n  /**\n   * A value of arbitrary data associated with this location.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.state\n   */\n  state: unknown;\n\n  /**\n   * A unique string associated with this location. May be used to safely store\n   * and retrieve data in some other storage API, like `localStorage`.\n   *\n   * Note: This value is always \"default\" on the initial location.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#location.key\n   */\n  key: Key;\n}\n\n/**\n * A partial Path object that may be missing some properties.\n *\n * @deprecated\n */\nexport type PartialPath = Partial<Path>;\n\n/**\n * A partial Location object that may be missing some properties.\n *\n * @deprecated\n */\nexport type PartialLocation = Partial<Location>;\n\n/**\n * A change to the current location.\n */\nexport interface Update {\n  /**\n   * The action that triggered the change.\n   */\n  action: Action;\n\n  /**\n   * The new location.\n   */\n  location: Location;\n}\n\n/**\n * A function that receives notifications about location changes.\n */\nexport interface Listener {\n  (update: Update): void;\n}\n\n/**\n * A change to the current location that was blocked. May be retried\n * after obtaining user confirmation.\n */\nexport interface Transition extends Update {\n  /**\n   * Retries the update to the current location.\n   */\n  retry(): void;\n}\n\n/**\n * A function that receives transitions when navigation is blocked.\n */\nexport interface Blocker {\n  (tx: Transition): void;\n}\n\n/**\n * Describes a location that is the destination of some navigation, either via\n * `history.push` or `history.replace`. May be either a URL or the pieces of a\n * URL path.\n */\nexport type To = string | Partial<Path>;\n\n/**\n * A history is an interface to the navigation stack. The history serves as the\n * source of truth for the current location, as well as provides a set of\n * methods that may be used to change it.\n *\n * It is similar to the DOM's `window.history` object, but with a smaller, more\n * focused API.\n */\nexport interface History {\n  /**\n   * The last action that modified the current location. This will always be\n   * Action.Pop when a history instance is first created. This value is mutable.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.action\n   */\n  readonly action: Action;\n\n  /**\n   * The current location. This value is mutable.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.location\n   */\n  readonly location: Location;\n\n  /**\n   * Returns a valid href for the given `to` value that may be used as\n   * the value of an <a href> attribute.\n   *\n   * @param to - The destination URL\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.createHref\n   */\n  createHref(to: To): string;\n\n  /**\n   * Pushes a new location onto the history stack, increasing its length by one.\n   * If there were any entries in the stack after the current one, they are\n   * lost.\n   *\n   * @param to - The new URL\n   * @param state - Data to associate with the new location\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.push\n   */\n  push(to: To, state?: any): void;\n\n  /**\n   * Replaces the current location in the history stack with a new one.  The\n   * location that was replaced will no longer be available.\n   *\n   * @param to - The new URL\n   * @param state - Data to associate with the new location\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.replace\n   */\n  replace(to: To, state?: any): void;\n\n  /**\n   * Navigates `n` entries backward/forward in the history stack relative to the\n   * current index. For example, a \"back\" navigation would use go(-1).\n   *\n   * @param delta - The delta in the stack index\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.go\n   */\n  go(delta: number): void;\n\n  /**\n   * Navigates to the previous entry in the stack. Identical to go(-1).\n   *\n   * Warning: if the current location is the first location in the stack, this\n   * will unload the current document.\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.back\n   */\n  back(): void;\n\n  /**\n   * Navigates to the next entry in the stack. Identical to go(1).\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.forward\n   */\n  forward(): void;\n\n  /**\n   * Sets up a listener that will be called whenever the current location\n   * changes.\n   *\n   * @param listener - A function that will be called when the location changes\n   * @returns unlisten - A function that may be used to stop listening\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.listen\n   */\n  listen(listener: Listener): () => void;\n\n  /**\n   * Prevents the current location from changing and sets up a listener that\n   * will be called instead.\n   *\n   * @param blocker - A function that will be called when a transition is blocked\n   * @returns unblock - A function that may be used to stop blocking\n   *\n   * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#history.block\n   */\n  block(blocker: Blocker): () => void;\n}\n\n/**\n * A browser history stores the current location in regular URLs in a web\n * browser environment. This is the standard for most web apps and provides the\n * cleanest URLs the browser's address bar.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory\n */\nexport interface BrowserHistory extends History {}\n\n/**\n * A hash history stores the current location in the fragment identifier portion\n * of the URL in a web browser environment.\n *\n * This is ideal for apps that do not control the server for some reason\n * (because the fragment identifier is never sent to the server), including some\n * shared hosting environments that do not provide fine-grained controls over\n * which pages are served at which URLs.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory\n */\nexport interface HashHistory extends History {}\n\n/**\n * A memory history stores locations in memory. This is useful in stateful\n * environments where there is no web browser, such as node tests or React\n * Native.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#memoryhistory\n */\nexport interface MemoryHistory extends History {\n  readonly index: number;\n}\n\nconst readOnly: <T>(obj: T) => Readonly<T> = __DEV__\n  ? (obj) => Object.freeze(obj)\n  : (obj) => obj;\n\nfunction warning(cond: any, message: string) {\n  if (!cond) {\n    // eslint-disable-next-line no-console\n    if (typeof console !== \"undefined\") console.warn(message);\n\n    try {\n      // Welcome to debugging history!\n      //\n      // This error is thrown as a convenience so you can more easily\n      // find the source for a warning that appears in the console by\n      // enabling \"pause on exceptions\" in your JavaScript debugger.\n      throw new Error(message);\n      // eslint-disable-next-line no-empty\n    } catch (e) {}\n  }\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// BROWSER\n////////////////////////////////////////////////////////////////////////////////\n\ntype HistoryState = {\n  usr: any;\n  key?: string;\n  idx: number;\n};\n\nconst BeforeUnloadEventType = \"beforeunload\";\nconst HashChangeEventType = \"hashchange\";\nconst PopStateEventType = \"popstate\";\n\nexport type BrowserHistoryOptions = { window?: Window };\n\n/**\n * Browser history stores the location in regular URLs. This is the standard for\n * most web apps, but it requires some configuration on the server to ensure you\n * serve the same app at multiple URLs.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory\n */\nexport function createBrowserHistory(\n  options: BrowserHistoryOptions = {}\n): BrowserHistory {\n  let { window = document.defaultView! } = options;\n  let globalHistory = window.history;\n\n  function getIndexAndLocation(): [number, Location] {\n    let { pathname, search, hash } = window.location;\n    let state = globalHistory.state || {};\n    return [\n      state.idx,\n      readOnly<Location>({\n        pathname,\n        search,\n        hash,\n        state: state.usr || null,\n        key: state.key || \"default\",\n      }),\n    ];\n  }\n\n  let blockedPopTx: Transition | null = null;\n  function handlePop() {\n    if (blockedPopTx) {\n      blockers.call(blockedPopTx);\n      blockedPopTx = null;\n    } else {\n      let nextAction = Action.Pop;\n      let [nextIndex, nextLocation] = getIndexAndLocation();\n\n      if (blockers.length) {\n        if (nextIndex != null) {\n          let delta = index - nextIndex;\n          if (delta) {\n            // Revert the POP\n            blockedPopTx = {\n              action: nextAction,\n              location: nextLocation,\n              retry() {\n                go(delta * -1);\n              },\n            };\n\n            go(delta);\n          }\n        } else {\n          // Trying to POP to a location with no index. We did not create\n          // this location, so we can't effectively block the navigation.\n          warning(\n            false,\n            // TODO: Write up a doc that explains our blocking strategy in\n            // detail and link to it here so people can understand better what\n            // is going on and how to avoid it.\n            `You are trying to block a POP navigation to a location that was not ` +\n              `created by the history library. The block will fail silently in ` +\n              `production, but in general you should do all navigation with the ` +\n              `history library (instead of using window.history.pushState directly) ` +\n              `to avoid this situation.`\n          );\n        }\n      } else {\n        applyTx(nextAction);\n      }\n    }\n  }\n\n  window.addEventListener(PopStateEventType, handlePop);\n\n  let action = Action.Pop;\n  let [index, location] = getIndexAndLocation();\n  let listeners = createEvents<Listener>();\n  let blockers = createEvents<Blocker>();\n\n  if (index == null) {\n    index = 0;\n    globalHistory.replaceState({ ...globalHistory.state, idx: index }, \"\");\n  }\n\n  function createHref(to: To) {\n    return typeof to === \"string\" ? to : createPath(to);\n  }\n\n  // state defaults to `null` because `window.history.state` does\n  function getNextLocation(to: To, state: any = null): Location {\n    return readOnly<Location>({\n      pathname: location.pathname,\n      hash: \"\",\n      search: \"\",\n      ...(typeof to === \"string\" ? parsePath(to) : to),\n      state,\n      key: createKey(),\n    });\n  }\n\n  function getHistoryStateAndUrl(\n    nextLocation: Location,\n    index: number\n  ): [HistoryState, string] {\n    return [\n      {\n        usr: nextLocation.state,\n        key: nextLocation.key,\n        idx: index,\n      },\n      createHref(nextLocation),\n    ];\n  }\n\n  function allowTx(action: Action, location: Location, retry: () => void) {\n    return (\n      !blockers.length || (blockers.call({ action, location, retry }), false)\n    );\n  }\n\n  function applyTx(nextAction: Action) {\n    action = nextAction;\n    [index, location] = getIndexAndLocation();\n    listeners.call({ action, location });\n  }\n\n  function push(to: To, state?: any) {\n    let nextAction = Action.Push;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      push(to, state);\n    }\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      let [historyState, url] = getHistoryStateAndUrl(nextLocation, index + 1);\n\n      // TODO: Support forced reloading\n      // try...catch because iOS limits us to 100 pushState calls :/\n      try {\n        globalHistory.pushState(historyState, \"\", url);\n      } catch (error) {\n        // They are going to lose state here, but there is no real\n        // way to warn them about it since the page will refresh...\n        window.location.assign(url);\n      }\n\n      applyTx(nextAction);\n    }\n  }\n\n  function replace(to: To, state?: any) {\n    let nextAction = Action.Replace;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      replace(to, state);\n    }\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      let [historyState, url] = getHistoryStateAndUrl(nextLocation, index);\n\n      // TODO: Support forced reloading\n      globalHistory.replaceState(historyState, \"\", url);\n\n      applyTx(nextAction);\n    }\n  }\n\n  function go(delta: number) {\n    globalHistory.go(delta);\n  }\n\n  let history: BrowserHistory = {\n    get action() {\n      return action;\n    },\n    get location() {\n      return location;\n    },\n    createHref,\n    push,\n    replace,\n    go,\n    back() {\n      go(-1);\n    },\n    forward() {\n      go(1);\n    },\n    listen(listener) {\n      return listeners.push(listener);\n    },\n    block(blocker) {\n      let unblock = blockers.push(blocker);\n\n      if (blockers.length === 1) {\n        window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);\n      }\n\n      return function () {\n        unblock();\n\n        // Remove the beforeunload listener so the document may\n        // still be salvageable in the pagehide event.\n        // See https://html.spec.whatwg.org/#unloading-documents\n        if (!blockers.length) {\n          window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);\n        }\n      };\n    },\n  };\n\n  return history;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// HASH\n////////////////////////////////////////////////////////////////////////////////\n\nexport type HashHistoryOptions = { window?: Window };\n\n/**\n * Hash history stores the location in window.location.hash. This makes it ideal\n * for situations where you don't want to send the location to the server for\n * some reason, either because you do cannot configure it or the URL space is\n * reserved for something else.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory\n */\nexport function createHashHistory(\n  options: HashHistoryOptions = {}\n): HashHistory {\n  let { window = document.defaultView! } = options;\n  let globalHistory = window.history;\n\n  function getIndexAndLocation(): [number, Location] {\n    let {\n      pathname = \"/\",\n      search = \"\",\n      hash = \"\",\n    } = parsePath(window.location.hash.substr(1));\n    let state = globalHistory.state || {};\n    return [\n      state.idx,\n      readOnly<Location>({\n        pathname,\n        search,\n        hash,\n        state: state.usr || null,\n        key: state.key || \"default\",\n      }),\n    ];\n  }\n\n  let blockedPopTx: Transition | null = null;\n  function handlePop() {\n    if (blockedPopTx) {\n      blockers.call(blockedPopTx);\n      blockedPopTx = null;\n    } else {\n      let nextAction = Action.Pop;\n      let [nextIndex, nextLocation] = getIndexAndLocation();\n\n      if (blockers.length) {\n        if (nextIndex != null) {\n          let delta = index - nextIndex;\n          if (delta) {\n            // Revert the POP\n            blockedPopTx = {\n              action: nextAction,\n              location: nextLocation,\n              retry() {\n                go(delta * -1);\n              },\n            };\n\n            go(delta);\n          }\n        } else {\n          // Trying to POP to a location with no index. We did not create\n          // this location, so we can't effectively block the navigation.\n          warning(\n            false,\n            // TODO: Write up a doc that explains our blocking strategy in\n            // detail and link to it here so people can understand better\n            // what is going on and how to avoid it.\n            `You are trying to block a POP navigation to a location that was not ` +\n              `created by the history library. The block will fail silently in ` +\n              `production, but in general you should do all navigation with the ` +\n              `history library (instead of using window.history.pushState directly) ` +\n              `to avoid this situation.`\n          );\n        }\n      } else {\n        applyTx(nextAction);\n      }\n    }\n  }\n\n  window.addEventListener(PopStateEventType, handlePop);\n\n  // popstate does not fire on hashchange in IE 11 and old (trident) Edge\n  // https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event\n  window.addEventListener(HashChangeEventType, () => {\n    let [, nextLocation] = getIndexAndLocation();\n\n    // Ignore extraneous hashchange events.\n    if (createPath(nextLocation) !== createPath(location)) {\n      handlePop();\n    }\n  });\n\n  let action = Action.Pop;\n  let [index, location] = getIndexAndLocation();\n  let listeners = createEvents<Listener>();\n  let blockers = createEvents<Blocker>();\n\n  if (index == null) {\n    index = 0;\n    globalHistory.replaceState({ ...globalHistory.state, idx: index }, \"\");\n  }\n\n  function getBaseHref() {\n    let base = document.querySelector(\"base\");\n    let href = \"\";\n\n    if (base && base.getAttribute(\"href\")) {\n      let url = window.location.href;\n      let hashIndex = url.indexOf(\"#\");\n      href = hashIndex === -1 ? url : url.slice(0, hashIndex);\n    }\n\n    return href;\n  }\n\n  function createHref(to: To) {\n    return getBaseHref() + \"#\" + (typeof to === \"string\" ? to : createPath(to));\n  }\n\n  function getNextLocation(to: To, state: any = null): Location {\n    return readOnly<Location>({\n      pathname: location.pathname,\n      hash: \"\",\n      search: \"\",\n      ...(typeof to === \"string\" ? parsePath(to) : to),\n      state,\n      key: createKey(),\n    });\n  }\n\n  function getHistoryStateAndUrl(\n    nextLocation: Location,\n    index: number\n  ): [HistoryState, string] {\n    return [\n      {\n        usr: nextLocation.state,\n        key: nextLocation.key,\n        idx: index,\n      },\n      createHref(nextLocation),\n    ];\n  }\n\n  function allowTx(action: Action, location: Location, retry: () => void) {\n    return (\n      !blockers.length || (blockers.call({ action, location, retry }), false)\n    );\n  }\n\n  function applyTx(nextAction: Action) {\n    action = nextAction;\n    [index, location] = getIndexAndLocation();\n    listeners.call({ action, location });\n  }\n\n  function push(to: To, state?: any) {\n    let nextAction = Action.Push;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      push(to, state);\n    }\n\n    warning(\n      nextLocation.pathname.charAt(0) === \"/\",\n      `Relative pathnames are not supported in hash history.push(${JSON.stringify(\n        to\n      )})`\n    );\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      let [historyState, url] = getHistoryStateAndUrl(nextLocation, index + 1);\n\n      // TODO: Support forced reloading\n      // try...catch because iOS limits us to 100 pushState calls :/\n      try {\n        globalHistory.pushState(historyState, \"\", url);\n      } catch (error) {\n        // They are going to lose state here, but there is no real\n        // way to warn them about it since the page will refresh...\n        window.location.assign(url);\n      }\n\n      applyTx(nextAction);\n    }\n  }\n\n  function replace(to: To, state?: any) {\n    let nextAction = Action.Replace;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      replace(to, state);\n    }\n\n    warning(\n      nextLocation.pathname.charAt(0) === \"/\",\n      `Relative pathnames are not supported in hash history.replace(${JSON.stringify(\n        to\n      )})`\n    );\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      let [historyState, url] = getHistoryStateAndUrl(nextLocation, index);\n\n      // TODO: Support forced reloading\n      globalHistory.replaceState(historyState, \"\", url);\n\n      applyTx(nextAction);\n    }\n  }\n\n  function go(delta: number) {\n    globalHistory.go(delta);\n  }\n\n  let history: HashHistory = {\n    get action() {\n      return action;\n    },\n    get location() {\n      return location;\n    },\n    createHref,\n    push,\n    replace,\n    go,\n    back() {\n      go(-1);\n    },\n    forward() {\n      go(1);\n    },\n    listen(listener) {\n      return listeners.push(listener);\n    },\n    block(blocker) {\n      let unblock = blockers.push(blocker);\n\n      if (blockers.length === 1) {\n        window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);\n      }\n\n      return function () {\n        unblock();\n\n        // Remove the beforeunload listener so the document may\n        // still be salvageable in the pagehide event.\n        // See https://html.spec.whatwg.org/#unloading-documents\n        if (!blockers.length) {\n          window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);\n        }\n      };\n    },\n  };\n\n  return history;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// MEMORY\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * A user-supplied object that describes a location. Used when providing\n * entries to `createMemoryHistory` via its `initialEntries` option.\n */\nexport type InitialEntry = string | Partial<Location>;\n\nexport type MemoryHistoryOptions = {\n  initialEntries?: InitialEntry[];\n  initialIndex?: number;\n};\n\n/**\n * Memory history stores the current location in memory. It is designed for use\n * in stateful non-browser environments like tests and React Native.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory\n */\nexport function createMemoryHistory(\n  options: MemoryHistoryOptions = {}\n): MemoryHistory {\n  let { initialEntries = [\"/\"], initialIndex } = options;\n  let entries: Location[] = initialEntries.map((entry) => {\n    let location = readOnly<Location>({\n      pathname: \"/\",\n      search: \"\",\n      hash: \"\",\n      state: null,\n      key: createKey(),\n      ...(typeof entry === \"string\" ? parsePath(entry) : entry),\n    });\n\n    warning(\n      location.pathname.charAt(0) === \"/\",\n      `Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: ${JSON.stringify(\n        entry\n      )})`\n    );\n\n    return location;\n  });\n  let index = clamp(\n    initialIndex == null ? entries.length - 1 : initialIndex,\n    0,\n    entries.length - 1\n  );\n\n  let action = Action.Pop;\n  let location = entries[index];\n  let listeners = createEvents<Listener>();\n  let blockers = createEvents<Blocker>();\n\n  function createHref(to: To) {\n    return typeof to === \"string\" ? to : createPath(to);\n  }\n\n  function getNextLocation(to: To, state: any = null): Location {\n    return readOnly<Location>({\n      pathname: location.pathname,\n      search: \"\",\n      hash: \"\",\n      ...(typeof to === \"string\" ? parsePath(to) : to),\n      state,\n      key: createKey(),\n    });\n  }\n\n  function allowTx(action: Action, location: Location, retry: () => void) {\n    return (\n      !blockers.length || (blockers.call({ action, location, retry }), false)\n    );\n  }\n\n  function applyTx(nextAction: Action, nextLocation: Location) {\n    action = nextAction;\n    location = nextLocation;\n    listeners.call({ action, location });\n  }\n\n  function push(to: To, state?: any) {\n    let nextAction = Action.Push;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      push(to, state);\n    }\n\n    warning(\n      location.pathname.charAt(0) === \"/\",\n      `Relative pathnames are not supported in memory history.push(${JSON.stringify(\n        to\n      )})`\n    );\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      index += 1;\n      entries.splice(index, entries.length, nextLocation);\n      applyTx(nextAction, nextLocation);\n    }\n  }\n\n  function replace(to: To, state?: any) {\n    let nextAction = Action.Replace;\n    let nextLocation = getNextLocation(to, state);\n    function retry() {\n      replace(to, state);\n    }\n\n    warning(\n      location.pathname.charAt(0) === \"/\",\n      `Relative pathnames are not supported in memory history.replace(${JSON.stringify(\n        to\n      )})`\n    );\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      entries[index] = nextLocation;\n      applyTx(nextAction, nextLocation);\n    }\n  }\n\n  function go(delta: number) {\n    let nextIndex = clamp(index + delta, 0, entries.length - 1);\n    let nextAction = Action.Pop;\n    let nextLocation = entries[nextIndex];\n    function retry() {\n      go(delta);\n    }\n\n    if (allowTx(nextAction, nextLocation, retry)) {\n      index = nextIndex;\n      applyTx(nextAction, nextLocation);\n    }\n  }\n\n  let history: MemoryHistory = {\n    get index() {\n      return index;\n    },\n    get action() {\n      return action;\n    },\n    get location() {\n      return location;\n    },\n    createHref,\n    push,\n    replace,\n    go,\n    back() {\n      go(-1);\n    },\n    forward() {\n      go(1);\n    },\n    listen(listener) {\n      return listeners.push(listener);\n    },\n    block(blocker) {\n      return blockers.push(blocker);\n    },\n  };\n\n  return history;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// UTILS\n////////////////////////////////////////////////////////////////////////////////\n\nfunction clamp(n: number, lowerBound: number, upperBound: number) {\n  return Math.min(Math.max(n, lowerBound), upperBound);\n}\n\nfunction promptBeforeUnload(event: BeforeUnloadEvent) {\n  // Cancel the event.\n  event.preventDefault();\n  // Chrome (and legacy IE) requires returnValue to be set.\n  event.returnValue = \"\";\n}\n\ntype Events<F> = {\n  length: number;\n  push: (fn: F) => () => void;\n  call: (arg: any) => void;\n};\n\nfunction createEvents<F extends Function>(): Events<F> {\n  let handlers: F[] = [];\n\n  return {\n    get length() {\n      return handlers.length;\n    },\n    push(fn: F) {\n      handlers.push(fn);\n      return function () {\n        handlers = handlers.filter((handler) => handler !== fn);\n      };\n    },\n    call(arg) {\n      handlers.forEach((fn) => fn && fn(arg));\n    },\n  };\n}\n\nfunction createKey() {\n  return Math.random().toString(36).substr(2, 8);\n}\n\n/**\n * Creates a string URL path from the given pathname, search, and hash components.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath\n */\nexport function createPath({\n  pathname = \"/\",\n  search = \"\",\n  hash = \"\",\n}: Partial<Path>) {\n  if (search && search !== \"?\")\n    pathname += search.charAt(0) === \"?\" ? search : \"?\" + search;\n  if (hash && hash !== \"#\")\n    pathname += hash.charAt(0) === \"#\" ? hash : \"#\" + hash;\n  return pathname;\n}\n\n/**\n * Parses a string URL path into its separate pathname, search, and hash components.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath\n */\nexport function parsePath(path: string): Partial<Path> {\n  let parsedPath: Partial<Path> = {};\n\n  if (path) {\n    let hashIndex = path.indexOf(\"#\");\n    if (hashIndex >= 0) {\n      parsedPath.hash = path.substr(hashIndex);\n      path = path.substr(0, hashIndex);\n    }\n\n    let searchIndex = path.indexOf(\"?\");\n    if (searchIndex >= 0) {\n      parsedPath.search = path.substr(searchIndex);\n      path = path.substr(0, searchIndex);\n    }\n\n    if (path) {\n      parsedPath.pathname = path;\n    }\n  }\n\n  return parsedPath;\n}\n"
  },
  {
    "path": "packages/history/node-main.js",
    "content": "/* eslint-env node */\n\nif (process.env.NODE_ENV === \"production\") {\n  module.exports = require(\"./umd/history.production.min.js\");\n} else {\n  module.exports = require(\"./umd/history.development.js\");\n}\n"
  },
  {
    "path": "packages/history/package.json",
    "content": "{\n  \"name\": \"history\",\n  \"version\": \"5.3.0\",\n  \"description\": \"Manage session history with JavaScript\",\n  \"author\": \"Remix Software <hello@remix.run>\",\n  \"repository\": \"remix-run/history\",\n  \"license\": \"MIT\",\n  \"main\": \"main.js\",\n  \"module\": \"index.js\",\n  \"types\": \"index.d.ts\",\n  \"unpkg\": \"umd/history.production.min.js\",\n  \"sideEffects\": false,\n  \"dependencies\": {\n    \"@babel/runtime\": \"^7.7.6\"\n  },\n  \"keywords\": [\n    \"history\",\n    \"location\"\n  ]\n}\n"
  },
  {
    "path": "scripts/build.js",
    "content": "const path = require(\"path\");\nconst execSync = require(\"child_process\").execSync;\n\nlet config = path.resolve(__dirname, \"rollup/history.config.js\");\n\nexecSync(`rollup -c ${config}`, {\n  env: process.env,\n  stdio: \"inherit\",\n});\n"
  },
  {
    "path": "scripts/karma.conf.js",
    "content": "var path = require(\"path\");\nvar webpack = require(\"webpack\");\n\nmodule.exports = function (config) {\n  var customLaunchers = {\n    BS_Chrome: {\n      name: \"Chrome\",\n      base: \"BrowserStack\",\n      os: \"Windows\",\n      os_version: \"10\",\n      browser: \"Chrome\",\n      browser_version: \"73.0\",\n    },\n    // BS_ChromeAndroid: {\n    //   base: 'BrowserStack',\n    //   device: 'Samsung Galaxy S8',\n    //   os_version: '7.0',\n    //   real_mobile: true\n    // },\n    BS_Firefox: {\n      name: \"Firefox\",\n      base: \"BrowserStack\",\n      os: \"Windows\",\n      os_version: \"10\",\n      browser: \"Firefox\",\n      browser_version: \"67.0\",\n    },\n    BS_Edge: {\n      name: \"Edge\",\n      base: \"BrowserStack\",\n      os: \"Windows\",\n      os_version: \"10\",\n      browser: \"Edge\",\n      browser_version: \"17.0\",\n    },\n    BS_IE11: {\n      name: \"IE 11\",\n      base: \"BrowserStack\",\n      os: \"Windows\",\n      os_version: \"10\",\n      browser: \"IE\",\n      browser_version: \"11.0\",\n    },\n    // Safari throws an error if you use replaceState more\n    // than 100 times in 30 seconds :/\n    // BS_Safari: {\n    //   base: 'BrowserStack',\n    //   os: 'OS X',\n    //   os_version: 'Mojave',\n    //   browser: 'Safari',\n    //   browser_version: '12.1'\n    // }\n    // BS_iPhoneX: {\n    //   base: 'BrowserStack',\n    //   device: 'iPhone X',\n    //   os_version: '11',\n    //   real_mobile: true\n    // },\n    // BS_iPhoneXS: {\n    //   base: 'BrowserStack',\n    //   device: 'iPhone XS',\n    //   os_version: '12',\n    //   real_mobile: true\n    // },\n  };\n\n  config.set({\n    singleRun: true,\n    customLaunchers: customLaunchers,\n    browsers: [\"Chrome\" /*, 'Firefox'*/],\n    frameworks: [\"mocha\" /*, 'webpack' */],\n    reporters: [\"mocha\"],\n    files: [\"tests.webpack.js\"],\n    preprocessors: {\n      \"tests.webpack.js\": [\"webpack\", \"sourcemap\"],\n    },\n    webpack: {\n      // TODO: Webpack 4+\n      // mode: 'none',\n      devtool: \"inline-source-map\",\n      resolve: {\n        modules: [path.resolve(__dirname, \"../\"), \"node_modules\"],\n        alias: {\n          history: path.resolve(__dirname, \"../build/history\"),\n        },\n      },\n      module: {\n        rules: [\n          {\n            test: /__tests__\\/.*\\.js$/,\n            exclude: /node_modules/,\n            use: {\n              loader: \"babel-loader\",\n              options: {\n                presets: [\"@babel/preset-env\"],\n              },\n            },\n          },\n        ],\n      },\n      plugins: [\n        new webpack.DefinePlugin({\n          \"process.env.NODE_ENV\": JSON.stringify(\"test\"),\n        }),\n      ],\n    },\n    webpackServer: {\n      noInfo: true,\n    },\n  });\n\n  if (process.env.TRAVIS || process.env.USE_CLOUD) {\n    config.browsers = Object.keys(customLaunchers);\n    config.reporters = [\"dots\"];\n    config.concurrency = 2;\n    config.browserDisconnectTimeout = 10000;\n    config.browserDisconnectTolerance = 3;\n\n    if (process.env.TRAVIS) {\n      config.browserStack = {\n        project: \"history\",\n        build: process.env.TRAVIS_BRANCH,\n      };\n    } else {\n      config.browserStack = {\n        project: \"history\",\n      };\n    }\n  }\n};\n"
  },
  {
    "path": "scripts/publish.js",
    "content": "const path = require(\"path\");\nconst execSync = require(\"child_process\").execSync;\n\nconst jsonfile = require(\"jsonfile\");\nconst semver = require(\"semver\");\n\nconst rootDir = path.resolve(__dirname, \"..\");\n\nfunction invariant(cond, message) {\n  if (!cond) throw new Error(message);\n}\n\nfunction getTaggedVersion() {\n  let output = execSync(\"git tag --list --points-at HEAD\").toString();\n  return output.replace(/^v|\\n+$/g, \"\");\n}\n\nasync function ensureBuildVersion(packageName, version) {\n  let file = path.join(rootDir, \"build\", packageName, \"package.json\");\n  let json = await jsonfile.readFile(file);\n  invariant(\n    json.version === version,\n    `Package ${packageName} is on version ${json.version}, but should be on ${version}`\n  );\n}\n\nfunction publishBuild(packageName, tag) {\n  let buildDir = path.join(rootDir, \"build\", packageName);\n  console.log();\n  console.log(`  npm publish ${buildDir} --tag ${tag}`);\n  console.log();\n  execSync(`npm publish ${buildDir} --tag ${tag}`, { stdio: \"inherit\" });\n}\n\nasync function run() {\n  try {\n    // 0. Ensure we are in CI. We don't do this manually\n    invariant(\n      process.env.CI,\n      `You should always run the publish script from the CI environment!`\n    );\n\n    // 1. Get the current tag, which has the release version number\n    let version = getTaggedVersion();\n    invariant(\n      version !== \"\",\n      \"Missing release version. Run the version script first.\"\n    );\n\n    // 2. Determine the appropriate npm tag to use\n    let tag = semver.prerelease(version) == null ? \"latest\" : \"next\";\n\n    console.log();\n    console.log(`  Publishing version ${version} to npm with tag \"${tag}\"`);\n\n    // 3. Ensure build versions match the release version\n    await ensureBuildVersion(\"history\", version);\n\n    // 4. Publish to npm\n    publishBuild(\"history\", tag);\n  } catch (error) {\n    console.log();\n    console.error(`  ${error.message}`);\n    console.log();\n    return 1;\n  }\n\n  return 0;\n}\n\nrun().then((code) => {\n  process.exit(code);\n});\n"
  },
  {
    "path": "scripts/rollup/history.config.js",
    "content": "import { babel } from \"@rollup/plugin-babel\";\nimport copy from \"rollup-plugin-copy\";\nimport prettier from \"rollup-plugin-prettier\";\nimport replace from \"@rollup/plugin-replace\";\nimport { terser } from \"rollup-plugin-terser\";\nimport typescript from \"rollup-plugin-typescript2\";\n\nconst PRETTY = !!process.env.PRETTY;\nconst SOURCE_DIR = \"packages/history\";\nconst OUTPUT_DIR = \"build/history\";\n\nconst modules = [\n  {\n    input: `${SOURCE_DIR}/index.ts`,\n    output: {\n      file: `${OUTPUT_DIR}/index.js`,\n      format: \"esm\",\n      sourcemap: !PRETTY,\n    },\n    external: [\"@babel/runtime/helpers/esm/extends\"],\n    plugins: [\n      typescript({\n        tsconfigDefaults: {\n          compilerOptions: {\n            declaration: true,\n          },\n        },\n      }),\n      babel({\n        exclude: /node_modules/,\n        extensions: [\".ts\"],\n        presets: [[\"@babel/preset-env\", { loose: true }]],\n        plugins: [\n          \"babel-plugin-dev-expression\",\n          [\"@babel/plugin-transform-runtime\", { useESModules: true }],\n        ],\n        babelHelpers: \"runtime\",\n      }),\n      copy({\n        targets: [\n          { src: \"README.md\", dest: OUTPUT_DIR },\n          { src: \"LICENSE\", dest: OUTPUT_DIR },\n          { src: `${SOURCE_DIR}/package.json`, dest: OUTPUT_DIR },\n        ],\n        verbose: true,\n      }),\n    ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n  },\n  ...[\"browser\", \"hash\"].map((env) => {\n    return {\n      input: `${SOURCE_DIR}/${env}.ts`,\n      output: {\n        file: `${OUTPUT_DIR}/${env}.js`,\n        format: \"esm\",\n        sourcemap: !PRETTY,\n      },\n      plugins: [\n        typescript({\n          tsconfigDefaults: {\n            compilerOptions: {\n              declaration: true,\n            },\n          },\n        }),\n        babel({\n          exclude: /node_modules/,\n          extensions: [\".ts\"],\n          presets: [[\"@babel/preset-env\", { loose: true }]],\n          plugins: [\"babel-plugin-dev-expression\"],\n          babelHelpers: \"bundled\",\n        }),\n      ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n    };\n  }),\n];\n\nconst webModules = [\n  {\n    input: `${SOURCE_DIR}/index.ts`,\n    output: {\n      file: `${OUTPUT_DIR}/history.development.js`,\n      format: \"esm\",\n      sourcemap: !PRETTY,\n    },\n    plugins: [\n      typescript({\n        tsconfigOverride: {\n          compilerOptions: {\n            target: \"es2016\",\n          },\n        },\n      }),\n      babel({\n        exclude: /node_modules/,\n        extensions: [\".ts\"],\n        presets: [\"@babel/preset-modules\"],\n        plugins: [\"babel-plugin-dev-expression\"],\n        babelHelpers: \"bundled\",\n      }),\n      replace({\n        \"process.env.NODE_ENV\": JSON.stringify(\"development\"),\n        preventAssignment: false,\n      }),\n    ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n  },\n  {\n    input: `${SOURCE_DIR}/index.ts`,\n    output: {\n      file: `${OUTPUT_DIR}/history.production.min.js`,\n      format: \"esm\",\n      sourcemap: !PRETTY,\n    },\n    plugins: [\n      typescript({\n        tsconfigOverride: {\n          compilerOptions: {\n            target: \"es2016\",\n          },\n        },\n      }),\n      babel({\n        exclude: /node_modules/,\n        extensions: [\".ts\"],\n        presets: [\"@babel/preset-modules\"],\n        plugins: [\"babel-plugin-dev-expression\"],\n        babelHelpers: \"bundled\",\n      }),\n      replace({\n        \"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n        preventAssignment: false,\n      }),\n      terser({ ecma: 8, safari10: true }),\n    ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n  },\n];\n\nconst globals = [\n  {\n    input: `${SOURCE_DIR}/index.ts`,\n    output: {\n      file: `${OUTPUT_DIR}/umd/history.development.js`,\n      format: \"umd\",\n      sourcemap: !PRETTY,\n      name: \"HistoryLibrary\",\n    },\n    plugins: [\n      typescript(),\n      babel({\n        exclude: /node_modules/,\n        extensions: [\".ts\"],\n        presets: [[\"@babel/preset-env\", { loose: true }]],\n        plugins: [\"babel-plugin-dev-expression\"],\n        babelHelpers: \"bundled\",\n      }),\n      replace({\n        \"process.env.NODE_ENV\": JSON.stringify(\"development\"),\n        preventAssignment: false,\n      }),\n    ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n  },\n  {\n    input: `${SOURCE_DIR}/index.ts`,\n    output: {\n      file: `${OUTPUT_DIR}/umd/history.production.min.js`,\n      format: \"umd\",\n      sourcemap: !PRETTY,\n      name: \"HistoryLibrary\",\n    },\n    plugins: [\n      typescript(),\n      babel({\n        exclude: /node_modules/,\n        extensions: [\".ts\"],\n        presets: [[\"@babel/preset-env\", { loose: true }]],\n        plugins: [\"babel-plugin-dev-expression\"],\n        babelHelpers: \"bundled\",\n      }),\n      replace({\n        \"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n        preventAssignment: false,\n      }),\n      terser(),\n    ].concat(PRETTY ? prettier({ parser: \"babel\" }) : []),\n  },\n];\n\nconst node = [\n  {\n    input: `${SOURCE_DIR}/node-main.js`,\n    output: {\n      file: `${OUTPUT_DIR}/main.js`,\n      format: \"cjs\",\n    },\n    plugins: PRETTY ? prettier({ parser: \"babel\" }) : [],\n  },\n];\n\nconst config = [...modules, ...webModules, ...globals, ...node];\n\nexport default config;\n"
  },
  {
    "path": "scripts/test.js",
    "content": "const path = require(\"path\");\nconst execSync = require(\"child_process\").execSync;\n\nlet karmaConfig = path.resolve(__dirname, \"karma.conf.js\");\n\nexecSync(`karma start ${karmaConfig}`, {\n  env: process.env,\n  stdio: \"inherit\",\n});\n"
  },
  {
    "path": "scripts/tests.webpack.js",
    "content": "var context = require.context(\"../packages\", true, /-test\\.js$/);\ncontext.keys().forEach(context);\n"
  },
  {
    "path": "scripts/version.js",
    "content": "const path = require(\"path\");\nconst execSync = require(\"child_process\").execSync;\n\nconst chalk = require(\"chalk\");\nconst Confirm = require(\"prompt-confirm\");\nconst jsonfile = require(\"jsonfile\");\nconst semver = require(\"semver\");\n\nconst rootDir = path.resolve(__dirname, \"..\");\n\nfunction packageJson(packageName) {\n  return path.join(rootDir, \"packages\", packageName, \"package.json\");\n}\n\nfunction invariant(cond, message) {\n  if (!cond) throw new Error(message);\n}\n\nfunction ensureCleanWorkingDirectory() {\n  let status = execSync(`git status --porcelain`).toString().trim();\n  let lines = status.split(\"\\n\");\n  invariant(\n    lines.every((line) => line === \"\" || line.startsWith(\"?\")),\n    \"Working directory is not clean. Please commit or stash your changes.\"\n  );\n}\n\nfunction getNextVersion(currentVersion, givenVersion, prereleaseId) {\n  invariant(\n    givenVersion != null,\n    `Missing next version. Usage: node version.js [nextVersion]`\n  );\n\n  if (/^pre/.test(givenVersion)) {\n    invariant(\n      prereleaseId != null,\n      `Missing prerelease id. Usage: node version.js ${givenVersion} [prereleaseId]`\n    );\n  }\n\n  let nextVersion = semver.inc(currentVersion, givenVersion, prereleaseId);\n\n  invariant(nextVersion != null, `Invalid version specifier: ${givenVersion}`);\n\n  return nextVersion;\n}\n\nasync function prompt(question) {\n  let confirm = new Confirm(question);\n  let answer = await confirm.run();\n  return answer;\n}\n\nasync function getPackageVersion(packageName) {\n  let file = packageJson(packageName);\n  let json = await jsonfile.readFile(file);\n  return json.version;\n}\n\nasync function updatePackageConfig(packageName, transform) {\n  let file = packageJson(packageName);\n  let json = await jsonfile.readFile(file);\n  transform(json);\n  await jsonfile.writeFile(file, json, { spaces: 2 });\n}\n\nasync function run() {\n  try {\n    let args = process.argv.slice(2);\n    let givenVersion = args[0];\n    let prereleaseId = args[1];\n\n    // 0. Make sure the working directory is clean\n    ensureCleanWorkingDirectory();\n\n    // 1. Get the next version number\n    let currentVersion = await getPackageVersion(\"history\");\n    let version = semver.valid(givenVersion);\n    if (version == null) {\n      version = getNextVersion(currentVersion, givenVersion, prereleaseId);\n    }\n\n    // 2. Confirm the next version number\n    let answer = await prompt(\n      `Are you sure you want to bump version ${currentVersion} to ${version}? [Yn] `\n    );\n\n    if (answer === false) return 0;\n\n    // 3. Update history version\n    await updatePackageConfig(\"history\", (config) => {\n      config.version = version;\n    });\n    console.log(chalk.green(`  Updated history to version ${version}`));\n\n    // 4. Commit and tag\n    execSync(`git commit --all --message=\"Version ${version}\"`);\n    execSync(`git tag -a -m \"Version ${version}\" v${version}`);\n    console.log(chalk.green(`  Committed and tagged version ${version}`));\n  } catch (error) {\n    console.log();\n    console.error(chalk.red(`  ${error.message}`));\n    console.log();\n    return 1;\n  }\n\n  return 0;\n}\n\nrun().then((code) => {\n  process.exit(code);\n});\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"include\": [\"packages\", \"types\"],\n  \"compilerOptions\": {\n    \"lib\": [\"dom\", \"esnext\"],\n    \"module\": \"esnext\",\n    \"target\": \"es2018\",\n    \"moduleResolution\": \"node\",\n    \"esModuleInterop\": true,\n    \"strict\": true,\n    \"noUnusedLocals\": true,\n    \"noUnusedParameters\": true,\n    \"noImplicitReturns\": true\n  }\n}\n"
  },
  {
    "path": "types/global.d.ts",
    "content": "// eslint-disable-next-line no-unused-vars\ndeclare const __DEV__: boolean;\n"
  }
]