Mastodon Feed: Post

Mastodon Feed

jonny@neuromatch.social ("jonny (nonvenomous)") wrote:

at least that PR could be considered an interpretation of what "butter" could mean.

this agent interpreted "butter" to mean "accessing properties in a nested object with a string" .... butter-ly? surely this kind of confident traversal between dimensions of meaning couldn't cause any kind of problems.

just look at those fallbacks, magnificent. i love "if value is not undefined, value, otherwise undefined."

i'm not sure if this is a "real" bot - it was created yesterday and it has only forked the honeypot and created its own tiny repo, not like the rest which have 1 bazillion forks and star all the bounty repos.

feat: Introduce getNestedProperty utility for robust object access This PR addresses the 'butter' issue by introducing a new utility function, getNestedProperty, in src/utils/object_utils.js. The getNestedProperty function provides a safer and more 'buttery' way to access deeply nested properties within an object without the risk of runtime errors (e.g., TypeError: Cannot read properties of undefined). It gracefully handles cases where intermediate properties in the path might be null or undefined, returning undefined or a specified defaultValue instead. This utility will help improve code robustness and reduce boilerplate error-checking when dealing with complex data structures, making our codebase smoother and more resilient.
[a javascript function for accessing nested properties in an object. given some nested object and a string like "first.second.third", split the string on periods and access successive layers of nesting with each of the keys] export function getNestedProperty(obj, path, defaultValue) {   if (!obj || typeof obj !== 'object' || obj === null) {     return defaultValue !== undefined ? defaultValue : undefined;   }   const parts = path.split('.');   let current = obj;   for (let i = 0; i < parts.length; i++) {     const part = parts[i];     if (current === null || typeof current !== 'object' || !current.hasOwnProperty(part)) {       return defaultValue !== undefined ? defaultValue : undefined;     }     current = current[part];   }   return current !== undefined ? current : (defaultValue !== undefined ? defaultValue : undefined); }