@tanstack/router-core 0.0.1-beta.156 → 0.0.1-beta.157

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.156",
4
+ "version": "0.0.1-beta.157",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -43,7 +43,7 @@
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@gisatcz/cross-package-react-context": "^0.2.0",
46
- "@tanstack/react-store": "0.0.1-beta.156"
46
+ "@tanstack/react-store": "0.0.1-beta.157"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
@@ -2,7 +2,10 @@ import { decode, encode } from './qss'
2
2
  import { AnySearchSchema } from './route'
3
3
 
4
4
  export const defaultParseSearch = parseSearchWith(JSON.parse)
5
- export const defaultStringifySearch = stringifySearchWith(JSON.stringify)
5
+ export const defaultStringifySearch = stringifySearchWith(
6
+ JSON.stringify,
7
+ JSON.parse,
8
+ )
6
9
 
7
10
  export function parseSearchWith(parser: (str: string) => any) {
8
11
  return (searchStr: string): AnySearchSchema => {
@@ -28,7 +31,30 @@ export function parseSearchWith(parser: (str: string) => any) {
28
31
  }
29
32
  }
30
33
 
31
- export function stringifySearchWith(stringify: (search: any) => string) {
34
+ export function stringifySearchWith(
35
+ stringify: (search: any) => string,
36
+ parser?: (str: string) => any,
37
+ ) {
38
+ function stringifyValue(val: any) {
39
+ if (typeof val === 'object' && val !== null) {
40
+ try {
41
+ return stringify(val)
42
+ } catch (err) {
43
+ // silent
44
+ }
45
+ } else if (typeof val === 'string' && typeof parser === 'function') {
46
+ try {
47
+ // Check if it's a valid parseable string.
48
+ // If it is, then stringify it again.
49
+ parser(val)
50
+ return stringify(val)
51
+ } catch (err) {
52
+ // silent
53
+ }
54
+ }
55
+ return val
56
+ }
57
+
32
58
  return (search: Record<string, any>) => {
33
59
  search = { ...search }
34
60
 
@@ -37,12 +63,10 @@ export function stringifySearchWith(stringify: (search: any) => string) {
37
63
  const val = search[key]
38
64
  if (typeof val === 'undefined' || val === undefined) {
39
65
  delete search[key]
40
- } else if (val && typeof val === 'object' && val !== null) {
41
- try {
42
- search[key] = stringify(val)
43
- } catch (err) {
44
- // silent
45
- }
66
+ } else if (Array.isArray(val)) {
67
+ search[key] = val.map(stringifyValue)
68
+ } else {
69
+ search[key] = stringifyValue(val)
46
70
  }
47
71
  })
48
72
  }