I am using this code in a slightly modified version.
function parseUrl(url) { var idx = url.indexOf("?"); var data = { path:"", param:{} }; if (idx >= 0) { var args = url.substr(idx + 1).split("&"); for (var n in args) { var arg = args[n]; var eq = arg.indexOf("="); if (eq < 0) { eq = arg.length; } data.param[arg.substr(0, eq)] = arg.substr(eq + 1); } data.path = url.substr(0, idx); } else { data.path = url; } return data; }
This way i get a JSON Object with path and parameter.
parseURL("/hello?key=val&foo=bar&something"); //{"path":"/hello","param":{"key":"val","foo":"bar","something":''}}
@loopMasta started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I am using this code in a slightly modified version.
This way i get a JSON Object with path and parameter.