# common-history

> Consistent API of HTML5 history API and hash fragments control.

Latest version **0.0.1** (published 2015-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install common-history
pnpm add common-history
yarn add common-history
bun add common-history
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-03-18 |
| First published | 2015-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | 8th713 |
| Maintainers | 8th713 |
| Keywords | history, location |

## Links

- npm: https://www.npmjs.com/package/common-history
- Repository: https://github.com/8th713/common-history
- Issues: https://github.com/8th713/common-history/issues
- npm.io page: https://npm.io/package/common-history

## Recent versions

- 0.0.1 (latest) — 2015-03-18

## README

# common-history
Consistent API of HTML5 history API and hash fragments control.

## Installation
```sh
npm install common-history
```

## Usage
common-history consist of `HashLocation` and `HistoryLocation`.
It provides same interface.

- `HashLocation` is wrap hash fragments control.
- `HistoryLocation` is wrap HTML5 history API.

```js
// ececute http://example.com/
import {HashLocation} from 'common-history';

const hashLocation = new HashLocation();

// It is executed each time the location is changed.
hashLocation.addListener(changes => {
  let {path, type} = changes;
  console.log('current path:' + path);
  console.log('transition type:' + type);
  console.log(location.href);
});

hashLocation.push('/path/to');
// current path: /path/to
// transition type: PUSH
// http://example.com/#/path/to
```

### #current
(string): The path of current location. In hashLocation deal with hash fragments.

### #addListener(listener)
Adds a function to be called by a location changes. 

1. **listener (function)**: The listener of location changes.

Listener is executed when the following:

- In HashLocation when `hashchange` event was dispatched.
- In HistoryLocation when `popstate` event was dispatched.
- In HistoryLocation when execute of `push` and `replace`.

### #removeListener(listener)
Stop calling the given function.

1. **listener (function)**: The listener of location changes.

### #push(path)
Change the URL in the browser’s location bar without page transition.

1. **path (string)**: The path of destination.

### #replace(path)
Change the URL in the browser’s location bar without page transition. It does not remain in the history.

1. **path (string)**: The path of destination.

### #pop()
Go back one entry in the history.

## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request

## License
MIT License

---
_Source: https://npm.io/package/common-history · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
