MCPcopy
hub / github.com/tighten/ziggy / toString

Method toString

src/js/Router.js:49–70  ·  view source on GitHub ↗

* Get the compiled URL string for the current route and parameters. * * @example * // with 'posts.show' route 'posts/{post}' * (new Router('posts.show', 1)).toString(); // 'https://ziggy.dev/posts/1' * * @return {String}

()

Source from the content-addressed store, hash-verified

47 * @return {String}
48 */
49 toString() {
50 // Get parameters that don't correspond to any route segments to append them to the query
51 const unhandled = Object.keys(this._params)
52 .filter((key) => !this._route.parameterSegments.some(({ name }) => name === key))
53 .filter((key) => key !== '_query')
54 .reduce((result, current) => ({ ...result, [current]: this._params[current] }), {});
55
56 return (
57 this._route.compile(this._params) +
58 stringify(
59 { ...unhandled, ...this._params['_query'] },
60 {
61 addQueryPrefix: true,
62 arrayFormat: 'indices',
63 encodeValuesOnly: true,
64 skipNulls: true,
65 encoder: (value, encoder) =>
66 typeof value === 'boolean' ? Number(value) : encoder(value),
67 },
68 )
69 );
70 }
71
72 /**
73 * Get the parameters, values, and metadata from the given URL.

Callers 2

routeFunction · 0.95
valueOfMethod · 0.95

Calls 1

compileMethod · 0.80

Tested by

no test coverage detected