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.7.1 to 0.7.2

dist/scroll-restoration.d.ts

1

dist/index.d.ts

@@ -5,1 +5,2 @@ export * from "./nav-opts";

export * from "./routes";
export * from "./scroll-restoration";

2

dist/index.js

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

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

@@ -23,5 +23,5 @@ export type PathOrHref = string | string[];

private _h?;
constructor(pathOrHref: PathOrHref, m?: NavMeta);
constructor(pathOrHref: PathOrHref, { hash, pop, replace, search, state }?: NavMeta);
get href(): string;
get go(): (path: PathOrHref, opts?: NavMeta) => NavOpts;
}
{
"name": "esroute",
"version": "0.7.1",
"version": "0.7.2",
"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