UNPKG

next-wayfinder

Version:

Apply multiple next.js middlewares with ease

2 lines (1 loc) 1.84 kB
"use strict";var o=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var R=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},f=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!w.call(e,r)&&r!==a&&o(e,r,{get:()=>t[r],enumerable:!(s=x(t,r))||s.enumerable});return e};var N=e=>f(o({},"__esModule",{value:!0}),e);var H={};R(H,{addParams:()=>E,applyContext:()=>y,checkMethod:()=>m,findMiddleware:()=>q,getInjectorDescriptor:()=>P,getParams:()=>d,getParamsDescriptor:()=>u,parse:()=>g,replaceValues:()=>b});module.exports=N(H);var i=require("path-to-regexp");var n={isRewrite:e=>"rewriteTo"in e,isRedirect:e=>"redirectTo"in e,isPath:e=>"path"in e,isHostname:e=>"hostname"in e};var g=e=>{let t=e.headers.get("host")??"",a=e.nextUrl.pathname;return{hostname:t,pathname:a}},d=(e,t)=>(0,i.match)(e)(t).params??{};function m(e,t){return n.isHostname(e)?!1:e.method===t}var l=(e,t)=>typeof e=="string"?e===t:e instanceof RegExp?e.test(t):e instanceof Function?e(t):!1;function q(e,{path:t,hostname:a,method:s}){return e.find(r=>{let T=!1;if(n.isHostname(r))return Array.isArray(r.hostname)?r.hostname.some(c=>l(c,a)):l(r.hostname,a);T=(0,i.pathToRegexp)(r.path).test(t);let p=!0,h=!0;return r.method&&(h=m(r,s)),r.guard&&(p=r.guard(d(r.path,t))),T&&h&&p})}var u=e=>({enumerable:!0,writable:!1,value:e,configurable:!0}),P=e=>({enumerable:!0,writable:!1,value:e,configurable:!0}),y=(e,t)=>(Object.defineProperty(e,"ctx",P(t)),e),E=(e,t,a)=>(Object.defineProperty(e,"params",u(d(t,a))),e),b=(e,t)=>Object.entries(t).reduce((a,[s,r])=>r?a.replace(`:${s}`,Array.isArray(r)?r.join("/"):r):a,e);0&&(module.exports={addParams,applyContext,checkMethod,findMiddleware,getInjectorDescriptor,getParams,getParamsDescriptor,parse,replaceValues});