{"_id":"field-trip","_rev":"4646746","name":"field-trip","description":"walk a directed graph async without knowing its structure ahead of time","dist-tags":{"latest":"0.0.3"},"maintainers":[{"name":"noffle","email":"stephen.whitmore@gmail.com"}],"time":{"modified":"2026-04-10T20:19:27.000Z","created":"2016-06-07T19:01:58.938Z","0.0.3":"2016-06-15T02:00:20.343Z","0.0.2":"2016-06-07T20:17:29.710Z","0.0.1":"2016-06-07T19:01:58.938Z"},"users":{},"repository":{"url":"git://github.com/noffle/field-trip.git"},"versions":{"0.0.3":{"name":"field-trip","description":"walk a directed graph async without knowing its structure ahead of time","version":"0.0.3","repository":{"url":"git://github.com/noffle/field-trip.git"},"keywords":["traverse","walk","visit","dag","directed","graph","async"],"main":"index.js","scripts":{"test":"tape test/*.js"},"dependencies":{},"devDependencies":{"tape":"*"},"license":"ISC","gitHead":"102dc94fef9cf5cd4c9e7a3084fdfd5ca71413cf","bugs":{"url":"https://github.com/noffle/field-trip/issues"},"homepage":"https://github.com/noffle/field-trip#readme","_id":"field-trip@0.0.3","_shasum":"46bed751a97d072b7c265ca392615e9b55b75269","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.9.0","_npmUser":{"name":"noffle","email":"stephen.whitmore@gmail.com"},"dist":{"shasum":"46bed751a97d072b7c265ca392615e9b55b75269","size":1987,"noattachment":false,"key":"/field-trip/-/field-trip-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/field-trip/download/field-trip-0.0.3.tgz"},"maintainers":[{"name":"noffle","email":"stephen.whitmore@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/field-trip-0.0.3.tgz_1465956015189_0.9164753293152899"},"directories":{},"publish_time":1465956020343,"_hasShrinkwrap":false,"_cnpm_publish_time":1465956020343,"_cnpmcore_publish_time":"2021-12-16T20:53:10.253Z"},"0.0.2":{"name":"field-trip","description":"walk a directed graph async without knowing its structure ahead of time","version":"0.0.2","repository":{"url":"git://github.com/noffle/field-trip.git"},"keywords":["traverse","walk","visit","dag","directed","graph","async"],"main":"index.js","scripts":{"test":"tape test/*.js"},"dependencies":{},"devDependencies":{"tape":"*"},"license":"ISC","gitHead":"38c5829c0d3e6352ddb43e9ca9806363df7afd7a","bugs":{"url":"https://github.com/noffle/field-trip/issues"},"homepage":"https://github.com/noffle/field-trip#readme","_id":"field-trip@0.0.2","_shasum":"d9067de915340ac847452920f9df59b9ce89b23f","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.9.0","_npmUser":{"name":"noffle","email":"stephen.whitmore@gmail.com"},"dist":{"shasum":"d9067de915340ac847452920f9df59b9ce89b23f","size":1982,"noattachment":false,"key":"/field-trip/-/field-trip-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/field-trip/download/field-trip-0.0.2.tgz"},"maintainers":[{"name":"noffle","email":"stephen.whitmore@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/field-trip-0.0.2.tgz_1465330649246_0.7627403808292001"},"directories":{},"publish_time":1465330649710,"_hasShrinkwrap":false,"_cnpm_publish_time":1465330649710,"_cnpmcore_publish_time":"2021-12-16T20:53:10.440Z"},"0.0.1":{"name":"field-trip","description":"walk a directed graph async without knowing its structure ahead of time","version":"0.0.1","repository":{"url":"git://github.com/noffle/field-trip.git"},"main":"index.js","scripts":{"test":"tape test/*.js"},"dependencies":{},"devDependencies":{"tape":"*"},"license":"ISC","gitHead":"d5b913fab8c8d9240604dc622f3debfd30077988","bugs":{"url":"https://github.com/noffle/field-trip/issues"},"homepage":"https://github.com/noffle/field-trip#readme","_id":"field-trip@0.0.1","_shasum":"94f84e703f5d1494ee86d0ca552a0682202bf575","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.9.0","_npmUser":{"name":"noffle","email":"stephen.whitmore@gmail.com"},"dist":{"shasum":"94f84e703f5d1494ee86d0ca552a0682202bf575","size":1885,"noattachment":false,"key":"/field-trip/-/field-trip-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/field-trip/download/field-trip-0.0.1.tgz"},"maintainers":[{"name":"noffle","email":"stephen.whitmore@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/field-trip-0.0.1.tgz_1465326115833_0.1989761171862483"},"directories":{},"publish_time":1465326118938,"_hasShrinkwrap":false,"_cnpm_publish_time":1465326118938,"_cnpmcore_publish_time":"2021-12-16T20:53:10.641Z"}},"readme":"# field-trip\n\n> walk a directed graph async without knowing its structure ahead of time\n\n## Background\n\nThere are plenty of modules for traversing\n\n1. file systems\n2. arrays\n3. trees\n\nso long as their structure is known ahead of time. What if you require the asynchronous\nprocess of visiting a node in order to learn of its children?\n\n## Usage\n\nLet's take a field trip through a tree, pretending to be ignorant of its\nstructure up front:\n\n```js\nvar fieldtrip = require('field-trip')\n\nvar db = {}\ndb[0] = {key: 0, value: 1, kids: []}\ndb[1] = {key: 1, value: 2, kids: [0]}\ndb[2] = {key: 2, value: 3, kids: [4]}\ndb[3] = {key: 3, value: 4, kids: [2]}\ndb[4] = {key: 4, value: -1, kids: [0, 1]}\n\n// Begin taking a field trip through this unknown structure!\nfieldtrip([3], visit, function () {\n  console.log('all done')\n})\n\n// Visit a single node. 'add' to add children; 'done' when finished visting.\nfunction visit (key, add, done) {\n  lookupKey(key, function (err, node) {\n    if (err) return done(err)\n\n    console.log('KEY', key, 'VALUE', node.value)\n\n    node.kids.forEach(add)\n\n    done()\n  })\n}\n\n// Look up a key through some intensive asynchronous process.\nfunction lookupKey (key, cb) {\n  setTimeout(function () {\n    cb(null, db[key])\n  }, Math.floor(Math.random() * 100))\n}\n```\n\nThis will output\n\n```\nKEY 3 VALUE 4\nKEY 2 VALUE 3\nKEY 4 VALUE -1\nKEY 0 VALUE 1\nKEY 1 VALUE 2\nKEY 0 VALUE 1\nall done\n```\n\n## API\n\n```js\nvar fieldtrip = require('field-trip')\n```\n\n### fieldtrip(origins, visit, finish)\n\nCalls the function `visit` on each element in the array `origins`.\n\nEach call to visit expects the signature `function (node, add, done)`, where\n`add` can be called with another node to visit, and `done` **MUST** be called to\nsignal that this node's visitation has completed. Call `done(err)` to signal an\nerror and end the traversal.\n\n`finish` is called when either all nodes have been visited, or an error has\noccurred.\n\n## Install\n\nWith [npm](https://npmjs.org/) installed, run\n\n```\n$ npm install field-trip\n```\n\n## Thanks!\n\nThanks to chrisdickenson's\n[walk-dag](https://github.com/chrisdickinson/walk-dag) module, which was the\nclosest I could find to this. Example and tests are mostly stolen from his work.\n:)\n\n## License\n\nISC\n","_attachments":{},"homepage":"https://github.com/noffle/field-trip#readme","bugs":{"url":"https://github.com/noffle/field-trip/issues"},"license":"ISC"}