Socket
Socket
Sign inDemoInstall

itty-router

Package Overview
Dependencies
Maintainers
2
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itty-router - npm Package Compare versions

Comparing version 3.0.11-next.30 to 3.0.11-next.31

4

dist/extras/index.d.ts

@@ -15,5 +15,1 @@ export * from './StatusError';

export * from './createCors';
export * from './badRequest';
export * from './forbidden';
export * from './notFound';
export * from './unauthorized';

2

dist/index.js

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

"use strict";class e extends Error{status;constructor(e=500,t="Internal Server Error"){"string"==typeof t?super(t):(super(t.error),Object.assign(this,t)),this.status=e}}const t=(e="text/plain; charset=utf-8",t)=>(s,r={})=>{const{headers:o={},...n}=r;return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...o},...n})},s=t("application/json; charset=utf-8",JSON.stringify),r=e=>new Response(null,{status:e}),o=(e=500,t)=>{if(e instanceof Error){const{message:s,...r}=e;return t={error:e.message,...r},o(e.status||500,t)}return t&&"Request"!==t?.constructor?.name?s({status:e,..."object"==typeof t?t:{error:t}},{status:e}):r(e)},n=t("text/html"),a=t("image/jpeg"),p=t("image/png"),c=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(s,r,o)=>(s,...n)=>t.push([r.toUpperCase(),RegExp(`^${(e+"/"+s).replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),n])&&o}),routes:t,async handle(e,...s){let r,o,n=new URL(e.url),a=e.query={};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,p,c]of t)if((a===e.method||"ALL"===a)&&(o=n.pathname.match(p))){e.params=o.groups||{};for(let t of c)if(void 0!==(r=await t(e.proxy||e,...s)))return r}}}),exports.StatusError=e,exports.badRequest=e=>o(400,e),exports.createCors=(e={})=>{const{origins:t=["*"],maxAge:s,methods:r=["GET"],headers:o={}}=e;let n;const a={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...o};s&&(a["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;if([101,301,302,308].includes(s))return e;const o=Object.fromEntries(t);return o["access-control-allow-origin"]?e:new Response(r,{status:s,headers:{...o,...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const s=[...new Set(["OPTIONS",...r])],o=e.headers.get("origin")||"";if(n=(t.includes(o)||t.includes("*"))&&{"Access-Control-Allow-Origin":o},"OPTIONS"===e.method){if(null!==e.headers.get("Origin")&&null!==e.headers.get("Access-Control-Request-Method")&&null!==e.headers.get("Access-Control-Request-Headers")){const t={...a,"Access-Control-Allow-Methods":s.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:t})}return new Response(null,{headers:{Allow:s.join(", ")}})}}}},exports.createResponse=t,exports.error=o,exports.forbidden=e=>o(403,e),exports.html=n,exports.jpeg=a,exports.json=s,exports.notFound=e=>o(404,e),exports.png=p,exports.status=r,exports.text=(e,t)=>new Response(e,t),exports.unauthorized=e=>o(401,e),exports.webp=c,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])=>(e[t]=s,e)),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(e,t)=>void 0!==e[t]?e[t]:e?.params?.[t]})};
"use strict";class e extends Error{status;constructor(e=500,t="Internal Server Error"){"string"==typeof t?super(t):(super(t.error),Object.assign(this,t)),this.status=e}}const t=(e="text/plain; charset=utf-8",t)=>(s,r={})=>{const{headers:o={},...n}=r;return"Response"===s?.constructor.name?s:new Response(t?t(s):s,{headers:{"content-type":e,...o},...n})},s=t("application/json; charset=utf-8",JSON.stringify),r=t("text/html"),o=t("image/jpeg"),n=t("image/png"),a=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(s,r,o)=>(s,...n)=>t.push([r.toUpperCase(),RegExp(`^${(e+"/"+s).replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),n])&&o}),routes:t,async handle(e,...s){let r,o,n=new URL(e.url),a=e.query={};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,c,p]of t)if((a===e.method||"ALL"===a)&&(o=n.pathname.match(c))){e.params=o.groups||{};for(let t of p)if(void 0!==(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={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...o};s&&(a["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;if([101,301,302,308].includes(s))return e;const o=Object.fromEntries(t);return o["access-control-allow-origin"]?e:new Response(r,{status:s,headers:{...o,...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const s=[...new Set(["OPTIONS",...r])],o=e.headers.get("origin")||"";if(n=(t.includes(o)||t.includes("*"))&&{"Access-Control-Allow-Origin":o},"OPTIONS"===e.method){if(null!==e.headers.get("Origin")&&null!==e.headers.get("Access-Control-Request-Method")&&null!==e.headers.get("Access-Control-Request-Headers")){const t={...a,"Access-Control-Allow-Methods":s.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:t})}return new Response(null,{headers:{Allow:s.join(", ")}})}}}},exports.createResponse=t,exports.error=(e=500,t)=>{if(e instanceof Error){const{message:s,...r}=e;t={error:e.message,...r},e=e.status||500}return t&&"Request"===t?.constructor?.name||(t={status:e,..."object"==typeof t?t:{error:t}}),s(t,{status:e})},exports.html=r,exports.jpeg=o,exports.json=s,exports.png=n,exports.status=e=>new Response(null,{status:e}),exports.text=(e,t)=>new Response(e,t),exports.webp=a,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])=>(e[t]=s,e)),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(e,t)=>void 0!==e[t]?e[t]:e?.params?.[t]})};
{
"name": "itty-router",
"version": "3.0.11-next.30",
"version": "3.0.11-next.31",
"description": "Tiny, zero-dependency API router - built for Cloudflare Workers, but works everywhere!",

@@ -5,0 +5,0 @@ "sourceType": "module",

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