From b6b0d02df94701e42588992f43a24356853d0fa7 Mon Sep 17 00:00:00 2001 From: pana Date: Sat, 24 Oct 2015 17:21:47 +0800 Subject: [PATCH] update docs --- docs/api/context.md | 2 +- docs/api/index.md | 32 ++++++++++++++++---------------- docs/api/request.md | 2 +- docs/api/response.md | 8 ++++---- docs/guide.md | 22 +++++++++++----------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/api/context.md b/docs/api/context.md index 149e95f..beee697 100644 --- a/docs/api/context.md +++ b/docs/api/context.md @@ -99,7 +99,7 @@ this.throw('something exploded'); For example `this.throw('name required', 400)` is equivalent to: ```js -var err = new Error('name required'); +const err = new Error('name required'); err.status = 400; throw err; ``` diff --git a/docs/api/index.md b/docs/api/index.md index b64de65..e3db9bf 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -29,8 +29,8 @@ $ node my-koa-app.js The obligatory hello world application: ```js -var koa = require('koa'); -var app = new Koa(); +const koa = require('koa'); +const app = new Koa(); app.use(function *(){ this.body = 'Hello World'; @@ -55,24 +55,24 @@ app.listen(3000); its upstream behaviour. ```js -var koa = require('koa'); -var app = new Koa(); +const koa = require('koa'); +const app = new Koa(); // x-response-time app.use(function *(next){ - var start = new Date; + const start = new Date; yield next; - var ms = new Date - start; + const ms = new Date - start; this.set('X-Response-Time', ms + 'ms'); }); // logger app.use(function *(next){ - var start = new Date; + const start = new Date; yield next; - var ms = new Date - start; + const ms = new Date - start; console.log('%s %s - %s', this.method, this.url, ms); }); @@ -105,17 +105,17 @@ app.listen(3000); `Server#listen()`. These arguments are documented on [nodejs.org](http://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback). The following is a useless Koa application bound to port `3000`: ```js -var koa = require('koa'); -var app = new Koa(); +const koa = require('koa'); +const app = new Koa(); app.listen(3000); ``` The `app.listen(...)` method is simply sugar for the following: ```js -var http = require('http'); -var koa = require('koa'); -var app = new Koa(); +const http = require('http'); +const koa = require('koa'); +const app = new Koa(); http.createServer(app.callback()).listen(3000); ``` @@ -123,9 +123,9 @@ http.createServer(app.callback()).listen(3000); or on multiple addresses: ```js -var http = require('http'); -var koa = require('koa'); -var app = new Koa(); +const http = require('http'); +const koa = require('koa'); +const app = new Koa(); http.createServer(app.callback()).listen(3000); http.createServer(app.callback()).listen(3001); ``` diff --git a/docs/api/request.md b/docs/api/request.md index 8602c90..e569880 100644 --- a/docs/api/request.md +++ b/docs/api/request.md @@ -96,7 +96,7 @@ this.request.href Get request `Content-Type` void of parameters such as "charset". ```js -var ct = this.request.type; +const ct = this.request.type; // => "image/png" ``` diff --git a/docs/api/response.md b/docs/api/response.md index a5a4ac6..7fd0dcc 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -145,7 +145,7 @@ If `response.status` has not been set, Koa will automatically set the status to Get a response header field value with case-insensitive `field`. ```js -var etag = this.get('ETag'); +const etag = this.get('ETag'); ``` ### response.set(field, value) @@ -183,7 +183,7 @@ this.set({ Get response `Content-Type` void of parameters such as "charset". ```js -var ct = this.type; +const ct = this.type; // => "image/png" ``` @@ -214,14 +214,14 @@ this.type = 'png'; all HTML responses except for streams. ```js -var minify = require('html-minifier'); +const minify = require('html-minifier'); app.use(function *minifyHTML(next){ yield next; if (!this.response.is('html')) return; - var body = this.body; + const body = this.body; if (!body || body.pipe) return; if (Buffer.isBuffer(body)) body = body.toString(); diff --git a/docs/guide.md b/docs/guide.md index cb916ea..62779af 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -14,9 +14,9 @@ ```js function *responseTime(next) { - var start = new Date; + const start = new Date; yield next; - var ms = new Date - start; + const ms = new Date - start; this.set('X-Response-Time', ms + 'ms'); } @@ -27,9 +27,9 @@ app.use(responseTime); ```js app.use(function *(next){ - var start = new Date; + const start = new Date; yield next; - var ms = new Date - start; + const ms = new Date - start; this.set('X-Response-Time', ms + 'ms'); }); ``` @@ -92,7 +92,7 @@ function logger(format) { format = format || ':method ":url"'; return function *(next){ - var str = format + const str = format .replace(':method', this.method) .replace(':url', this.url); @@ -218,12 +218,12 @@ app.use(function *(next){ ```js -var fs = require('co-fs'); +const fs = require('co-fs'); app.use(function *(){ - var paths = yield fs.readdir('docs'); + const paths = yield fs.readdir('docs'); - var files = yield paths.map(function(path){ + const files = yield paths.map(function(path){ return fs.readFile('docs/' + path, 'utf8'); }); @@ -255,10 +255,10 @@ $ DEBUG=koa* node --harmony examples/simple For example: ```js -var path = require('path'); -var static = require('koa-static'); +const path = require('path'); +const static = require('koa-static'); -var publicFiles = static(path.join(__dirname, 'public')); +const publicFiles = static(path.join(__dirname, 'public')); publicFiles._name = 'static /public'; app.use(publicFiles);