@svelte-navigator/history
Version:
History module for svelte-navigator
58 lines (57 loc) • 2.11 kB
TypeScript
import type { HistoryLocation, To } from "./types";
export declare const substr: (str: string, start: number, end?: number | undefined) => string;
export declare const startsWith: (str: string, start: string) => boolean;
/**
* Create a globally unique id
*
* @returns An id
*/
export declare const createGlobalId: () => string;
export declare const noop: () => void;
export declare const isString: (maybeStr: unknown) => maybeStr is string;
export declare const isNumber: (maybeNum: unknown) => maybeNum is number;
/**
* Creates a location object from an url.
* It is used to create a location from the url prop used in SSR
*
* @param {string} url The url string (e.g. "/path/to/somewhere")
* @returns {HistoryLocation} The location
*
* @example
* ```js
* const path = "/search?q=falafel#result-3";
* const location = parsePath(path);
* // -> {
* // pathname: "/search",
* // search: "?q=falafel",
* // hash: "#result-3",
* // };
* ```
*/
export declare const parsePath: (path: string) => HistoryLocation;
/**
* Joins a location object to one path string.
*
* @param {HistoryLocation} location The location object
* @returns {string} A path, created from the location
*
* @example
* ```js
* const location = {
* pathname: "/search",
* search: "?q=falafel",
* hash: "#result-3",
* };
* const path = stringifyPath(location);
* // -> "/search?q=falafel#result-3"
* ```
*/
export declare const stringifyPath: (location: HistoryLocation) => string;
export declare const getPathString: (to: To) => string;
export declare const getPathObject: (to: To) => HistoryLocation;
export declare const addListener: (target: EventTarget, type: string, handler: () => void) => (() => void);
export declare const POP = "POP";
export declare const PUSH = "PUSH";
export declare const REPLACE = "REPLACE";
export declare const assertPushReplaceArgs: (uri: string, isStringId: number, startsWithSlashId: number) => void;
export declare const assertGoArgs: (delta: number, deltaIsNumId: number, deltaIsIntId: number) => void;