Socket
Socket
Sign inDemoInstall

itty-router

Package Overview
Dependencies
0
Maintainers
2
Versions
264
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.25-next.0 to 4.0.25-next.1

2

index.js

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

"use strict";class e extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const t=(e="text/plain; charset=utf-8",t)=>(s,{headers:r={},...o}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...r},...o}),s=t("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=t("text/plain; charset=utf-8",String),n=t("text/html"),a=t("image/jpeg"),c=t("image/png"),p=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(s,r,o,n)=>(s,...a)=>(a=a.map((e=>e.handle?e.base?e.handle:(t,...r)=>(t.url=new URL(t.url),t.url.pathname=t.url.pathname.replace(s.replace(/\/\*$/,""),""),e.handle(t,...r)):e)),t.push([r.toUpperCase?.(),RegExp(`^${(n=(e+s).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n]),o)}),routes:t,base:e,async handle(e,...s){let r,o,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=a[e]?[].concat(a[e],t):t;for(let[a,c,p,l]of t)if((a===e.method||"ALL"===a)&&(o=n.pathname.match(c))){e.params=o.groups||{},e.route=l;for(let t of p)if(null!=(r=await t(e.proxy??e,...s)))return r}}}),exports.StatusError=e,exports.createCors=(e={})=>{const{origins:t=["*"],maxAge:s,methods:r=["GET"],headers:o={}}=e;let n;const a="function"==typeof t?t:e=>t.includes(e)||t.includes("*"),c={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...o};s&&(c["Access-Control-Max-Age"]=s);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:s,body:r}=e;return[101,301,302,308].includes(s)||t.get("access-control-allow-origin")?e:new Response(r,{status:s,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const t=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=a(s)&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const s={...c,"Access-Control-Allow-Methods":t.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?s:{Allow:t.join(", ")}})}}}},exports.createResponse=t,exports.error=(e=500,t)=>{if(e instanceof Error){const{message:s,...o}=e;e=e.status||500,t={error:s||r(e),...o}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},s(t,{status:e})},exports.html=n,exports.jpeg=a,exports.json=s,exports.png=c,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=o,exports.webp=p,exports.withContent=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,s])=>s?(e[t]=s,e):e),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,s)=>void 0!==t[s]?t[s].bind?.(e)||t[s]:t?.params?.[s]})};
"use strict";class e extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const t=(e="text/plain; charset=utf-8",t)=>(s,{headers:r={},...o}={})=>void 0===s||"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...r},...o}),s=t("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=t("text/plain; charset=utf-8",String),n=t("text/html"),a=t("image/jpeg"),c=t("image/png"),p=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(s,r,o,n)=>(s,...a)=>(a=a.map((e=>e.handle?e.base?e.handle:(t,...r)=>(t.url=new URL(t.url),t.url.pathname=t.url.pathname.replace(s.replace(/\/\*$/,""),""),e.handle(t,...r)):e)),t.push([r.toUpperCase(),RegExp(`^${(n=(e+s).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n]),o)}),routes:t,base:e,async handle(e,...s){let r,o,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=a[e]?[].concat(a[e],t):t;for(let[a,c,p,l]of t)if((a===e.method||"ALL"===a)&&(o=n.pathname.match(c))){e.params=o.groups||{},e.route=l;for(let t of p)if(null!=(r=await t(e.proxy??e,...s)))return r}}}),exports.StatusError=e,exports.createCors=(e={})=>{const{origins:t=["*"],maxAge:s,methods:r=["GET"],headers:o={}}=e;let n;const a="function"==typeof t?t:e=>t.includes(e)||t.includes("*"),c={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...o};s&&(c["Access-Control-Max-Age"]=s);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:s,body:r}=e;return[101,301,302,308].includes(s)||t.get("access-control-allow-origin")?e:new Response(r,{status:s,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const t=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=a(s)&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const s={...c,"Access-Control-Allow-Methods":t.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?s:{Allow:t.join(", ")}})}}}},exports.createResponse=t,exports.error=(e=500,t)=>{if(e instanceof Error){const{message:s,...o}=e;e=e.status||500,t={error:s||r(e),...o}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},s(t,{status:e})},exports.html=n,exports.jpeg=a,exports.json=s,exports.png=c,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=o,exports.webp=p,exports.withContent=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,s])=>s?(e[t]=s,e):e),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,s)=>void 0!==t[s]?t[s].bind?.(e)||t[s]:t?.params?.[s]})};
{
"name": "itty-router",
"version": "4.0.25-next.0",
"version": "4.0.25-next.1",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",

@@ -5,0 +5,0 @@ "main": "./index.js",

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

"use strict";exports.Router=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(a,l,t,o)=>(a,...p)=>(p=p.map((e=>e.handle?e.base?e.handle:(r,...l)=>(r.url=new URL(r.url),r.url.pathname=r.url.pathname.replace(a.replace(/\/\*$/,""),""),e.handle(r,...l)):e)),r.push([l.toUpperCase?.(),RegExp(`^${(o=(e+a).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),p,o]),t)}),routes:r,base:e,async handle(e,...a){let l,t,o=new URL(e.url),p=e.query={__proto__:null};for(let[e,r]of o.searchParams)p[e]=p[e]?[].concat(p[e],r):r;for(let[p,u,n,s]of r)if((p===e.method||"ALL"===p)&&(t=o.pathname.match(u))){e.params=t.groups||{},e.route=s;for(let r of n)if(null!=(l=await r(e.proxy??e,...a)))return l}}});
"use strict";exports.Router=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(a,l,t,o)=>(a,...p)=>(p=p.map((e=>e.handle?e.base?e.handle:(r,...l)=>(r.url=new URL(r.url),r.url.pathname=r.url.pathname.replace(a.replace(/\/\*$/,""),""),e.handle(r,...l)):e)),r.push([l.toUpperCase(),RegExp(`^${(o=(e+a).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),p,o]),t)}),routes:r,base:e,async handle(e,...a){let l,t,o=new URL(e.url),p=e.query={__proto__:null};for(let[e,r]of o.searchParams)p[e]=p[e]?[].concat(p[e],r):r;for(let[p,u,n,s]of r)if((p===e.method||"ALL"===p)&&(t=o.pathname.match(u))){e.params=t.groups||{},e.route=s;for(let r of n)if(null!=(l=await r(e.proxy??e,...a)))return l}}});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc