Skip to content

Commit

Permalink
Fix style in sys.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 1, 2010
1 parent f86a214 commit d62b0f4
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions lib/sys.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
var events = require('events');


exports.print = function () {
for (var i = 0, len = arguments.length; i < len; ++i) {
process.stdout.write(arguments[i]);
}
};


exports.puts = function () {
for (var i = 0, len = arguments.length; i < len; ++i) {
process.stdout.write(arguments[i] + '\n');
}
};


exports.debug = function (x) {
process.binding('stdio').writeError("DEBUG: " + x + "\n");
};


var error = exports.error = function (x) {
for (var i = 0, len = arguments.length; i < len; ++i) {
process.binding('stdio').writeError(arguments[i] + '\n');
}
};


/**
* Echos the value of a value. Trys to print the value out
* in the best way possible given the different types.
*
* @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) {
var seen = [];
Expand All @@ -45,7 +51,9 @@ exports.inspect = function (obj, showHidden, depth) {
// Primitive types cannot have properties
switch (typeof value) {
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 'boolean': return '' + value;
}
Expand Down Expand Up @@ -164,7 +172,9 @@ exports.inspect = function (obj, showHidden, depth) {
name = name.substr(1, name.length-2);
}
else {
name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
}
}

Expand All @@ -181,7 +191,13 @@ exports.inspect = function (obj, showHidden, depth) {
},0);

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 {
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
Expand All @@ -191,11 +207,15 @@ exports.inspect = function (obj, showHidden, depth) {
}
return format(obj, (typeof depth === 'undefined' ? 2 : depth));
};


function isArray (ar) {
return ar instanceof Array
|| Array.isArray(ar)
|| (ar && ar !== Object.prototype && isArray(ar.__proto__));
}


function isRegExp (re) {
var s = ""+re;
return re instanceof RegExp // easy case
Expand All @@ -207,6 +227,8 @@ function isRegExp (re) {
&& s.charAt(0) === "/"
&& s.substr(-1) === "/";
}


function isDate (d) {
if (d instanceof Date) return true;
if (typeof d !== "object") return false;
Expand All @@ -215,6 +237,7 @@ function isDate (d) {
return JSON.stringify(proto) === JSON.stringify(properties);
}


var pWarning;

exports.p = function () {
Expand All @@ -227,10 +250,12 @@ exports.p = function () {
}
};


function pad (n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10);
}


var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

// 26 Feb 16:19:34
Expand All @@ -242,9 +267,11 @@ function timestamp () {
].join(' ');
}


exports.log = function (msg) {
exports.puts(timestamp() + ' - ' + msg.toString());
}
};


var execWarning;
exports.exec = function () {
Expand All @@ -253,7 +280,8 @@ exports.exec = function () {
error(execWarning);
}
return require('child_process').exec.apply(this, arguments);
}
};


/**
* Inherit the prototype methods from one constructor into another.
Expand All @@ -275,5 +303,3 @@ exports.inherits = function (ctor, superCtor) {
ctor.prototype = new tempCtor();
ctor.prototype.constructor = ctor;
};


0 comments on commit d62b0f4

Please sign in to comment.