- Notifications
You must be signed in to change notification settings - Fork4
use iconv-lite to encode the body and set charset to content-type
License
NotificationsYou must be signed in to change notification settings
koajs/charset
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Useiconv-lite to encode the body and set charset to content-type.
# npm ..npm i koa-charset# yarn ..yarn add koa-charset
const Koa = require('koa');const charset = require('koa-charset');const app = new Koa();app.use(charset());app.use(function (ctx) { ctx.body = '你好'; ctx.type = 'text/html; charset=gbk';});app.listen(3000);
- charset: set global charset by options.charset
You can setctx.charset
to cover the global charset.
app.use(function (ctx) { ctx.charset = 'gb2312'; ctx.body = '你好';});
You can disable charset byctx.charset = false
.
app.use(function (ctx) { ctx.charset = false; ctx.body = 'hello';});
also this module will get the charset fromContent-Type
, so you can just usekoa-charset
,then this middleware will automatically re-encode the body only if the charset is not utf8.
const app = new Koa();app.use(charset());app.use(function () { const charset = ctx.acceptsCharsets('utf8', 'gbk') || 'utf8'; ctx.vary('accept-charset'); ctx.type = `text/plain; charset=${charset}`; ctx.body = 'something';});
About
use iconv-lite to encode the body and set charset to content-type
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.