Coder Social home page Coder Social logo

charset's Introduction

charset

NPM version build status Coveralls David deps node version Gittip

use iconv-lite to encode the body and set charset to content-type.

Install

npm install koa-charset

Usage

var koa = require('koa');
var charset = require('koa-charset');

var app = koa();
app.use(charset({ charset: 'gbk' }));

app.use(function* () {
  this.body = '你好';
});

Options

  • charset: set global charset by options.charset

Manually turning charset on and off

You can set this.charset to cover the global charset.

app.use(function* () {
  this.charset = 'gb2312';
  this.body = '你好';
});

You can disable charset by this.charset = false.

app.use(function* () {
  this.charset = false;
  this.body = 'hello';
});

also this module will get the charset from Content-Type, so you can just use koa-charset, then this middleware will automatically re-encode the body only if the charset is not utf8.

var app = koa();
app.use(charset());
app.use(function* () {
  var charset = this.acceptsCharsets('utf8', 'gbk') || 'utf8';
  this.vary('accept-charset');
  this.type = 'text/plain; charset=' + charset;
  this.body = 'something';
});

License

MIT

charset's People

Contributors

dead-horse avatar greenkeeperio-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.