{"_id":"yoyaku","_rev":"32-731980c7877e3094c4654bb3e8994f14","name":"yoyaku","description":"Easily create promise-like APIs with this simple wrapper.","dist-tags":{"latest":"0.0.12"},"versions":{"0.0.1":{"name":"yoyaku","version":"0.0.1","description":"Easily create promise-like APIs. Extremely simple wrapper.","main":"index.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\n\n### Example\n\n```javascript\nvar p = require(\"yoyaku\");\n\nvar exists = promise([\"exists\",\"enoent\"],existsInt);\nfunction existsInt(file,promises) {\n\t\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","_id":"yoyaku@0.0.1","dist":{"shasum":"b1bd67396067cb5d69d35f0b82ca587930c35f5e","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.1.tgz","integrity":"sha512-7lzT6ZWuZcTpJou1eDkq0jSqsE+Tj5iy7VfEC9buX5YcwbQ5+/l01d3J9ppIEdyYlAsc0EMyGfBZdI9vWnQSHQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEtrSnmBu4EFeSqqiIOrwBtTM5NicqMHqWhrZdEqQZ6LAiEAywWPsEORclyOnxhu9U47ow4TGnWdVIrmycGqwXl9Pcc="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"}],"directories":{}},"0.0.2":{"name":"yoyaku","version":"0.0.2","description":"Easily create promise-like APIs. Extremely simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\n\n### Example\n\n```javascript\nvar promise = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = promise([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.2","dist":{"shasum":"9c979b95fcad5b418a2c14c8c018500a475cee85","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.2.tgz","integrity":"sha512-e7y1kj4USDGoWd7ZUmJiOo10/A9HaUfXvMVBpFLuHiN8s/C61NdzNmlAAXOt9wyV03FIUvln6ZgrVFU7+tUAqA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF2TAagtoc75hpwHMzT3KrhWDU6kY7BvEbV+3KNrQVjoAiEAy06koze+bfp4n+aTDves+rG5sXUmZEMigDI8zy7THa0="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}],"directories":{}},"0.0.3":{"name":"yoyaku","version":"0.0.3","description":"Easily create promise-like APIs. Extremely simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\nEasily streamline node's first-argument-as-error style callback functions.\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar promise = require(\"yoyaku\");\n\nvar exists = promise.yepnope(fs.stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar promise = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = promise([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.3","dist":{"shasum":"6fbde22962993112374288c16776860f629429ac","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.3.tgz","integrity":"sha512-G8MMLr9BIBst0CXYotwWt2dJG9jTiMbaJCnfB8WPok9VINqDkSVKZBHXTJZJdVJiV8A7Wi7n/pXlE7PJ5UKbkA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCuRIstGX58lVZpoF7oEON8oVlT0xnzYYwuja1xm2EZwwIgXg8tJ++ymSa01G3mzN9aS52w5pB/POzLG1ZYv9IrrDA="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}],"directories":{}},"0.0.4":{"name":"yoyaku","version":"0.0.4","description":"Easily create promise-like APIs. Extremely simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\nEasily streamline node's first-argument-as-error style callback functions.\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar promise = require(\"yoyaku\");\n\nvar exists = promise.yepnope(fs.stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar promise = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = promise([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.4","dist":{"shasum":"d501db8227bab8018d3cdad774cb5d70ab226ed3","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.4.tgz","integrity":"sha512-IjyKmOrMoge47Zv5BDj8W7k5xqM7l+oKWzQY5x7xVGGqmyOUDmbmX6kQsfDTfRHSpBZDyrTqGXF4hu7K50zMXg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCgJdLO4zvbGPC3tfiPGRYg08Y0gildKvUW9AoGa2cdTwIhAPynidyba/CHIMqkGSnZlbYS4xEGHTdmDH4+x+LJ97O0"}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}],"directories":{}},"0.0.5":{"name":"yoyaku","version":"0.0.5","description":"Easily create promise-like APIs. Extremely simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\nEasily streamline node's first-argument-as-error style callback functions. Yoyaku\ncan even automatically wrap entire APIs, such as node's `fs`.\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.5","dist":{"shasum":"ad9f3dbafc460788985e536eb89a3b23734820d5","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.5.tgz","integrity":"sha512-n3xuf17ciU+uNljmEWDkS6IQpCFX/s1hxRjNYPmqjZzZ5mNnYeVeWrn6uGVtsiyjv/3t3Cgc3Lqff0vTJTffwQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC5LB8nGpW6BhqN+NOcalJeqPNJeBMJxvYID3t20zxdmwIgfeQWs87M89IRBjV5SytEXziqaFBjsWhueNen0U1e6bM="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}],"directories":{}},"0.0.6":{"name":"yoyaku","version":"0.0.6","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDelayed execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#delayed-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Delayed execution\n\nDelayed execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.delay`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.delay(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without delayed execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.6","dist":{"shasum":"2d73037b9e3526bedf986c839468512d1f7c61a9","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.6.tgz","integrity":"sha512-jWKZu5lu2AO1Df+9rPxihGLXBHYjdbzoTxNmufy8md+nyLvbpK6Udw6QWtp5tAXNihMK43LW3mCbxLhsPKrZOg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCIwAtUYpDfNkvUr5A7T7XFbhzds886M9Ltdat4GPqlpwIgN3NmAqncSN/0rUNyMpjVC/BLvjbTouVkIzUx3St0uxE="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.7":{"name":"yoyaku","version":"0.0.7","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDelayed execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#delayed-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Delayed execution\n\nDelayed execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.delay`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.delay(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without delayed execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.7","dist":{"shasum":"043dd353993c1182757709f8746ee21a0b9e1462","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.7.tgz","integrity":"sha512-z/5aLaW+pu3S8AcjIIW2k3MCx4leCokDcQnZoKF7YhZjv0m1nEQjhe2wpcswlpi5pKT5OPc6Jpnr03ylHjwiFg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCVpbPHtbu4MXM3w8Sn43V4ZgHD+LVSL70uL1kTdxbviQIhAKmn098OcqXCRSXgwOTZEsIQhNRMzBAQiD2brDhim/jV"}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.8":{"name":"yoyaku","version":"0.0.8","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDeferred execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#deferred-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Deferred execution\n\nDeferred execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.defer`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.defer(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without deferred execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.8","dist":{"shasum":"bd04a5efbf53573015386e9aedebaeb63bf8142f","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.8.tgz","integrity":"sha512-hGshCaZry8Bvz+KbnEw/rIJYG+1wy98IeyM/BIaPsxeu4R8VJaY7odDzC1YyS+xJ9xXwllz7xs2AItlZyxebsg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICqJgJNdEMEBw5W+VVeGXhc22wbg6692TNDIZholN4aNAiBiQTzRic7J+LRFHw7e2pvsEYs5Y6IntU99HQ3Ee6iNoQ=="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.9":{"name":"yoyaku","version":"0.0.9","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDeferred execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#deferred-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Deferred execution\n\nDeferred execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.defer`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.defer(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without deferred execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.9","dist":{"shasum":"2bd77692d2703e544618d3b213ec41b70b8a9f84","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.9.tgz","integrity":"sha512-cKcpYTfdEEjeOty2btLo2qbCun58H5SsGwFJD9v1wXtg5P5S0Bq2LH+g/cQ/MN4L3WKrkRcUoh9jCRm0Gzn5Tw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDR7PgRUYxbhmLb0pXGAoHEScgx1PBoU044C7Wa7XR8/AiB8MkvfK/0EIU0B8/j15CNybhxsvTHFhjNyxCCGraAyeQ=="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.10":{"name":"yoyaku","version":"0.0.10","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDeferred execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#deferred-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Deferred execution\n\nDeferred execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.defer`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.defer(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without deferred execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.10","dist":{"shasum":"7045a720ef5e2b00570581806a0e53e7f2a98c51","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.10.tgz","integrity":"sha512-GmfFaPBggu2HAazbrCaeRVJluiKJbb6uDZQxU9YBUw7PoQzuhRfydxo/5f/9fubhhTM/9cpTw8Gwm8j0M1twtw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCRmUBoJyyayqwlkItyJBxV9dhIWInmZCMphbtdr1kTJgIhANO0sYA98kz5pPa85HfTglkH/O3CcTmyJVYP3b8ZDVVU"}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.11":{"name":"yoyaku","version":"0.0.11","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tDeferred execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#deferred-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Deferred execution\n\nDeferred execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.defer`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.defer(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without deferred execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n#### `wrappedFunction.last` (experimental)\n\nContains a reference to the returned promise map generated the last time the\nwrapped function was called. This enables greater brevity, but potentially enables\nrace conditions where the wrapped function might be used simultaneously somewhere else.\n\n```javascript\n\nyoyaku.yepnope(fs.stat);\n\nfs.stat(\"myfile\");\n\n// do something else\n\nfs.stat.last.yep(function() {});\n```\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.11","dist":{"shasum":"129072fb97b618e272cca2488c80f8d21e1b351b","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.11.tgz","integrity":"sha512-+oHK0UA+gURSuuUX4mbo2aUDsAA5THhgT2f7X1nRsB8x8FRgcdZxidl7Y9ljxBMnoQyv3uWWvHDV6/JiI+hy2g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHOGty5aWW0DX0NQSv6KIK1/oEMjOjYGCRWrEKL0IjSiAiB9oIA1uQd+yHek13HPO+OFYRksiLN2IeN2r/LEGdLYWQ=="}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]},"0.0.12":{"name":"yoyaku","version":"0.0.12","description":"Easily create promise-like APIs with this simple wrapper.","main":"yoyaku.js","scripts":{"test":"mocha -R spec"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"},"keywords":["promise","contract","yakusoku","yoyaku","promises","callback","callbackhell","hell"],"devDependencies":{"mocha":"1.8.x","chai":"~1.5.0"},"author":"","license":"BSD","readme":"Yoyaku\n======\n\n*\tAvoid callback hell with this ultra-simple wrapper for your functions.\n*\tEasily streamline node's first-argument-as-error style callbacks.\n*\tAutomatically wrap entire APIs, such as node's `fs`.\n*\tAllows easy currying of functions to an arbitrarily defined depth\n*\tDeferred execution: passing a function call without ugly `function(){}` syntax.\n\t(See [example](#deferred-execution))\n\n*Serving suggestion*: combine with [async](http://github.com/caolan/async) for\nadded flavour (see [recipe](#async).)\n\n### Example 1\n\nIn one line of code, turn node's fs.stat into a promise-like API! Toss `if (err)`\nto the curb!\n\n```javascript\n\nvar yoyaku = require(\"yoyaku\");\n\nvar exists = yoyaku.yepnope(require(\"fs\").stat);\n\n// Now, use it!\nexists(\"foo.txt\")\n\t.nope(function() {\n\t\tconsole.log(\"No - we'd better create that file!\");\n\t})\n\t.yep(function() {\n\t\tconsole.log(\"Yeah my file exists!\");\n\t})\n\n```\n\n### Example 2\n\nThe more flexible method that allows *any* function to be wrapped:\n\n```javascript\nvar yoyaku = require(\"yoyaku\");\n\nfunction existsInt(file,promises) {\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\nvar exists = yoyaku([\"exists\",\"enoent\"],existsInt);\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Example 3\n\nAutomatically wrapping an entire API for easy promisey access:\n\n```javascript\nvar yoyaku\t= require(\"yoyaku\"),\n\tfs\t\t= yoyaku.api(require(\"fs\"));\n\nfs.readFile(\"foo.txt\")\n\t.yep(function(data) {\n\t\t// do something with the file data\n\t});\n\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Async\n\nI find this makes async much more palatable. This is a very small example that I\nthink demonstrates how Yoyaku cleans up the callback syntax.\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tasync\t= yoyaku.api(require(\"async\")),\n\tfs\t\t= require(\"fs\"),\n\twrite\t= yoyaku.yepnope(fs.writeFile),\n\teach\t= async.each;\n\nfiles = [ \"foo.txt\", \"bar.txt\", \"baz.txt\" ];\n\neach(files,fs.readFile)\n\t.yep(function(data) {\n\t\twrite(\"combined.txt\",data.join(\"\\n\"))\n\t\t\t.yep(somethingToDoWhenFinished);\n\t});\n\nfunction somethingToDoWhenFinished() {\n\tconsole.log(\"It all worked awesomely!\")\n}\n\n```\n\n### Deferred execution\n\nDeferred execution lets you omit function-expression syntax when passing wrapped\nfunctions as callbacks. Instead of calling the function directly, call `.defer`\non it and pass in the arguments you normally would.\n\nTake this example for instance:\n\n```javascript\n\nvar yoyaku\t= require(\"yoyaku\"),\n\tmkdirp\t= yoyaku.yepnope(require(\"mkdirp\")),\n\texists\t= yoyaku.yepnope(require(\"fs\").stat);\n\nfunction createDirIfMissing(path,callback) {\n\texists(path)\n\t\t.yep(callback)\n\t\t.nope(\n\t\t\tmkdirp.defer(path)\n\t\t\t\t.yep(callback));\n}\n```\n\nThe function simply takes a filepath, and creates the directory specified by the\npath if it does not already exist. Writing the function without deferred execution\nand Yoyaku would look like:\n\n```javascript\n\nvar mkdirp\t= require(\"mkdirp\"),\n\tfs\t\t= require(\"fs\");\n\nfunction createDirIfMissing(path,callback) {\n\tfs.stat(path,function(err) {\n\t\tif (!err) return callback();\n\t\t\n\t\tmkdirp(path,function(err) {\n\t\t\tif (err) throw err;\n\t\t\t\n\t\t\tcallback();\n\t\t});\n\t});\n}\n```\n\nIt's not the reduced line count (5 vs 7 SLOC) that is the main factor in Yoyaku's\nfavour - rather the terseness of the code, and the lack of non-specific cruft,\nlike handlers for error callbacks and function expressions. This has let me be\nmore expressive and feel less hindered by *callback-coding* in my own work. I hope\nit works for you too.\n\n### Function Reference\n\n#### `yoyaku(promiseArray,function)`\n\nWraps a single function in another function that manages promises and callbacks.\nPasses all the arguments the wrapper function was called with through to the\nwrapped function, but adds an additional argument on the end: an map of functions\nnamed according to the array which was passed to `yoyaku` when it was invoked.\n\n#### `yoyaku.yepnope(function, [callwith])`\n\nAutomatically converts node-style callback APIs (callback as last parameter, error\ncondition passed as first parameter to callback if applicable) to a promise-like API.\n\nThe returned promises are `.yep` and `.nope`, hence the name of the method.\n\nIf you do not specify a handler for `.nope`, it will throw an exception should the\nmethod fail. This is desirable behaviour (there's nothing worse than invisible errors\nquietly multiplying inside a program!)\n\n#### `yoyaku.api(object)`\n\nRuns `yoyaku.yepnope` against every function parameter of an object, and saves the\nnewly wrapped functions on a new object. Essentially this converts an entire API\nto a promise-like interface.\n\n#### `wrappedFunction.defer( ...arguments... )`\n\nDefers execution of the function as described in the [deferred execution](#deferred-execution)\nsection of the document above. Takes an arbitrary list of arguments and stores/caches\nthem against a function which it then returns. Executing this returned function will\nin turn execute the originally wrapped function with these arguments.\n\nThis function actually calls `wrappedFunction.curry(0, [args])` behind the scenes.\n\n#### `wrappedFunction.curry(requiredArgumentCount, [...arguments...] )`\n\nCurries the wrapped function. The first parameter tells Yoyaku how many arguments\nto require before the wrapped function is executed. Any successive parameters are\ncached, and passed to the final function in order.\n\nUntil the required number of parameters has been reached or exceeded, Yoyaku will\nreturn a function, which has promise setters available as object methods.\n\n#### `wrappedFunction.last` (experimental)\n\nContains a reference to the returned promise map generated the last time the\nwrapped function was called, deferred, or curried. This enables greater brevity,\nbut potentially enables race conditions where the wrapped function might be used\nsimultaneously somewhere else. Use only where you can guarantee linear execution.\n\n```javascript\n\nyoyaku.yepnope(fs.stat);\n\nfs.stat(\"myfile\");\n\n// do something else\n\nfs.stat.last.yep(function() {});\n```\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","_id":"yoyaku@0.0.12","dist":{"shasum":"5b40cd2b7bb9564f8ca92cb6ff72aea392cecb86","tarball":"https://registry.npmjs.org/yoyaku/-/yoyaku-0.0.12.tgz","integrity":"sha512-XQ3NdQa+Tae8pIKRBv6+VfwpY0FVsI5mdS04lhkMQRaxRaoMgveE48s3p/zRw+b7nH3q5TNWFFvW+sOVKfNiDg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+qV2oRZYHn6VpsIwLaBI60RYwbbsX6tIKV49c7uO5bgIhAN6YBSpzxTREEN/qZEy0y1uOR/11EJkbUrvIIm+iZo7d"}]},"maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}]}},"readme":"Yoyaku\n======\n\nAvoid callback hell with this ultra-simple wrapper for your functions.\n\n### Example\n\n```javascript\nvar p = require(\"yoyaku\");\n\nvar exists = promise([\"exists\",\"enoent\"],existsInt);\nfunction existsInt(file,promises) {\n\t\n\tfs.stat(file,function(err,data) {\n\t\tif (err) return promises.enoent();\n\t\t\n\t\tpromises.exists(data);\n\t});\n}\n\n\nexists(\"./foo.txt\")\n\t.exists(successFunc)\n\t.enoent(failFunc);\n```\n\n### Installing\n\nIf you're using it in the browser, simply include yoyaku.js in your page.\n\nIf you're using node, simply `npm install yoyaku`.\n\n### About\n\nThis won't banish callback hell completely. But used in conjunction with other\ntechniques, it'll certainly help.\n\n`Yoyaku` does not mean promise in Japanese - it means 'reservation', 'contract',\nor 'agreement'. Since this isn't strictly a *promise* API, rather, a *promise-like*\nAPI, I decided to use a promise-like word to describe it. Hence, yoyaku.\n\n### Testing\n\n\tnpm test\n\n### Licence (BSD)\n\nCopyright (c) 2013, Christopher Giffard\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n*\tRedistributions of source code must retain the above copyright notice, this list\n\tof conditions and the following disclaimer.\n*\tRedistributions in binary form must reproduce the above copyright notice, this\n\tlist of conditions and the following disclaimer in the documentation and/or\n\tother materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\nBUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\nADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","maintainers":[{"name":"Christopher Giffard","email":"christopher.giffard@cgiffard.com"},{"name":"cgiffard","email":"christopher.giffard@cgiffard.com"}],"time":{"modified":"2022-06-29T08:13:36.429Z","created":"2013-03-04T07:11:46.732Z","0.0.1":"2013-03-04T07:11:50.113Z","0.0.2":"2013-03-04T11:16:38.479Z","0.0.3":"2013-03-06T02:07:08.945Z","0.0.4":"2013-03-06T05:03:13.535Z","0.0.5":"2013-03-07T05:09:26.692Z","0.0.6":"2013-03-07T10:46:37.633Z","0.0.7":"2013-03-08T01:29:43.636Z","0.0.8":"2013-03-12T22:14:51.741Z","0.0.9":"2013-03-13T00:43:10.078Z","0.0.10":"2013-04-03T10:44:40.858Z","0.0.11":"2013-04-09T12:18:22.170Z","0.0.12":"2013-04-10T01:40:06.299Z"},"repository":{"type":"git","url":"git://github.com/cgiffard/Yoyaku.git"}}