MCPcopy Create free account
hub / github.com/ashawkey/camera_viewer / parsePythonList

Method parsePythonList

js/poseParser.js:278–293  ·  view source on GitHub ↗

* Parse Python list notation that might not be valid JSON * @param {string} input * @returns {Array}

(input)

Source from the content-addressed store, hash-verified

276 * @returns {Array}
277 */
278 static parsePythonList(input) {
279 // Use Function constructor to safely evaluate the array
280 // This is safer than eval() as it only allows expressions
281 const sanitized = input
282 .replace(/\bnan\b/gi, 'NaN')
283 .replace(/\binf\b/gi, 'Infinity')
284 .replace(/\b-inf\b/gi, '-Infinity');
285
286 // Try to evaluate as JavaScript array literal
287 try {
288 const fn = new Function(`return ${sanitized}`);
289 return fn();
290 } catch (e) {
291 throw new Error(`Could not parse input as array: ${e.message}`);
292 }
293 }
294
295 /**
296 * Validate and convert parsed data to [T, 4, 4] format

Callers 1

parseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected