mirror of
https://github.com/sstent/node_app.git
synced 2026-01-26 15:13:02 +00:00
initial commit
This commit is contained in:
209
node_modules/util/node_modules/events.node/events.js
generated
vendored
Normal file
209
node_modules/util/node_modules/events.node/events.js
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
if ('undefined' === typeof process) {
|
||||
process = {};
|
||||
}
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
process.EventEmitter = process.EventEmitter || function () {};
|
||||
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
||||
var isArray = Array.isArray;
|
||||
|
||||
// By default EventEmitters will print a warning if more than
|
||||
// 10 listeners are added to it. This is a useful default which
|
||||
// helps finding memory leaks.
|
||||
//
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (!this._events) this._events = {};
|
||||
this._events.maxListeners = n;
|
||||
};
|
||||
|
||||
|
||||
EventEmitter.prototype.emit = function(type) {
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events || !this._events.error ||
|
||||
(isArray(this._events.error) && !this._events.error.length))
|
||||
{
|
||||
if (arguments[1] instanceof Error) {
|
||||
throw arguments[1]; // Unhandled 'error' event
|
||||
} else {
|
||||
throw new Error("Uncaught, unspecified 'error' event.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._events) return false;
|
||||
var handler = this._events[type];
|
||||
if (!handler) return false;
|
||||
|
||||
if (typeof handler == 'function') {
|
||||
switch (arguments.length) {
|
||||
// fast cases
|
||||
case 1:
|
||||
handler.call(this);
|
||||
break;
|
||||
case 2:
|
||||
handler.call(this, arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
handler.call(this, arguments[1], arguments[2]);
|
||||
break;
|
||||
// slower
|
||||
default:
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
handler.apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (isArray(handler)) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
var listeners = handler.slice();
|
||||
for (var i = 0, l = listeners.length; i < l; i++) {
|
||||
listeners[i].apply(this, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// EventEmitter is defined in src/node_events.cc
|
||||
// EventEmitter.prototype.emit() is also defined there.
|
||||
EventEmitter.prototype.addListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('addListener only takes instances of Function');
|
||||
}
|
||||
|
||||
if (!this._events) this._events = {};
|
||||
|
||||
// To avoid recursion in the case that type == "newListeners"! Before
|
||||
// adding it to the listeners, first emit "newListeners".
|
||||
this.emit('newListener', type, listener);
|
||||
|
||||
if (!this._events[type]) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
this._events[type] = listener;
|
||||
} else if (isArray(this._events[type])) {
|
||||
|
||||
// If we've already got an array, just append.
|
||||
this._events[type].push(listener);
|
||||
|
||||
// Check for listener leak
|
||||
if (!this._events[type].warned) {
|
||||
var m;
|
||||
if (this._events.maxListeners !== undefined) {
|
||||
m = this._events.maxListeners;
|
||||
} else {
|
||||
m = defaultMaxListeners;
|
||||
}
|
||||
|
||||
if (m && m > 0 && this._events[type].length > m) {
|
||||
this._events[type].warned = true;
|
||||
console.error('(node) warning: possible EventEmitter memory ' +
|
||||
'leak detected. %d listeners added. ' +
|
||||
'Use emitter.setMaxListeners() to increase limit.',
|
||||
this._events[type].length);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Adding the second element, need to change to array.
|
||||
this._events[type] = [this._events[type], listener];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.once = function(type, listener) {
|
||||
var self = this;
|
||||
function g() {
|
||||
self.removeListener(type, g);
|
||||
listener.apply(this, arguments);
|
||||
};
|
||||
|
||||
g.listener = listener;
|
||||
self.on(type, g);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('removeListener only takes instances of Function');
|
||||
}
|
||||
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (!this._events || !this._events[type]) return this;
|
||||
|
||||
var list = this._events[type];
|
||||
|
||||
if (isArray(list)) {
|
||||
var position = -1;
|
||||
for (var i = 0, length = list.length; i < length; i++) {
|
||||
if (list[i] === listener ||
|
||||
(list[i].listener && list[i].listener === listener))
|
||||
{
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0) return this;
|
||||
list.splice(position, 1);
|
||||
if (list.length == 0)
|
||||
delete this._events[type];
|
||||
} else if (list === listener ||
|
||||
(list.listener && list.listener === listener))
|
||||
{
|
||||
delete this._events[type];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (type && this._events && this._events[type]) this._events[type] = null;
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listeners = function(type) {
|
||||
if (!this._events) this._events = {};
|
||||
if (!this._events[type]) this._events[type] = [];
|
||||
if (!isArray(this._events[type])) {
|
||||
this._events[type] = [this._events[type]];
|
||||
}
|
||||
return this._events[type];
|
||||
};
|
||||
|
||||
}());
|
||||
39
node_modules/util/node_modules/events.node/package.json
generated
vendored
Normal file
39
node_modules/util/node_modules/events.node/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"author": {
|
||||
"name": "Joyent",
|
||||
"url": "http://www.joyent.com"
|
||||
},
|
||||
"name": "events.node",
|
||||
"description": "Node.JS events module (packaged for Node.JS and Ender.JS)",
|
||||
"keywords": [
|
||||
"ender",
|
||||
"events"
|
||||
],
|
||||
"version": "0.4.9",
|
||||
"homepage": "http://nodejs.org/docs/v0.4.9/api/events.html",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coolaj86/nodejs-libs-4-browser.git"
|
||||
},
|
||||
"provides": "events",
|
||||
"main": "./events.js",
|
||||
"directories": {
|
||||
"lib": "."
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.2.0",
|
||||
"ender": ">= 0.5.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"_id": "events.node@0.4.9",
|
||||
"optionalDependencies": {},
|
||||
"_engineSupported": true,
|
||||
"_npmVersion": "1.1.21",
|
||||
"_nodeVersion": "v0.6.18",
|
||||
"_defaultsLoaded": true,
|
||||
"dist": {
|
||||
"shasum": "6b8516ec011e2d8bc4db228136879d5f28665c1a"
|
||||
},
|
||||
"_from": "events.node@>= 0.4.0"
|
||||
}
|
||||
40
node_modules/util/package.json
generated
vendored
Normal file
40
node_modules/util/package.json
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"author": {
|
||||
"name": "Joyent",
|
||||
"url": "http://www.joyent.com"
|
||||
},
|
||||
"name": "util",
|
||||
"description": "Node.JS util module",
|
||||
"keywords": [
|
||||
"ender",
|
||||
"util"
|
||||
],
|
||||
"version": "0.4.9",
|
||||
"homepage": "http://nodejs.org/docs/v0.4.9/api/util.html",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coolaj86/nodejs-libs-4-browser.git"
|
||||
},
|
||||
"main": "./util.js",
|
||||
"directories": {
|
||||
"lib": "."
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.2.0",
|
||||
"ender": ">= 0.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"events.node": ">= 0.4.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"_id": "util@0.4.9",
|
||||
"optionalDependencies": {},
|
||||
"_engineSupported": true,
|
||||
"_npmVersion": "1.1.21",
|
||||
"_nodeVersion": "v0.6.18",
|
||||
"_defaultsLoaded": true,
|
||||
"dist": {
|
||||
"shasum": "6b0d7e32d99b6f7be0cbf2351d34e5f806e1bf27"
|
||||
},
|
||||
"_from": "util"
|
||||
}
|
||||
439
node_modules/util/util.js
generated
vendored
Normal file
439
node_modules/util/util.js
generated
vendored
Normal file
@@ -0,0 +1,439 @@
|
||||
var process = process;
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var events = require('events.node');
|
||||
|
||||
|
||||
exports.print = function() {
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
process.stdout.write(String(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} obj The object to print out.
|
||||
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
||||
* properties of objects.
|
||||
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
||||
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
||||
* output. Default is false (no coloring).
|
||||
*/
|
||||
exports.inspect = function(obj, showHidden, depth, colors) {
|
||||
var seen = [];
|
||||
|
||||
var stylize = function(str, styleType) {
|
||||
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||
var styles =
|
||||
{ 'bold' : [1, 22],
|
||||
'italic' : [3, 23],
|
||||
'underline' : [4, 24],
|
||||
'inverse' : [7, 27],
|
||||
'white' : [37, 39],
|
||||
'grey' : [90, 39],
|
||||
'black' : [30, 39],
|
||||
'blue' : [34, 39],
|
||||
'cyan' : [36, 39],
|
||||
'green' : [32, 39],
|
||||
'magenta' : [35, 39],
|
||||
'red' : [31, 39],
|
||||
'yellow' : [33, 39] };
|
||||
|
||||
var style =
|
||||
{ 'special': 'cyan',
|
||||
'number': 'blue',
|
||||
'boolean': 'yellow',
|
||||
'undefined': 'grey',
|
||||
'null': 'bold',
|
||||
'string': 'green',
|
||||
'date': 'magenta',
|
||||
// "name": intentionally not styling
|
||||
'regexp': 'red' }[styleType];
|
||||
|
||||
if (style) {
|
||||
return '\x1B[' + styles[style][0] + 'm' + str +
|
||||
'\x1B[' + styles[style][1] + 'm';
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
};
|
||||
if (! colors) {
|
||||
stylize = function(str, styleType) { return str; };
|
||||
}
|
||||
|
||||
function format(value, recurseTimes) {
|
||||
// Provide a hook for user-specified inspect functions.
|
||||
// Check that value is an object with an inspect function on it
|
||||
if (value && typeof value.inspect === 'function' &&
|
||||
// Filter out the util module, it's inspect function is special
|
||||
value !== exports &&
|
||||
// Also filter out any prototype objects using the circular check.
|
||||
!(value.constructor && value.constructor.prototype === value)) {
|
||||
return value.inspect(recurseTimes);
|
||||
}
|
||||
|
||||
// Primitive types cannot have properties
|
||||
switch (typeof value) {
|
||||
case 'undefined':
|
||||
return stylize('undefined', 'undefined');
|
||||
|
||||
case 'string':
|
||||
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"') + '\'';
|
||||
return stylize(simple, 'string');
|
||||
|
||||
case 'number':
|
||||
return stylize('' + value, 'number');
|
||||
|
||||
case 'boolean':
|
||||
return stylize('' + value, 'boolean');
|
||||
}
|
||||
// For some reason typeof null is "object", so special case here.
|
||||
if (value === null) {
|
||||
return stylize('null', 'null');
|
||||
}
|
||||
|
||||
// Look up the keys of the object.
|
||||
var visible_keys = Object.keys(value);
|
||||
var keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys;
|
||||
|
||||
// Functions without properties can be shortcutted.
|
||||
if (typeof value === 'function' && keys.length === 0) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
var name = value.name ? ': ' + value.name : '';
|
||||
return stylize('[Function' + name + ']', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
// Dates without properties can be shortcutted
|
||||
if (isDate(value) && keys.length === 0) {
|
||||
return stylize(value.toUTCString(), 'date');
|
||||
}
|
||||
|
||||
var base, type, braces;
|
||||
// Determine the object type
|
||||
if (isArray(value)) {
|
||||
type = 'Array';
|
||||
braces = ['[', ']'];
|
||||
} else {
|
||||
type = 'Object';
|
||||
braces = ['{', '}'];
|
||||
}
|
||||
|
||||
// Make functions say that they are functions
|
||||
if (typeof value === 'function') {
|
||||
var n = value.name ? ': ' + value.name : '';
|
||||
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
|
||||
} else {
|
||||
base = '';
|
||||
}
|
||||
|
||||
// Make dates with properties first say the date
|
||||
if (isDate(value)) {
|
||||
base = ' ' + value.toUTCString();
|
||||
}
|
||||
|
||||
if (keys.length === 0) {
|
||||
return braces[0] + base + braces[1];
|
||||
}
|
||||
|
||||
if (recurseTimes < 0) {
|
||||
if (isRegExp(value)) {
|
||||
return stylize('' + value, 'regexp');
|
||||
} else {
|
||||
return stylize('[Object]', 'special');
|
||||
}
|
||||
}
|
||||
|
||||
seen.push(value);
|
||||
|
||||
var output = keys.map(function(key) {
|
||||
var name, str;
|
||||
if (value.__lookupGetter__) {
|
||||
if (value.__lookupGetter__(key)) {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize('[Getter/Setter]', 'special');
|
||||
} else {
|
||||
str = stylize('[Getter]', 'special');
|
||||
}
|
||||
} else {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = stylize('[Setter]', 'special');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible_keys.indexOf(key) < 0) {
|
||||
name = '[' + key + ']';
|
||||
}
|
||||
if (!str) {
|
||||
if (seen.indexOf(value[key]) < 0) {
|
||||
if (recurseTimes === null) {
|
||||
str = format(value[key]);
|
||||
} else {
|
||||
str = format(value[key], recurseTimes - 1);
|
||||
}
|
||||
if (str.indexOf('\n') > -1) {
|
||||
if (isArray(value)) {
|
||||
str = str.split('\n').map(function(line) {
|
||||
return ' ' + line;
|
||||
}).join('\n').substr(2);
|
||||
} else {
|
||||
str = '\n' + str.split('\n').map(function(line) {
|
||||
return ' ' + line;
|
||||
}).join('\n');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
str = stylize('[Circular]', 'special');
|
||||
}
|
||||
}
|
||||
if (typeof name === 'undefined') {
|
||||
if (type === 'Array' && key.match(/^\d+$/)) {
|
||||
return str;
|
||||
}
|
||||
name = JSON.stringify('' + key);
|
||||
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
||||
name = name.substr(1, name.length - 2);
|
||||
name = stylize(name, 'name');
|
||||
} else {
|
||||
name = name.replace(/'/g, "\\'")
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/(^"|"$)/g, "'");
|
||||
name = stylize(name, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
return name + ': ' + str;
|
||||
});
|
||||
|
||||
seen.pop();
|
||||
|
||||
var numLinesEst = 0;
|
||||
var length = output.reduce(function(prev, cur) {
|
||||
numLinesEst++;
|
||||
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
||||
return prev + cur.length + 1;
|
||||
}, 0);
|
||||
|
||||
if (length > (require('readline').columns || 50)) {
|
||||
output = braces[0] +
|
||||
(base === '' ? '' : base + '\n ') +
|
||||
' ' +
|
||||
output.join(',\n ') +
|
||||
' ' +
|
||||
braces[1];
|
||||
|
||||
} else {
|
||||
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
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
|
||||
// duck-type for context-switching evalcx case
|
||||
typeof(re) === 'function' &&
|
||||
re.constructor.name === 'RegExp' &&
|
||||
re.compile &&
|
||||
re.test &&
|
||||
re.exec &&
|
||||
s.match(/^\/.*\/[gim]{0,3}$/);
|
||||
}
|
||||
|
||||
|
||||
function isDate(d) {
|
||||
if (d instanceof Date) return true;
|
||||
if (typeof d !== 'object') return false;
|
||||
var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype);
|
||||
var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__);
|
||||
return JSON.stringify(proto) === JSON.stringify(properties);
|
||||
}
|
||||
|
||||
|
||||
var pWarning;
|
||||
|
||||
exports.p = function() {
|
||||
if (!pWarning) {
|
||||
pWarning = 'util.p will be removed in future versions of Node. ' +
|
||||
'Use util.puts(util.inspect()) instead.\n';
|
||||
exports.error(pWarning);
|
||||
}
|
||||
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
error(exports.inspect(arguments[i]));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
function timestamp() {
|
||||
var d = new Date();
|
||||
var time = [pad(d.getHours()),
|
||||
pad(d.getMinutes()),
|
||||
pad(d.getSeconds())].join(':');
|
||||
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
||||
}
|
||||
|
||||
|
||||
exports.log = function(msg) {
|
||||
exports.puts(timestamp() + ' - ' + msg.toString());
|
||||
};
|
||||
|
||||
|
||||
var execWarning;
|
||||
exports.exec = function() {
|
||||
if (!execWarning) {
|
||||
execWarning = 'util.exec has moved to the "child_process" module.' +
|
||||
' Please update your source code.';
|
||||
error(execWarning);
|
||||
}
|
||||
return require('child_process').exec.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
||||
exports.pump = function(readStream, writeStream, callback) {
|
||||
var callbackCalled = false;
|
||||
|
||||
function call(a, b, c) {
|
||||
if (callback && !callbackCalled) {
|
||||
callback(a, b, c);
|
||||
callbackCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!readStream.pause) {
|
||||
readStream.pause = function() {readStream.emit('pause');};
|
||||
}
|
||||
|
||||
if (!readStream.resume) {
|
||||
readStream.resume = function() {readStream.emit('resume');};
|
||||
}
|
||||
|
||||
readStream.addListener('data', function(chunk) {
|
||||
if (writeStream.write(chunk) === false) readStream.pause();
|
||||
});
|
||||
|
||||
writeStream.addListener('pause', function() {
|
||||
readStream.pause();
|
||||
});
|
||||
|
||||
writeStream.addListener('drain', function() {
|
||||
readStream.resume();
|
||||
});
|
||||
|
||||
writeStream.addListener('resume', function() {
|
||||
readStream.resume();
|
||||
});
|
||||
|
||||
readStream.addListener('end', function() {
|
||||
writeStream.end();
|
||||
});
|
||||
|
||||
readStream.addListener('close', function() {
|
||||
call();
|
||||
});
|
||||
|
||||
readStream.addListener('error', function(err) {
|
||||
writeStream.end();
|
||||
call(err);
|
||||
});
|
||||
|
||||
writeStream.addListener('error', function(err) {
|
||||
readStream.destroy();
|
||||
call(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Inherit the prototype methods from one constructor into another.
|
||||
*
|
||||
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
||||
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
||||
* during bootstrapping this function needs to be revritten using some native
|
||||
* functions as prototype setup using normal JavaScript does not work as
|
||||
* expected during bootstrapping (see mirror.js in r114903).
|
||||
*
|
||||
* @param {function} ctor Constructor function which needs to inherit the
|
||||
* prototype.
|
||||
* @param {function} superCtor Constructor function to inherit prototype from.
|
||||
*/
|
||||
exports.inherits = function(ctor, superCtor) {
|
||||
ctor.super_ = superCtor;
|
||||
ctor.prototype = Object.create(superCtor.prototype, {
|
||||
constructor: {
|
||||
value: ctor,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
||||
Reference in New Issue
Block a user