{"_id":"unwrapper","_rev":"363607","name":"unwrapper","description":"unwrap an array from a function that receives `err, result`","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"jcrugzz","email":"jcrugzz@gmail.com"}],"time":{"modified":"2021-07-13T09:00:00.000Z","created":"2015-11-10T07:37:20.400Z","1.1.0":"2016-06-24T18:19:34.532Z","1.0.0":"2015-11-10T07:37:20.400Z"},"users":{},"author":{"name":"Jarrett Cruger"},"repository":{"type":"git","url":"git+ssh://git@github.com/jcrugzz/unwrapper.git"},"versions":{"1.1.0":{"name":"unwrapper","version":"1.1.0","description":"unwrap an array from a function that receives `err, result`","main":"index.js","scripts":{"test":"istanbul cover _mocha test.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/jcrugzz/unwrapper.git"},"keywords":["unwrap","api","arguments","array"],"author":{"name":"Jarrett Cruger"},"license":"MIT","bugs":{"url":"https://github.com/jcrugzz/unwrapper/issues"},"homepage":"https://github.com/jcrugzz/unwrapper#readme","devDependencies":{"assume":"^1.4.1","istanbul":"^0.4.4","mocha":"^2.5.3"},"gitHead":"1cbd24c07a2915264e8f3dc6cc180c8539276aca","_id":"unwrapper@1.1.0","_shasum":"f963c8918461146f527b86f19d2913a5c93ad959","_from":".","_npmVersion":"3.9.6","_nodeVersion":"4.4.3","_npmUser":{"name":"jcrugzz","email":"jcrugzz@gmail.com"},"dist":{"shasum":"f963c8918461146f527b86f19d2913a5c93ad959","size":2691,"noattachment":false,"key":"/unwrapper/-/unwrapper-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/unwrapper/download/unwrapper-1.1.0.tgz"},"maintainers":[{"name":"jcrugzz","email":"jcrugzz@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/unwrapper-1.1.0.tgz_1466792370940_0.6300691666547209"},"directories":{},"publish_time":1466792374532,"_cnpm_publish_time":1466792374532,"_hasShrinkwrap":false},"1.0.0":{"name":"unwrapper","version":"1.0.0","description":"unwrap an array from a function that receives `err, result`","main":"index.js","scripts":{"test":"node index.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/jcrugzz/unwrapper.git"},"keywords":["unwrap","api","arguments","array"],"author":{"name":"Jarrett Cruger"},"license":"MIT","bugs":{"url":"https://github.com/jcrugzz/unwrapper/issues"},"homepage":"https://github.com/jcrugzz/unwrapper#readme","gitHead":"e98cc936f603da27530c21d5697cedecc049bb96","_id":"unwrapper@1.0.0","_shasum":"c3f64bc4ce5b4988b31947b88391b9d5e483b423","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.2","_npmUser":{"name":"jcrugzz","email":"jcrugzz@gmail.com"},"dist":{"shasum":"c3f64bc4ce5b4988b31947b88391b9d5e483b423","size":2417,"noattachment":false,"key":"/unwrapper/-/unwrapper-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/unwrapper/download/unwrapper-1.0.0.tgz"},"maintainers":[{"name":"jcrugzz","email":"jcrugzz@gmail.com"}],"directories":{},"publish_time":1447141040400,"_cnpm_publish_time":1447141040400,"_hasShrinkwrap":false}},"readme":"# unwrapper\n\n[![build\nstatus](https://secure.travis-ci.org/jcrugzz/unwrapper.svg)](http://travis-ci.org/jcrugzz/unwrapper)\n\nA simple module that unwraps an array when deemed necessary for the result\npassed to a given function. The threshold in which it is deemed necessary is\ndetermined by the length of the array returned. A length of 1 is assumed to be\nsomething you want unwrapped.\n\n## install\n\n```sh\nnpm i unwrapper --save\n```\n\n## Example\n\n```js\nvar unwrap = require('unwrapper');\nvar api = require('./api');\n\n//\n// Pretend this API returns an [] even when you expect it to be a single entity\n//\napi.get('/books-by', 'barney rubble', unwrap(function (err, result) {\n  // expect `result` to be a single object.\n}));\n```\n\n## API\n\n``` js\nunwrap(fn, def, pred)\nunwrap(fn, pred)\nunwrap(fn);\n```\n\n* `fn`: Function to execute\n* `def`: **Optional** Default value to use if no results returned\n* `pred`: Predicate function for more advanced decisions than an Array of length `1`\n\n#### Advanced usage\n\nIn some scenarios you may want to only unwrap certain Arrays of length one (e.g. listing directories of a length 1). In this case you can pass a `pred` argument to `unwrapper`:\n\n``` js\nunwrap(fn, function (err, result) {\n  //\n  // Result will always be the first element in the Array\n  // - return true to unwrap\n  // - return false to NOT unwrap\n  //\n  return result.expected === 'some-expected-value';\n});\n```\n\n##### Author: [Jarrett Cruger](https://github.com/jcrugzz)\n","_attachments":{},"homepage":"https://github.com/jcrugzz/unwrapper#readme","bugs":{"url":"https://github.com/jcrugzz/unwrapper/issues"},"license":"MIT"}