Skip to content

Function: pickOwnParams()

API / @xmachines/play-url / index / pickOwnParams

function pickOwnParams(params, names, requiredNames?): Record<string, string> | null;

Defined in: packages/play-url/src/framework-params.ts:84

Keeps the entries of params whose name the pattern of the machine declares, and only when the result covers EVERY name of that pattern.

A complete pick is an answer, and a partial pick is not: a wrapper route of the host can declare a subset of the params of the machine — a tenant segment, for example, but not the document one — and keeping that subset drops the rest from a route that declares them. The caller falls back to its own extraction for null.

The result has a null prototype, so a param named __proto__ stays an own key.

An OPTIONAL name of the pattern (:name?) is covered whether the framework reports it or not: a segment that did not match has no value, and that is a complete answer. At least one declared name must come back, though — a framework that reports none matched another route, and the path may still hold a value that only the fallback reads. A pattern whose params are ALL optional therefore always answers null here when the framework reports nothing; resolveFrameworkParams then reads the PATH, which settles the question without the framework and without URLPattern.

Parameters

ParameterTypeDefault valueDescription
paramsRecord<string, string>undefinedThe params of the framework router. cleanFrameworkParams removes each empty value already, and one that reaches here anyway counts as absent: an empty value says that the segment did not match, and never that the path carries the empty string.
namesreadonly string[]undefinedThe names that the pattern of the machine declares.
requiredNamesreadonly string[]namesThe names the pattern REQUIRES. The default treats every name as required, so a two-argument call keeps the strict test.

Returns

Record<string, string> | null

The params of the machine, or null when the framework covers them not.