mirror of https://gitee.com/bigwinds/arangodb
added node modules
This commit is contained in:
parent
7abef532f4
commit
854f68ba9c
|
@ -1,3 +1,3 @@
|
||||||
[javascript]
|
[javascript]
|
||||||
startup-directory = ./js
|
startup-directory = ./js
|
||||||
modules-path = ./js/client/modules;./js/common/modules
|
modules-path = ./js/client/modules;./js/common/modules;./js/node-0.8.21/modules
|
||||||
|
|
|
@ -0,0 +1,453 @@
|
||||||
|
// 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 isWindows = process.platform === 'win32';
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
|
||||||
|
// resolves . and .. elements in a path array with directory names there
|
||||||
|
// must be no slashes, empty elements, or device names (c:\) in the array
|
||||||
|
// (so also no leading and trailing slashes - it does not distinguish
|
||||||
|
// relative and absolute paths)
|
||||||
|
function normalizeArray(parts, allowAboveRoot) {
|
||||||
|
// if the path tries to go above the root, `up` ends up > 0
|
||||||
|
var up = 0;
|
||||||
|
for (var i = parts.length - 1; i >= 0; i--) {
|
||||||
|
var last = parts[i];
|
||||||
|
if (last == '.') {
|
||||||
|
parts.splice(i, 1);
|
||||||
|
} else if (last === '..') {
|
||||||
|
parts.splice(i, 1);
|
||||||
|
up++;
|
||||||
|
} else if (up) {
|
||||||
|
parts.splice(i, 1);
|
||||||
|
up--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the path is allowed to go above the root, restore leading ..s
|
||||||
|
if (allowAboveRoot) {
|
||||||
|
for (; up--; up) {
|
||||||
|
parts.unshift('..');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isWindows) {
|
||||||
|
// Regex to split a windows path into three parts: [*, device, slash,
|
||||||
|
// tail] windows-only
|
||||||
|
var splitDeviceRe =
|
||||||
|
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?([\s\S]*?)$/;
|
||||||
|
|
||||||
|
// Regex to split the tail part of the above into [*, dir, basename, ext]
|
||||||
|
var splitTailRe =
|
||||||
|
/^([\s\S]+[\\\/](?!$)|[\\\/])?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/\\]*)?)$/;
|
||||||
|
|
||||||
|
// Function to split a filename into [root, dir, basename, ext]
|
||||||
|
// windows version
|
||||||
|
var splitPath = function(filename) {
|
||||||
|
// Separate device+slash from tail
|
||||||
|
var result = splitDeviceRe.exec(filename),
|
||||||
|
device = (result[1] || '') + (result[2] || ''),
|
||||||
|
tail = result[3] || '';
|
||||||
|
// Split the tail into dir, basename and extension
|
||||||
|
var result2 = splitTailRe.exec(tail),
|
||||||
|
dir = result2[1] || '',
|
||||||
|
basename = result2[2] || '',
|
||||||
|
ext = result2[3] || '';
|
||||||
|
return [device, dir, basename, ext];
|
||||||
|
};
|
||||||
|
|
||||||
|
// path.resolve([from ...], to)
|
||||||
|
// windows version
|
||||||
|
exports.resolve = function() {
|
||||||
|
var resolvedDevice = '',
|
||||||
|
resolvedTail = '',
|
||||||
|
resolvedAbsolute = false;
|
||||||
|
|
||||||
|
for (var i = arguments.length - 1; i >= -1; i--) {
|
||||||
|
var path;
|
||||||
|
if (i >= 0) {
|
||||||
|
path = arguments[i];
|
||||||
|
} else if (!resolvedDevice) {
|
||||||
|
path = process.cwd();
|
||||||
|
} else {
|
||||||
|
// Windows has the concept of drive-specific current working
|
||||||
|
// directories. If we've resolved a drive letter but not yet an
|
||||||
|
// absolute path, get cwd for that drive. We're sure the device is not
|
||||||
|
// an unc path at this points, because unc paths are always absolute.
|
||||||
|
path = process.env['=' + resolvedDevice];
|
||||||
|
// Verify that a drive-local cwd was found and that it actually points
|
||||||
|
// to our drive. If not, default to the drive's root.
|
||||||
|
if (!path || path.slice(0, 3).toLowerCase() !==
|
||||||
|
resolvedDevice.toLowerCase() + '\\') {
|
||||||
|
path = resolvedDevice + '\\';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip empty and invalid entries
|
||||||
|
if (typeof path !== 'string' || !path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = splitDeviceRe.exec(path),
|
||||||
|
device = result[1] || '',
|
||||||
|
isUnc = device && device.charAt(1) !== ':',
|
||||||
|
isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute
|
||||||
|
tail = result[3];
|
||||||
|
|
||||||
|
if (device &&
|
||||||
|
resolvedDevice &&
|
||||||
|
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
||||||
|
// This path points to another device so it is not applicable
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!resolvedDevice) {
|
||||||
|
resolvedDevice = device;
|
||||||
|
}
|
||||||
|
if (!resolvedAbsolute) {
|
||||||
|
resolvedTail = tail + '\\' + resolvedTail;
|
||||||
|
resolvedAbsolute = isAbsolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resolvedDevice && resolvedAbsolute) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace slashes (in UNC share name) by backslashes
|
||||||
|
resolvedDevice = resolvedDevice.replace(/\//g, '\\');
|
||||||
|
|
||||||
|
// At this point the path should be resolved to a full absolute path,
|
||||||
|
// but handle relative paths to be safe (might happen when process.cwd()
|
||||||
|
// fails)
|
||||||
|
|
||||||
|
// Normalize the tail path
|
||||||
|
|
||||||
|
function f(p) {
|
||||||
|
return !!p;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f),
|
||||||
|
!resolvedAbsolute).join('\\');
|
||||||
|
|
||||||
|
return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) ||
|
||||||
|
'.';
|
||||||
|
};
|
||||||
|
|
||||||
|
// windows version
|
||||||
|
exports.normalize = function(path) {
|
||||||
|
var result = splitDeviceRe.exec(path),
|
||||||
|
device = result[1] || '',
|
||||||
|
isUnc = device && device.charAt(1) !== ':',
|
||||||
|
isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute
|
||||||
|
tail = result[3],
|
||||||
|
trailingSlash = /[\\\/]$/.test(tail);
|
||||||
|
|
||||||
|
// Normalize the tail path
|
||||||
|
tail = normalizeArray(tail.split(/[\\\/]+/).filter(function(p) {
|
||||||
|
return !!p;
|
||||||
|
}), !isAbsolute).join('\\');
|
||||||
|
|
||||||
|
if (!tail && !isAbsolute) {
|
||||||
|
tail = '.';
|
||||||
|
}
|
||||||
|
if (tail && trailingSlash) {
|
||||||
|
tail += '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert slashes to backslashes when `device` points to an UNC root.
|
||||||
|
device = device.replace(/\//g, '\\');
|
||||||
|
|
||||||
|
return device + (isAbsolute ? '\\' : '') + tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
// windows version
|
||||||
|
exports.join = function() {
|
||||||
|
function f(p) {
|
||||||
|
return p && typeof p === 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths = Array.prototype.slice.call(arguments, 0).filter(f);
|
||||||
|
var joined = paths.join('\\');
|
||||||
|
|
||||||
|
// Make sure that the joined path doesn't start with two slashes
|
||||||
|
// - it will be mistaken for an unc path by normalize() -
|
||||||
|
// unless the paths[0] also starts with two slashes
|
||||||
|
if (/^[\\\/]{2}/.test(joined) && !/^[\\\/]{2}/.test(paths[0])) {
|
||||||
|
joined = joined.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exports.normalize(joined);
|
||||||
|
};
|
||||||
|
|
||||||
|
// path.relative(from, to)
|
||||||
|
// it will solve the relative path from 'from' to 'to', for instance:
|
||||||
|
// from = 'C:\\orandea\\test\\aaa'
|
||||||
|
// to = 'C:\\orandea\\impl\\bbb'
|
||||||
|
// The output of the function should be: '..\\..\\impl\\bbb'
|
||||||
|
// windows version
|
||||||
|
exports.relative = function(from, to) {
|
||||||
|
from = exports.resolve(from);
|
||||||
|
to = exports.resolve(to);
|
||||||
|
|
||||||
|
// windows is not case sensitive
|
||||||
|
var lowerFrom = from.toLowerCase();
|
||||||
|
var lowerTo = to.toLowerCase();
|
||||||
|
|
||||||
|
function trim(arr) {
|
||||||
|
var start = 0;
|
||||||
|
for (; start < arr.length; start++) {
|
||||||
|
if (arr[start] !== '') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var end = arr.length - 1;
|
||||||
|
for (; end >= 0; end--) {
|
||||||
|
if (arr[end] !== '') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start > end) return [];
|
||||||
|
return arr.slice(start, end - start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var toParts = trim(to.split('\\'));
|
||||||
|
|
||||||
|
var lowerFromParts = trim(lowerFrom.split('\\'));
|
||||||
|
var lowerToParts = trim(lowerTo.split('\\'));
|
||||||
|
|
||||||
|
var length = Math.min(lowerFromParts.length, lowerToParts.length);
|
||||||
|
var samePartsLength = length;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
if (lowerFromParts[i] !== lowerToParts[i]) {
|
||||||
|
samePartsLength = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (samePartsLength == 0) {
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
var outputParts = [];
|
||||||
|
for (var i = samePartsLength; i < lowerFromParts.length; i++) {
|
||||||
|
outputParts.push('..');
|
||||||
|
}
|
||||||
|
|
||||||
|
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
||||||
|
|
||||||
|
return outputParts.join('\\');
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.sep = '\\';
|
||||||
|
|
||||||
|
} else /* posix */ {
|
||||||
|
|
||||||
|
// Split a filename into [root, dir, basename, ext], unix version
|
||||||
|
// 'root' is just a slash, or nothing.
|
||||||
|
var splitPathRe =
|
||||||
|
/^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/;
|
||||||
|
var splitPath = function(filename) {
|
||||||
|
var result = splitPathRe.exec(filename);
|
||||||
|
return [result[1] || '', result[2] || '', result[3] || '', result[4] || ''];
|
||||||
|
};
|
||||||
|
|
||||||
|
// path.resolve([from ...], to)
|
||||||
|
// posix version
|
||||||
|
exports.resolve = function() {
|
||||||
|
var resolvedPath = '',
|
||||||
|
resolvedAbsolute = false;
|
||||||
|
|
||||||
|
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
||||||
|
var path = (i >= 0) ? arguments[i] : process.cwd();
|
||||||
|
|
||||||
|
// Skip empty and invalid entries
|
||||||
|
if (typeof path !== 'string' || !path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvedPath = path + '/' + resolvedPath;
|
||||||
|
resolvedAbsolute = path.charAt(0) === '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point the path should be resolved to a full absolute path, but
|
||||||
|
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||||||
|
|
||||||
|
// Normalize the path
|
||||||
|
resolvedPath = normalizeArray(resolvedPath.split('/').filter(function(p) {
|
||||||
|
return !!p;
|
||||||
|
}), !resolvedAbsolute).join('/');
|
||||||
|
|
||||||
|
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||||||
|
};
|
||||||
|
|
||||||
|
// path.normalize(path)
|
||||||
|
// posix version
|
||||||
|
exports.normalize = function(path) {
|
||||||
|
var isAbsolute = path.charAt(0) === '/',
|
||||||
|
trailingSlash = path.slice(-1) === '/';
|
||||||
|
|
||||||
|
// Normalize the path
|
||||||
|
path = normalizeArray(path.split('/').filter(function(p) {
|
||||||
|
return !!p;
|
||||||
|
}), !isAbsolute).join('/');
|
||||||
|
|
||||||
|
if (!path && !isAbsolute) {
|
||||||
|
path = '.';
|
||||||
|
}
|
||||||
|
if (path && trailingSlash) {
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (isAbsolute ? '/' : '') + path;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// posix version
|
||||||
|
exports.join = function() {
|
||||||
|
var paths = Array.prototype.slice.call(arguments, 0);
|
||||||
|
return exports.normalize(paths.filter(function(p, index) {
|
||||||
|
return p && typeof p === 'string';
|
||||||
|
}).join('/'));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// path.relative(from, to)
|
||||||
|
// posix version
|
||||||
|
exports.relative = function(from, to) {
|
||||||
|
from = exports.resolve(from).substr(1);
|
||||||
|
to = exports.resolve(to).substr(1);
|
||||||
|
|
||||||
|
function trim(arr) {
|
||||||
|
var start = 0;
|
||||||
|
for (; start < arr.length; start++) {
|
||||||
|
if (arr[start] !== '') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var end = arr.length - 1;
|
||||||
|
for (; end >= 0; end--) {
|
||||||
|
if (arr[end] !== '') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start > end) return [];
|
||||||
|
return arr.slice(start, end - start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fromParts = trim(from.split('/'));
|
||||||
|
var toParts = trim(to.split('/'));
|
||||||
|
|
||||||
|
var length = Math.min(fromParts.length, toParts.length);
|
||||||
|
var samePartsLength = length;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
if (fromParts[i] !== toParts[i]) {
|
||||||
|
samePartsLength = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var outputParts = [];
|
||||||
|
for (var i = samePartsLength; i < fromParts.length; i++) {
|
||||||
|
outputParts.push('..');
|
||||||
|
}
|
||||||
|
|
||||||
|
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
||||||
|
|
||||||
|
return outputParts.join('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.sep = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.dirname = function(path) {
|
||||||
|
var result = splitPath(path),
|
||||||
|
root = result[0],
|
||||||
|
dir = result[1];
|
||||||
|
|
||||||
|
if (!root && !dir) {
|
||||||
|
// No dirname whatsoever
|
||||||
|
return '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir) {
|
||||||
|
// It has a dirname, strip trailing slash
|
||||||
|
dir = dir.substring(0, dir.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return root + dir;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.basename = function(path, ext) {
|
||||||
|
var f = splitPath(path)[2];
|
||||||
|
// TODO: make this comparison case-insensitive on windows?
|
||||||
|
if (ext && f.substr(-1 * ext.length) === ext) {
|
||||||
|
f = f.substr(0, f.length - ext.length);
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.extname = function(path) {
|
||||||
|
return splitPath(path)[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.exists = util.deprecate(function(path, callback) {
|
||||||
|
require('fs').exists(path, callback);
|
||||||
|
}, 'path.exists is now called `fs.exists`.');
|
||||||
|
|
||||||
|
|
||||||
|
exports.existsSync = util.deprecate(function(path) {
|
||||||
|
return require('fs').existsSync(path);
|
||||||
|
}, 'path.existsSync is now called `fs.existsSync`.');
|
||||||
|
|
||||||
|
|
||||||
|
if (isWindows) {
|
||||||
|
exports._makeLong = function(path) {
|
||||||
|
path = '' + path;
|
||||||
|
if (!path) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolvedPath = exports.resolve(path);
|
||||||
|
|
||||||
|
if (resolvedPath.match(/^[a-zA-Z]\:\\/)) {
|
||||||
|
// path is local filesystem path, which needs to be converted
|
||||||
|
// to long UNC path.
|
||||||
|
return '\\\\?\\' + resolvedPath;
|
||||||
|
} else if (resolvedPath.match(/^\\\\[^?.]/)) {
|
||||||
|
// path is network UNC path, which needs to be converted
|
||||||
|
// to long UNC path.
|
||||||
|
return '\\\\?\\UNC\\' + resolvedPath.substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
exports._makeLong = function(path) {
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,562 @@
|
||||||
|
// 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 formatRegExp = /%[sdj%]/g;
|
||||||
|
exports.format = function(f) {
|
||||||
|
if (typeof f !== 'string') {
|
||||||
|
var objects = [];
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
objects.push(inspect(arguments[i]));
|
||||||
|
}
|
||||||
|
return objects.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
var i = 1;
|
||||||
|
var args = arguments;
|
||||||
|
var len = args.length;
|
||||||
|
var str = String(f).replace(formatRegExp, function(x) {
|
||||||
|
if (x === '%%') return '%';
|
||||||
|
if (i >= len) return x;
|
||||||
|
switch (x) {
|
||||||
|
case '%s': return String(args[i++]);
|
||||||
|
case '%d': return Number(args[i++]);
|
||||||
|
case '%j': return JSON.stringify(args[i++]);
|
||||||
|
default:
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (var x = args[i]; i < len; x = args[++i]) {
|
||||||
|
if (x === null || typeof x !== 'object') {
|
||||||
|
str += ' ' + x;
|
||||||
|
} else {
|
||||||
|
str += ' ' + inspect(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Mark that a method should not be used.
|
||||||
|
// Returns a modified function which warns once by default.
|
||||||
|
// If --no-deprecation is set, then it is a no-op.
|
||||||
|
exports.deprecate = function(fn, msg) {
|
||||||
|
if (process.noDeprecation === true) {
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
var warned = false;
|
||||||
|
function deprecated() {
|
||||||
|
if (!warned) {
|
||||||
|
if (process.traceDeprecation) {
|
||||||
|
console.trace(msg);
|
||||||
|
} else {
|
||||||
|
console.error(msg);
|
||||||
|
}
|
||||||
|
warned = true;
|
||||||
|
}
|
||||||
|
return fn.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deprecated;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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.stderr.write('DEBUG: ' + x + '\n');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var error = exports.error = function(x) {
|
||||||
|
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||||
|
process.stderr.write(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).
|
||||||
|
*/
|
||||||
|
function inspect(obj, showHidden, depth, colors) {
|
||||||
|
var ctx = {
|
||||||
|
showHidden: showHidden,
|
||||||
|
seen: [],
|
||||||
|
stylize: colors ? stylizeWithColor : stylizeNoColor
|
||||||
|
};
|
||||||
|
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
||||||
|
}
|
||||||
|
exports.inspect = inspect;
|
||||||
|
|
||||||
|
|
||||||
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||||
|
var colors = {
|
||||||
|
'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]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Don't use 'blue' not visible on cmd.exe
|
||||||
|
var styles = {
|
||||||
|
'special': 'cyan',
|
||||||
|
'number': 'yellow',
|
||||||
|
'boolean': 'yellow',
|
||||||
|
'undefined': 'grey',
|
||||||
|
'null': 'bold',
|
||||||
|
'string': 'green',
|
||||||
|
'date': 'magenta',
|
||||||
|
// "name": intentionally not styling
|
||||||
|
'regexp': 'red'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function stylizeWithColor(str, styleType) {
|
||||||
|
var style = styles[styleType];
|
||||||
|
|
||||||
|
if (style) {
|
||||||
|
return '\u001b[' + colors[style][0] + 'm' + str +
|
||||||
|
'\u001b[' + colors[style][1] + 'm';
|
||||||
|
} else {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function stylizeNoColor(str, styleType) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function arrayToHash(array) {
|
||||||
|
var hash = {};
|
||||||
|
|
||||||
|
array.forEach(function(val, idx) {
|
||||||
|
hash[val] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatValue(ctx, 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.inspect !== exports.inspect &&
|
||||||
|
// Also filter out any prototype objects using the circular check.
|
||||||
|
!(value.constructor && value.constructor.prototype === value)) {
|
||||||
|
return String(value.inspect(recurseTimes));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Primitive types cannot have properties
|
||||||
|
var primitive = formatPrimitive(ctx, value);
|
||||||
|
if (primitive) {
|
||||||
|
return primitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up the keys of the object.
|
||||||
|
var keys = Object.keys(value);
|
||||||
|
var visibleKeys = arrayToHash(keys);
|
||||||
|
|
||||||
|
if (ctx.showHidden) {
|
||||||
|
keys = Object.getOwnPropertyNames(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some type of object without properties can be shortcutted.
|
||||||
|
if (keys.length === 0) {
|
||||||
|
if (typeof value === 'function') {
|
||||||
|
var name = value.name ? ': ' + value.name : '';
|
||||||
|
return ctx.stylize('[Function' + name + ']', 'special');
|
||||||
|
}
|
||||||
|
if (isRegExp(value)) {
|
||||||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||||
|
}
|
||||||
|
if (isDate(value)) {
|
||||||
|
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
||||||
|
}
|
||||||
|
if (isError(value)) {
|
||||||
|
return formatError(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var base = '', array = false, braces = ['{', '}'];
|
||||||
|
|
||||||
|
// Make Array say that they are Array
|
||||||
|
if (isArray(value)) {
|
||||||
|
array = true;
|
||||||
|
braces = ['[', ']'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make functions say that they are functions
|
||||||
|
if (typeof value === 'function') {
|
||||||
|
var n = value.name ? ': ' + value.name : '';
|
||||||
|
base = ' [Function' + n + ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make RegExps say that they are RegExps
|
||||||
|
if (isRegExp(value)) {
|
||||||
|
base = ' ' + RegExp.prototype.toString.call(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make dates with properties first say the date
|
||||||
|
if (isDate(value)) {
|
||||||
|
base = ' ' + Date.prototype.toUTCString.call(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make error with message first say the error
|
||||||
|
if (isError(value)) {
|
||||||
|
base = ' ' + formatError(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keys.length === 0 && (!array || value.length == 0)) {
|
||||||
|
return braces[0] + base + braces[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recurseTimes < 0) {
|
||||||
|
if (isRegExp(value)) {
|
||||||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||||
|
} else {
|
||||||
|
return ctx.stylize('[Object]', 'special');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.seen.push(value);
|
||||||
|
|
||||||
|
var output;
|
||||||
|
if (array) {
|
||||||
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
||||||
|
} else {
|
||||||
|
output = keys.map(function(key) {
|
||||||
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.seen.pop();
|
||||||
|
|
||||||
|
return reduceToSingleString(output, base, braces);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatPrimitive(ctx, value) {
|
||||||
|
switch (typeof value) {
|
||||||
|
case 'undefined':
|
||||||
|
return ctx.stylize('undefined', 'undefined');
|
||||||
|
|
||||||
|
case 'string':
|
||||||
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
||||||
|
.replace(/'/g, "\\'")
|
||||||
|
.replace(/\\"/g, '"') + '\'';
|
||||||
|
return ctx.stylize(simple, 'string');
|
||||||
|
|
||||||
|
case 'number':
|
||||||
|
return ctx.stylize('' + value, 'number');
|
||||||
|
|
||||||
|
case 'boolean':
|
||||||
|
return ctx.stylize('' + value, 'boolean');
|
||||||
|
}
|
||||||
|
// For some reason typeof null is "object", so special case here.
|
||||||
|
if (value === null) {
|
||||||
|
return ctx.stylize('null', 'null');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatError(value) {
|
||||||
|
return '[' + Error.prototype.toString.call(value) + ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||||
|
var output = [];
|
||||||
|
for (var i = 0, l = value.length; i < l; ++i) {
|
||||||
|
if (hasOwnProperty(value, String(i))) {
|
||||||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
||||||
|
String(i), true));
|
||||||
|
} else {
|
||||||
|
output.push('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keys.forEach(function(key) {
|
||||||
|
if (!key.match(/^\d+$/)) {
|
||||||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
||||||
|
key, true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
||||||
|
var name, str, desc;
|
||||||
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
||||||
|
if (desc.get) {
|
||||||
|
if (desc.set) {
|
||||||
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
||||||
|
} else {
|
||||||
|
str = ctx.stylize('[Getter]', 'special');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (desc.set) {
|
||||||
|
str = ctx.stylize('[Setter]', 'special');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasOwnProperty(visibleKeys, key)) {
|
||||||
|
name = '[' + key + ']';
|
||||||
|
}
|
||||||
|
if (!str) {
|
||||||
|
if (ctx.seen.indexOf(desc.value) < 0) {
|
||||||
|
if (recurseTimes === null) {
|
||||||
|
str = formatValue(ctx, desc.value, null);
|
||||||
|
} else {
|
||||||
|
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
||||||
|
}
|
||||||
|
if (str.indexOf('\n') > -1) {
|
||||||
|
if (array) {
|
||||||
|
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 = ctx.stylize('[Circular]', 'special');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof name === 'undefined') {
|
||||||
|
if (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 = ctx.stylize(name, 'name');
|
||||||
|
} else {
|
||||||
|
name = name.replace(/'/g, "\\'")
|
||||||
|
.replace(/\\"/g, '"')
|
||||||
|
.replace(/(^"|"$)/g, "'");
|
||||||
|
name = ctx.stylize(name, 'string');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name + ': ' + str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function reduceToSingleString(output, base, braces) {
|
||||||
|
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 > 60) {
|
||||||
|
return braces[0] +
|
||||||
|
(base === '' ? '' : base + '\n ') +
|
||||||
|
' ' +
|
||||||
|
output.join(',\n ') +
|
||||||
|
' ' +
|
||||||
|
braces[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
||||||
|
// because it is fragile and can be easily faked with `Object.create()`.
|
||||||
|
function isArray(ar) {
|
||||||
|
return Array.isArray(ar) ||
|
||||||
|
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
||||||
|
}
|
||||||
|
exports.isArray = isArray;
|
||||||
|
|
||||||
|
|
||||||
|
function isRegExp(re) {
|
||||||
|
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
||||||
|
}
|
||||||
|
exports.isRegExp = isRegExp;
|
||||||
|
|
||||||
|
|
||||||
|
function isDate(d) {
|
||||||
|
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
||||||
|
}
|
||||||
|
exports.isDate = isDate;
|
||||||
|
|
||||||
|
|
||||||
|
function isError(e) {
|
||||||
|
return typeof e === 'object' && objectToString(e) === '[object Error]';
|
||||||
|
}
|
||||||
|
exports.isError = isError;
|
||||||
|
|
||||||
|
|
||||||
|
function objectToString(o) {
|
||||||
|
return Object.prototype.toString.call(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.p = exports.deprecate(function() {
|
||||||
|
for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||||
|
error(exports.inspect(arguments[i]));
|
||||||
|
}
|
||||||
|
}, 'util.p: Use console.error() instead.');
|
||||||
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.exec = exports.deprecate(function() {
|
||||||
|
return require('child_process').exec.apply(this, arguments);
|
||||||
|
}, 'util.exec is now called `child_process.exec`.');
|
||||||
|
|
||||||
|
|
||||||
|
exports.pump = function(readStream, writeStream, callback) {
|
||||||
|
var callbackCalled = false;
|
||||||
|
|
||||||
|
function call(a, b, c) {
|
||||||
|
if (callback && !callbackCalled) {
|
||||||
|
callback(a, b, c);
|
||||||
|
callbackCalled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readStream.addListener('data', function(chunk) {
|
||||||
|
if (writeStream.write(chunk) === false) readStream.pause();
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.addListener('drain', 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 rewritten 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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports._extend = function(origin, add) {
|
||||||
|
// Don't do anything if add isn't an object
|
||||||
|
if (!add || typeof add !== 'object') return origin;
|
||||||
|
|
||||||
|
var keys = Object.keys(add);
|
||||||
|
var i = keys.length;
|
||||||
|
while (i--) {
|
||||||
|
origin[keys[i]] = add[keys[i]];
|
||||||
|
}
|
||||||
|
return origin;
|
||||||
|
};
|
||||||
|
|
||||||
|
function hasOwnProperty(obj, prop) {
|
||||||
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
exports.eval = function () {};
|
Loading…
Reference in New Issue