<commit_before># InMemory API

```js
import InMemory from "@hickory/in-memory";

const history = InMemory();
```

## Options

* `locations` - An array of location objects or strings.

* `index` - The index of the "current" location in the locations array.

* `query` - An object with two required properties: `parse` and `stringify`.

  * `parse` - A function that will convert a search string to a query value. This function should return a default value when it is called with no arguments.

  * `stringify` - A function that will convert a query value into a search string. This function should return an empty string when it is called with no arguments.

* `decode` - Whether or not to automatically decode the `pathname` when creating a location. This should almost always be `true`, but if you have a reason to use invalid URIs, then you _can_ set this to `false` (possibly to your own peril). (default: `true`)

* `raw` - A function that will be used to set the `rawPathname` property of location objects. When creating a location from a string, this function will be passed the `pathname` section parsed from the string. When creating a location from an object, this function will be passed the `pathname` section of that object. The default value of this option is an identity function.

* `baseSegment` - This is a string that begins with a forward slash and ends with a non-foward slash character. It should be provided if your application is not being served from the root of your server.

## Properties

### location

The current location object.

### action

The action used to get to the current location object.

### locations

The array of all visited locations.

### index

The index of the current location in the locations array.

## Methods

### navigate()

```js
history.navigate("/the-producers");
history.navigate({
  pathname: "/oklahoma",
  state: { musical: true }
});
```

The `navigate` function is used to navigate to a new location.

There are three ways that it can do this: `PUSH`, `REPLACE`, and `ANCHOR`.

1.  `PUSH` navigation pushes the new location onto the session history after the current location. Any existing locations after the current location are dropped.

```js
history.navigate("/lion-king", "PUSH");
history.navigate(
  {
    pathname: "/wicked",
    state: { musical: true }
  },
  "PUSH"
);
```

2.  `REPLACE` navigation replaces the current location with the new location. Any existing locations after the current location are unaffected.

```js
history.navigate("/cats", "REPLACE");
history.navigate(
  {
    pathname: "/rent",
    state: { musical: true }
  },
  "REPLACE"
);
```

3.  `ANCHOR` mimics the behavior of clicking on an `<a>` element. When the new location's URL is exactly the same as the current location's, it will act like `REPLACE`; when they are different, it will act like `PUSH`.

```js
history.navigate("/hairspray", "ANCHOR");
history.navigate(
  {
    pathname: "/hamilton",
    state: { musical: true }
  },
  "ANCHOR"
);
```

#### arguments

`to` - This can either be a string or an object. If it is a string, it will be parsed to create a location object. If it is an object, then its properties will be used to create a new location object. If the provided object is missing any location properties, then those will be given default values on the new location object.

`navType` - `ANCHOR`, `PUSH`, or `REPLACE`. If none are provided, this will default to `ANCHOR`.

### go()

```js
history.go(-1);
history.go();
history.go(2);
```

The `go` function is used to jump forward and backward to already visited locations. If you call it with a negative number, it goes backward. With a positive number, it goes forward. If you call it with no value (or `0`), it will re-emit the current location (with a `POP` action).]

#### arguments

`num` - The number of steps forward or backward to go.

### reset()

```js
history.reset({
  locations: ["/one", "/two"],
  index: 1
});
```

#### arguments

An object with the following (optional) properties:

* `locations` - An array of location objects or strings.<commit_msg>InMemory reset() description [ci skip]<commit_after># InMemory API

```js
import InMemory from "@hickory/in-memory";

const history = InMemory();
```

## Options

* `locations` - An array of location objects or strings.

* `index` - The index of the "current" location in the locations array.

* `query` - An object with two required properties: `parse` and `stringify`.

  * `parse` - A function that will convert a search string to a query value. This function should return a default value when it is called with no arguments.

  * `stringify` - A function that will convert a query value into a search string. This function should return an empty string when it is called with no arguments.

* `decode` - Whether or not to automatically decode the `pathname` when creating a location. This should almost always be `true`, but if you have a reason to use invalid URIs, then you _can_ set this to `false` (possibly to your own peril). (default: `true`)

* `raw` - A function that will be used to set the `rawPathname` property of location objects. When creating a location from a string, this function will be passed the `pathname` section parsed from the string. When creating a location from an object, this function will be passed the `pathname` section of that object. The default value of this option is an identity function.

* `baseSegment` - This is a string that begins with a forward slash and ends with a non-foward slash character. It should be provided if your application is not being served from the root of your server.

## Properties

### location

The current location object.

### action

The action used to get to the current location object.

### locations

The array of all visited locations.

### index

The index of the current location in the locations array.

## Methods

### navigate()

```js
history.navigate("/the-producers");
history.navigate({
  pathname: "/oklahoma",
  state: { musical: true }
});
```

The `navigate` function is used to navigate to a new location.

There are three ways that it can do this: `PUSH`, `REPLACE`, and `ANCHOR`.

1.  `PUSH` navigation pushes the new location onto the session history after the current location. Any existing locations after the current location are dropped.

```js
history.navigate("/lion-king", "PUSH");
history.navigate(
  {
    pathname: "/wicked",
    state: { musical: true }
  },
  "PUSH"
);
```

2.  `REPLACE` navigation replaces the current location with the new location. Any existing locations after the current location are unaffected.

```js
history.navigate("/cats", "REPLACE");
history.navigate(
  {
    pathname: "/rent",
    state: { musical: true }
  },
  "REPLACE"
);
```

3.  `ANCHOR` mimics the behavior of clicking on an `<a>` element. When the new location's URL is exactly the same as the current location's, it will act like `REPLACE`; when they are different, it will act like `PUSH`.

```js
history.navigate("/hairspray", "ANCHOR");
history.navigate(
  {
    pathname: "/hamilton",
    state: { musical: true }
  },
  "ANCHOR"
);
```

#### arguments

`to` - This can either be a string or an object. If it is a string, it will be parsed to create a location object. If it is an object, then its properties will be used to create a new location object. If the provided object is missing any location properties, then those will be given default values on the new location object.

`navType` - `ANCHOR`, `PUSH`, or `REPLACE`. If none are provided, this will default to `ANCHOR`.

### go()

```js
history.go(-1);
history.go();
history.go(2);
```

The `go` function is used to jump forward and backward to already visited locations. If you call it with a negative number, it goes backward. With a positive number, it goes forward. If you call it with no value (or `0`), it will re-emit the current location (with a `POP` action).]

#### arguments

`num` - The number of steps forward or backward to go.

### reset()

```js
history.reset({
  locations: ["/one", "/two"],
  index: 1
});
```

Reset the location state of the `history` instance.

#### arguments

An object with the following (optional) properties:

* `locations` - An array of location objects or strings.
{'fraction_non_alphanumeric': 0.10246794096298088, 'fraction_numerical': 0.0016936849745947254, 'mean_word_length': 3.9473369239976064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3472608', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2275, 'n_words': 1179}