Socket
Socket
Sign inDemoInstall

hash-regex-router

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-regex-router - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/router-standalone.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.route = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
function dispatch(){var e=current();if(last!==e&&enabled){if(blocked=!1,"function"==typeof route.leave&&(blocked=!route.leave.call(route)),blocked)return void(window.location.hash="#"+last);route.leave=null,last=e;for(var t=0;t<routes.length;t++){var n=routes[t],o=e.match(n.regexp);if(o){n.cb.apply(null,o.slice(1,o.length));break}}}}function current(){var e=location.href.match(/#(.+)$/);return e?e[1]:""}var routes=[],route=module.exports=function(e,t){if(!(e instanceof RegExp))throw new Error("Route must be a regexp.");if("function"!=typeof t)throw new Error("Route handler must be a function.");routes.push({regexp:e,cb:t})};route.go=function(e){var t=Array.prototype.slice.call(arguments,1);window.location.hash="#"+e+(t.length>0?"/"+t.join("/"):"")};var last;route.refresh=function(){dispatch()};var enabled=!1,enable=route.enable=function(){enabled||(window.addEventListener("load",dispatch,!1),window.addEventListener("hashchange",dispatch,!1),enabled=!0)};route.disable=function(){enabled&&(window.removeEventListener("load",dispatch,!1),window.removeEventListener("hashchange",dispatch,!1),enabled=!1)},enable();
function dispatch(){var e=current();last!==e&&dispatchHash(e)}function dispatchHash(e){if(enabled){if(blocked=!1,"function"==typeof route.leave&&(blocked=!route.leave.call(route)),blocked)return void(window.location.hash="#"+last);route.leave=null,last=e;for(var t=0;t<routes.length;t++){var n=routes[t],a=e.match(n.regexp);if(a){n.cb.apply(null,a.slice(1,a.length));break}}}}function current(){var e=location.href.match(/#(.+)$/);return e?e[1]:""}var routes=[],route=module.exports=function(e,t){if(!(e instanceof RegExp))throw new Error("Route must be a regexp.");if("function"!=typeof t)throw new Error("Route handler must be a function.");routes.push({regexp:e,cb:t})};route.go=function(e){var t=Array.prototype.slice.call(arguments,1);window.location.hash="#"+e+(t.length>0?"/"+t.join("/"):"")};var last;route.refresh=function(){dispatchHash(current())};var enabled=!1,enable=route.enable=function(){enabled||(window.addEventListener("load",dispatch,!1),window.addEventListener("hashchange",dispatch,!1),enabled=!0)};route.disable=function(){enabled&&(window.removeEventListener("load",dispatch,!1),window.removeEventListener("hashchange",dispatch,!1),enabled=!1)},enable();
},{}]},{},[1])(1)
});
{
"name": "hash-regex-router",
"version": "1.0.0",
"version": "1.0.1",
"author": {

@@ -5,0 +5,0 @@ "name": "Raivo Laanemets",

@@ -50,3 +50,3 @@ // Simplest hashchange router.

if (last === hash || !enabled) {
if (last === hash) {

@@ -56,2 +56,15 @@ return;

dispatchHash(hash);
}
// Dispatches without requiring current
// route to be new.
function dispatchHash(hash) {
if (!enabled) {
return;
}
blocked = false;

@@ -106,6 +119,7 @@

// Refreshes the current location.
// Requires router to be enabled.
route.refresh = function() {
dispatch();
dispatchHash(current());
};

@@ -112,0 +126,0 @@

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