{"id":13563096,"url":"https://github.com/koajs/convert","last_synced_at":"2025-10-19T13:31:34.956Z","repository":{"id":60775069,"uuid":"44033526","full_name":"koajs/convert","owner":"koajs","description":"Convert koa generator-based middleware to promise-based middleware","archived":true,"fork":false,"pushed_at":"2020-09-10T18:43:48.000Z","size":22,"stargazers_count":251,"open_issues_count":4,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-12T07:22:50.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-11T00:26:08.000Z","updated_at":"2025-04-02T07:34:15.000Z","dependencies_parsed_at":"2022-10-04T16:16:43.423Z","dependency_job_id":null,"html_url":"https://github.com/koajs/convert","commit_stats":null,"previous_names":["gyson/koa-convert"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/koajs/convert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fconvert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fconvert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fconvert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fconvert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/convert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fconvert/sbom","scorecard":{"id":451209,"data":{"date":"2025-08-11","repo":{"name":"github.com/koajs/convert","commit":"bb06e77c8cf45d9afcbe5019c7fa9104631d5207"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.9,"checks":[{"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":"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":"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":"Code-Review","score":0,"reason":"Found 2/30 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":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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":"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"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/koajs/.github/SECURITY.md:1","Info: Found linked content: github.com/koajs/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/koajs/.github/SECURITY.md:1","Info: Found text in security policy: github.com/koajs/.github/SECURITY.md:1"],"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T08:13:50.645Z","repository_id":60775069,"created_at":"2025-08-19T08:13:50.645Z","updated_at":"2025-08-19T08:13:50.645Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018634,"owners_count":26086404,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-01T13:01:15.135Z","updated_at":"2025-10-19T13:31:34.937Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Middleware"],"sub_categories":[],"readme":"# koa-convert\n\n[![Build Status][travis-img]][travis-url]\n[![NPM version][npm-badge]][npm-url]\n[![License][license-badge]][license-url]\n![Code Size][code-size-badge]\n\n\u003c!-- [![Coverage Status][coverage-img]][coverage-url] --\u003e\n\n\u003c!-- ***************** --\u003e\n\n[travis-img]: https://travis-ci.org/koajs/convert.svg?branch=master\n[travis-url]: https://travis-ci.org/koajs/convert\n\n\u003c!-- \n  WAIT FOR ACCESS \n  [coverage-img]: https://coveralls.io/repos/github/koajs/convert/badge.svg?branch=master\n  [coverage-url]: https://coveralls.io/github/koajs/convert?branch=master\n--\u003e\n\n[npm-badge]: https://img.shields.io/npm/v/koa-better-request-id.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/koa-better-request-id\n[license-badge]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square\n[license-url]: https://github.com/koajs/koa-convert/blob/master/LICENSE\n[code-size-badge]: https://img.shields.io/github/languages/code-size/koajs/koa-convert\n\n\u003c!-- ***************** --\u003e\n\nConvert Koa legacy (0.x \u0026 1.x) generator middleware to modern promise middleware (2.x).\n\nIt could also convert modern promise middleware back to legacy generator middleware (useful to help modern middleware support Koa v0.x or v1.x).\n\n## Note\n\nRouter middleware is special case here. Because it reimplements middleware composition internally, we cannot not simply convert it.\n\nYou may use following packages for [routing](https://github.com/koajs/koa/wiki#routing-and-mounting), which are koa 2.x ready now:\n\n* [koa-route@3.0.0](https://github.com/koajs/route/tree/next)\n* [koa-simple-router](https://github.com/gyson/koa-simple-router)\n* [koa-router@next](https://github.com/alexmingoia/koa-router/tree/master)\n* [koa-66](https://github.com/menems/koa-66)\n\n## Installation\n\n```bash\n# npm ..\n$ npm i koa-convert\n# yarn ..\n$ yarn add koa-convert\n```\n\n## Usage\n\n```js\nconst Koa = require('koa') // koa v2.x\nconst convert = require('koa-convert')\nconst app = new Koa()\n\napp.use(modernMiddleware)\n\napp.use(convert(legacyMiddleware))\n\napp.use(convert.compose(legacyMiddleware, modernMiddleware))\n\nfunction * legacyMiddleware (next) {\n  // before\n  yield next\n  // after\n}\n\nfunction modernMiddleware (ctx, next) {\n  // before\n  return next().then(() =\u003e {\n    // after\n  })\n}\n```\n\n## Distinguish legacy and modern middleware\n\nIn koa 0.x and 1.x (without experimental flag), `app.use` has an assertion that all (legacy) middleware must be generator function and it's tested with `fn.constructor.name == 'GeneratorFunction'` at [here](https://github.com/koajs/koa/blob/7fe29d92f1e826d9ce36029e1b9263b94cba8a7c/lib/application.js#L105).\n\nTherefore, we can distinguish legacy and modern middleware with `fn.constructor.name == 'GeneratorFunction'`.\n\n## Migration\n\n`app.use(legacyMiddleware)` is everywhere in 0.x and 1.x and it would be painful to manually change all of them to `app.use(convert(legacyMiddleware))`.\n\nYou can use following snippet to make migration easier.\n\n```js\nconst _use = app.use\napp.use = x =\u003e _use.call(app, convert(x))\n```\n\nThe above snippet will override `app.use` method and implicitly convert all legacy generator middleware to modern promise middleware.\n\nTherefore, you can have both `app.use(modernMiddleware)` and `app.use(legacyMiddleware)` and your 0.x or 1.x should work without modification.\n\nComplete example:\n\n```js\nconst Koa = require('koa') // v2.x\nconst convert = require('koa-convert')\nconst app = new Koa()\n\n// ---------- override app.use method ----------\n\nconst _use = app.use\napp.use = x =\u003e _use.call(app, convert(x))\n\n// ---------- end ----------\n\napp.use(modernMiddleware)\n\n// this will be converted to modern promise middleware implicitly\napp.use(legacyMiddleware)\n\nfunction * legacyMiddleware (next) {\n  // before\n  yield next\n  // after\n}\n\nfunction modernMiddleware (ctx, next) {\n  // before\n  return next().then(() =\u003e {\n    // after\n  })\n}\n```\n\n## API\n\n#### `convert()`\n\nConvert legacy generator middleware to modern promise middleware.\n\n```js\nmodernMiddleware = convert(legacyMiddleware)\n```\n\n#### `convert.compose()`\n\nConvert and compose multiple middleware (could mix legacy and modern ones) and return modern promise middleware.\n\n```js\ncomposedModernMiddleware = convert.compose(legacyMiddleware, modernMiddleware)\n// or\ncomposedModernMiddleware = convert.compose([legacyMiddleware, modernMiddleware])\n```\n\n#### `convert.back()`\n\nConvert modern promise middleware back to legacy generator middleware.\n\nThis is useful to help modern promise middleware support koa 0.x or 1.x.\n\n```js\nlegacyMiddleware = convert.back(modernMiddleware)\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fconvert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fconvert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fconvert/lists"}