UNPKG

alb-router

Version:

A user-friendly router for Amazon Application Load Balancer paths. Effortlessly match URLs, extract parameters, and handle routing in Node.js.

1 lines 1.58 kB
{"version":3,"sources":["/Volumes/Work/Personal%20Projs/alb-router/dist/index.mjs"],"names":["match","extractParams","path","method","routes","route","matchFunc","pattern","decode","decodeURIComponent","matched","methods","params","key","handler"],"mappings":"AAAA,eAAe;AACf,SAASA,KAAK,QAAQ,iBAAiB;AACvC,IAAIC,gBAAgB,SAACC,MAAMC,QAAQC;QAC5B,kCAAA,2BAAA;;QAAL,QAAK,YAAeA,2BAAf,SAAA,6BAAA,QAAA,yBAAA,iCAAuB;YAAvB,IAAMC,QAAN;YACH,IAAMC,YAAYN,MAAMK,MAAME,OAAO,EAAE;gBAAEC,QAAQC;YAAmB;YACpE,IAAMC,UAAUJ,UAAUJ;YAC1B,IAAIQ,WAAWL,MAAMM,OAAO,CAACR,OAAO,EAAE;gBACpC,IAAMS,SAAS,CAAC;gBAChB,IAAK,IAAMC,OAAOH,QAAQE,MAAM,CAAE;oBAChC,IAAI,OAAOF,QAAQE,MAAM,CAACC,IAAI,KAAK,UAAU;wBAC3CD,MAAM,CAACC,IAAI,GAAGH,QAAQE,MAAM,CAACC,IAAI;oBACnC;gBACF;gBACA,OAAO;oBAAED,QAAAA;oBAAQE,SAAST,MAAMM,OAAO,CAACR,OAAO;gBAAC;YAClD;QACF;;QAZK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAaL,OAAO;QAAES,QAAQ,CAAC;QAAGE,SAAS;IAAK;AACrC;AACA,SACEb,aAAa,GACb","sourcesContent":["// src/index.ts\nimport { match } from \"path-to-regexp\";\nvar extractParams = (path, method, routes) => {\n for (const route of routes) {\n const matchFunc = match(route.pattern, { decode: decodeURIComponent });\n const matched = matchFunc(path);\n if (matched && route.methods[method]) {\n const params = {};\n for (const key in matched.params) {\n if (typeof matched.params[key] === \"string\") {\n params[key] = matched.params[key];\n }\n }\n return { params, handler: route.methods[method] };\n }\n }\n return { params: {}, handler: null };\n};\nexport {\n extractParams\n};\n"]}