@tanstack/router-core 1.114.33 → 1.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/qss.cjs CHANGED
@@ -2,21 +2,15 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const utils = require("./utils.cjs");
4
4
  function encode(obj, pfx) {
5
- let k, i, tmp, str = "";
6
- for (k in obj) {
7
- if ((tmp = obj[k]) !== void 0) {
8
- if (Array.isArray(tmp)) {
9
- for (i = 0; i < tmp.length; i++) {
10
- str && (str += "&");
11
- str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
12
- }
13
- } else {
14
- str && (str += "&");
15
- str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
16
- }
5
+ const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {
6
+ if (Array.isArray(value)) {
7
+ return value.map((v) => [key, String(v)]);
8
+ } else {
9
+ return [[key, String(value)]];
17
10
  }
18
- }
19
- return (pfx || "") + str;
11
+ });
12
+ const searchParams = new URLSearchParams(normalizedObject);
13
+ return (pfx || "") + searchParams.toString();
20
14
  }
21
15
  function toValue(mix) {
22
16
  if (!mix) return "";
@@ -26,26 +20,18 @@ function toValue(mix) {
26
20
  return +str * 0 === 0 && +str + "" === str ? +str : str;
27
21
  }
28
22
  function decode(str, pfx) {
29
- let tmp, k;
30
- const out = {}, arr = (pfx ? str.substr(pfx.length) : str).split("&");
31
- while (tmp = arr.shift()) {
32
- const equalIndex = tmp.indexOf("=");
33
- if (equalIndex !== -1) {
34
- k = tmp.slice(0, equalIndex);
35
- k = decodeURIComponent(k);
36
- const value = tmp.slice(equalIndex + 1);
37
- if (out[k] !== void 0) {
38
- out[k] = [].concat(out[k], toValue(value));
39
- } else {
40
- out[k] = toValue(value);
41
- }
23
+ const searchParamsPart = pfx ? str.slice(pfx.length) : str;
24
+ const searchParams = new URLSearchParams(searchParamsPart);
25
+ const entries = [...searchParams.entries()];
26
+ return entries.reduce((acc, [key, value]) => {
27
+ const previousValue = acc[key];
28
+ if (previousValue == null) {
29
+ acc[key] = toValue(value);
42
30
  } else {
43
- k = tmp;
44
- k = decodeURIComponent(k);
45
- out[k] = "";
31
+ acc[key] = Array.isArray(previousValue) ? [...previousValue, toValue(value)] : [previousValue, toValue(value)];
46
32
  }
47
- }
48
- return out;
33
+ return acc;
34
+ }, {});
49
35
  }
50
36
  exports.decode = decode;
51
37
  exports.encode = encode;
@@ -1 +1 @@
1
- {"version":3,"file":"qss.cjs","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program uses a modified version of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n */\n\nimport { hasUriEncodedChars } from './utils'\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param [pfx] - An optional prefix to add before the query string.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(obj: any, pfx?: string) {\n let k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(mix: any) {\n if (!mix) return ''\n const str = hasUriEncodedChars(mix)\n ? decodeURIComponent(mix)\n : decodeURIComponent(encodeURIComponent(mix))\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @param [pfx] - An optional prefix to filter out from the query string.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any, pfx?: string) {\n let tmp, k\n const out: any = {},\n arr = (pfx ? str.substr(pfx.length) : str).split('&')\n\n while ((tmp = arr.shift())) {\n const equalIndex = tmp.indexOf('=')\n if (equalIndex !== -1) {\n k = tmp.slice(0, equalIndex)\n k = decodeURIComponent(k)\n const value = tmp.slice(equalIndex + 1)\n if (out[k] !== void 0) {\n // @ts-expect-error\n out[k] = [].concat(out[k], toValue(value))\n } else {\n out[k] = toValue(value)\n }\n } else {\n k = tmp\n k = decodeURIComponent(k)\n out[k] = ''\n }\n }\n\n return out\n}\n"],"names":["hasUriEncodedChars"],"mappings":";;;AAmBgB,SAAA,OAAO,KAAU,KAAc;AACzC,MAAA,GACF,GACA,KACA,MAAM;AAER,OAAK,KAAK,KAAK;AACb,SAAK,MAAM,IAAI,CAAC,OAAO,QAAQ;AACzB,UAAA,MAAM,QAAQ,GAAG,GAAG;AACtB,aAAK,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AAC/B,kBAAQ,OAAO;AACf,iBAAO,mBAAmB,CAAC,IAAI,MAAM,mBAAmB,IAAI,CAAC,CAAC;AAAA,QAAA;AAAA,MAChE,OACK;AACL,gBAAQ,OAAO;AACf,eAAO,mBAAmB,CAAC,IAAI,MAAM,mBAAmB,GAAG;AAAA,MAAA;AAAA,IAC7D;AAAA,EACF;AAGF,UAAQ,OAAO,MAAM;AACvB;AAUA,SAAS,QAAQ,KAAU;AACrB,MAAA,CAAC,IAAY,QAAA;AACX,QAAA,MAAMA,yBAAmB,GAAG,IAC9B,mBAAmB,GAAG,IACtB,mBAAmB,mBAAmB,GAAG,CAAC;AAE1C,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAWgB,SAAA,OAAO,KAAU,KAAc;AAC7C,MAAI,KAAK;AACT,QAAM,MAAW,CACf,GAAA,OAAO,MAAM,IAAI,OAAO,IAAI,MAAM,IAAI,KAAK,MAAM,GAAG;AAE9C,SAAA,MAAM,IAAI,SAAU;AACpB,UAAA,aAAa,IAAI,QAAQ,GAAG;AAClC,QAAI,eAAe,IAAI;AACjB,UAAA,IAAI,MAAM,GAAG,UAAU;AAC3B,UAAI,mBAAmB,CAAC;AACxB,YAAM,QAAQ,IAAI,MAAM,aAAa,CAAC;AAClC,UAAA,IAAI,CAAC,MAAM,QAAQ;AAEjB,YAAA,CAAC,IAAI,CAAA,EAAG,OAAO,IAAI,CAAC,GAAG,QAAQ,KAAK,CAAC;AAAA,MAAA,OACpC;AACD,YAAA,CAAC,IAAI,QAAQ,KAAK;AAAA,MAAA;AAAA,IACxB,OACK;AACD,UAAA;AACJ,UAAI,mBAAmB,CAAC;AACxB,UAAI,CAAC,IAAI;AAAA,IAAA;AAAA,EACX;AAGK,SAAA;AACT;;;"}
1
+ {"version":3,"file":"qss.cjs","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n */\nimport { hasUriEncodedChars } from './utils'\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param [pfx] - An optional prefix to add before the query string.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(obj: any, pfx?: string) {\n const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {\n if (Array.isArray(value)) {\n return value.map((v) => [key, String(v)])\n } else {\n return [[key, String(value)]]\n }\n })\n\n const searchParams = new URLSearchParams(normalizedObject)\n\n return (pfx || '') + searchParams.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(mix: any) {\n if (!mix) return ''\n const str = hasUriEncodedChars(mix)\n ? decodeURIComponent(mix)\n : decodeURIComponent(encodeURIComponent(mix))\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @param [pfx] - An optional prefix to filter out from the query string.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any, pfx?: string): any {\n const searchParamsPart = pfx ? str.slice(pfx.length) : str\n const searchParams = new URLSearchParams(searchParamsPart)\n\n const entries = [...searchParams.entries()]\n\n return entries.reduce<Record<string, unknown>>((acc, [key, value]) => {\n const previousValue = acc[key]\n if (previousValue == null) {\n acc[key] = toValue(value)\n } else {\n acc[key] = Array.isArray(previousValue)\n ? [...previousValue, toValue(value)]\n : [previousValue, toValue(value)]\n }\n\n return acc\n }, {})\n}\n"],"names":["hasUriEncodedChars"],"mappings":";;;AAsBgB,SAAA,OAAO,KAAU,KAAc;AACvC,QAAA,mBAAmB,OAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACjE,QAAA,MAAM,QAAQ,KAAK,GAAG;AACjB,aAAA,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;AAAA,IAAA,OACnC;AACL,aAAO,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAAA,IAAA;AAAA,EAC9B,CACD;AAEK,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEjD,UAAA,OAAO,MAAM,aAAa,SAAS;AAC7C;AAUA,SAAS,QAAQ,KAAU;AACrB,MAAA,CAAC,IAAY,QAAA;AACX,QAAA,MAAMA,yBAAmB,GAAG,IAC9B,mBAAmB,GAAG,IACtB,mBAAmB,mBAAmB,GAAG,CAAC;AAE1C,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAWgB,SAAA,OAAO,KAAU,KAAmB;AAClD,QAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI;AACjD,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEzD,QAAM,UAAU,CAAC,GAAG,aAAa,SAAS;AAE1C,SAAO,QAAQ,OAAgC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAC9D,UAAA,gBAAgB,IAAI,GAAG;AAC7B,QAAI,iBAAiB,MAAM;AACrB,UAAA,GAAG,IAAI,QAAQ,KAAK;AAAA,IAAA,OACnB;AACL,UAAI,GAAG,IAAI,MAAM,QAAQ,aAAa,IAClC,CAAC,GAAG,eAAe,QAAQ,KAAK,CAAC,IACjC,CAAC,eAAe,QAAQ,KAAK,CAAC;AAAA,IAAA;AAG7B,WAAA;AAAA,EACT,GAAG,EAAE;AACP;;;"}
@@ -1,8 +1,3 @@
1
- /**
2
- * Program uses a modified version of the `qss` package:
3
- * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
4
- * https://github.com/lukeed/qss/blob/master/license.md
5
- */
6
1
  /**
7
2
  * Encodes an object into a query string.
8
3
  * @param obj - The object to encode into a query string.
package/dist/esm/qss.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * Program uses a modified version of the `qss` package:
3
- * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
4
- * https://github.com/lukeed/qss/blob/master/license.md
5
- */
6
1
  /**
7
2
  * Encodes an object into a query string.
8
3
  * @param obj - The object to encode into a query string.
package/dist/esm/qss.js CHANGED
@@ -1,20 +1,14 @@
1
1
  import { hasUriEncodedChars } from "./utils.js";
2
2
  function encode(obj, pfx) {
3
- let k, i, tmp, str = "";
4
- for (k in obj) {
5
- if ((tmp = obj[k]) !== void 0) {
6
- if (Array.isArray(tmp)) {
7
- for (i = 0; i < tmp.length; i++) {
8
- str && (str += "&");
9
- str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
10
- }
11
- } else {
12
- str && (str += "&");
13
- str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
14
- }
3
+ const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {
4
+ if (Array.isArray(value)) {
5
+ return value.map((v) => [key, String(v)]);
6
+ } else {
7
+ return [[key, String(value)]];
15
8
  }
16
- }
17
- return (pfx || "") + str;
9
+ });
10
+ const searchParams = new URLSearchParams(normalizedObject);
11
+ return (pfx || "") + searchParams.toString();
18
12
  }
19
13
  function toValue(mix) {
20
14
  if (!mix) return "";
@@ -24,26 +18,18 @@ function toValue(mix) {
24
18
  return +str * 0 === 0 && +str + "" === str ? +str : str;
25
19
  }
26
20
  function decode(str, pfx) {
27
- let tmp, k;
28
- const out = {}, arr = (pfx ? str.substr(pfx.length) : str).split("&");
29
- while (tmp = arr.shift()) {
30
- const equalIndex = tmp.indexOf("=");
31
- if (equalIndex !== -1) {
32
- k = tmp.slice(0, equalIndex);
33
- k = decodeURIComponent(k);
34
- const value = tmp.slice(equalIndex + 1);
35
- if (out[k] !== void 0) {
36
- out[k] = [].concat(out[k], toValue(value));
37
- } else {
38
- out[k] = toValue(value);
39
- }
21
+ const searchParamsPart = pfx ? str.slice(pfx.length) : str;
22
+ const searchParams = new URLSearchParams(searchParamsPart);
23
+ const entries = [...searchParams.entries()];
24
+ return entries.reduce((acc, [key, value]) => {
25
+ const previousValue = acc[key];
26
+ if (previousValue == null) {
27
+ acc[key] = toValue(value);
40
28
  } else {
41
- k = tmp;
42
- k = decodeURIComponent(k);
43
- out[k] = "";
29
+ acc[key] = Array.isArray(previousValue) ? [...previousValue, toValue(value)] : [previousValue, toValue(value)];
44
30
  }
45
- }
46
- return out;
31
+ return acc;
32
+ }, {});
47
33
  }
48
34
  export {
49
35
  decode,
@@ -1 +1 @@
1
- {"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program uses a modified version of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n */\n\nimport { hasUriEncodedChars } from './utils'\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param [pfx] - An optional prefix to add before the query string.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(obj: any, pfx?: string) {\n let k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(mix: any) {\n if (!mix) return ''\n const str = hasUriEncodedChars(mix)\n ? decodeURIComponent(mix)\n : decodeURIComponent(encodeURIComponent(mix))\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @param [pfx] - An optional prefix to filter out from the query string.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any, pfx?: string) {\n let tmp, k\n const out: any = {},\n arr = (pfx ? str.substr(pfx.length) : str).split('&')\n\n while ((tmp = arr.shift())) {\n const equalIndex = tmp.indexOf('=')\n if (equalIndex !== -1) {\n k = tmp.slice(0, equalIndex)\n k = decodeURIComponent(k)\n const value = tmp.slice(equalIndex + 1)\n if (out[k] !== void 0) {\n // @ts-expect-error\n out[k] = [].concat(out[k], toValue(value))\n } else {\n out[k] = toValue(value)\n }\n } else {\n k = tmp\n k = decodeURIComponent(k)\n out[k] = ''\n }\n }\n\n return out\n}\n"],"names":[],"mappings":";AAmBgB,SAAA,OAAO,KAAU,KAAc;AACzC,MAAA,GACF,GACA,KACA,MAAM;AAER,OAAK,KAAK,KAAK;AACb,SAAK,MAAM,IAAI,CAAC,OAAO,QAAQ;AACzB,UAAA,MAAM,QAAQ,GAAG,GAAG;AACtB,aAAK,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AAC/B,kBAAQ,OAAO;AACf,iBAAO,mBAAmB,CAAC,IAAI,MAAM,mBAAmB,IAAI,CAAC,CAAC;AAAA,QAAA;AAAA,MAChE,OACK;AACL,gBAAQ,OAAO;AACf,eAAO,mBAAmB,CAAC,IAAI,MAAM,mBAAmB,GAAG;AAAA,MAAA;AAAA,IAC7D;AAAA,EACF;AAGF,UAAQ,OAAO,MAAM;AACvB;AAUA,SAAS,QAAQ,KAAU;AACrB,MAAA,CAAC,IAAY,QAAA;AACX,QAAA,MAAM,mBAAmB,GAAG,IAC9B,mBAAmB,GAAG,IACtB,mBAAmB,mBAAmB,GAAG,CAAC;AAE1C,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAWgB,SAAA,OAAO,KAAU,KAAc;AAC7C,MAAI,KAAK;AACT,QAAM,MAAW,CACf,GAAA,OAAO,MAAM,IAAI,OAAO,IAAI,MAAM,IAAI,KAAK,MAAM,GAAG;AAE9C,SAAA,MAAM,IAAI,SAAU;AACpB,UAAA,aAAa,IAAI,QAAQ,GAAG;AAClC,QAAI,eAAe,IAAI;AACjB,UAAA,IAAI,MAAM,GAAG,UAAU;AAC3B,UAAI,mBAAmB,CAAC;AACxB,YAAM,QAAQ,IAAI,MAAM,aAAa,CAAC;AAClC,UAAA,IAAI,CAAC,MAAM,QAAQ;AAEjB,YAAA,CAAC,IAAI,CAAA,EAAG,OAAO,IAAI,CAAC,GAAG,QAAQ,KAAK,CAAC;AAAA,MAAA,OACpC;AACD,YAAA,CAAC,IAAI,QAAQ,KAAK;AAAA,MAAA;AAAA,IACxB,OACK;AACD,UAAA;AACJ,UAAI,mBAAmB,CAAC;AACxB,UAAI,CAAC,IAAI;AAAA,IAAA;AAAA,EACX;AAGK,SAAA;AACT;"}
1
+ {"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n */\nimport { hasUriEncodedChars } from './utils'\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param [pfx] - An optional prefix to add before the query string.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(obj: any, pfx?: string) {\n const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {\n if (Array.isArray(value)) {\n return value.map((v) => [key, String(v)])\n } else {\n return [[key, String(value)]]\n }\n })\n\n const searchParams = new URLSearchParams(normalizedObject)\n\n return (pfx || '') + searchParams.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(mix: any) {\n if (!mix) return ''\n const str = hasUriEncodedChars(mix)\n ? decodeURIComponent(mix)\n : decodeURIComponent(encodeURIComponent(mix))\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @param [pfx] - An optional prefix to filter out from the query string.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any, pfx?: string): any {\n const searchParamsPart = pfx ? str.slice(pfx.length) : str\n const searchParams = new URLSearchParams(searchParamsPart)\n\n const entries = [...searchParams.entries()]\n\n return entries.reduce<Record<string, unknown>>((acc, [key, value]) => {\n const previousValue = acc[key]\n if (previousValue == null) {\n acc[key] = toValue(value)\n } else {\n acc[key] = Array.isArray(previousValue)\n ? [...previousValue, toValue(value)]\n : [previousValue, toValue(value)]\n }\n\n return acc\n }, {})\n}\n"],"names":[],"mappings":";AAsBgB,SAAA,OAAO,KAAU,KAAc;AACvC,QAAA,mBAAmB,OAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACjE,QAAA,MAAM,QAAQ,KAAK,GAAG;AACjB,aAAA,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;AAAA,IAAA,OACnC;AACL,aAAO,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAAA,IAAA;AAAA,EAC9B,CACD;AAEK,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEjD,UAAA,OAAO,MAAM,aAAa,SAAS;AAC7C;AAUA,SAAS,QAAQ,KAAU;AACrB,MAAA,CAAC,IAAY,QAAA;AACX,QAAA,MAAM,mBAAmB,GAAG,IAC9B,mBAAmB,GAAG,IACtB,mBAAmB,mBAAmB,GAAG,CAAC;AAE1C,MAAA,QAAQ,QAAgB,QAAA;AACxB,MAAA,QAAQ,OAAe,QAAA;AACpB,SAAA,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AAWgB,SAAA,OAAO,KAAU,KAAmB;AAClD,QAAM,mBAAmB,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI;AACjD,QAAA,eAAe,IAAI,gBAAgB,gBAAgB;AAEzD,QAAM,UAAU,CAAC,GAAG,aAAa,SAAS;AAE1C,SAAO,QAAQ,OAAgC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAC9D,UAAA,gBAAgB,IAAI,GAAG;AAC7B,QAAI,iBAAiB,MAAM;AACrB,UAAA,GAAG,IAAI,QAAQ,KAAK;AAAA,IAAA,OACnB;AACL,UAAI,GAAG,IAAI,MAAM,QAAQ,aAAa,IAClC,CAAC,GAAG,eAAe,QAAQ,KAAK,CAAC,IACjC,CAAC,eAAe,QAAQ,KAAK,CAAC;AAAA,IAAA;AAG7B,WAAA;AAAA,EACT,GAAG,EAAE;AACP;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.114.33",
3
+ "version": "1.115.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@tanstack/store": "^0.7.0",
48
48
  "tiny-invariant": "^1.3.3",
49
- "@tanstack/history": "1.114.29"
49
+ "@tanstack/history": "1.115.0"
50
50
  },
51
51
  "scripts": {}
52
52
  }
package/src/qss.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  /**
2
- * Program uses a modified version of the `qss` package:
2
+ * Program is a reimplementation of the `qss` package:
3
3
  * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
4
4
  * https://github.com/lukeed/qss/blob/master/license.md
5
+ *
6
+ * This reimplementation uses modern browser APIs
7
+ * (namely URLSearchParams) and TypeScript while still
8
+ * maintaining the original functionality and interface.
5
9
  */
6
-
7
10
  import { hasUriEncodedChars } from './utils'
8
11
 
9
12
  /**
@@ -18,26 +21,17 @@ import { hasUriEncodedChars } from './utils'
18
21
  * ```
19
22
  */
20
23
  export function encode(obj: any, pfx?: string) {
21
- let k,
22
- i,
23
- tmp,
24
- str = ''
25
-
26
- for (k in obj) {
27
- if ((tmp = obj[k]) !== void 0) {
28
- if (Array.isArray(tmp)) {
29
- for (i = 0; i < tmp.length; i++) {
30
- str && (str += '&')
31
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])
32
- }
33
- } else {
34
- str && (str += '&')
35
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)
36
- }
24
+ const normalizedObject = Object.entries(obj).flatMap(([key, value]) => {
25
+ if (Array.isArray(value)) {
26
+ return value.map((v) => [key, String(v)])
27
+ } else {
28
+ return [[key, String(value)]]
37
29
  }
38
- }
30
+ })
39
31
 
40
- return (pfx || '') + str
32
+ const searchParams = new URLSearchParams(normalizedObject)
33
+
34
+ return (pfx || '') + searchParams.toString()
41
35
  }
42
36
 
43
37
  /**
@@ -68,29 +62,22 @@ function toValue(mix: any) {
68
62
  * // Example input: decode("token=foo&key=value")
69
63
  * // Expected output: { "token": "foo", "key": "value" }
70
64
  */
71
- export function decode(str: any, pfx?: string) {
72
- let tmp, k
73
- const out: any = {},
74
- arr = (pfx ? str.substr(pfx.length) : str).split('&')
65
+ export function decode(str: any, pfx?: string): any {
66
+ const searchParamsPart = pfx ? str.slice(pfx.length) : str
67
+ const searchParams = new URLSearchParams(searchParamsPart)
68
+
69
+ const entries = [...searchParams.entries()]
75
70
 
76
- while ((tmp = arr.shift())) {
77
- const equalIndex = tmp.indexOf('=')
78
- if (equalIndex !== -1) {
79
- k = tmp.slice(0, equalIndex)
80
- k = decodeURIComponent(k)
81
- const value = tmp.slice(equalIndex + 1)
82
- if (out[k] !== void 0) {
83
- // @ts-expect-error
84
- out[k] = [].concat(out[k], toValue(value))
85
- } else {
86
- out[k] = toValue(value)
87
- }
71
+ return entries.reduce<Record<string, unknown>>((acc, [key, value]) => {
72
+ const previousValue = acc[key]
73
+ if (previousValue == null) {
74
+ acc[key] = toValue(value)
88
75
  } else {
89
- k = tmp
90
- k = decodeURIComponent(k)
91
- out[k] = ''
76
+ acc[key] = Array.isArray(previousValue)
77
+ ? [...previousValue, toValue(value)]
78
+ : [previousValue, toValue(value)]
92
79
  }
93
- }
94
80
 
95
- return out
81
+ return acc
82
+ }, {})
96
83
  }