MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / getValueByPath

Function getValueByPath

devtools/modules/messageRenderer.js:358–383  ·  view source on GitHub ↗
(value, path)

Source from the content-addressed store, hash-verified

356}
357
358function getValueByPath(value, path) {
359 const keys = path.split('.').filter(Boolean);
360 let current = value;
361
362 for (const key of keys) {
363 if (current === null || current === undefined) {
364 return undefined;
365 }
366
367 if (Array.isArray(current)) {
368 if (/^\d+$/.test(key)) {
369 current = current[Number(key)];
370 } else {
371 const values = current
372 .map(item => getValueByPath(item, key))
373 .filter(item => item !== undefined);
374 current = values.length > 0 ? values : undefined;
375 }
376 continue;
377 }
378
379 current = current[key];
380 }
381
382 return current;
383}
384
385function formatDisplayFieldValue(value) {
386 if (value === null) return 'null';

Callers 1

getMessageDisplayDataFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected