Skip to content

url

Parses the request URL into pathname, parsed query parameters, and the raw search string. Uses a fast single-pass parser (indexOf + slice) instead of the URL constructor for performance. Multi-value query parameters automatically become arrays.

Pipeline stage: Negotiation

import { url } from "@centralping/ergo";

None. The url() factory takes no parameters.

Returns a URL descriptor stored at acc.url:

{
pathname: "/users",
search: "?page=1&filter=a&filter=b",
query: {
page: "1",
filter: ["a", "b"]
}
}
PropertyTypeDescription
pathnamestring | undefinedURL path before the query string
searchstring | undefinedRaw query string including leading ?; undefined when absent
queryRecord<string, string | string[]>Parsed query parameters; multi-value keys become arrays
  • query uses a null-prototype object to prevent prototype pollution
  • Bounded by maxPairs: 256 and maxQueryLength: 8192 defaults

None.

import { compose, url } from "@centralping/ergo";
const pipeline = compose(
{fn: url(), setPath: "url"},
(req, res, acc) => ({
response: {
body: {
path: acc.url.pathname,
page: acc.url.query.page,
},
},
}),
);

See the auto-generated url API docs.