MCPcopy Create free account
hub / github.com/middleapi/orpc / findDeepMatches

Function findDeepMatches

packages/shared/src/object.ts:3–26  ·  view source on GitHub ↗
(
  check: (value: unknown) => boolean,
  payload: unknown,
  segments: Segment[] = [],
  maps: Segment[][] = [],
  values: unknown[] = [],
)

Source from the content-addressed store, hash-verified

1export type Segment = string | number
2
3export function findDeepMatches(
4 check: (value: unknown) => boolean,
5 payload: unknown,
6 segments: Segment[] = [],
7 maps: Segment[][] = [],
8 values: unknown[] = [],
9): { maps: Segment[][], values: unknown[] } {
10 if (check(payload)) {
11 maps.push(segments)
12 values.push(payload)
13 }
14 else if (Array.isArray(payload)) {
15 payload.forEach((v, i) => {
16 findDeepMatches(check, v, [...segments, i], maps, values)
17 })
18 }
19 else if (isObject(payload)) {
20 for (const key in payload) {
21 findDeepMatches(check, payload[key], [...segments, key], maps, values)
22 }
23 }
24
25 return { maps, values }
26}
27
28/**
29 * Get constructor of the value

Callers 2

toOpenAPIContentFunction · 0.90
object.test.tsFile · 0.90

Calls 2

isObjectFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected