Documentation / @facturometro/validator / selectPath
Function: selectPath() ​
selectPath(
root,key):Hit<object,unknown>[]
Defined in: packages/validator/src/engine/selectors.ts:212
Resolves a DocumentPaths key ('taxTotal[].taxSubtotal[]', 'document', ...) against a document into the aggregate nodes found there, each with its model path and parent.
Repeated segments ([]) fan out over every array element; a segment that is absent, or whose value is not an object, yields nothing. An array met where the key expects a single node is fanned out as well, so a leniently mapped document still selects.
Parameters ​
root ​
object
The document.
key ​
string
The dotted key; document selects the root itself.
Returns ​
Hit<object, unknown>[]
The hits, in document order.
Example ​
ts
import { selectPath } from '@facturometro/validator';
selectPath(invoice, 'invoiceLine[].item').map((hit) => hit.path);
// [['invoiceLine', 0, 'item'], ['invoiceLine', 1, 'item']]