Fix style in sys.js
This commit is contained in:
parent
f86a214357
commit
d62b0f442a
42
lib/sys.js
42
lib/sys.js
@ -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 = [];
|
||||
@ -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;
|
||||
}
|
||||
@ -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, "'");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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];
|
||||
@ -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
|
||||
@ -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;
|
||||
@ -215,6 +237,7 @@ function isDate (d) {
|
||||
return JSON.stringify(proto) === JSON.stringify(properties);
|
||||
}
|
||||
|
||||
|
||||
var pWarning;
|
||||
|
||||
exports.p = function () {
|
||||
@ -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
|
||||
@ -242,9 +267,11 @@ function timestamp () {
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
|
||||
exports.log = function (msg) {
|
||||
exports.puts(timestamp() + ' - ' + msg.toString());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var execWarning;
|
||||
exports.exec = function () {
|
||||
@ -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.
|
||||
@ -275,5 +303,3 @@ exports.inherits = function (ctor, superCtor) {
|
||||
ctor.prototype = new tempCtor();
|
||||
ctor.prototype.constructor = ctor;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user