Fix style in sys.js

This commit is contained in:
Ryan Dahl 2010-06-01 09:28:31 -07:00
parent f86a214357
commit d62b0f442a

View File

@ -1,33 +1,39 @@
var events = require('events'); var events = require('events');
exports.print = function () { exports.print = function () {
for (var i = 0, len = arguments.length; i < len; ++i) { for (var i = 0, len = arguments.length; i < len; ++i) {
process.stdout.write(arguments[i]); process.stdout.write(arguments[i]);
} }
}; };
exports.puts = function () { exports.puts = function () {
for (var i = 0, len = arguments.length; i < len; ++i) { for (var i = 0, len = arguments.length; i < len; ++i) {
process.stdout.write(arguments[i] + '\n'); process.stdout.write(arguments[i] + '\n');
} }
}; };
exports.debug = function (x) { exports.debug = function (x) {
process.binding('stdio').writeError("DEBUG: " + x + "\n"); process.binding('stdio').writeError("DEBUG: " + x + "\n");
}; };
var error = exports.error = function (x) { var error = exports.error = function (x) {
for (var i = 0, len = arguments.length; i < len; ++i) { for (var i = 0, len = arguments.length; i < len; ++i) {
process.binding('stdio').writeError(arguments[i] + '\n'); process.binding('stdio').writeError(arguments[i] + '\n');
} }
}; };
/** /**
* Echos the value of a value. Trys to print the value out * Echos the value of a value. Trys to print the value out
* in the best way possible given the different types. * in the best way possible given the different types.
* *
* @param {Object} value The object to print out * @param {Object} value The object to print out
* @param {Boolean} showHidden Flag that shows hidden (not enumerable) properties of objects. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
* properties of objects.
*/ */
exports.inspect = function (obj, showHidden, depth) { exports.inspect = function (obj, showHidden, depth) {
var seen = []; var seen = [];
@ -45,7 +51,9 @@ exports.inspect = function (obj, showHidden, depth) {
// Primitive types cannot have properties // Primitive types cannot have properties
switch (typeof value) { switch (typeof value) {
case 'undefined': return 'undefined'; case 'undefined': return 'undefined';
case 'string': return JSON.stringify(value).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); case 'string': return JSON.stringify(value).replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
case 'number': return '' + value; case 'number': return '' + value;
case 'boolean': return '' + value; case 'boolean': return '' + value;
} }
@ -164,7 +172,9 @@ exports.inspect = function (obj, showHidden, depth) {
name = name.substr(1, name.length-2); name = name.substr(1, name.length-2);
} }
else { else {
name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
} }
} }
@ -181,7 +191,13 @@ exports.inspect = function (obj, showHidden, depth) {
},0); },0);
if (length > 50) { if (length > 50) {
output = braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join('\n, ') + (numLinesEst > 1 ? '\n' : ' ') + braces[1]; output = braces[0]
+ (base === '' ? '' : base + '\n ')
+ ' '
+ output.join('\n, ')
+ (numLinesEst > 1 ? '\n' : ' ')
+ braces[1]
;
} }
else { else {
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
@ -191,11 +207,15 @@ exports.inspect = function (obj, showHidden, depth) {
} }
return format(obj, (typeof depth === 'undefined' ? 2 : depth)); return format(obj, (typeof depth === 'undefined' ? 2 : depth));
}; };
function isArray (ar) { function isArray (ar) {
return ar instanceof Array return ar instanceof Array
|| Array.isArray(ar) || Array.isArray(ar)
|| (ar && ar !== Object.prototype && isArray(ar.__proto__)); || (ar && ar !== Object.prototype && isArray(ar.__proto__));
} }
function isRegExp (re) { function isRegExp (re) {
var s = ""+re; var s = ""+re;
return re instanceof RegExp // easy case return re instanceof RegExp // easy case
@ -207,6 +227,8 @@ function isRegExp (re) {
&& s.charAt(0) === "/" && s.charAt(0) === "/"
&& s.substr(-1) === "/"; && s.substr(-1) === "/";
} }
function isDate (d) { function isDate (d) {
if (d instanceof Date) return true; if (d instanceof Date) return true;
if (typeof d !== "object") return false; if (typeof d !== "object") return false;
@ -215,6 +237,7 @@ function isDate (d) {
return JSON.stringify(proto) === JSON.stringify(properties); return JSON.stringify(proto) === JSON.stringify(properties);
} }
var pWarning; var pWarning;
exports.p = function () { exports.p = function () {
@ -227,10 +250,12 @@ exports.p = function () {
} }
}; };
function pad (n) { function pad (n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10); return n < 10 ? '0' + n.toString(10) : n.toString(10);
} }
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// 26 Feb 16:19:34 // 26 Feb 16:19:34
@ -242,9 +267,11 @@ function timestamp () {
].join(' '); ].join(' ');
} }
exports.log = function (msg) { exports.log = function (msg) {
exports.puts(timestamp() + ' - ' + msg.toString()); exports.puts(timestamp() + ' - ' + msg.toString());
} };
var execWarning; var execWarning;
exports.exec = function () { exports.exec = function () {
@ -253,7 +280,8 @@ exports.exec = function () {
error(execWarning); error(execWarning);
} }
return require('child_process').exec.apply(this, arguments); return require('child_process').exec.apply(this, arguments);
} };
/** /**
* Inherit the prototype methods from one constructor into another. * Inherit the prototype methods from one constructor into another.
@ -275,5 +303,3 @@ exports.inherits = function (ctor, superCtor) {
ctor.prototype = new tempCtor(); ctor.prototype = new tempCtor();
ctor.prototype.constructor = ctor; ctor.prototype.constructor = ctor;
}; };