{"_id":"lookup","_rev":"7-8406c926ea1bd8dc11b522ad19e2c590","name":"lookup","description":"Transform a stream or array into a lookup object","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.0":{"name":"lookup","version":"0.0.0","description":"Transform a stream or array into a lookup object","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://github.com/grncdr/js-lookup.git"},"keywords":["lookup","hashmap","mapping"],"author":{"name":"Stephen Sugden","email":"me@stephensugden.com"},"license":"BSD-2-Clause","bugs":{"url":"https://github.com/grncdr/js-lookup/issues"},"devDependencies":{"tape":"~2.3.0","from":"~0.1.3"},"dependencies":{"through":"~2.3.4","pluck":"0.0.4"},"testling":{"files":"test.js","browsers":{"ie":[8,9],"firefox":[13],"chrome":[20],"safari":[5.1],"opera":[12]}},"_id":"lookup@0.0.0","dist":{"shasum":"761f694525ffefac71f9ddaf5cf66f79843a8c2f","tarball":"https://registry.npmjs.org/lookup/-/lookup-0.0.0.tgz","integrity":"sha512-S+llS3+lZKoupWwH2QUTKql88+ladbCKwNwg4AJZtMOdBHT/6G91CJSd5oLL6AknTN81HPdd2P5/YzHIubJwbA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHMbMMj09K/YuZsTRCKSto5aVEqzo788c2bQRVWTBIVQIhAMrDXwWGnDht2DKPqkU75FCqXWIDBRdacm0dKSwhnkCZ"}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"grncdr","email":"glurgle@gmail.com"},"maintainers":[{"name":"grncdr","email":"glurgle@gmail.com"}]},"0.1.0":{"name":"lookup","version":"0.1.0","description":"Transform a stream or array into a lookup object","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://github.com/grncdr/js-lookup.git"},"keywords":["lookup","hashmap","mapping"],"author":{"name":"Stephen Sugden","email":"me@stephensugden.com"},"license":"BSD-2-Clause","bugs":{"url":"https://github.com/grncdr/js-lookup/issues"},"devDependencies":{"tape":"~2.3.0","from":"~0.1.3"},"dependencies":{"through":"~2.3.4","pluck":"0.0.4"},"testling":{"files":"test.js","browsers":{"ie":[8,9],"firefox":[13],"chrome":[20],"safari":[5.1],"opera":[12]}},"gitHead":"320859d41135f5777678d20620d92f38d28fc745","homepage":"https://github.com/grncdr/js-lookup","_id":"lookup@0.1.0","_shasum":"4669a69ff69beada808afe1a4af395ebd7681650","_from":".","_npmVersion":"1.4.20","_npmUser":{"name":"grncdr","email":"glurgle@gmail.com"},"maintainers":[{"name":"grncdr","email":"glurgle@gmail.com"}],"dist":{"shasum":"4669a69ff69beada808afe1a4af395ebd7681650","tarball":"https://registry.npmjs.org/lookup/-/lookup-0.1.0.tgz","integrity":"sha512-oUhI7PHTrNvFiL1IpU/rfj+TgfWSFJKhZT6wsrLTGEEu/NpgZHWJ+yYxJRKF4HzyUwNsjfWbW+DsUBTuBy2k4Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC0NfB6Rl3euAjgVWT5egPdN6yhanbqrHAfkVW/UJ8AvwIgRRebOm1h3Rw491nvBAOHzqI1pnOzMBm36u+iPFdkp3o="}]}}},"readme":"# lookup\n\n[![browser support](https://ci.testling.com/grncdr/js-lookup.png)](https://ci.testling.com/grncdr/js-lookup)\n\n## API\n\n### module.exports = function lookup (hash=pluck(\"id\"), onCollision=\"last\")\n\n`lookup` creates a reducing function (suitable for passing to `Array.prototype.reduce` or [reducible](https://npm.im/reducible)) that builds a lookup table using the provided hash function. The function returned looks something like this:\n\n```javascript\nfunction reducer (mapping, object) {\n  mapping[hash(object)] = object\n  return mapping\n}\n```\n#### Creating a lookup on a property.\n\nWhen the `hash` parameter is a string, the corresponding property name will be used as the hash value of each object. E.g. `lookup('name')` will return a hash function something like this:\n\n```javascript\nfunction reducer (mapping, object) {\n  mapping[object['name']] = object\n  return mapping\n}\n```\n\n#### Collision Handling\n\nThe second parameter to `lookup` determines what happens when two objects have the same hash value. There are currently 4 options:\n\n - `'last'` - This is the default. If an object hashes to a key that is already used, the old value is overwritten.\n - `'first'` - The opposite of `'last'`. If an object hashes to a key that is already used, the new value is discarded.\n - `'array'` - Keep all values for each object in the order they appeared. The values in the final mapping will alway be arrays.\n - `'concat'` - Keep all values for each object in the order they appeared. If a key was only seen once, it won't be wrapped in an array.\n\n### lookup.reduce(arr, hash=pluck(\"id\"), onCollision=\"last\")\n\nA short-hand way of writing `arr.reduce(lookup(hash, onCollision), {})`.\n\n### lookup.writableStream(hash=pluck(\"id\"), onCollision=\"last\", callback)\n\nReturns a writable stream that will use the reducer function to aggregate objects written to it into a single mapping. While the first two arguments are optional a callback must be provided. The callback will be called with the complete lookup table when the source stream ends.\n\n## License\n\nBSD (2 clause)\n","maintainers":[{"name":"grncdr","email":"glurgle@gmail.com"}],"time":{"modified":"2022-06-19T14:07:35.077Z","created":"2013-12-07T20:53:39.841Z","0.0.0":"2013-12-07T20:53:43.617Z","0.1.0":"2014-07-17T21:11:30.797Z"},"author":{"name":"Stephen Sugden","email":"me@stephensugden.com"},"repository":{"type":"git","url":"https://github.com/grncdr/js-lookup.git"},"homepage":"https://github.com/grncdr/js-lookup","keywords":["lookup","hashmap","mapping"],"bugs":{"url":"https://github.com/grncdr/js-lookup/issues"},"license":"BSD-2-Clause","readmeFilename":"README.md"}