{"id":21461775,"url":"https://github.com/appletjs/call2p","last_synced_at":"2025-06-16T19:02:56.907Z","repository":{"id":57193021,"uuid":"138128072","full_name":"appletjs/call2p","owner":"appletjs","description":"将函数结果转换成promise形式。","archived":false,"fork":false,"pushed_at":"2018-06-21T09:01:12.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T23:19:00.670Z","etag":null,"topics":["callback","error-first","promise"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/appletjs.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":"2018-06-21T06:22:38.000Z","updated_at":"2018-06-21T09:01:14.000Z","dependencies_parsed_at":"2022-09-01T06:01:12.748Z","dependency_job_id":null,"html_url":"https://github.com/appletjs/call2p","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fcall2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fcall2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fcall2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fcall2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appletjs","download_url":"https://codeload.github.com/appletjs/call2p/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976503,"owners_count":20377692,"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":["callback","error-first","promise"],"created_at":"2024-11-23T07:10:53.659Z","updated_at":"2025-03-17T04:50:14.942Z","avatar_url":"https://github.com/appletjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## call2p\n\n将函数执行结果装换成 promise 形式。\n\n\n## 安装\n\n```bash\n$ npm install call2p\n```\n\n\n## API\n\n#### call2p(executor)\n\n- `{Function} executor`\n\n```js\nconst call2p = require('call2p');\nconst fs = require('fs');\n\n// 执行一个函数，结使用 Promise 包装其果，该函数\n// 只接受的参数 cb 是一个符合 error-first 规范的回调函数\ncall2p(function(cb) {\n  fs.readFile(__filename, cb);\n}).then(function(content) {\n  console.log(content.toString('utf8'));\n}).catch(function(err) {\n  console.log(err.stack || err.message || err);\n});\n```\n\n#### call2p.wrap(handle)\n\n- `{Function} handle`\n\n```js\nconst call2p = require('call2p');\nconst fs = require('fs');\n\n// 将函数包装成新的函数，新函数内部使用 call2p 执行就函数，所以执行新函数会返回一个 Promise 实例；\n// 该函数接受的最后一个参数 cb 是一个符合 error-first 规范的回调函数\nconst readFile = call2cb.wrap(function(file, cb) {\n  fs.readFile(file, cb);\n});\n\nreadFile(__filename).then(function(content) {\n  console.log(content.toString('utf8'));\n}).catch(function(err) {\n  console.log(err.stack || err.message || err);\n});\n```\n\n\n## Todo\n\n- [ ] 添加测试用例\n- [ ] 重写开发文档\n\n\n## License\n\nMIT © 2018, [Maofeng Zhang](mailto:japplet@163.com \"mailto:japplet@163.com\")","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappletjs%2Fcall2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappletjs%2Fcall2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappletjs%2Fcall2p/lists"}