{"id":28684890,"url":"https://github.com/node-modules/thunkify-wrap","last_synced_at":"2025-06-14T03:07:35.819Z","repository":{"id":14182291,"uuid":"16888523","full_name":"node-modules/thunkify-wrap","owner":"node-modules","description":"a more powerful thunkify","archived":false,"fork":false,"pushed_at":"2022-02-12T03:06:26.000Z","size":305,"stargazers_count":53,"open_issues_count":2,"forks_count":4,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-09T05:35:47.063Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"belalelessa/OmicronProject","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-modules.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-16T16:24:54.000Z","updated_at":"2025-03-10T10:46:15.000Z","dependencies_parsed_at":"2022-07-10T05:30:59.843Z","dependency_job_id":null,"html_url":"https://github.com/node-modules/thunkify-wrap","commit_stats":null,"previous_names":["dead-horse/node-thunkify-wrap"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/node-modules/thunkify-wrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fthunkify-wrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fthunkify-wrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fthunkify-wrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fthunkify-wrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/thunkify-wrap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fthunkify-wrap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259752078,"owners_count":22905972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-14T03:07:31.825Z","updated_at":"2025-06-14T03:07:35.812Z","avatar_url":"https://github.com/node-modules.png","language":"JavaScript","readme":"\nthunkify-wrap\n===========\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Gittip][gittip-image]][gittip-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/thunkify-wrap.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/thunkify-wrap\n[travis-image]: https://img.shields.io/travis/node-modules/thunkify-wrap.svg?style=flat-square\n[travis-url]: https://travis-ci.org/node-modules/thunkify-wrap\n[coveralls-image]: https://img.shields.io/coveralls/node-modules/thunkify-wrap.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/node-modules/thunkify-wrap?branch=master\n[gittip-image]: https://img.shields.io/gittip/dead-horse.svg?style=flat-square\n[gittip-url]: https://www.gittip.com/dead-horse/\n[david-image]: https://img.shields.io/david/node-modules/thunkify-wrap.svg?style=flat-square\n[david-url]: https://david-dm.org/node-modules/thunkify-wrap\n[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/thunkify-wrap.svg?style=flat-square\n[download-url]: https://npmjs.org/package/thunkify-wrap\n\n  Turn each node function in an object return a thunk.\n  Turn a regular node function into one which returns a thunk,\n  useful for generator-based flow control such as [co](https://github.com/visionmedia/co).\n\n## Installation\n\n```sh\nnpm install thunkify-wrap --save\n```\n\n## Example\n\n```js\n// the same as thunkify\nvar thunkify = require('thunkify-wrap');\nvar fs = require('fs');\n\nfs.readFile = thunkify(fs.readFile);\n\nfs.readFile('package.json', 'utf8')(function(err, str){\n\n});\n\n// thunkify an object\nvar user = {\n  add: function () {},\n  show: function () {},\n  list: function () {}\n}\n\nmodule.exports = thunkify(user);\n// module.exports = thunkify(user, ['add', 'show']);\n// module.exports = thunkify(user, 'add');\n```\n\n## genify\n\nWrap every function return a `GeneratorFunction`,\nthat will be easy to write codes in only one way: `yield* fn()`.\n\n```js\nvar genify = require('thunkify-wrap').genify;\nvar fs = require('fs');\n\nfs.readFile = genify(fs.readFile);\n\nvar content = yield* fs.readFile(__filename, 'utf8');\n```\n\n## event support\n\nyou can pass an event object, give end event name list, wrap event to thunk like this\n\n```\nvar e = new EventEmitter();\nvar end = thunkify.event(e, 'finish');\n\nyield end();\nor\nyield.end(['close', 'end']); // will cover `finish` event\n```\n\nwhen specified events emitted, this generator will go on. see more in the source code.\n\n## ctx\n\nalso you can pass `ctx` as contenxt into thunkify, and `thunkify(object)` will use object as the context by default.\n\n```js\nvar thunkify = require('thunkify-wrap');\nvar Cal = function (a, b) {\n  this.a = a;\n  this.b = b;\n};\n\nCal.prototype.plus = function(callback) {\n  var self = this;\n  setTimeout(function () {\n    callback(null, self.a + self.b);\n  }, 5);\n};\n\nCal.prototype.minus = function (callback) {\n  var self = this;\n  setTimeout(function () {\n    callback(null, self.a - self.b);\n  }, 5);\n};\n\nmodule.exports = Cal;\n\nexports.create1 = function (a, b) {\n  return thunkify(new Cal(a, b));\n};\n\n// or\nexports.create2 = function (a, b) {\n  var cal = new Cal(a, b);\n  cal.plus = thunkify(cal.plus, cal);\n  cal.minus = thunkify(cal.minus, cal);\n};\n```\n\n### methods\n\nby pass `methods` list, support only thunkify a part of methods in an object.\n\n```\nexports.create3 = function (a, b) {\n  var cal = new Cal(a, b);\n  thunkify(cal, cal, ['plus']);\n  // or\n  thunkify(cal, ['plus']);\n};\n```\n\n# License\n\n  MIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fthunkify-wrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fthunkify-wrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fthunkify-wrap/lists"}