{"ScriptPreparationCode":"var querystring = \u0027foo=bar\u0026baz=qux\u0026quxx=corge\u0026grault=garply\u0026waldo=fred\u0026plugh=xyzzy\u0027\r\n\r\nvar queryobj = {\r\n foo: \u0027bar\u0027,\r\n baz: \u0027qux\u0027,\r\n quux: \u0027corge\u0027,\r\n grault: \u0027garply\u0027,\r\n waldo: \u0027fred\u0027,\r\n plugh: \u0027xyzzy\u0027\r\n}\r\n\r\nfunction encode(data) {\r\n let result = \u0027?\u0027\r\n\r\n for (const key in data) {\r\n if (data[key] != null) {\r\n result \u002B= key \u002B \u0027=\u0027 \u002B data[key] \u002B \u0027\u0026\u0027\r\n }\r\n }\r\n\r\n return result.slice(0, -1)\r\n}\r\n\r\nfunction encodeNative(data) {\r\n return new URLSearchParams(data).toString()\r\n}\r\n\r\nfunction buildQueryString(params) {\r\n const query = Object.entries(params)\r\n .filter(([_, value]) =\u003E value !== undefined \u0026\u0026 value !== null)\r\n .map(([key, value]) =\u003E \u0060${key}=${encodeURIComponent(String(value))}\u0060)\r\n .join(\u0027\u0026\u0027);\r\n\r\n return query ? \u0060?${query}\u0060 : \u0027\u0027;\r\n}\r\n\r\nfunction fastBuildQueryString(params) {\r\n let result = \u0027?\u0027;\r\n let first = true;\r\n \r\n for (const key of Object.keys(params)) {\r\n const value = params[key];\r\n if (value != null) {\r\n if (!first) result \u002B= \u0027\u0026\u0027;\r\n result \u002B= key \u002B \u0027=\u0027 \u002B encodeURIComponent(String(value));\r\n first = false;\r\n }\r\n }\r\n \r\n return first ? \u0027\u0027 : result;\r\n}\r\n\r\nfunction buildQueryString2(params) {\r\n const filteredParams = Object.fromEntries(\r\n Object.entries(params).filter(([_, value]) =\u003E value != null)\r\n );\r\n const query = new URLSearchParams(filteredParams).toString();\r\n return query ? \u0060?${query}\u0060 : \u0027\u0027;\r\n}","TestCases":[{"Name":"URLSearchParams","Code":"encodeNative(queryobj)","IsDeferred":false},{"Name":"Custom (safe)","Code":"buildQueryString(queryobj)","IsDeferred":false},{"Name":"Custom 2 (unsafe)","Code":"encode(queryobj)","IsDeferred":false},{"Name":"Custom (fast)","Code":"fastBuildQueryString(queryobj)","IsDeferred":false},{"Name":"Custom (both)","Code":"buildQueryString2(queryobj)","IsDeferred":false}]}