1.0.0 • Published 5 years ago

fake-history v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

fake-history

fake-history is a fake History object.

Installation

$ npm install fake-history

Usage

import assert from 'assert';
import { FakeHistory } from 'fake-history';

const history = new FakeHistory();
history.pushState(1, '1', '/1');
history.pushState(2, '2', '/2');
history.pushState(3, '3', '/3');
history.back();

assert(history.length === 3);
assert(history.state === 2);

// extended
assert(history.current === '/2');
assert(history.currentState === 2);
assert(history.next === '/3');
assert(history.nextState === 3);
assert(history.previous === '/1');
assert(history.previousState === 1);

API

See: History - Web APIs | MDN

export interface History {
  readonly length: number;
  readonly state: any;
  scrollRestoration: 'auto' | 'manual';
  back(): void;
  forward(): void;
  go(delta?: number): void;
  pushState(data: any, title: string, url?: string | null): void;
  replaceState(data: any, title: string, url?: string | null): void;
}

export interface ExtendedHistory {
  readonly current: string | null;
  readonly currentState: any | null;
  readonly next: string | null;
  readonly nextState: any | null;
  readonly previous: string | null;
  readonly previousState: any | null;
}

export class FakeHistory implements ExtendedHistory { /* ... */ }

Related Project

Badges

npm version Travis CI

License

MIT

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)