Permalink
Browse files

Consistent use of quotes

  • Loading branch information...
1 parent 69a3ef2 commit 09f67d80056858b041fb642953c49da5b3ad4092 @mjackson committed Sep 26, 2012
@@ -2,7 +2,7 @@ var crypto = require('crypto');
var utils = require('./utils');
module.exports = function (app, headerName, sessionKey, byteLength) {
- headerName = (headerName || "X-Authenticity-Token").toLowerCase();
+ headerName = (headerName || 'X-Authenticity-Token').toLowerCase();
sessionKey = sessionKey || 'strata.csrf';
byteLength = byteLength || 32;
View
@@ -1,6 +1,6 @@
-var utils = require("./utils");
-var urlMap = require("./urlmap");
-var router = require("./router");
+var utils = require('./utils');
+var urlMap = require('./urlmap');
+var router = require('./router');
/**
* A middleware that may be used to construct a middleware pipeline. It does
@@ -16,29 +16,29 @@ var router = require("./router");
* automatically create an instance of this middleware, as in the following
* example.
*
- * var strata = require("strata");
+ * var strata = require('strata');
*
* strata.use(strata.contentLength);
- * strata.use(strata.contentType, "text/html");
+ * strata.use(strata.contentType, 'text/html');
* strata.use(strata.sessionCookie);
*
- * strata.map("/images", function (app) {
+ * strata.map('/images', function (app) {
* // This app is called for all requests starting with "/images". Let's
* // try to serve them out of /path/to/images using a strata.file.
- * app.use(strata.file, "/path/to/images");
+ * app.use(strata.file, '/path/to/images');
* });
*
- * strata.get("/", function (env, callback) {
+ * strata.get('/', function (env, callback) {
* // This is called on GET /
* });
*
* strata.run(function (env, callback) {
* // This function is called when no mappings/routes match.
- * callback(200, {}, "Hello world!");
+ * callback(200, {}, 'Hello world!');
* });
*/
module.exports = function (app, callback) {
- if (typeof app === "function") {
+ if (typeof app === 'function') {
callback = app;
app = null;
}
@@ -108,7 +108,7 @@ module.exports = function (app, callback) {
// Add the ability to call router functions. When one is called, instantiate
// the localRouter variable and call the function on that object.
- ["route", "get", "post", "put", "delete", "head", "options"].forEach(function (method) {
+ ['route', 'get', 'post', 'put', 'delete', 'head', 'options'].forEach(function (method) {
build[method] = function () {
if (localRouter == null) {
localRouter = router();
@@ -131,7 +131,7 @@ module.exports = function (app, callback) {
}
};
- if (typeof callback === "function") {
+ if (typeof callback === 'function') {
callback(build);
}
View
@@ -1,4 +1,4 @@
-var utils = require("./utils");
+var utils = require('./utils');
/**
* A middleware that tries each of the given apps in turn, returning the
View
@@ -1,5 +1,5 @@
-var strftime = require("strftime").strftime;
-var Request = require("./request");
+var strftime = require('strftime').strftime;
+var Request = require('./request');
/**
* A middleware that logs the request to the given stream on its way out,
@@ -16,24 +16,24 @@ module.exports = function (app, stream) {
app(env, function (status, headers, body) {
var req = new Request(env);
- var addr = req.remoteAddr || "-";
- var id = "-";
- var user = env.remoteUser || "-";
- var timestamp = "[" + strftime("%d/%b/%Y:%H:%M:%S %z", env.requestTime) + "]";
- var protoVersion = "HTTP/" + env.protocolVersion;
- var reqline = '"' + req.method + " " + req.fullPath + " " + protoVersion + '"';
- var length = "-";
-
- if ("Content-Length" in headers) {
- length = headers["Content-Length"];
- } else if (typeof body === "string") {
+ var addr = req.remoteAddr || '-';
+ var id = '-';
+ var user = env.remoteUser || '-';
+ var timestamp = '[' + strftime('%d/%b/%Y:%H:%M:%S %z', env.requestTime) + ']';
+ var protoVersion = 'HTTP/' + env.protocolVersion;
+ var reqline = '"' + req.method + ' ' + req.fullPath + ' ' + protoVersion + '"';
+ var length = '-';
+
+ if ('Content-Length' in headers) {
+ length = headers['Content-Length'];
+ } else if (typeof body === 'string') {
length = String(Buffer.byteLength(body));
- } else if (typeof body.length === "number") {
+ } else if (typeof body.length === 'number') {
length = String(body.length);
}
- var entry = [addr, id, user, timestamp, reqline, status, length].join(" ");
- stream.write(entry + "\n");
+ var entry = [addr, id, user, timestamp, reqline, status, length].join(' ');
+ stream.write(entry + '\n');
callback(status, headers, body);
});
View
@@ -1,4 +1,4 @@
-var utils = require("./utils");
+var utils = require('./utils');
/**
* A middleware that sets the Content-Length header if it is missing on string
@@ -7,13 +7,13 @@ var utils = require("./utils");
module.exports = function (app) {
function contentLength(env, callback) {
app(env, function (status, headers, body) {
- if (!("Content-Length" in headers) && !headers["Transfer-Encoding"] && !utils.emptyBody(status)) {
- if (typeof body === "string") {
- headers["Content-Length"] = String(Buffer.byteLength(body));
- } else if (typeof body.length === "number") {
- headers["Content-Length"] = String(body.length);
+ if (!('Content-Length' in headers) && !headers['Transfer-Encoding'] && !utils.emptyBody(status)) {
+ if (typeof body === 'string') {
+ headers['Content-Length'] = String(Buffer.byteLength(body));
+ } else if (typeof body.length === 'number') {
+ headers['Content-Length'] = String(body.length);
} else {
- env.error.write("Cannot set Content-Length for body with no length\n");
+ env.error.write('Cannot set Content-Length for body with no length\n');
}
}
View
@@ -3,12 +3,12 @@
* already been set in a downstream app.
*/
module.exports = function (app, defaultType) {
- defaultType = defaultType || "text/html";
+ defaultType = defaultType || 'text/html';
function contentType(env, callback) {
app(env, function (status, headers, body) {
- if (!headers["Content-Type"]) {
- headers["Content-Type"] = defaultType;
+ if (!headers['Content-Type']) {
+ headers['Content-Type'] = defaultType;
}
callback(status, headers, body);
View
@@ -1,17 +1,17 @@
-var path = require("path");
-var fs = require("fs");
-var util = require("util");
-var mime = require("mime");
-var strata = require("./index");
-var utils = require("./utils");
+var path = require('path');
+var fs = require('fs');
+var util = require('util');
+var mime = require('mime');
+var strata = require('./index');
+var utils = require('./utils');
/**
* A middleware that responds to requests that target a directory with an HTML
* page listing that directory's contents.
*/
module.exports = function (app, root) {
- if (typeof root !== "string") {
- throw new strata.Error("Invalid root directory");
+ if (typeof root !== 'string') {
+ throw new strata.Error('Invalid root directory');
}
if (!fs.existsSync(root)) {
@@ -26,7 +26,7 @@ module.exports = function (app, root) {
var scriptName = unescape(env.scriptName);
var pathInfo = unescape(env.pathInfo);
- if (pathInfo.indexOf("..") !== -1) {
+ if (pathInfo.indexOf('..') !== -1) {
utils.forbidden(callback);
return;
}
@@ -85,7 +85,7 @@ var page = [
'<address>%s/%s</address>',
'</body>',
'</html>'
-].join("\n");
+].join('\n');
var row = [
'<tr class="%s">',
@@ -94,11 +94,11 @@ var row = [
' <td class="type">%s</td>',
' <td class="mtime">%s</td>',
'</tr>'
-].join("\n");
+].join('\n');
function generateListing(env, callback, root, pathInfo, scriptName) {
var dir = path.join(root, pathInfo);
- var rows = util.format(row, "", "../", "Parent Directory", "", "", "");
+ var rows = util.format(row, '', '../', 'Parent Directory', '', '', '');
fs.readdir(dir, function (err, files) {
if (err && strata.handleError(err, env, callback)) {
@@ -117,29 +117,29 @@ function generateListing(env, callback, root, pathInfo, scriptName) {
var size, type;
if (stats.isDirectory()) {
- size = "-";
- type = "directory";
- url += "/";
- file += "/";
+ size = '-';
+ type = 'directory';
+ url += '/';
+ file += '/';
} else {
size = utils.byteSizeFormat(stats.size);
type = mime.lookup(file);
}
- var className = index % 2 === 0 ? "even" : "odd";
+ var className = index % 2 === 0 ? 'even' : 'odd';
- rows += "\n";
+ rows += '\n';
rows += util.format(row, className, url, file, size, type, mtime);
});
- var title = "Index of " + pathInfo;
- var name = "Strata";
- var version = strata.version.join(".");
+ var title = 'Index of ' + pathInfo;
+ var name = 'Strata';
+ var version = strata.version.join('.');
var content = util.format(page, title, title, rows, name, version);
callback(200, {
- "Content-Type": "text/html",
- "Content-Length": String(Buffer.byteLength(content))
+ 'Content-Type': 'text/html',
+ 'Content-Length': String(Buffer.byteLength(content))
}, content);
});
}
View
@@ -1,8 +1,8 @@
-var path = require("path");
-var fs = require("fs");
-var mime = require("mime");
-var strata = require("./index");
-var utils = require("./utils");
+var path = require('path');
+var fs = require('fs');
+var mime = require('mime');
+var strata = require('./index');
+var utils = require('./utils');
/**
* A middleware for serving files efficiently from the given root directory
@@ -15,8 +15,8 @@ var utils = require("./utils");
* downstream app. Otherwise, the file is streamed through to the callback.
*/
module.exports = function (app, root, index) {
- if (typeof root !== "string") {
- throw new strata.Error("Invalid root directory");
+ if (typeof root !== 'string') {
+ throw new strata.Error('Invalid root directory');
}
if (!fs.existsSync(root)) {
@@ -27,19 +27,19 @@ module.exports = function (app, root, index) {
throw new strata.Error('"' + root + '" is not a directory');
}
- if (index && typeof index === "string") {
+ if (index && typeof index === 'string') {
index = [index];
}
function file(env, callback) {
- if (env.requestMethod !== "GET") {
+ if (env.requestMethod !== 'GET') {
app(env, callback);
return;
}
var pathInfo = unescape(env.pathInfo);
- if (pathInfo.indexOf("..") != -1) {
+ if (pathInfo.indexOf('..') != -1) {
utils.forbidden(env, callback);
return;
}
@@ -115,8 +115,8 @@ module.exports = function (app, root, index) {
function sendFile(callback, path, stats) {
callback(200, {
- "Content-Type": mime.lookup(path),
- "Content-Length": stats.size.toString(),
- "Last-Modified": stats.mtime.toUTCString()
+ 'Content-Type': mime.lookup(path),
+ 'Content-Length': stats.size.toString(),
+ 'Last-Modified': stats.mtime.toUTCString()
}, fs.createReadStream(path));
}
View
@@ -1,14 +1,14 @@
-var Request = require("./request");
+var Request = require('./request');
/**
* A middleware that sets the flash environment variable with one in the
* session, if available.
*/
module.exports = function (app) {
function flash(env, callback) {
- if (env.session && env.session["strata.flash"]) {
- env.flash = env.session["strata.flash"];
- delete env.session["strata.flash"];
+ if (env.session && env.session['strata.flash']) {
+ env.flash = env.session['strata.flash'];
+ delete env.session['strata.flash'];
}
app(env, callback);
@@ -25,7 +25,7 @@ module.exports.set = function (env, message) {
env.session = {};
}
- env.session["strata.flash"] = String(message);
+ env.session['strata.flash'] = String(message);
};
/**
Oops, something went wrong.

0 comments on commit 09f67d8

Please sign in to comment.