Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nano-router/history

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nano-router/history - npm Package Compare versions

Comparing version 1.5.0 to 2.0.0-alpha.6

LICENSE

10

package.json
{
"name": "@nano-router/history",
"version": "1.5.0",
"description": "Fork of the history package to make it tree shakeable",
"version": "2.0.0-alpha.6+1dfcaec",
"description": "Manage session history with JavaScript",
"main": "src/index.js",

@@ -19,3 +19,5 @@ "module": "src/index.js",

"mocha": "^8.1.1",
"unexpected": "^11.14.0"
"sinon": "^9.0.3",
"unexpected": "^11.14.0",
"unexpected-sinon": "^10.11.2"
},

@@ -25,3 +27,3 @@ "publishConfig": {

},
"gitHead": "4d70e2134fadc6b391e7e2df04e793ddc56f60ae"
"gitHead": "1dfcaec6c88254b5c5fb183cfab6bfd9b8e1a905"
}

42

src/browser.js
import {
allowTx,
createEvents,
createHref,
getNextLocation,

@@ -14,2 +13,10 @@ ensureRootRelative,

function createPath({ pathname = "/", search = "", hash = "" }) {
return pathname + search + hash;
}
function createHref(to) {
return typeof to === "string" ? to : createPath(to);
}
export function createBrowserHistory(options = {}) {

@@ -152,2 +159,32 @@ const { window = document.defaultView } = options;

function pushLocation(url, target) {
function retry() {
pushLocation(url);
}
if (target && target !== "_self") {
window.open(url, target, "noopener");
} else {
const nextAction = "PUSH";
const nextLocation = getNextLocation(location, url);
if (allowTx(blockers, nextAction, nextLocation, retry)) {
window.location.assign(url);
}
}
}
function replaceLocation(url) {
const nextAction = "REPLACE";
const nextLocation = getNextLocation(location, url);
function retry() {
replaceLocation(url);
}
if (allowTx(blockers, nextAction, nextLocation, retry)) {
window.location.replace(url);
}
}
function go(delta) {

@@ -164,5 +201,6 @@ globalHistory.go(delta);

},
createHref,
push,
replace,
pushLocation,
replaceLocation,
go,

@@ -169,0 +207,0 @@ back() {

@@ -5,4 +5,3 @@ import {

createKey,
createHref,
parsePath,
parseUrl,
getNextLocation,

@@ -25,3 +24,3 @@ ensureRootRelative,

key: createKey(),
...(typeof entry === "string" ? parsePath(entry) : entry),
...(typeof entry === "string" ? parseUrl(entry) : entry),
};

@@ -41,2 +40,3 @@

let location = entries[index];
let openedWindow = null;
const listeners = createEvents();

@@ -82,2 +82,36 @@ const blockers = createEvents();

function pushLocation(url, target) {
function retry() {
pushLocation(url);
}
if (target && target !== "_self") {
openedWindow = { url, target };
} else {
const nextAction = "PUSH";
const nextLocation = getNextLocation(location, url);
if (allowTx(blockers, nextAction, nextLocation, retry)) {
entries[index] = nextLocation;
action = nextAction;
location = nextLocation;
}
}
}
function replaceLocation(url) {
const nextAction = "REPLACE";
const nextLocation = getNextLocation(location, url);
function retry() {
replaceLocation(url);
}
if (allowTx(blockers, nextAction, nextLocation, retry)) {
entries[index] = nextLocation;
action = nextAction;
location = nextLocation;
}
}
function go(delta) {

@@ -107,5 +141,9 @@ const nextIndex = clamp(index + delta, 0, entries.length - 1);

},
createHref,
get openedWindow() {
return openedWindow;
},
push,
replace,
pushLocation,
replaceLocation,
go,

@@ -112,0 +150,0 @@ back() {

@@ -39,10 +39,13 @@ export function createKey() {

function createPath({ pathname = "/", search = "", hash = "" }) {
return pathname + search + hash;
}
export function parseUrl(url) {
const partialPath = { href: url, search: "", hash: "" };
export function parsePath(path) {
const partialPath = {};
if (url) {
let path = url;
const protocolIndex = url.indexOf("//");
if (protocolIndex !== -1) {
const pathIndex = url.indexOf("/", protocolIndex + 2);
path = url.slice(pathIndex);
}
if (path) {
const hashIndex = path.indexOf("#");

@@ -68,10 +71,5 @@ if (hashIndex >= 0) {

export function createHref(to) {
return typeof to === "string" ? to : createPath(to);
}
export function getNextLocation(currentLocation, to, state = null) {
return {
...currentLocation,
...(typeof to === "string" ? parsePath(to) : to),
...(typeof to === "string" ? parseUrl(to) : to),
state,

@@ -78,0 +76,0 @@ key: createKey(),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc