MCPcopy
hub / github.com/deepstreamIO/deepstream.io / getValue

Function getValue

src/utils/json-path.ts:8–22  ·  view source on GitHub ↗
(data: any, path: string)

Source from the content-addressed store, hash-verified

6* undefined if the path can't be resolved
7*/
8export function getValue (data: any, path: string): any {
9 const tokens = tokenize(path)
10 let value = data
11 for (let i = 0; i < tokens.length; i++) {
12 if (value === undefined) {
13 return undefined
14 }
15 if (typeof value !== 'object') {
16 throw new Error('invalid data or path')
17 }
18 value = value[tokens[i]]
19 }
20
21 return value
22 }
23
24/**
25 * This class allows to set or get specific

Callers 1

setMethod · 0.90

Calls 1

tokenizeFunction · 0.85

Tested by

no test coverage detected