{"id":15462953,"url":"https://github.com/laomu1988/koa2-extend","last_synced_at":"2025-09-05T21:36:22.313Z","repository":{"id":76746126,"uuid":"85306648","full_name":"laomu1988/koa2-extend","owner":"laomu1988","description":"koa@next的一些扩展函数","archived":false,"fork":false,"pushed_at":"2017-03-22T02:59:36.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T06:18:18.910Z","etag":null,"topics":["koa","koa2"],"latest_commit_sha":null,"homepage":null,"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/laomu1988.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-17T11:55:28.000Z","updated_at":"2017-06-17T03:22:06.000Z","dependencies_parsed_at":"2023-06-18T04:15:28.712Z","dependency_job_id":null,"html_url":"https://github.com/laomu1988/koa2-extend","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"ace286e900bec98b17d89a9ad6908dea7b23b579"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laomu1988%2Fkoa2-extend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laomu1988%2Fkoa2-extend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laomu1988%2Fkoa2-extend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laomu1988%2Fkoa2-extend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laomu1988","download_url":"https://codeload.github.com/laomu1988/koa2-extend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246017727,"owners_count":20710242,"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":["koa","koa2"],"created_at":"2024-10-02T00:06:18.493Z","updated_at":"2025-03-28T11:21:07.058Z","avatar_url":"https://github.com/laomu1988.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa@next的一些扩展函数\n 要求node版本\u003e=6.0.0\n\n## install\n```\nnpm install koa2-extend\n```\n\n## usage\n```\nvar koa = require('koa');\nrequire('koa2-extend');  // 要在实例化app前引入koa2-extend\nvar app = new koa();\n\napp.use(function(ctx) {\n    console.log('fullUrl:',ctx.fullUrl);\n    if(ctx.url.indexOf('json') \u003e= 0) {\n        ctx.response.body = '{\"encode\":true}';\n        console.log(ctx.response.json.encode);\n        // 将输出: true\n    }\n    else {\n        ctx.response.body = '\u003cbody\u003etest\u003c/body\u003e';\n        var $ = ctx.response.$;\n        $('body').addClass('test');\n        ctx.response.body = $.html();\n        console.log(ctx.response.body);\n        // 将输出: \u003cbody class=\"test\"\u003etest\u003c/body\u003e\n    }\n});\n\n\n```\n\n## api\n* ctx.fullUrl            同request.fullUrl\n* ctx.isBinary(filepath) 根据文件路劲判断是否是二进制文件\n* ctx.sendFile(filepath) 发送文件\n* ctx.isDir(path)        判断本地路径是否是文件夹\n* request.fullUrl        包含protocol和host的完全链接\n* response.$             使用cheerio包裹后的html对象, 使用时转码, 转换失败返回''\n* response.json          使用JSON.parse转换body后的对象,   使用时转换, 转换失败返回''","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaomu1988%2Fkoa2-extend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaomu1988%2Fkoa2-extend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaomu1988%2Fkoa2-extend/lists"}