1.0.0 • Published 5 years ago
fake-history v1.0.0
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
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
- bouzuya/fake-history-fns ... fake-history functions