{"id":18834590,"url":"https://github.com/gkovacs/cfy","last_synced_at":"2026-02-09T00:04:09.706Z","repository":{"id":57150134,"uuid":"62974157","full_name":"gkovacs/cfy","owner":"gkovacs","description":"Use generators and yield to write regular callback-based functions","archived":false,"fork":false,"pushed_at":"2017-01-30T22:58:54.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T10:57:05.799Z","etag":null,"topics":["async-functions","callback","livescript","nodeback","promise"],"latest_commit_sha":null,"homepage":"","language":"LiveScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkovacs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2016-07-10T00:05:53.000Z","updated_at":"2018-12-01T10:13:42.000Z","dependencies_parsed_at":"2022-09-03T17:51:25.171Z","dependency_job_id":null,"html_url":"https://github.com/gkovacs/cfy","commit_stats":null,"previous_names":["gkovacs/ycall"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkovacs/cfy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkovacs%2Fcfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkovacs%2Fcfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkovacs%2Fcfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkovacs%2Fcfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkovacs","download_url":"https://codeload.github.com/gkovacs/cfy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkovacs%2Fcfy/sbom","scorecard":{"id":429005,"data":{"date":"2025-08-11","repo":{"name":"github.com/gkovacs/cfy","commit":"45ce67156d6717fe99983d37c286465398e2eed4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T02:53:14.053Z","repository_id":57150134,"created_at":"2025-08-19T02:53:14.053Z","updated_at":"2025-08-19T02:53:14.053Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29250235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T22:49:53.206Z","status":"ssl_error","status_checked_at":"2026-02-08T22:49:51.384Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async-functions","callback","livescript","nodeback","promise"],"created_at":"2024-11-08T02:13:20.597Z","updated_at":"2026-02-09T00:04:09.689Z","avatar_url":"https://github.com/gkovacs.png","language":"LiveScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cfy - CallbackiFY\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n\nSimplifies interop between [co](https://www.npmjs.com/package/co) (promise / generator-based) async functions, and async callback-based functions (both node-style nodebacks where the first parameter is an error, and regular callbacks).\n\n## Features\n\n* Write callback-based async functions using generators (using `cfy`). Can also write node-style (\"nodeback\") async functions (using `cfy_node`). If the resulting function is not passed a callback, an ES6 Promise is returned.\n* Can `yield` callback-based functions in generators (using `yfy`), as well as node-style nodeback-based functions (using `yfy_node`).\n* All features of generators wrapped with [co](https://www.npmjs.com/package/co) (such as yielding Promises) can be used in generators wrapped with `cfy` and `cfy_node`.\n\n## Install\n\n```\nnpm install cfy\n```\n\n## Usage\n\nFor the purpose of these examples, we assume you have required the library as follows:\n\n```javascript\nvar {cfy, cfy_node, yfy, yfy_node} = require('cfy');\n```\n\nNote that if you only need to use the `cfy` function, you can simply require it as:\n\n```javascript\nvar cfy = require('cfy');\n```\n\n## Examples\n\n### Turning a generator into a callback/promise-based async function\n\n```javascript\nvar cfy = require('cfy');\n\nvar cfy_example = cfy(function*() {\n  var result = yield Promise.resolve(5); // 5\n  return result;\n});\n\ncfy_example(function(x) { console.log(x) }); // 5\ncfy_example().then(function(x) { console.log(x) }); // 5\n```\n\n### Using callback-based async functions in generators\n\n```javascript\nvar {cfy, yfy} = require('cfy');\n\nfunction add_async(x, y, callback) {\n  setTimeout(function() {\n    callback(x + y);\n  }, 1000);\n}\n\nvar yfy_example_with_arguments = cfy(function*(a, b) {\n  var result = yield yfy(add_async)(5, 1); // 6\n  return result + a + b;\n});\n\nyfy_example_with_arguments(2, 7, function(x) { console.log(x) }); // 15\nyfy_example_with_arguments(2, 7).then(function(x) { console.log(x) }); // 15\n```\n\n### Writing a wrapper for setTimeout (sleep)\n\n```javascript\nvar sleep = cfy(function*(time) {\n  function sleep_base(msecs, callback) {\n    setTimeout(callback, msecs);\n  }\n  yield yfy(sleep_base)(time);\n});\n\nvar sleep_example = cfy(function*() {\n  yield sleep(3000); // sleeps for 3 seconds\n  return 7;\n});\n\nsleep_example(function(x) { console.log(x) }); // 7\n```\n\n## API\n\n### cfy\n\n`cfy` creates a callback-style function from a generator\n\n```javascript\nvar cfy_example = cfy(function*() {\n  var result = yield Promise.resolve(5); // 5\n  return result;\n});\n\ncfy_example(function(x) { console.log(x) }); // 5\n```\n\nIf the last argument is not a function, a promise will be returned instead:\n\n```javascript\ncfy_example().then(function(x) { console.log(x) }); // 5\n```\n\n### cfy_node\n\n`cfy_node` creates a nodeback-style function from a generator\n\n\n```javascript\nvar cfy_node_example = cfy_node(function*() {\n  var result = yield Promise.resolve(5); // 5\n  return result;\n});\n\ncfy_node_example(function(err, x) { console.log(x) }); // 5\n```\n\nIf the last argument is not a function, a promise will be returned instead:\n\n```javascript\ncfy_node_example().then(function(x) { console.log(x) });\n```\n\n### yfy\n\n`yfy` transforms a callback-style function into a promise which can be yielded within a generator. If the callback has multiple results, only the first one will be output. (Use `yfy_multi` if you need all the results).\n\n```javascript\nfunction add_async(x, y, callback) {\n  setTimeout(function() {\n    callback(x + y);\n  }, 1000);\n}\n\nvar yfy_example_with_arguments = cfy(function*(a, b) {\n  var result = yield yfy(add_async)(5, 1); // 6\n  return result + a + b;\n});\n\nyfy_example_with_arguments(2, 7, function(x) { console.log(x) }); // 15\n```\n\n### yfy_node\n\n`yfy_node` transforms a nodeback-style function into a promise which can be yielded within a generator. If the callback has multiple results, only the first one will be output (the error parameter will not be included). (Use `yfy_multi_node` if you need all the results).\n\n```javascript\nfunction add_async_node(x, y, nodeback) {\n  setTimeout(function() {\n    nodeback(null, x + 1);\n  }, 1000);\n}\n\nvar yfy_node_example_with_arguments = cfy_node(function*(a, b) {\n  var result = yield yfy_node(add_async_node)(5, 1); // 6\n  return result + a + b;\n});\n\nyfy_node_example_with_arguments(2, 7, function(err, x) { console.log(x) }); // 15\n```\n\n### yfy_multi\n\n`yfy_multi` transforms a callback-style function into a promise which can be yielded within a generator. The promise will resolve to an array containing all the arguments to the callback function.\n\n```javascript\nvar yfy_multi_example = yfy_multi(function(x, callback) {\n  callback(x + 1, x + 2);\n})\n\nyfy_multi_example(2).then(function(x) {console.log(x)}); // [3, 4]\n```\n\n### yfy_multi_node\n\n`yfy_multi_node` transforms a nodeback-style function into a promise which can be yielded within a generator. The promise will resolve to an array containing all the arguments to the callback function, except the first one (error parameter).\n\n```javascript\nvar yfy_multi_node_example = yfy_multi_node(function(x, callback) {\n  callback(null, x + 1, x + 2);\n})\n\nyfy_multi_node_example(2).then(function(x) {console.log(x)}); // [3, 4]\n```\n\n## More Examples\n\nYou will find more examples in [`example.js`](https://github.com/gkovacs/cfy/blob/master/examples/example.js) (for interop with normal callback-based async functions) and [`example_node.js`](https://github.com/gkovacs/cfy/blob/master/examples/example_node.js) (for interop with node-style nodeback-based async functions). The unit tests include examples of usage from Livescript.\n\n## Notes\n\n### Unhandled promise rejections\n\nYou sure ensure that unhandled promise rejections get printed or thrown, otherwise uncaught errors that occur in code that returns promises (ie, the body of `cfy` and `yfy` functions) will be silent (will not be printed). In nodejs, you can throw an Error when there is an unhandled rejection by adding to the top of your file:\n\n```javascript\nprocess.on('unhandledRejection', function(reason, p) {\n  throw new Error(reason);\n});\n```\n\nIn the browser, you can throw an Error when there is an unhandled rejection by adding to the top of your file:\n\n```javascript\nwindow.addEventListener('unhandledrejection', function(evt) {\n  throw evt.reason;\n});\n```\n\n### cfy with generator functions that take variable numbers of parameters\n\nNote that `cfy` will always return a promise-style function if you are using it with generator functions that take variable numbers of arguments. This is because it is not possible to distinguish whether the last argument is intended to be used as a callback or another argument.\n\nIf you wish to use `cfy` to get a callback-style function from a generator function that takes variable numbers of arguments, or a generator function that does not have the `.length` property correctly set, you can use `cfy(your_function, {varargs: true})`. If you are using the `varargs` option, ensure that your generator function's last parameter is never a function, otherwise it will be mistakenly assumed to be a callback.\n\n### yfy with functions that take variable numbers of parameters\n\nNote that `yfy` will always return a promise-style function if you are using it with functions that take variable numbers of arguments. This is because it is not possible to distinguish whether the last argument is intended to be used as a callback or another argument.\n\n## License\n\nMIT\n\n## Credits\n\nBy [Geza Kovacs](https://github.com/gkovacs)\n\n[npm-image]: https://img.shields.io/npm/v/cfy.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/cfy\n[travis-image]: https://img.shields.io/travis/gkovacs/cfy.svg?style=flat-square\n[travis-url]: https://travis-ci.org/gkovacs/cfy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkovacs%2Fcfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkovacs%2Fcfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkovacs%2Fcfy/lists"}