You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, currently the pointer package only exposes post-iteration dicts/index - it would be nice if the walk function an iterator/generator interface was exposed, e.g.,
import{join}from"json8-pointer"/* JSON Pointer iterator * * yields [ entryPath, entryObj, entryKey, parentPath, parentObj ] * but values are of course ignorable, so this works fine: * * for (const [key, val] of entries(obj)) console.log(key, val) */exportfunction*entries(tree){constisContainer=(o)=>typeofo==="object"&&o!==nullconstisEnumerable=(o)=>Array.isArray(o)||oinstanceofSetconstisKeyvalue=(o)=>typeofo==="object"||oinstanceofMapyield[[],tree]yield*children([],tree)function*children(parentPath,parentObj){if(!isContainer(parentObj))returnif(isEnumerable(parentObj)){letc=0for(constchildObjofparentObj){constchildKey=String(c++)constchildPath=join(parentPath,childKey)yield[childPath,childObj,childKey,parentPath,parentObj]yield*children(childPath,childObj)}return}if(isKeyvalue(parentObj)){for(const[childKey,childObj]ofObject.entries(parentObj)){constchildPath=join(parentPath,childKey)yield[childPath,childObj,childKey,parentPath,parentObj]yield*children(childPath,childObj)}return}thrownewTypeError(parentObj+" is not a structure")}}
Hi, currently the pointer package only exposes post-iteration dicts/index - it would be nice if the
walk
function an iterator/generator interface was exposed, e.g.,Maybe
entries
,flatEntries
,primitives
, or something like that, to select what to iterate over.The text was updated successfully, but these errors were encountered: