New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

esroute

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esroute - npm Package Compare versions

Comparing version 0.8.1 to 0.8.3

2

dist/index.js

@@ -1,2 +0,2 @@

var f=class a{constructor(o,n={}){this.params=[];let{path:l,href:s,hash:e,pop:r,replace:c,search:h,state:i}=typeof o=="string"||Array.isArray(o)?n:o;if(l)this.path=l;else if(s||typeof o=="string"){s??=o,s.startsWith("/")||(s=`/${s}`),h||(this._h=s);let[,d,,v,,t]=s.match(/([^?#]+)(\?([^#]+))?(#(.+))?/);this.path=d.split("/").filter(Boolean),v&&(this.search=Object.fromEntries(new URLSearchParams(v).entries())),t&&(this.hash=t)}else this.path=o;e!==void 0&&(this.hash=e),r!==void 0&&(this.pop=r),h!==void 0&&(this.search=h),i!==void 0&&(this.state=i),c!==void 0&&(this.replace=c),this.search??={}}get href(){if(!this._h){let o=new URLSearchParams(this.search).toString(),n=`/${this.path.join("/")}`;this._h=`${n}${o?`?${o}`:""}`}return this._h}get go(){return(o,n={})=>new a(o,{search:n.search,state:n.state,replace:n.replace??this.replace})}};var g=10,y=async(a,o,n)=>{let l=o,s=new Array;for(;l instanceof f&&s.length<=g;){o=l,s.push(o);let e=await N(a,o)??[n];for(let r of e)if(l=await r(o,l instanceof f?void 0:l),l instanceof f)break}if(s.length>g)throw new Error(`More than ${g} redirects: ${s.map(e=>e.href).join(" -> ")}`);return{value:l,opts:o}},N=async(a,o)=>{let{path:n,params:l}=o,s=[],e=a;for(let r=0;r<n.length;r++){let c=n[r];if(!e||typeof e=="function")return null;let h=await w(e,o);if(h)return[()=>h];if(typeof e["?"]=="function"){let d=await e["?"](o);if(d instanceof f)return[()=>d]}let i=e[""];typeof i=="function"&&s.unshift(i),c in e?e=e[c]:"*"in e?(l.push(c),e=e["*"]):typeof i=="object"&&(e=i,r--)}do{if(typeof e=="function")return s.unshift(e),s;let r=await w(e,o);if(r)return[()=>r]}while(e=e[""]);return null},w=async(a,o)=>{if(typeof a["?"]=="function"){let n=await a["?"](o);if(n instanceof f)return n}};var A=({routes:a={},notFound:o=({go:s})=>s([]),noClick:n=!1,onResolve:l}={})=>{let s,e=new Set(l?[l]:[]),r,c={routes:a,get resolution(){return r},init(){window.addEventListener("popstate",i),n||document.addEventListener("click",h),i({state:history.state})},dispose(){window.removeEventListener("popstate",i),document.removeEventListener("click",h)},async go(t,p){let u=await this.resolution;if(typeof t=="function"){if(!u)throw new Error("Cannot call go() with a function before the first navigation has been started.");t=t(u.opts)}let m=t instanceof f?t:typeof t=="string"||Array.isArray(t)?new f(t,p):new f(t),R=await d(y(c.routes,m,o));v(R.opts)},onResolve(t){return e.add(t),s&&t(s),()=>e.delete(t)}},h=t=>{let p=T(t.target)?t.target:t.composedPath?.().find(T);p&&p.origin===location.origin&&(c.go(p.href.substring(location.origin.length),{replace:"replace"in p.dataset}),t.preventDefault())},i=async t=>{let{href:p,origin:u}=window.location,m=new f(p.substring(u.length),{state:t.state,...t instanceof PopStateEvent&&{pop:!0}}),{opts:R}=await d(y(c.routes,m,o));R!==m&&v(new f(R.path,{replace:!0,search:R.search,state:R.state}))},d=async t=>{let p=s;r=t;try{return s=await t,e.forEach(u=>u(s)),t}catch(u){throw s=p,r=Promise.resolve(p),u}},v=({state:t,replace:p,href:u})=>{let m=window.history;p?m.replaceState(t,"",u):m.pushState(t,"",u)};return c},T=a=>a instanceof HTMLAnchorElement;var k=({container:a=document.scrollingElement??document.body,find:o=e=>document.getElementById(e),offset:n=0,hashScroll:l=!0,stateProp:s="__scroll"}={})=>{history.scrollRestoration="manual";let e=()=>history.replaceState({...history.state,[s]:a.scrollTop},"",location.href),r=i=>{typeof i=="number"&&(a.scrollTop=i)},c=()=>(history.state&&history.state[s])??void 0,h=l&&(i=>(o(i)?.getBoundingClientRect().top??0)-n+a.scrollTop);return e&&(window.addEventListener("beforeunload",e),window.addEventListener("visibilitychange",e)),window.addEventListener("popstate",()=>r(c())),({opts:{hash:i,pop:d}})=>{let v=c();if(console.log(location.pathname,d,v),v)return r(v);if(!v&&i&&h)return r(h(i));a.scrollTop=0}};export{f as NavOpts,A as createRouter,y as resolve,k as restoreHandling};
var f=class a{constructor(t,n={}){this.params=[];let{path:c,href:r,hash:e,pop:s,replace:p,search:h,state:i}=typeof t=="string"||Array.isArray(t)?n:t;if(c)this.path=c;else if(r||typeof t=="string"){r??=t,r.startsWith("/")||(r=`/${r}`),h||(this._h=r);let[,v,,u,,o]=r.match(/([^?#]+)(\?([^#]+))?(#(.+))?/);this.path=v.split("/").filter(Boolean),u&&(this.search=Object.fromEntries(new URLSearchParams(u).entries())),o&&(this.hash=o)}else this.path=t;e!==void 0&&(this.hash=e),s!==void 0&&(this.pop=s),h!==void 0&&(this.search=h),i!==void 0&&(this.state=i),p!==void 0&&(this.replace=p),this.search??={}}get href(){if(!this._h){let t=new URLSearchParams(this.search).toString(),n=`/${this.path.join("/")}`;this._h=`${n}${t?`?${t}`:""}`}return this._h}get go(){return(t,n={})=>new a(t,{search:n.search,state:n.state,replace:n.replace??this.replace})}};var R=10,y=async(a,t,n)=>{let c=t,r=new Array;for(;c instanceof f&&r.length<=R;){t=c,r.push(t);let e=await N(a,t)??[n];for(let s of e)if(c=await s(t,c instanceof f?void 0:c),c instanceof f)break}if(r.length>R)throw new Error(`More than ${R} redirects: ${r.map(e=>e.href).join(" -> ")}`);return{value:c,opts:t}},N=async(a,t)=>{let{path:n,params:c}=t,r=[],e=a;for(let s=0;s<n.length;s++){let p=n[s];if(!e||typeof e=="function")return null;let h=await w(e,t);if(h)return[()=>h];if(typeof e["?"]=="function"){let v=await e["?"](t);if(v instanceof f)return[()=>v]}let i=e[""];typeof i=="function"&&r.unshift(i),p in e?e=e[p]:"*"in e?(c.push(p),e=e["*"]):typeof i=="object"&&(e=i,s--)}do{if(typeof e=="function")return r.unshift(e),r;let s=await w(e,t);if(s)return[()=>s]}while(e=e[""]);return null},w=async(a,t)=>{if(typeof a["?"]=="function"){let n=await a["?"](t);if(n instanceof f)return n}};var A=({routes:a={},notFound:t=({go:r})=>r([]),noClick:n=!1,onResolve:c}={})=>{let r,e=new Set(c?[c]:[]),s,p={routes:a,get current(){return r.opts},get resolution(){return s},init(){window.addEventListener("popstate",i),n||document.addEventListener("click",h),i({state:history.state})},dispose(){window.removeEventListener("popstate",i),document.removeEventListener("click",h)},async go(o,l){let d=await this.resolution;if(typeof o=="function"){if(!d)throw new Error("Cannot call go() with a function before the first navigation has been started.");o=o(d.opts)}let m=o instanceof f?o:typeof o=="string"||Array.isArray(o)?new f(o,l):new f(o),g=await v(y(p.routes,m,t));u(g.opts)},onResolve(o){return e.add(o),r&&o(r),()=>e.delete(o)}},h=o=>{let l=T(o.target)?o.target:o.composedPath?.().find(T);l&&l.origin===location.origin&&(p.go(l.href.substring(location.origin.length),{replace:"replace"in l.dataset}),o.preventDefault())},i=async o=>{let{href:l,origin:d}=window.location,m=new f(l.substring(d.length),{state:o.state,...o instanceof PopStateEvent&&{pop:!0}}),{opts:g}=await v(y(p.routes,m,t));g!==m&&u(new f(g.path,{replace:!0,search:g.search,state:g.state}))},v=async o=>{s=o;try{let l=await o;return e.forEach(d=>d(l)),r=l}catch(l){throw s=Promise.resolve(r),l}},u=({state:o,replace:l,href:d})=>{let m=window.history;l?m.replaceState(o,"",d):m.pushState(o,"",d)};return p},T=a=>a instanceof HTMLAnchorElement;var k=({container:a=document.scrollingElement??document.body,find:t=e=>document.getElementById(e),offset:n=0,hashScroll:c=!0,stateProp:r="__scroll"}={})=>{history.scrollRestoration="manual";let e=()=>history.replaceState({...history.state,[r]:a.scrollTop},"",location.href),s=i=>{typeof i=="number"&&(a.scrollTop=i)},p=()=>(history.state&&history.state[r])??void 0,h=c&&(i=>(t(i)?.getBoundingClientRect().top??0)-n+a.scrollTop);return e&&(window.addEventListener("beforeunload",e),window.addEventListener("visibilitychange",e)),window.addEventListener("popstate",()=>s(p())),({opts:{hash:i,pop:v}})=>{let u=p();if(console.log(location.pathname,v,u),u)return s(u);if(!u&&i&&h)return s(h(i));a.scrollTop=0}};export{f as NavOpts,A as createRouter,y as resolve,k as restoreHandling};
//# sourceMappingURL=index.js.map

@@ -13,2 +13,7 @@ import { NavMeta, NavOpts, PathOrHref, StrictNavMeta } from "./nav-opts";

/**
* The current resolved route.
* It is updated after each route resolution.
*/
readonly current: NavOpts;
/**
* Triggers a navigation.

@@ -15,0 +20,0 @@ * You can modify the navigation options by passing in a second argument.

{
"name": "esroute",
"version": "0.8.1",
"version": "0.8.3",
"description": "A small efficient framework-agnostic client-side routing library, written in TypeScript.",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is not supported yet

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