Skip to content

Commit

Permalink
Additional ES6 style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Dec 22, 2015
1 parent cbab9fc commit ef243e1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -39,11 +39,11 @@ The following creates a basic static file server that can be used to serve html
`public` directory on port 3000:

```js
var Path = require('path');
var Hapi = require('hapi');
var Inert = require('inert');
const Path = require('path');
const Hapi = require('hapi');
const Inert = require('inert');

var server = new Hapi.Server({
const server = new Hapi.Server({
connections: {
routes: {
files: {
Expand All @@ -54,7 +54,7 @@ var server = new Hapi.Server({
});
server.connection({ port: 3000 });

server.register(Inert, function () {});
server.register(Inert, () => {});

server.route({
method: 'GET',
Expand All @@ -68,7 +68,7 @@ server.route({
}
});

server.start(function (err) {
server.start((err) => {

if (err) {
throw err;
Expand Down Expand Up @@ -102,7 +102,7 @@ server.route({
path: '/file',
handler: function (request, reply) {

var path = 'plain.txt';
let path = 'plain.txt';
if (request.headers['x-magic'] === 'sekret') {
path = 'awesome.png';
}
Expand All @@ -113,7 +113,7 @@ server.route({

server.ext('onPostHandler', function (request, reply) {

var response = request.response;
const response = request.response;
if (response.isBoom &&
response.output.statusCode === 404) {

Expand Down
10 changes: 5 additions & 5 deletions lib/directory.js
Expand Up @@ -33,7 +33,7 @@ exports.handler = function (route, options) {
const settings = Joi.attempt(options, internals.schema, 'Invalid directory handler options (' + route.path + ')');
Hoek.assert(route.path[route.path.length - 1] === '}', 'The route path must end with a parameter:', route.path);

const normalize = function (paths) {
const normalize = (paths) => {

const normalized = [];
for (let i = 0; i < paths.length; ++i) {
Expand All @@ -55,7 +55,7 @@ exports.handler = function (route, options) {

// Declare handler

const handler = function (request, reply) {
const handler = (request, reply) => {

let paths = normalized;
if (typeof settings.path === 'function') {
Expand Down Expand Up @@ -214,18 +214,18 @@ internals.generateListing = function (path, resource, selection, hasTrailingSlas

if (selection) {
const parent = resource.substring(0, resource.lastIndexOf('/', resource.length - (hasTrailingSlash ? 2 : 1))) + '/';
html += '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
html = html + '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
}

for (let i = 0; i < files.length; ++i) {
if (settings.showHidden ||
!internals.isFileHidden(files[i])) {

html += '<li><a href="' + internals.pathEncode(resource + (selection && !hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
html = html + '<li><a href="' + internals.pathEncode(resource + (selection && !hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
}
}

html += '</ul></body></html>';
html = html + '</ul></body></html>';

return reply(request.generateResponse(html));
});
Expand Down
5 changes: 2 additions & 3 deletions lib/etag.js
Expand Up @@ -54,8 +54,7 @@ internals.computeHashed = function (response, stat, next) {
// Call pending callbacks

delete pendings[pendingsId];
const il = nexts.length;
for (let i = 0; i < il; ++i) {
for (let i = 0; i < nexts.length; ++i) {
Hoek.nextTick(nexts[i])(err, hash);
}
});
Expand Down Expand Up @@ -102,7 +101,7 @@ exports.apply = function (response, stat, next) {
return next();
}

const applyEtag = function (err, etag) {
const applyEtag = (err, etag) => {

if (err) {
return next(err);
Expand Down
2 changes: 1 addition & 1 deletion lib/file.js
Expand Up @@ -36,7 +36,7 @@ exports.handler = function (route, options) {
settings = (typeof options !== 'object' ? { path: options } : settings);
Hoek.assert(typeof settings.path !== 'string' || settings.path[settings.path.length - 1] !== '/', 'File path cannot end with a \'/\':', route.path);

const handler = function (request, reply) {
const handler = (request, reply) => {

const path = (typeof settings.path === 'function' ? settings.path(request) : settings.path);
return reply(exports.response(path, settings, request));
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -35,6 +35,7 @@ exports.register = function (server, options, next) {
return next();
};


exports.register.attributes = {
pkg: require('../package.json'),
connections: false,
Expand Down
12 changes: 6 additions & 6 deletions test/directory.js
Expand Up @@ -30,7 +30,7 @@ describe('directory', () => {

describe('handler()', () => {

const provisionServer = function (connection, debug) {
const provisionServer = (connection, debug) => {

const server = new Hapi.Server({ debug: debug });
server.connection(connection || { routes: { files: { relativeTo: __dirname } }, router: { stripTrailingSlash: false } });
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('directory', () => {
path: '/multiple/{path*}',
handler: {
directory: {
path: function () {
path: () => {

return ['./', '../'];
},
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('directory', () => {

it('returns the correct file when using a fn directory handler', (done) => {

const directoryFn = function (request) {
const directoryFn = (request) => {

return '../lib';
};
Expand Down Expand Up @@ -653,7 +653,7 @@ describe('directory', () => {

it('resolves path name from plugin using specified path', (done) => {

const plugin = function (server, options, next) {
const plugin = (server, options, next) => {

server.path(__dirname);
server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'directory'), index: false, listing: false } } } });
Expand All @@ -676,7 +676,7 @@ describe('directory', () => {

it('resolves path name from plugin using relative path', (done) => {

const plugin = function (server, options, next) {
const plugin = (server, options, next) => {

server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'test', 'directory'), index: false, listing: false } } } });
return next();
Expand Down Expand Up @@ -740,7 +740,7 @@ describe('directory', () => {

it('returns error when path function returns invalid response', (done) => {

const path = function () {
const path = () => {

return 5;
};
Expand Down
11 changes: 4 additions & 7 deletions test/file.js
Expand Up @@ -302,7 +302,7 @@ describe('file', () => {

it('returns a file using the file function with the built-in handler config', (done) => {

const filenameFn = function (request) {
const filenameFn = (request) => {

return '../lib/' + request.params.file;
};
Expand Down Expand Up @@ -811,8 +811,7 @@ describe('file', () => {

let count = 0;
const lines = lsof.split('\n');
const il = lines.length;
for (let i = 0; i < il; ++i) {
for (let i = 0; i < lines.length; ++i) {
count += !!lines[i].match(/package.json/);
}

Expand Down Expand Up @@ -853,8 +852,7 @@ describe('file', () => {

let count = 0;
const lines = lsof.split('\n');
const il = lines.length;
for (let i = 0; i < il; ++i) {
for (let i = 0; i < lines.length; ++i) {
count += !!lines[i].match(/package.json/);
}

Expand Down Expand Up @@ -1434,8 +1432,7 @@ describe('file', () => {

let count = 0;
const lines = lsof.split('\n');
const il = lines.length;
for (let i = 0; i < il; ++i) {
for (let i = 0; i < lines.length; ++i) {
count += !!lines[i].match(/package.json/);
}

Expand Down

0 comments on commit ef243e1

Please sign in to comment.