Client.prototype._addHandle = function(desc) {
- if (!util.isObject(desc) || !util.isNumber(desc.handle)) {
+ if (desc === null || typeof desc !== 'object' ||
+ typeof desc.handle !== 'number') {
return;
}
this.req(req, function(err, res) {
if (err) return cb(err);
for (var ref in res) {
- if (util.isObject(res[ref])) {
+ if (res[ref] !== null && typeof res[ref] === 'object') {
self._addHandle(res[ref]);
}
}
mirrorValue = '[?]';
}
-
- if (util.isArray(mirror) && !util.isNumber(prop.name)) {
+ if (Array.isArray(mirror) && typeof prop.name !== 'number') {
// Skip the 'length' property.
return;
}
val = function() {};
} else if (handle.type === 'null') {
val = null;
- } else if (!util.isUndefined(handle.value)) {
+ } else if (handle.value !== undefined) {
val = handle.value;
} else if (handle.type === 'undefined') {
val = undefined;
if (this.killed) return;
this.clearline();
- this.stdout.write(util.isString(text) ? text : util.inspect(text));
+ this.stdout.write(typeof text === 'string' ? text : util.inspect(text));
if (oneline !== true) {
this.stdout.write('\n');
this.pause();
for (var id in client.scripts) {
var script = client.scripts[id];
- if (util.isObject(script) && script.name) {
+ if (script !== null && typeof script === 'object' && script.name) {
if (displayNatives ||
script.name == client.currentScript ||
!script.isNative) {
ambiguous;
// setBreakpoint() should insert breakpoint on current line
- if (util.isUndefined(script)) {
+ if (script === undefined) {
script = this.client.currentScript;
line = this.client.currentSourceLine + 1;
}
// setBreakpoint(line-number) should insert breakpoint in current script
- if (util.isUndefined(line) && util.isNumber(script)) {
+ if (line === undefined && typeof script === 'number') {
line = script;
script = this.client.currentScript;
}
if (bp.scriptId === script ||
bp.scriptReq === script ||
(bp.script && bp.script.indexOf(script) !== -1)) {
- if (!util.isUndefined(index)) {
+ if (index !== undefined) {
ambiguous = true;
}
scriptId = script;
if (ambiguous) return this.error('Script name is ambiguous');
- if (util.isUndefined(scriptId)) {
+ if (scriptId === undefined) {
return this.error('Script ' + script + ' not found');
}
- if (util.isUndefined(breakpoint)) {
+ if (breakpoint === undefined) {
return this.error('Breakpoint not found on line ' + line);
}
var self = this;
OutgoingMessage.call(self);
- if (util.isString(options)) {
+ if (typeof options === 'string') {
options = url.parse(options);
}
var defaultAgent = options._defaultAgent || Agent.globalAgent;
if (agent === false) {
agent = new defaultAgent.constructor();
- } else if (util.isNullOrUndefined(agent) && !options.createConnection) {
+ } else if ((agent === null || agent === undefined) &&
+ !options.createConnection) {
agent = defaultAgent;
}
self.agent = agent;
var port = options.port = options.port || defaultPort || 80;
var host = options.host = options.hostname || options.host || 'localhost';
- if (util.isUndefined(options.setHost)) {
+ if (options.setHost === undefined) {
var setHost = true;
}
self.once('response', cb);
}
- if (!util.isArray(options.headers)) {
+ if (!Array.isArray(options.headers)) {
if (options.headers) {
var keys = Object.keys(options.headers);
for (var i = 0, l = keys.length; i < l; i++) {
self.useChunkedEncodingByDefault = true;
}
- if (util.isArray(options.headers)) {
+ if (Array.isArray(options.headers)) {
self._storeHeader(self.method + ' ' + self.path + ' HTTP/1.1\r\n',
options.headers);
} else if (self.getHeader('expect')) {
httpSocketSetup(socket);
// Propagate headers limit from request object to parser
- if (util.isNumber(req.maxHeadersCount)) {
+ if (typeof req.maxHeadersCount === 'number') {
parser.maxHeaderPairs = req.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
const readStart = incoming.readStart;
const readStop = incoming.readStop;
-const isNumber = require('util').isNumber;
const debug = require('util').debuglog('http');
exports.debug = debug;
parser.incoming._addHeaderLines(headers, n);
- if (isNumber(method)) {
+ if (typeof method === 'number') {
// server only
parser.incoming.method = HTTPParser.methods[method];
} else {
switch (field) {
// Array headers:
case 'set-cookie':
- if (!util.isUndefined(dest[field])) {
+ if (dest[field] !== undefined) {
dest[field].push(value);
} else {
dest[field] = [value];
case 'location':
case 'max-forwards':
// drop duplicates
- if (util.isUndefined(dest[field]))
+ if (dest[field] === undefined)
dest[field] = value;
break;
default:
// make comma-separated list
- if (!util.isUndefined(dest[field]))
+ if (dest[field] !== undefined)
dest[field] += ', ' + value;
else {
dest[field] = value;
// the same packet. Future versions of Node are going to take care of
// this at a lower level and in a more general way.
if (!this._headerSent) {
- if (util.isString(data) &&
+ if (typeof data === 'string' &&
encoding !== 'hex' &&
encoding !== 'base64') {
data = this._header + data;
OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) {
- if (util.isFunction(encoding)) {
+ if (typeof encoding === 'function') {
callback = encoding;
encoding = null;
}
if (data.length === 0) {
- if (util.isFunction(callback))
+ if (typeof callback === 'function')
process.nextTick(callback);
return true;
}
if (headers) {
var keys = Object.keys(headers);
- var isArray = util.isArray(headers);
+ var isArray = Array.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {
value = headers[key];
}
- if (util.isArray(value)) {
+ if (Array.isArray(value)) {
for (var j = 0; j < value.length; j++) {
storeHeader(this, state, field, value[j]);
}
return true;
}
- if (!util.isString(chunk) && !util.isBuffer(chunk)) {
+ if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new TypeError('first argument must be a string or Buffer');
}
var len, ret;
if (this.chunkedEncoding) {
- if (util.isString(chunk) &&
+ if (typeof chunk === 'string' &&
encoding !== 'hex' &&
encoding !== 'base64' &&
encoding !== 'binary') {
ret = this._send(chunk, encoding, callback);
} else {
// buffer, or a non-toString-friendly encoding
- if (util.isString(chunk))
+ if (typeof chunk === 'string')
len = Buffer.byteLength(chunk, encoding);
else
len = chunk.length;
OutgoingMessage.prototype.addTrailers = function(headers) {
this._trailer = '';
var keys = Object.keys(headers);
- var isArray = util.isArray(headers);
+ var isArray = Array.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
OutgoingMessage.prototype.end = function(data, encoding, callback) {
- if (util.isFunction(data)) {
+ if (typeof data === 'function') {
callback = data;
data = null;
- } else if (util.isFunction(encoding)) {
+ } else if (typeof encoding === 'function') {
callback = encoding;
encoding = null;
}
- if (data && !util.isString(data) && !util.isBuffer(data)) {
+ if (data && typeof data !== 'string' && !(data instanceof Buffer)) {
throw new TypeError('first argument must be a string or Buffer');
}
self.emit('finish');
}
- if (util.isFunction(callback))
+ if (typeof callback === 'function')
this.once('finish', callback);
-
if (!this._header) {
this._implicitHeader();
}
ServerResponse.prototype.writeHead = function(statusCode, reason, obj) {
var headers;
- if (util.isString(reason)) {
+ if (typeof reason === 'string') {
// writeHead(statusCode, reasonPhrase[, headers])
this.statusMessage = reason;
} else {
parser.incoming = null;
// Propagate headers limit from server instance to parser
- if (util.isNumber(this.maxHeadersCount)) {
+ if (typeof this.maxHeadersCount === 'number') {
parser.maxHeaderPairs = this.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
}
}
- if (!util.isUndefined(req.headers.expect) &&
+ if (req.headers.expect !== undefined &&
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1) &&
continueExpression.test(req.headers['expect'])) {
res._expect_continue = true;
Readable.prototype.push = function(chunk, encoding) {
var state = this._readableState;
- if (util.isString(chunk) && !state.objectMode) {
+ if (!state.objectMode && typeof chunk === 'string') {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = new Buffer(chunk, encoding);
if (state.objectMode)
return n === 0 ? 0 : 1;
- if (util.isNull(n) || isNaN(n)) {
+ if (n === null || isNaN(n)) {
// only flow one buffer at a time
if (state.flowing && state.buffer.length)
return state.buffer[0].length;
var state = this._readableState;
var nOrig = n;
- if (!util.isNumber(n) || n > 0)
+ if (typeof n !== 'number' || n > 0)
state.emittedReadable = false;
// if we're doing read(0) to trigger a readable event, but we
else
ret = null;
- if (util.isNull(ret)) {
+ if (ret === null) {
state.needReadable = true;
n = 0;
}
if (nOrig !== n && state.ended && state.length === 0)
endReadable(this);
- if (!util.isNull(ret))
+ if (ret !== null)
this.emit('data', ret);
return ret;
function chunkInvalid(state, chunk) {
var er = null;
- if (!util.isBuffer(chunk) &&
- !util.isString(chunk) &&
- !util.isNullOrUndefined(chunk) &&
+ if (!(chunk instanceof Buffer) &&
+ typeof chunk !== 'string' &&
+ chunk !== null &&
+ chunk !== undefined &&
!state.objectMode) {
er = new TypeError('Invalid non-string/buffer chunk');
}
chunk = state.decoder.write(chunk);
// don't skip over falsy values in objectMode
- //if (state.objectMode && util.isNullOrUndefined(chunk))
if (state.objectMode && (chunk === null || chunk === undefined))
return;
else if (!state.objectMode && (!chunk || !chunk.length))
// proxy all the other methods.
// important when wrapping filters and duplexes.
for (var i in stream) {
- if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
+ if (this[i] === undefined && typeof stream[i] === 'function') {
this[i] = function(method) { return function() {
return stream[method].apply(stream, arguments);
}}(i);
ts.writechunk = null;
ts.writecb = null;
- if (!util.isNullOrUndefined(data))
+ if (data !== null && data !== undefined)
stream.push(data);
if (cb)
this._readableState.sync = false;
this.once('prefinish', function() {
- if (util.isFunction(this._flush))
+ if (typeof this._flush === 'function')
this._flush(function(er) {
done(stream, er);
});
Transform.prototype._read = function(n) {
var ts = this._transformState;
- if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
+ if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
ts.transforming = true;
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
} else {
// how many bytes or characters.
function validChunk(stream, state, chunk, cb) {
var valid = true;
- if (!util.isBuffer(chunk) &&
- !util.isString(chunk) &&
- !util.isNullOrUndefined(chunk) &&
+
+ if (!(chunk instanceof Buffer) &&
+ typeof chunk !== 'string' &&
+ chunk !== null &&
+ chunk !== undefined &&
!state.objectMode) {
var er = new TypeError('Invalid non-string/buffer chunk');
stream.emit('error', er);
var state = this._writableState;
var ret = false;
- if (util.isFunction(encoding)) {
+ if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
- if (util.isBuffer(chunk))
+ if (chunk instanceof Buffer)
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
- if (!util.isFunction(cb))
+ if (typeof cb !== 'function')
cb = nop;
if (state.ended)
function decodeChunk(state, chunk, encoding) {
if (!state.objectMode &&
state.decodeStrings !== false &&
- util.isString(chunk)) {
+ typeof chunk === 'string') {
chunk = new Buffer(chunk, encoding);
}
return chunk;
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, chunk, encoding, cb) {
chunk = decodeChunk(state, chunk, encoding);
- if (util.isBuffer(chunk))
+
+ if (chunk instanceof Buffer)
encoding = 'buffer';
var len = state.objectMode ? 1 : chunk.length;
Writable.prototype.end = function(chunk, encoding, cb) {
var state = this._writableState;
- if (util.isFunction(chunk)) {
+ if (typeof chunk === 'function') {
cb = chunk;
chunk = null;
encoding = null;
- } else if (util.isFunction(encoding)) {
+ } else if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
- if (!util.isNullOrUndefined(chunk))
+ if (chunk !== null && chunk !== undefined)
this.write(chunk, encoding);
// .end() fully uncorks
'use strict';
-const util = require('util');
const constants = require('constants');
const tls = require('tls');
// NOTE: It's important to add CA before the cert to be able to load
// cert's issuer in C++ code.
if (options.ca) {
- if (util.isArray(options.ca)) {
+ if (Array.isArray(options.ca)) {
for (var i = 0, len = options.ca.length; i < len; i++) {
c.context.addCACert(options.ca[i]);
}
else
c.context.setCiphers(tls.DEFAULT_CIPHERS);
- if (util.isUndefined(options.ecdhCurve))
+ if (options.ecdhCurve === undefined)
c.context.setECDHCurve(tls.DEFAULT_ECDH_CURVE);
else if (options.ecdhCurve)
c.context.setECDHCurve(options.ecdhCurve);
if (options.dhparam) c.context.setDHParam(options.dhparam);
if (options.crl) {
- if (util.isArray(options.crl)) {
+ if (Array.isArray(options.crl)) {
for (var i = 0, len = options.crl.length; i < len; i++) {
c.context.addCRL(options.crl[i]);
}
var actualSize = this.remaining;
- if (!util.isNull(size)) actualSize = Math.min(size, actualSize);
+ if (size !== null) actualSize = Math.min(size, actualSize);
var bytes = fn.call(context, this.pool, this.offset, actualSize);
if (bytes > 0) {
this._finished = false;
this._opposite = null;
- if (util.isNull(slabBuffer)) slabBuffer = new SlabBuffer();
+ if (slabBuffer === null) slabBuffer = new SlabBuffer();
this._buffer = slabBuffer;
this.once('finish', onCryptoStreamFinish);
CryptoStream.prototype._write = function write(data, encoding, cb) {
- assert(util.isNull(this._pending));
+ assert(this._pending === null);
// Black-hole data
if (!this.pair.ssl) return cb(null);
// Invoke callback only when all data read from opposite stream
if (this._opposite._halfRead) {
- assert(util.isNull(this._sslOutCb));
+ assert(this._sslOutCb === null);
this._sslOutCb = cb;
} else {
cb(null);
}
// Try writing pending data
- if (!util.isNull(this._pending)) this._writePending();
- if (!util.isNull(this._opposite._pending)) this._opposite._writePending();
+ if (this._pending !== null) this._writePending();
+ if (this._opposite._pending !== null) this._opposite._writePending();
if (bytesRead === 0) {
// EOF when cleartext has finished and we have nothing to read
}
// Write pending data first
- if (!util.isNull(this._pending)) this._writePending();
+ if (this._pending !== null) this._writePending();
this.writable = false;
};
TLSSocket.prototype.setSession = function(session) {
- if (util.isString(session))
+ if (typeof session === 'string')
session = new Buffer(session, 'binary');
this.ssl.setSession(session);
};
//
function Server(/* [options], listener */) {
var options, listener;
- if (util.isObject(arguments[0])) {
+
+ if (arguments[0] !== null && typeof arguments[0] === 'object') {
options = arguments[0];
listener = arguments[1];
- } else if (util.isFunction(arguments[0])) {
+ } else if (typeof arguments[0] === 'function') {
options = {};
listener = arguments[0];
}
var timeout = options.handshakeTimeout || (120 * 1000);
- if (!util.isNumber(timeout)) {
+ if (typeof timeout !== 'number') {
throw new TypeError('handshakeTimeout must be a number');
}
Server.prototype.setOptions = function(options) {
- if (util.isBoolean(options.requestCert)) {
+ if (typeof options.requestCert === 'boolean') {
this.requestCert = options.requestCert;
} else {
this.requestCert = false;
}
- if (util.isBoolean(options.rejectUnauthorized)) {
+ if (typeof options.rejectUnauthorized === 'boolean') {
this.rejectUnauthorized = options.rejectUnauthorized;
} else {
this.rejectUnauthorized = false;
if (options.secureProtocol) this.secureProtocol = options.secureProtocol;
if (options.crl) this.crl = options.crl;
if (options.ciphers) this.ciphers = options.ciphers;
- if (!util.isUndefined(options.ecdhCurve))
+ if (options.ecdhCurve !== undefined)
this.ecdhCurve = options.ecdhCurve;
if (options.dhparam) this.dhparam = options.dhparam;
if (options.sessionTimeout) this.sessionTimeout = options.sessionTimeout;
var ctx;
this.server._contexts.some(function(elem) {
- if (!util.isNull(servername.match(elem[0]))) {
+ if (servername.match(elem[0]) !== null) {
ctx = elem[1];
return true;
}
var options = args[0];
var cb = args[1];
- if (util.isObject(listArgs[1])) {
+ if (listArgs[1] !== null && typeof listArgs[1] === 'object') {
options = util._extend(options, listArgs[1]);
- } else if (util.isObject(listArgs[2])) {
+ } else if (listArgs[2] !== null && typeof listArgs[2] === 'object') {
options = util._extend(options, listArgs[2]);
}
util.inherits(assert.AssertionError, Error);
function truncate(s, n) {
- if (util.isString(s)) {
+ if (typeof s === 'string') {
return s.length < n ? s : s.slice(0, n);
} else {
return s;
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
-
- } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
+ } else if (actual instanceof Buffer && expected instanceof Buffer) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
- } else if (!util.isObject(actual) && !util.isObject(expected)) {
+ } else if ((actual === null || typeof actual !== 'object') &&
+ (expected === null || typeof expected !== 'object')) {
return actual == expected;
// 7.5 For all other Object pairs, including Array objects, equivalence is
}
function objEquiv(a, b) {
- if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
+ if (a === null || a === undefined || b === null || b === undefined)
return false;
// an identical 'prototype' property.
if (a.prototype !== b.prototype) return false;
function _throws(shouldThrow, block, expected, message) {
var actual;
- if (!util.isFunction(block)) {
+ if (typeof block !== 'function') {
throw new TypeError('block must be a function');
}
- if (util.isString(expected)) {
+ if (typeof expected === 'string') {
message = expected;
expected = null;
}
function Buffer(subject, encoding) {
- if (!util.isBuffer(this))
+ if (!(this instanceof Buffer))
return new Buffer(subject, encoding);
- if (util.isNumber(subject)) {
+ if (typeof subject === 'number') {
this.length = +subject;
- } else if (util.isString(subject)) {
- if (!util.isString(encoding) || encoding.length === 0)
+ } else if (typeof subject === 'string') {
+ if (typeof encoding !== 'string' || encoding.length === 0)
encoding = 'utf8';
this.length = Buffer.byteLength(subject, encoding);
// Handle Arrays, Buffers, Uint8Arrays or JSON.
- } else if (util.isObject(subject)) {
- if (subject.type === 'Buffer' && util.isArray(subject.data))
+ } else if (subject !== null && typeof subject === 'object') {
+ if (subject.type === 'Buffer' && Array.isArray(subject.data))
subject = subject.data;
this.length = +subject.length;
alloc(this, this.length);
}
- if (util.isNumber(subject)) {
+ if (typeof subject === 'number') {
return;
}
- if (util.isString(subject)) {
+ if (typeof subject === 'string') {
// In the case of base64 it's possible that the size of the buffer
// allocated was slightly too large. In this case we need to rewrite
// the length to the actual length written.
poolOffset -= (prevLen - len);
}
- } else if (util.isBuffer(subject)) {
+ } else if (subject instanceof Buffer) {
subject.copy(this, 0, 0, this.length);
- } else if (util.isNumber(subject.length) || util.isArray(subject)) {
+ } else if (typeof subject.length === 'number' || Array.isArray(subject)) {
// Really crappy way to handle Uint8Arrays, but V8 doesn't give a simple
// way to access the data from the C++ API.
for (var i = 0; i < this.length; i++)
// Static methods
Buffer.isBuffer = function isBuffer(b) {
- return util.isBuffer(b);
+ return b instanceof Buffer;
};
Buffer.concat = function(list, length) {
- if (!util.isArray(list))
+ if (!Array.isArray(list))
throw new TypeError('Usage: Buffer.concat(list[, length])');
- if (util.isUndefined(length)) {
+ if (length === undefined) {
length = 0;
for (var i = 0; i < list.length; i++)
length += list[i].length;
var loweredCase = false;
start = start >>> 0;
- end = util.isUndefined(end) || end === Infinity ? this.length : end >>> 0;
+ end = end === undefined || end === Infinity ? this.length : end >>> 0;
if (!encoding) encoding = 'utf8';
if (start < 0) start = 0;
' Use write(string[, offset[, length]][, encoding]) instead.';
Buffer.prototype.write = function(string, offset, length, encoding) {
// Buffer#write(string);
- if (util.isUndefined(offset)) {
+ if (offset === undefined) {
encoding = 'utf8';
length = this.length;
offset = 0;
// Buffer#write(string, encoding)
- } else if (util.isUndefined(length) && util.isString(offset)) {
+ } else if (length === undefined && typeof offset === 'string') {
encoding = offset;
length = this.length;
offset = 0;
offset = offset >>> 0;
if (isFinite(length)) {
length = length >>> 0;
- if (util.isUndefined(encoding))
+ if (encoding === undefined)
encoding = 'utf8';
} else {
encoding = length;
}
var remaining = this.length - offset;
- if (util.isUndefined(length) || length > remaining)
+ if (length === undefined || length > remaining)
length = remaining;
encoding = !!encoding ? (encoding + '').toLowerCase() : 'utf8';
Buffer.prototype.slice = function(start, end) {
var len = this.length;
start = ~~start;
- end = util.isUndefined(end) ? len : ~~end;
+ end = end === undefined ? len : ~~end;
if (start < 0) {
start += len;
sliceOnto(this, buf, start, end);
buf.length = end - start;
if (buf.length > 0)
- buf.parent = util.isUndefined(this.parent) ? this : this.parent;
+ buf.parent = this.parent === undefined ? this : this.parent;
return buf;
};
Object.defineProperty(handleWraps, name, {
get: function() {
- if (!util.isUndefined(cons)) return cons;
+ if (cons !== undefined) return cons;
return cons = callback();
}
});
const INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
var eventName = 'message';
- if (!util.isNull(message) &&
- util.isObject(message) &&
- util.isString(message.cmd) &&
+ if (message !== null &&
+ typeof message === 'object' &&
+ typeof message.cmd === 'string' &&
message.cmd.length > INTERNAL_PREFIX.length &&
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
eventName = 'internalMessage';
target.on('internalMessage', function(message, handle) {
// Once acknowledged - continue sending handles.
if (message.cmd === 'NODE_HANDLE_ACK') {
- assert(util.isArray(target._handleQueue));
+ assert(Array.isArray(target._handleQueue));
var queue = target._handleQueue;
target._handleQueue = null;
target._send = function(message, handle, swallowErrors) {
assert(this.connected || this._channel);
- if (util.isUndefined(message))
+ if (message === undefined)
throw new TypeError('message cannot be undefined');
// package messages with a handle object
// Get options and args arguments.
var options, args, execArgv;
- if (util.isArray(arguments[1])) {
+ if (Array.isArray(arguments[1])) {
args = arguments[1];
options = util._extend({}, arguments[2]);
} else {
function normalizeExecArgs(command /*, options, callback */) {
var file, args, options, callback;
- if (util.isFunction(arguments[1])) {
+ if (typeof arguments[1] === 'function') {
options = undefined;
callback = arguments[1];
} else {
// Parse the parameters.
- if (util.isFunction(arguments[arguments.length - 1])) {
+ if (typeof arguments[arguments.length - 1] === 'function') {
callback = arguments[arguments.length - 1];
}
- if (util.isArray(arguments[1])) {
+ if (Array.isArray(arguments[1])) {
args = arguments[1];
options = util._extend(options, arguments[2]);
} else {
ipcFd;
// Replace shortcut with an array
- if (util.isString(stdio)) {
+ if (typeof stdio === 'string') {
switch (stdio) {
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break;
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break;
case 'inherit': stdio = [0, 1, 2]; break;
default: throw new TypeError('Incorrect value of stdio option: ' + stdio);
}
- } else if (!util.isArray(stdio)) {
+ } else if (!Array.isArray(stdio)) {
throw new TypeError('Incorrect value of stdio option: ' +
util.inspect(stdio));
}
}
// Defaults
- if (util.isNullOrUndefined(stdio)) {
+ if (stdio === null || stdio === undefined) {
stdio = i < 3 ? 'pipe' : 'ignore';
}
if (stdio === null || stdio === 'ignore') {
acc.push({type: 'ignore'});
- } else if (stdio === 'pipe' || util.isNumber(stdio) && stdio < 0) {
+ } else if (stdio === 'pipe' || typeof stdio === 'number' && stdio < 0) {
var a = {
type: 'pipe',
readable: i === 0,
acc.push(a);
} else if (stdio === 'ipc') {
- if (sync || !util.isUndefined(ipc)) {
+ if (sync || ipc !== undefined) {
// Cleanup previously created pipes
cleanup();
if (!sync)
type: 'inherit',
fd: i
});
- } else if (util.isNumber(stdio) || util.isNumber(stdio.fd)) {
+ } else if (typeof stdio === 'number' || typeof stdio.fd === 'number') {
acc.push({
type: 'fd',
fd: stdio.fd || stdio
wrapType: getHandleWrapType(handle),
handle: handle
});
- } else if (util.isBuffer(stdio) || util.isString(stdio)) {
+ } else if (stdio instanceof Buffer || typeof stdio === 'string') {
if (!sync) {
cleanup();
throw new TypeError('Asynchronous forks do not support Buffer input: ' +
if (Array.isArray(arguments[1])) {
args = arguments[1].slice(0);
options = arguments[2];
- } else if (arguments[1] !== undefined && !util.isObject(arguments[1])) {
+ } else if (arguments[1] !== undefined &&
+ (arguments[1] === null || typeof arguments[1] !== 'object')) {
throw new TypeError('Incorrect value of args option');
} else {
args = [];
if (options === undefined)
options = {};
- else if (!util.isObject(options))
+ else if (options === null || typeof options !== 'object')
throw new TypeError('options argument must be an object');
options = util._extend({}, options);
ipcFd = stdio.ipcFd;
stdio = options.stdio = stdio.stdio;
- if (!util.isUndefined(ipc)) {
+ if (ipc !== undefined) {
// Let child process know about opened IPC channel
options.envPairs = options.envPairs || [];
options.envPairs.push('NODE_CHANNEL_FD=' + ipcFd);
}
});
- this.stdin = stdio.length >= 1 && !util.isUndefined(stdio[0].socket) ?
+ this.stdin = stdio.length >= 1 && stdio[0].socket !== undefined ?
stdio[0].socket : null;
- this.stdout = stdio.length >= 2 && !util.isUndefined(stdio[1].socket) ?
+ this.stdout = stdio.length >= 2 && stdio[1].socket !== undefined ?
stdio[1].socket : null;
- this.stderr = stdio.length >= 3 && !util.isUndefined(stdio[2].socket) ?
+ this.stderr = stdio.length >= 3 && stdio[2].socket !== undefined ?
stdio[2].socket : null;
this.stdio = stdio.map(function(stdio) {
- return util.isUndefined(stdio.socket) ? null : stdio.socket;
+ return stdio.socket === undefined ? null : stdio.socket;
});
// Add .send() method and start listening for IPC data
- if (!util.isUndefined(ipc)) setupChannel(this, ipc);
+ if (ipc !== undefined) setupChannel(this, ipc);
return err;
};
signal = constants[sig];
}
- if (util.isUndefined(signal)) {
+ if (signal === undefined) {
throw new Error('Unknown signal: ' + sig);
}
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
if (Buffer.isBuffer(input))
pipe.input = input;
- else if (util.isString(input))
+ else if (typeof input === 'string')
pipe.input = new Buffer(input, options.encoding);
else
throw new TypeError(util.format(
EventEmitter.call(this);
- if (!util.isObject(options))
+ if (options === null || typeof options !== 'object')
options = {};
this.suicide = undefined;
else
rval = net._createServerHandle(address, port, addressType, fd);
- if (util.isNumber(rval))
+ if (typeof rval === 'number')
this.errno = rval;
else
this.handle = rval;
self.handoff(worker); // In case there are connections pending.
}
- if (util.isNull(this.server)) return done();
+ if (this.server === null) return done();
// Still busy binding.
this.server.once('listening', done);
this.server.once('error', function(err) {
return; // Worker is closing (or has closed) the server.
}
var handle = this.handles.shift();
- if (util.isUndefined(handle)) {
+ if (handle === undefined) {
this.free.push(worker); // Add to ready queue again.
return;
}
'rr': SCHED_RR
}[process.env.NODE_CLUSTER_SCHED_POLICY];
- if (util.isUndefined(schedulingPolicy)) {
+ if (schedulingPolicy === undefined) {
// FIXME Round-robin doesn't perform well on Windows right now due to the
// way IOCP is wired up. Bert is going to fix that, eventually.
schedulingPolicy = (process.platform === 'win32') ? SCHED_NONE : SCHED_RR;
message.fd];
var key = args.join(':');
var handle = handles[key];
- if (util.isUndefined(handle)) {
+ if (handle === undefined) {
var constructor = RoundRobinHandle;
// UDP is exempt from round-robin connection balancing for what should
// be obvious reasons: it's connectionless. There is nothing to send to
delete handles[key];
return close.apply(this, arguments);
};
- assert(util.isUndefined(handles[key]));
+ assert(handles[key] === undefined);
handles[key] = handle;
cb(message.errno, handle);
}
// the ack by the master process in which we can still receive handles.
// onconnection() below handles that by sending those handles back to
// the master.
- if (util.isUndefined(key)) return;
+ if (key === undefined) return;
send({ act: 'close', key: key });
delete handles[key];
key = undefined;
if (message.sockname) {
handle.getsockname = getsockname; // TCP handles only.
}
- assert(util.isUndefined(handles[key]));
+ assert(handles[key] === undefined);
handles[key] = handle;
cb(0, handle);
}
function onconnection(message, handle) {
var key = message.key;
var server = handles[key];
- var accepted = !util.isUndefined(server);
+ var accepted = server !== undefined;
send({ ack: message.seq, accepted: accepted });
if (accepted) server.onconnection(0, handle);
}
return function(message, handle) {
if (message.cmd !== 'NODE_CLUSTER') return;
var fn = cb;
- if (!util.isUndefined(message.ack)) {
+ if (message.ack !== undefined) {
fn = callbacks[message.ack];
delete callbacks[message.ack];
}
if (!(this instanceof Console)) {
return new Console(stdout, stderr);
}
- if (!stdout || !util.isFunction(stdout.write)) {
+ if (!stdout || typeof stdout.write !== 'function') {
throw new TypeError('Console expects a writable stream instance');
}
if (!stderr) {
// to break them unnecessarily.
function toBuf(str, encoding) {
encoding = encoding || 'binary';
- if (util.isString(str)) {
+ if (typeof str === 'string') {
if (encoding === 'buffer')
encoding = 'binary';
str = new Buffer(str, encoding);
Hash.prototype.update = function(data, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
- if (encoding === 'buffer' && util.isString(data))
+ if (encoding === 'buffer' && typeof data === 'string')
encoding = 'binary';
this._handle.update(data, encoding);
return this;
if (!(this instanceof DiffieHellman))
return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding);
- if (!util.isBuffer(sizeOrKey) &&
+ if (!(sizeOrKey instanceof Buffer) &&
typeof sizeOrKey !== 'number' &&
typeof sizeOrKey !== 'string')
throw new TypeError('First argument should be number, string or Buffer');
function ECDH(curve) {
- if (!util.isString(curve))
+ if (typeof curve !== 'string')
throw new TypeError('curve should be a string');
this._handle = new binding.ECDH(curve);
keylen,
digest,
callback) {
- if (util.isFunction(digest)) {
+ if (typeof digest === 'function') {
callback = digest;
digest = undefined;
}
- if (!util.isFunction(callback))
+ if (typeof callback !== 'function')
throw new Error('No callback provided to pbkdf2');
return pbkdf2(password, salt, iterations, keylen, digest, callback);
exports.setEngine = function setEngine(id, flags) {
- if (!util.isString(id))
+ if (typeof id !== 'string')
throw new TypeError('id should be a string');
- if (flags && !util.isNumber(flags))
+ if (flags && typeof flags !== 'number')
throw new TypeError('flags should be a number, if present');
flags = flags >>> 0;
exports._createSocketHandle = function(address, port, addressType, fd) {
// Opening an existing fd is not supported for UDP handles.
- assert(!util.isNumber(fd) || fd < 0);
+ assert(typeof fd !== 'number' || fd < 0);
var handle = newHandle(addressType);
// If true - UV_UDP_REUSEADDR flag will be set
this._reuseAddr = options && options.reuseAddr;
- if (util.isFunction(listener))
+ if (typeof listener === 'function')
this.on('message', listener);
}
util.inherits(Socket, events.EventEmitter);
this._bindState = BIND_STATE_BINDING;
- if (util.isFunction(arguments[arguments.length - 1]))
+ if (typeof arguments[arguments.length - 1] === 'function')
self.once('listening', arguments[arguments.length - 1]);
const UDP = process.binding('udp_wrap').UDP;
var address;
var exclusive;
- if (util.isObject(port)) {
+ if (port !== null && typeof port === 'object') {
address = port.address || '';
exclusive = !!port.exclusive;
port = port.port;
} else {
- address = util.isFunction(arguments[1]) ? '' : arguments[1];
+ address = typeof arguments[1] === 'function' ? '' : arguments[1];
exclusive = false;
}
port,
address,
callback) {
- if (!util.isNumber(offset) || !util.isNumber(length))
+ if (typeof offset !== 'number' || typeof length !== 'number')
throw new Error('send takes offset and length as args 2 and 3');
- if (!util.isString(address))
+ if (typeof address !== 'string')
throw new Error(this.type + ' sockets must send to port, address');
this.send(buffer, offset, length, port, address, callback);
callback) {
var self = this;
- if (util.isString(buffer))
+ if (typeof buffer === 'string')
buffer = new Buffer(buffer);
- if (!util.isBuffer(buffer))
+ if (!(buffer instanceof Buffer))
throw new TypeError('First argument must be a buffer or string.');
offset = offset | 0;
// Normalize callback so it's either a function or undefined but not anything
// else.
- if (!util.isFunction(callback))
+ if (typeof callback !== 'function')
callback = undefined;
self._healthCheck();
Socket.prototype.setTTL = function(arg) {
- if (!util.isNumber(arg)) {
+ if (typeof arg !== 'number') {
throw new TypeError('Argument must be a number');
}
Socket.prototype.setMulticastTTL = function(arg) {
- if (!util.isNumber(arg)) {
+ if (typeof arg !== 'number') {
throw new TypeError('Argument must be a number');
}
// callback.immediately = true;
// }
function makeAsync(callback) {
- if (!util.isFunction(callback)) {
+ if (typeof callback !== 'function') {
return callback;
}
return function asyncCallback() {
family = 0;
} else if (typeof callback !== 'function') {
throw TypeError('invalid arguments: callback must be passed');
- } else if (util.isObject(options)) {
+ } else if (options !== null && typeof options === 'object') {
hints = options.hints >>> 0;
family = options.family >>> 0;
var binding = cares[bindingName];
return function query(name, callback) {
- if (!util.isString(name)) {
+ if (typeof name !== 'string') {
throw new Error('Name must be a string');
- } else if (!util.isFunction(callback)) {
+ } else if (typeof callback !== 'function') {
throw new Error('Callback must be a function');
}
exports.resolve = function(hostname, type_, callback_) {
var resolver, callback;
- if (util.isString(type_)) {
+ if (typeof type_ === 'string') {
resolver = resolveMap[type_];
callback = callback_;
- } else if (util.isFunction(type_)) {
+ } else if (typeof type_ === 'function') {
resolver = exports.resolve4;
callback = type_;
} else {
throw new Error('Type must be a string');
}
- if (util.isFunction(resolver)) {
+ if (typeof resolver === 'function') {
return resolver(hostname, callback);
} else {
throw new Error('Unknown type "' + type_ + '"');
'use strict';
var domain;
-const util = require('util');
function EventEmitter() {
EventEmitter.init.call(this);
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
- if (!util.isNumber(n) || n < 0 || isNaN(n))
+ if (typeof n !== 'number' || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
function $getMaxListeners(that) {
- if (util.isUndefined(that._maxListeners))
+ if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
handler = this._events[type];
- if (util.isUndefined(handler))
+ if (handler === undefined)
return false;
if (this.domain && this !== process)
this.domain.enter();
- if (util.isFunction(handler)) {
+ if (typeof handler === 'function') {
switch (arguments.length) {
// fast cases
case 1:
args[i - 1] = arguments[i];
handler.apply(this, args);
}
- } else if (util.isObject(handler)) {
+ } else if (handler !== null && typeof handler === 'object') {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
EventEmitter.prototype.addListener = function addListener(type, listener) {
var m;
- if (!util.isFunction(listener))
+ if (typeof listener !== 'function')
throw TypeError('listener must be a function');
if (!this._events)
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
- util.isFunction(listener.listener) ?
+ typeof listener.listener === 'function' ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
- else if (util.isObject(this._events[type]))
+ else if (typeof this._events[type] === 'object')
// If we've already got an array, just append.
this._events[type].push(listener);
else
this._events[type] = [this._events[type], listener];
// Check for listener leak
- if (util.isObject(this._events[type]) && !this._events[type].warned) {
+ if (this._events[type] !== null && typeof this._events[type] === 'object' &&
+ !this._events[type].warned) {
var m = $getMaxListeners(this);
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function once(type, listener) {
- if (!util.isFunction(listener))
+ if (typeof listener !== 'function')
throw TypeError('listener must be a function');
var fired = false;
function removeListener(type, listener) {
var list, position, length, i;
- if (!util.isFunction(listener))
+ if (typeof listener !== 'function')
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
position = -1;
if (list === listener ||
- (util.isFunction(list.listener) && list.listener === listener)) {
+ (typeof list.listener === 'function' &&
+ list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
- } else if (util.isObject(list)) {
+ } else if (list !== null && typeof list === 'object') {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
listeners = this._events[type];
- if (util.isFunction(listeners)) {
+ if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (Array.isArray(listeners)) {
// LIFO order
var ret;
if (!this._events || !this._events[type])
ret = [];
- else if (util.isFunction(this._events[type]))
+ else if (typeof this._events[type] === 'function')
ret = [this._events[type]];
else
ret = this._events[type].slice();
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
- else if (util.isFunction(emitter._events[type]))
+ else if (typeof emitter._events[type] === 'function')
ret = 1;
else
ret = emitter._events[type].length;
}
function maybeCallback(cb) {
- return util.isFunction(cb) ? cb : rethrow();
+ return typeof cb === 'function' ? cb : rethrow();
}
// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
function makeCallback(cb) {
- if (!util.isFunction(cb)) {
+ if (typeof cb !== 'function') {
return rethrow();
}
fs.readFile = function(path, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (util.isFunction(options) || !options) {
+ if (!options || typeof options === 'function') {
options = { encoding: null, flag: 'r' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, flag: 'r' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
fs.readFileSync = function(path, options) {
if (!options) {
options = { encoding: null, flag: 'r' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, flag: 'r' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
// Used by binding.open and friends
function stringToFlags(flag) {
// Only mess with strings
- if (!util.isString(flag)) {
+ if (typeof flag !== 'string') {
return flag;
}
};
function modeNum(m, def) {
- if (util.isNumber(m))
+ if (typeof m === 'number')
return m;
- if (util.isString(m))
+ if (typeof m === 'string')
return parseInt(m, 8);
if (def)
return modeNum(def);
};
fs.read = function(fd, buffer, offset, length, position, callback) {
- if (!util.isBuffer(buffer)) {
+ if (!(buffer instanceof Buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
var cb = arguments[4],
encoding = arguments[3];
fs.readSync = function(fd, buffer, offset, length, position) {
var legacy = false;
- if (!util.isBuffer(buffer)) {
+ if (!(buffer instanceof Buffer)) {
// legacy string interface (fd, length, position, encoding, callback)
legacy = true;
var encoding = arguments[3];
callback(err, written || 0, buffer);
}
- if (util.isBuffer(buffer)) {
+ if (buffer instanceof Buffer) {
// if no position is passed then assume null
- if (util.isFunction(position)) {
+ if (typeof position === 'function') {
callback = position;
position = null;
}
return binding.writeBuffer(fd, buffer, offset, length, position, req);
}
- if (util.isString(buffer))
+ if (typeof buffer === 'string')
buffer += '';
- if (!util.isFunction(position)) {
- if (util.isFunction(offset)) {
+ if (typeof position !== 'function') {
+ if (typeof offset === 'function') {
position = offset;
offset = null;
} else {
// OR
// fs.writeSync(fd, string[, position[, encoding]]);
fs.writeSync = function(fd, buffer, offset, length, position) {
- if (util.isBuffer(buffer)) {
- if (util.isUndefined(position))
+ if (buffer instanceof Buffer) {
+ if (position === undefined)
position = null;
return binding.writeBuffer(fd, buffer, offset, length, position);
}
- if (!util.isString(buffer))
+ if (typeof buffer !== 'string')
buffer += '';
- if (util.isUndefined(offset))
+ if (offset === undefined)
offset = null;
return binding.writeString(fd, buffer, offset, length, position);
};
};
fs.truncate = function(path, len, callback) {
- if (util.isNumber(path)) {
+ if (typeof path === 'number') {
var req = new FSReqWrap();
req.oncomplete = callback;
return fs.ftruncate(path, len, req);
}
- if (util.isFunction(len)) {
+ if (typeof len === 'function') {
callback = len;
len = 0;
- } else if (util.isUndefined(len)) {
+ } else if (len === undefined) {
len = 0;
}
};
fs.truncateSync = function(path, len) {
- if (util.isNumber(path)) {
+ if (typeof path === 'number') {
// legacy
return fs.ftruncateSync(path, len);
}
- if (util.isUndefined(len)) {
+ if (len === undefined) {
len = 0;
}
// allow error to be thrown, but still close fd.
};
fs.ftruncate = function(fd, len, callback) {
- if (util.isFunction(len)) {
+ if (typeof len === 'function') {
callback = len;
len = 0;
- } else if (util.isUndefined(len)) {
+ } else if (len === undefined) {
len = 0;
}
var req = new FSReqWrap();
};
fs.ftruncateSync = function(fd, len) {
- if (util.isUndefined(len)) {
+ if (len === undefined) {
len = 0;
}
return binding.ftruncate(fd, len);
};
fs.mkdir = function(path, mode, callback) {
- if (util.isFunction(mode)) callback = mode;
+ if (typeof mode === 'function') callback = mode;
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
var req = new FSReqWrap();
}
fs.symlink = function(destination, path, type_, callback) {
- var type = (util.isString(type_) ? type_ : null);
+ var type = (typeof type_ === 'string' ? type_ : null);
var callback = makeCallback(arguments[arguments.length - 1]);
if (!nullCheck(destination, callback)) return;
};
fs.symlinkSync = function(destination, path, type) {
- type = (util.isString(type) ? type : null);
+ type = (typeof type === 'string' ? type : null);
nullCheck(destination);
nullCheck(path);
// converts Date or number to a fractional UNIX timestamp
function toUnixTimestamp(time) {
- if (util.isNumber(time)) {
+ if (typeof time === 'number') {
return time;
}
if (util.isDate(time)) {
fs.writeFile = function(path, data, options, callback) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (util.isFunction(options) || !options) {
+ if (!options || typeof options === 'function') {
options = { encoding: 'utf8', mode: 0o666, flag: 'w' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'w' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
if (openErr) {
if (callback) callback(openErr);
} else {
- var buffer = util.isBuffer(data) ? data : new Buffer('' + data,
+ var buffer = (data instanceof Buffer) ? data : new Buffer('' + data,
options.encoding || 'utf8');
var position = /a/.test(flag) ? null : 0;
writeAll(fd, buffer, 0, buffer.length, position, callback);
fs.writeFileSync = function(path, data, options) {
if (!options) {
options = { encoding: 'utf8', mode: 0o666, flag: 'w' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'w' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
var flag = options.flag || 'w';
var fd = fs.openSync(path, flag, options.mode);
- if (!util.isBuffer(data)) {
+ if (!(data instanceof Buffer)) {
data = new Buffer('' + data, options.encoding || 'utf8');
}
var written = 0;
fs.appendFile = function(path, data, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
- if (util.isFunction(options) || !options) {
+ if (!options || typeof options === 'function') {
options = { encoding: 'utf8', mode: 0o666, flag: 'a' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'a' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
fs.appendFileSync = function(path, data, options) {
if (!options) {
options = { encoding: 'utf8', mode: 0o666, flag: 'a' };
- } else if (util.isString(options)) {
+ } else if (typeof options === 'string') {
options = { encoding: options, mode: 0o666, flag: 'a' };
- } else if (!util.isObject(options)) {
+ } else if (typeof options !== 'object') {
throw new TypeError('Bad arguments');
}
if (!options.flag)
var options;
var listener;
- if (util.isObject(arguments[1])) {
+ if (arguments[1] !== null && typeof arguments[1] === 'object') {
options = arguments[1];
listener = arguments[2];
} else {
listener = arguments[1];
}
- if (util.isUndefined(options.persistent)) options.persistent = true;
- if (util.isUndefined(options.recursive)) options.recursive = false;
+ if (options.persistent === undefined) options.persistent = true;
+ if (options.recursive === undefined) options.recursive = false;
watcher = new FSWatcher();
watcher.start(filename, options.persistent, options.recursive);
persistent: true
};
- if (util.isObject(arguments[1])) {
+ if (arguments[1] !== null && typeof arguments[1] === 'object') {
options = util._extend(options, arguments[1]);
listener = arguments[2];
} else {
var stat = statWatchers[filename];
- if (util.isFunction(listener)) {
+ if (typeof listener === 'function') {
stat.removeListener('change', listener);
} else {
stat.removeAllListeners('change');
linkTarget = seenLinks[id];
}
}
- if (util.isNull(linkTarget)) {
+ if (linkTarget === null) {
fs.statSync(base);
linkTarget = fs.readlinkSync(base);
}
fs.realpath = function realpath(p, cache, cb) {
- if (!util.isFunction(cb)) {
+ if (typeof cb !== 'function') {
cb = maybeCallback(cache);
cache = null;
}
options.autoClose : true;
this.pos = undefined;
- if (!util.isUndefined(this.start)) {
- if (!util.isNumber(this.start)) {
+ if (this.start !== undefined) {
+ if (typeof this.start !== 'number') {
throw TypeError('start must be a Number');
}
- if (util.isUndefined(this.end)) {
+ if (this.end === undefined) {
this.end = Infinity;
- } else if (!util.isNumber(this.end)) {
+ } else if (typeof this.end !== 'number') {
throw TypeError('end must be a Number');
}
this.pos = this.start;
}
- if (!util.isNumber(this.fd))
+ if (typeof this.fd !== 'number')
this.open();
this.on('end', function() {
};
ReadStream.prototype._read = function(n) {
- if (!util.isNumber(this.fd))
+ if (typeof this.fd !== 'number')
return this.once('open', function() {
this._read(n);
});
var toRead = Math.min(pool.length - pool.used, n);
var start = pool.used;
- if (!util.isUndefined(this.pos))
+ if (this.pos !== undefined)
toRead = Math.min(this.end - this.pos + 1, toRead);
// already read everything we were supposed to read!
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread);
// move the pool positions, and internal position for reading.
- if (!util.isUndefined(this.pos))
+ if (this.pos !== undefined)
this.pos += toRead;
pool.used += toRead;
var self = this;
if (cb)
this.once('close', cb);
- if (this.closed || !util.isNumber(this.fd)) {
- if (!util.isNumber(this.fd)) {
+ if (this.closed || typeof this.fd !== 'number') {
+ if (typeof this.fd !== 'number') {
this.once('open', close);
return;
}
this.pos = undefined;
this.bytesWritten = 0;
- if (!util.isUndefined(this.start)) {
- if (!util.isNumber(this.start)) {
+ if (this.start !== undefined) {
+ if (typeof this.start !== 'number') {
throw TypeError('start must be a Number');
}
if (this.start < 0) {
this.pos = this.start;
}
- if (!util.isNumber(this.fd))
+ if (typeof this.fd !== 'number')
this.open();
// dispose on finish.
WriteStream.prototype._write = function(data, encoding, cb) {
- if (!util.isBuffer(data))
+ if (!(data instanceof Buffer))
return this.emit('error', new Error('Invalid data'));
- if (!util.isNumber(this.fd))
+ if (typeof this.fd !== 'number')
return this.once('open', function() {
this._write(data, encoding, cb);
});
cb();
});
- if (!util.isUndefined(this.pos))
+ if (this.pos !== undefined)
this.pos += data.length;
};
// parse arguments
if (arg1) {
- if (util.isString(arg1)) {
+ if (typeof arg1 === 'string') {
encoding = arg1;
cb = arg2;
- } else if (util.isFunction(arg1)) {
+ } else if (typeof arg1 === 'function') {
cb = arg1;
} else {
throw new Error('bad arg');
assertEncoding(encoding);
// Change strings to buffers. SLOW
- if (util.isString(data)) {
+ if (typeof data === 'string') {
data = new Buffer(data, encoding);
}
const url = require('url');
const http = require('http');
const util = require('util');
-const inherits = require('util').inherits;
+const inherits = util.inherits;
const debug = util.debuglog('https');
function Server(opts, requestListener) {
// HTTPS agents.
function createConnection(port, host, options) {
- if (util.isObject(port)) {
+ if (port !== null && typeof port === 'object') {
options = port;
- } else if (util.isObject(host)) {
+ } else if (host !== null && typeof host === 'object') {
options = host;
- } else if (util.isObject(options)) {
+ } else if (options !== null && typeof options === 'object') {
options = options;
} else {
options = {};
}
- if (util.isNumber(port)) {
+ if (typeof port === 'number') {
options.port = port;
}
- if (util.isString(host)) {
+ if (typeof host === 'string') {
options.host = host;
}
name += options.pfx;
name += ':';
- if (!util.isUndefined(options.rejectUnauthorized))
+ if (options.rejectUnauthorized !== undefined)
name += options.rejectUnauthorized;
return name;
exports.Agent = Agent;
exports.request = function(options, cb) {
- if (util.isString(options)) {
+ if (typeof options === 'string') {
options = url.parse(options);
} else {
options = util._extend({}, options);
// `exports` property.
Module.prototype.require = function(path) {
assert(path, 'missing path');
- assert(util.isString(path), 'path must be a string');
+ assert(typeof path === 'string', 'path must be a string');
return Module._load(path, this);
};
const debug = util.debuglog('net');
function isPipeName(s) {
- return util.isString(s) && toNumber(s) === false;
+ return typeof s === 'string' && toNumber(s) === false;
}
exports.createServer = function() {
function normalizeConnectArgs(args) {
var options = {};
- if (util.isObject(args[0])) {
+ if (args[0] !== null && typeof args[0] === 'object') {
// connect(options, [cb])
options = args[0];
} else if (isPipeName(args[0])) {
} else {
// connect(port, [host], [cb])
options.port = args[0];
- if (util.isString(args[1])) {
+ if (typeof args[1] === 'string') {
options.host = args[1];
}
}
var cb = args[args.length - 1];
- return util.isFunction(cb) ? [options, cb] : [options];
+ return typeof cb === 'function' ? [options, cb] : [options];
}
exports._normalizeConnectArgs = normalizeConnectArgs;
this._handle = null;
this._host = null;
- if (util.isNumber(options))
+ if (typeof options === 'number')
options = { fd: options }; // Legacy interface.
- else if (util.isUndefined(options))
+ else if (options === undefined)
options = {};
stream.Duplex.call(this, options);
if (options.handle) {
this._handle = options.handle; // private
- } else if (!util.isUndefined(options.fd)) {
+ } else if (options.fd !== undefined) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
if ((options.fd == 1 || options.fd == 2) &&
// of the other side sending a FIN. The standard 'write after end'
// is overly vague, and makes it seem like the user's code is to blame.
function writeAfterFIN(chunk, encoding, cb) {
- if (util.isFunction(encoding)) {
+ if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
var self = this;
// TODO: defer error events consistently everywhere, not just the cb
self.emit('error', er);
- if (util.isFunction(cb)) {
+ if (typeof cb === 'function') {
process.nextTick(function() {
cb(er);
});
Socket.prototype.setNoDelay = function(enable) {
// backwards compatibility: assume true when `enable` is omitted
if (this._handle && this._handle.setNoDelay)
- this._handle.setNoDelay(util.isUndefined(enable) ? true : !!enable);
+ this._handle.setNoDelay(enable === undefined ? true : !!enable);
};
Socket.prototype.write = function(chunk, encoding, cb) {
- if (!util.isString(chunk) && !util.isBuffer(chunk))
+ if (typeof chunk !== 'string' && !(chunk instanceof Buffer))
throw new TypeError('invalid data');
return stream.Duplex.prototype.write.apply(this, arguments);
};
if (err === 0) req._chunks = chunks;
} else {
var enc;
- if (util.isBuffer(data)) {
+ if (data instanceof Buffer) {
req.buffer = data; // Keep reference alive.
enc = 'buffer';
} else {
encoding = this._pendingEncoding;
state.getBuffer().forEach(function(el) {
- if (util.isBuffer(el.chunk))
+ if (el.chunk instanceof Buffer)
bytes += el.chunk.length;
else
bytes += Buffer.byteLength(el.chunk, el.encoding);
});
if (data) {
- if (util.isBuffer(data))
+ if (data instanceof Buffer)
bytes += data.length;
else
bytes += Buffer.byteLength(data, encoding);
if (this.write !== Socket.prototype.write)
this.write = Socket.prototype.write;
- if (!util.isObject(options)) {
+ if (options === null || typeof options !== 'object') {
// Old API:
// connect(port, [host], [cb])
// connect(path, [cb]);
initSocketHandle(this);
}
- if (util.isFunction(cb)) {
+ if (typeof cb === 'function') {
self.once('connect', cb);
}
if (localAddress && !exports.isIP(localAddress))
throw new TypeError('localAddress must be a valid IP: ' + localAddress);
- if (localPort && !util.isNumber(localPort))
+ if (localPort && typeof localPort !== 'number')
throw new TypeError('localPort should be a number: ' + localPort);
if (port <= 0 || port > 65535)
var options;
- if (util.isFunction(arguments[0])) {
+ if (typeof arguments[0] === 'function') {
options = {};
self.on('connection', arguments[0]);
} else {
options = arguments[0] || {};
- if (util.isFunction(arguments[1])) {
+ if (typeof arguments[1] === 'function') {
self.on('connection', arguments[1]);
}
}
var handle;
var isTCP = false;
- if (util.isNumber(fd) && fd >= 0) {
+ if (typeof fd === 'number' && fd >= 0) {
try {
handle = createHandle(fd);
}
var rval = null;
- if (!address && !util.isNumber(fd)) {
+ if (!address && typeof fd !== 'number') {
rval = createServerHandle('::', port, 6, fd);
- if (util.isNumber(rval)) {
+ if (typeof rval === 'number') {
rval = null;
address = '0.0.0.0';
addressType = 4;
if (rval === null)
rval = createServerHandle(address, port, addressType, fd);
- if (util.isNumber(rval)) {
+ if (typeof rval === 'number') {
var error = exceptionWithHostPort(rval, 'listen', address, port);
process.nextTick(function() {
self.emit('error', error);
var self = this;
var lastArg = arguments[arguments.length - 1];
- if (util.isFunction(lastArg)) {
+ if (typeof lastArg === 'function') {
self.once('listening', lastArg);
}
const TCP = process.binding('tcp_wrap').TCP;
- if (arguments.length === 0 || util.isFunction(arguments[0])) {
+ if (arguments.length === 0 || typeof arguments[0] === 'function') {
// Bind to a random port.
listen(self, null, 0, null, backlog);
- } else if (util.isObject(arguments[0])) {
+ } else if (arguments[0] !== null && typeof arguments[0] === 'object') {
var h = arguments[0];
h = h._handle || h.handle || h;
if (h instanceof TCP) {
self._handle = h;
listen(self, null, -1, -1, backlog);
- } else if (util.isNumber(h.fd) && h.fd >= 0) {
+ } else if (typeof h.fd === 'number' && h.fd >= 0) {
listen(self, null, null, null, backlog, h.fd);
} else {
// The first argument is a configuration object
if (h.backlog)
backlog = h.backlog;
- if (util.isNumber(h.port)) {
+ if (typeof h.port === 'number') {
if (h.host)
listenAfterLookup(h.port, h.host, backlog, h.exclusive);
else
var pipeName = self._pipeName = arguments[0];
listen(self, pipeName, -1, -1, backlog);
- } else if (util.isUndefined(arguments[1]) ||
- util.isFunction(arguments[1]) ||
- util.isNumber(arguments[1])) {
+ } else if (arguments[1] === undefined ||
+ typeof arguments[1] === 'function' ||
+ typeof arguments[1] === 'number') {
// The first argument is the port, no IP given.
listen(self, null, port, 4, backlog);
var simultaneousAccepts;
exports._setSimultaneousAccepts = function(handle) {
- if (util.isUndefined(handle)) {
+ if (handle === undefined) {
return;
}
- if (util.isUndefined(simultaneousAccepts)) {
+ if (simultaneousAccepts === undefined) {
simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
process.env.NODE_MANY_ACCEPTS !== '0');
}
'use strict';
const isWindows = process.platform === 'win32';
-const util = require('util');
-
// resolves . and .. elements in a path array with directory names there
// must be no slashes or device names (c:\) in the array
}
// Skip empty and invalid entries
- if (!util.isString(path)) {
+ if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
win32.join = function() {
function f(p) {
- if (!util.isString(p)) {
+ if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
win32._makeLong = function(path) {
// Note: this will *probably* throw somewhere.
- if (!util.isString(path))
+ if (typeof path !== 'string')
return path;
if (!path) {
win32.format = function(pathObject) {
- if (!util.isObject(pathObject)) {
+ if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError(
"Parameter 'pathObject' must be an object, not " + typeof pathObject
);
var root = pathObject.root || '';
- if (!util.isString(root)) {
+ if (typeof root !== 'string') {
throw new TypeError(
"'pathObject.root' must be a string or undefined, not " +
typeof pathObject.root
win32.parse = function(pathString) {
- if (!util.isString(pathString)) {
+ if (typeof pathString !== 'string') {
throw new TypeError(
"Parameter 'pathString' must be a string, not " + typeof pathString
);
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
- if (!util.isString(path)) {
+ if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
var path = '';
for (var i = 0; i < arguments.length; i++) {
var segment = arguments[i];
- if (!util.isString(segment)) {
+ if (typeof segment !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
if (segment) {
posix.format = function(pathObject) {
- if (!util.isObject(pathObject)) {
+ if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError(
"Parameter 'pathObject' must be an object, not " + typeof pathObject
);
var root = pathObject.root || '';
- if (!util.isString(root)) {
+ if (typeof root !== 'string') {
throw new TypeError(
"'pathObject.root' must be a string or undefined, not " +
typeof pathObject.root
posix.parse = function(pathString) {
- if (!util.isString(pathString)) {
+ if (typeof pathString !== 'string') {
throw new TypeError(
"Parameter 'pathString' must be a string, not " + typeof pathString
);
'use strict';
const QueryString = exports;
-const util = require('util');
-
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
};
var stringifyPrimitive = function(v) {
- if (util.isString(v))
+ let type = typeof v;
+
+ if (type === 'string')
return v;
- if (util.isBoolean(v))
+ if (type === 'boolean')
return v ? 'true' : 'false';
- if (util.isNumber(v))
+ if (type === 'number')
return isFinite(v) ? v : '';
return '';
};
encode = options.encodeURIComponent;
}
- if (util.isObject(obj)) {
+ if (obj !== null && typeof obj === 'object') {
var keys = Object.keys(obj);
var fields = [];
var v = obj[k];
var ks = encode(stringifyPrimitive(k)) + eq;
- if (util.isArray(v)) {
+ if (Array.isArray(v)) {
for (var j = 0; j < v.length; j++)
fields.push(ks + encode(stringifyPrimitive(v[j])));
} else {
eq = eq || '=';
var obj = {};
- if (!util.isString(qs) || qs.length === 0) {
+ if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
qs = qs.split(sep);
var maxKeys = 1000;
- if (options && util.isNumber(options.maxKeys)) {
+ if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
- } else if (util.isArray(obj[k])) {
+ } else if (Array.isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
completer = completer || function() { return []; };
- if (!util.isFunction(completer)) {
+ if (typeof completer !== 'function') {
throw new TypeError('Argument \'completer\' must be a function');
}
// backwards compat; check the isTTY prop of the output stream
// when `terminal` was not specified
- if (util.isUndefined(terminal) && !util.isNullOrUndefined(output)) {
+ if (terminal === undefined && !(output === null || output === undefined)) {
terminal = !!output.isTTY;
}
}
function onend() {
- if (util.isString(self._line_buffer) && self._line_buffer.length > 0) {
+ if (typeof self._line_buffer === 'string' &&
+ self._line_buffer.length > 0) {
self.emit('line', self._line_buffer);
}
self.close();
}
function ontermend() {
- if (util.isString(self.line) && self.line.length > 0) {
+ if (typeof self.line === 'string' && self.line.length > 0) {
self.emit('line', self.line);
}
self.close();
this.history = [];
this.historyIndex = -1;
- if (!util.isNullOrUndefined(output))
+ if (output !== null && output !== undefined)
output.on('resize', onresize);
self.once('close', function() {
input.removeListener('keypress', onkeypress);
input.removeListener('end', ontermend);
- if (!util.isNullOrUndefined(output)) {
+ if (output !== null && output !== undefined) {
output.removeListener('resize', onresize);
}
});
Interface.prototype._setRawMode = function(mode) {
- if (util.isFunction(this.input.setRawMode)) {
+ if (typeof this.input.setRawMode === 'function') {
return this.input.setRawMode(mode);
}
};
Interface.prototype.question = function(query, cb) {
- if (util.isFunction(cb)) {
+ if (typeof cb === 'function') {
if (this._questionCallback) {
this.prompt();
} else {
};
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
- if (!util.isString(stringToWrite))
+ if (typeof stringToWrite !== 'string')
throw new TypeError('stringToWrite must be a string');
- if (!util.isNullOrUndefined(this.output))
+ if (this.output !== null && this.output !== undefined)
this.output.write(stringToWrite);
};
// \r\n, \n, or \r followed by something other than \n
const lineEnding = /\r?\n|\r(?!\n)/;
Interface.prototype._normalWrite = function(b) {
- if (util.isUndefined(b)) {
+ if (b === undefined) {
return;
}
var string = this._decoder.write(b);
break;
default:
- if (util.isBuffer(s))
+ if (s instanceof Buffer)
s = s.toString('utf-8');
if (s) {
].join('|'));
function emitKeys(stream, s) {
- if (util.isBuffer(s)) {
- if (s[0] > 127 && util.isUndefined(s[1])) {
+ if (s instanceof Buffer) {
+ if (s[0] > 127 && s[1] === undefined) {
s[0] -= 128;
s = '\x1b' + s.toString(stream.encoding || 'utf-8');
} else {
}
// Don't emit a key if no name was found
- if (util.isUndefined(key.name)) {
+ if (key.name === undefined) {
key = undefined;
}
*/
function cursorTo(stream, x, y) {
- if (util.isNullOrUndefined(stream))
+ if (stream === null || stream === undefined)
return;
- if (!util.isNumber(x) && !util.isNumber(y))
+ if (typeof x !== 'number' && typeof y !== 'number')
return;
- if (!util.isNumber(x))
+ if (typeof x !== 'number')
throw new Error("Can't set cursor row without also setting it's column");
- if (!util.isNumber(y)) {
+ if (typeof y !== 'number') {
stream.write('\x1b[' + (x + 1) + 'G');
} else {
stream.write('\x1b[' + (y + 1) + ';' + (x + 1) + 'H');
*/
function moveCursor(stream, dx, dy) {
- if (util.isNullOrUndefined(stream))
+ if (stream === null || stream === undefined)
return;
if (dx < 0) {
*/
function clearLine(stream, dir) {
- if (util.isNullOrUndefined(stream))
+ if (stream === null || stream === undefined)
return;
if (dir < 0) {
*/
function clearScreenDown(stream) {
- if (util.isNullOrUndefined(stream))
+ if (stream === null || stream === undefined)
return;
stream.write('\x1b[0J');
}
var options, input, output, dom;
- if (util.isObject(prompt)) {
+ if (prompt !== null && typeof prompt === 'object') {
// an options object was given
options = prompt;
stream = options.stream || options.socket;
ignoreUndefined = options.ignoreUndefined;
prompt = options.prompt;
dom = options.domain;
- } else if (!util.isString(prompt)) {
+ } else if (typeof prompt !== 'string') {
throw new Error('An options Object, or a prompt String are required');
} else {
options = {};
options.terminal
]);
- self.setPrompt(!util.isUndefined(prompt) ? prompt : '> ');
+ self.setPrompt(prompt !== undefined ? prompt : '> ');
this.commands = {};
defineDefaultCommands(this);
// figure out which "writer" function to use
self.writer = options.writer || exports.writer;
- if (util.isUndefined(options.useColors)) {
+ if (options.useColors === undefined) {
options.useColors = self.terminal;
}
self.useColors = !!options.useColors;
self.bufferedCommand = '';
// If we got any output - print it (if no error)
- if (!e && (!self.ignoreUndefined || !util.isUndefined(ret))) {
+ if (!e && (!self.ignoreUndefined || ret !== undefined)) {
self.context._ = ret;
self.outputStream.write(self.writer(ret) + '\n');
}
// getter code.
REPLServer.prototype.complete = function(line, callback) {
// There may be local variables to evaluate, try a nested REPL
- if (!util.isUndefined(this.bufferedCommand) && this.bufferedCommand.length) {
+ if (this.bufferedCommand !== undefined && this.bufferedCommand.length) {
// Get a new array of inputed lines
var tmp = this.lines.slice();
// Kill off all function declarations to push all local variables into
this.eval('.scope', this.context, 'repl', function(err, globals) {
if (err || !globals) {
addStandardGlobals(completionGroups, filter);
- } else if (util.isArray(globals[0])) {
+ } else if (Array.isArray(globals[0])) {
// Add grouped globals
globals.forEach(function(group) {
completionGroups.push(group);
// if (e) console.log(e);
if (obj != null) {
- if (util.isObject(obj) || util.isFunction(obj)) {
+ if (typeof obj === 'object' || typeof obj === 'function') {
memberGroups.push(Object.getOwnPropertyNames(obj));
}
// works for non-objects
try {
var sentinel = 5;
var p;
- if (util.isObject(obj) || util.isFunction(obj)) {
+ if (typeof obj === 'object' || typeof obj === 'function') {
p = Object.getPrototypeOf(obj);
} else {
p = obj.constructor ? obj.constructor.prototype : null;
}
- while (!util.isNull(p)) {
+ while (p !== null) {
memberGroups.push(Object.getOwnPropertyNames(p));
p = Object.getPrototypeOf(p);
// Circular refs possible? Let's guard against that.
REPLServer.prototype.defineCommand = function(keyword, cmd) {
- if (util.isFunction(cmd)) {
+ if (typeof cmd === 'function') {
cmd = {action: cmd};
- } else if (!util.isFunction(cmd.action)) {
+ } else if (typeof cmd.action !== 'function') {
throw new Error('bad argument, action must be a function');
}
this.commands[keyword] = cmd;
function alloc(n, obj, type) {
n = n >>> 0;
- if (util.isUndefined(obj))
+ if (obj === undefined)
obj = {};
- if (util.isNumber(obj)) {
+ if (typeof obj === 'number') {
type = obj >>> 0;
obj = {};
} else if (util.isPrimitive(obj)) {
// 1 == v8::kExternalUint8Array, 9 == v8::kExternalUint8ClampedArray
if (type < 1 || type > 9)
throw new TypeError('unknown external array type: ' + type);
- if (util.isArray(obj))
+ if (Array.isArray(obj))
throw new TypeError('Arrays are not supported');
if (n > kMaxLength)
throw new RangeError('n > kMaxLength');
function dispose(obj) {
if (util.isPrimitive(obj))
throw new TypeError('obj must be an Object');
- if (util.isBuffer(obj))
+ if (obj instanceof Buffer)
throw new TypeError('obj cannot be a Buffer');
if (smalloc.isTypedArray(obj))
throw new TypeError('obj cannot be a typed array');
if (didOnEnd) return;
didOnEnd = true;
- if (util.isFunction(dest.destroy)) dest.destroy();
+ if (typeof dest.destroy === 'function') dest.destroy();
}
// don't leave dangling pipes when there are errors.
// ("\x06spdy/2\x08http/1.1\x08http/1.0")
exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {
// If NPNProtocols is Array - translate it into buffer
- if (util.isArray(NPNProtocols)) {
+ if (Array.isArray(NPNProtocols)) {
var buff = new Buffer(NPNProtocols.reduce(function(p, c) {
return p + 1 + Buffer.byteLength(c);
}, 0));
}
// If it's already a Buffer - store it
- if (util.isBuffer(NPNProtocols)) {
+ if (NPNProtocols instanceof Buffer) {
out.NPNProtocols = NPNProtocols;
}
};
// RFC6125
if (matchCN) {
var commonNames = cert.subject.CN;
- if (util.isArray(commonNames)) {
+ if (Array.isArray(commonNames)) {
for (var i = 0, k = commonNames.length; i < k; ++i) {
dnsNames.push(regexpify(commonNames[i], true));
}
var key = parts[i].slice(0, sepIndex);
var value = parts[i].slice(sepIndex + 1);
if (key in out) {
- if (!util.isArray(out[key])) {
+ if (!Array.isArray(out[key])) {
out[key] = [out[key]];
}
out[key].push(value);
'use strict';
-const inherits = require('util').inherits;
+const util = require('util');
const net = require('net');
const TTY = process.binding('tty_wrap').TTY;
const isTTY = process.binding('tty_wrap').isTTY;
-const util = require('util');
-
+const inherits = util.inherits;
const errnoException = util._errnoException;
'use strict';
const punycode = require('punycode');
-const util = require('util');
exports.parse = urlParse;
exports.resolve = urlResolve;
const querystring = require('querystring');
function urlParse(url, parseQueryString, slashesDenoteHost) {
- if (url && util.isObject(url) && url instanceof Url) return url;
+ if (url instanceof Url) return url;
var u = new Url;
u.parse(url, parseQueryString, slashesDenoteHost);
}
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
- if (!util.isString(url)) {
+ if (typeof url !== 'string') {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}
// If it's an obj, this is a no-op.
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
- if (util.isString(obj)) obj = urlParse(obj);
+ if (typeof obj === 'string') obj = urlParse(obj);
if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
return obj.format();
}
}
}
- if (this.query &&
- util.isObject(this.query) &&
+ if (this.query !== null &&
+ typeof this.query === 'object' &&
Object.keys(this.query).length) {
query = querystring.stringify(this.query);
}
}
Url.prototype.resolveObject = function(relative) {
- if (util.isString(relative)) {
+ if (typeof relative === 'string') {
var rel = new Url();
rel.parse(relative, false, true);
relative = rel;
srcPath = srcPath.concat(relPath);
result.search = relative.search;
result.query = relative.query;
- } else if (!util.isNullOrUndefined(relative.search)) {
+ } else if (relative.search !== null && relative.search !== undefined) {
// just pull out the search.
// like href='?foo'.
// Put this after the other two cases because it simplifies the booleans
result.search = relative.search;
result.query = relative.query;
//to support http.request
- if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
+ if (result.pathname !== null || result.search !== null) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
}
//to support request.http
- if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
+ if (result.pathname !== null || result.search !== null) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
const formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
- if (!isString(f)) {
+ if (typeof f !== 'string') {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
}
});
for (var x = args[i]; i < len; x = args[++i]) {
- if (isNull(x) || !isObject(x)) {
+ if (x === null || typeof x !== 'object') {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
// If --no-deprecation is set, then it is a no-op.
exports.deprecate = function(fn, msg) {
// Allow for deprecating things in the process of starting up.
- if (isUndefined(global.process)) {
+ if (global.process === undefined) {
return function() {
return exports.deprecate(fn, msg).apply(this, arguments);
};
var debugs = {};
var debugEnviron;
exports.debuglog = function(set) {
- if (isUndefined(debugEnviron))
+ if (debugEnviron === undefined)
debugEnviron = process.env.NODE_DEBUG || '';
set = set.toUpperCase();
if (!debugs[set]) {
// legacy...
if (arguments.length >= 3) ctx.depth = arguments[2];
if (arguments.length >= 4) ctx.colors = arguments[3];
- if (isBoolean(opts)) {
+ if (typeof opts === 'boolean') {
// legacy...
ctx.showHidden = opts;
} else if (opts) {
exports._extend(ctx, opts);
}
// set default options
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
- if (isUndefined(ctx.depth)) ctx.depth = 2;
- if (isUndefined(ctx.colors)) ctx.colors = false;
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
+ if (ctx.showHidden === undefined) ctx.showHidden = false;
+ if (ctx.depth === undefined) ctx.depth = 2;
+ if (ctx.colors === undefined) ctx.colors = false;
+ if (ctx.customInspect === undefined) ctx.customInspect = true;
if (ctx.colors) ctx.stylize = stylizeWithColor;
return formatValue(ctx, obj, ctx.depth);
}
// Check that value is an object with an inspect function on it
if (ctx.customInspect &&
value &&
- isFunction(value.inspect) &&
+ 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)) {
var ret = value.inspect(recurseTimes, ctx);
- if (!isString(ret)) {
+ if (typeof ret !== 'string') {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
// ignore...
}
- if (isString(raw)) {
+ if (typeof raw === 'string') {
// for boxed Strings, we have to remove the 0-n indexed entries,
// since they just noisey up the output and are redundant
keys = keys.filter(function(key) {
// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
- if (isFunction(value)) {
+ if (typeof value === 'function') {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
}
return formatError(value);
}
// now check the `raw` value to handle boxed primitives
- if (isString(raw)) {
+ if (typeof raw === 'string') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[String: ' + formatted + ']', 'string');
}
- if (isNumber(raw)) {
+ if (typeof raw === 'number') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Number: ' + formatted + ']', 'number');
}
- if (isBoolean(raw)) {
+ if (typeof raw === 'boolean') {
formatted = formatPrimitiveNoColor(ctx, raw);
return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
}
var base = '', array = false, braces = ['{', '}'];
// Make Array say that they are Array
- if (isArray(value)) {
+ if (Array.isArray(value)) {
array = true;
braces = ['[', ']'];
}
// Make functions say that they are functions
- if (isFunction(value)) {
+ if (typeof value === 'function') {
var n = value.name ? ': ' + value.name : '';
base = ' [Function' + n + ']';
}
}
// Make boxed primitive Strings look like such
- if (isString(raw)) {
+ if (typeof raw === 'string') {
formatted = formatPrimitiveNoColor(ctx, raw);
base = ' ' + '[String: ' + formatted + ']';
}
// Make boxed primitive Numbers look like such
- if (isNumber(raw)) {
+ if (typeof raw === 'number') {
formatted = formatPrimitiveNoColor(ctx, raw);
base = ' ' + '[Number: ' + formatted + ']';
}
// Make boxed primitive Booleans look like such
- if (isBoolean(raw)) {
+ if (typeof raw === 'boolean') {
formatted = formatPrimitiveNoColor(ctx, raw);
base = ' ' + '[Boolean: ' + formatted + ']';
}
function formatPrimitive(ctx, value) {
- if (isUndefined(value))
+ if (value === undefined)
return ctx.stylize('undefined', 'undefined');
- if (isString(value)) {
+
+ // For some reason typeof null is "object", so special case here.
+ if (value === null)
+ return ctx.stylize('null', 'null');
+
+ var type = typeof value;
+
+ if (type === 'string') {
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
}
- if (isNumber(value)) {
+ if (type === 'number') {
// Format -0 as '-0'. Strict equality won't distinguish 0 from -0,
// so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 .
if (value === 0 && 1 / value < 0)
return ctx.stylize('-0', 'number');
return ctx.stylize('' + value, 'number');
}
- if (isBoolean(value))
+ if (type === 'boolean')
return ctx.stylize('' + value, 'boolean');
- // For some reason typeof null is "object", so special case here.
- if (isNull(value))
- return ctx.stylize('null', 'null');
// es6 symbol primitive
- if (isSymbol(value))
+ if (type === 'symbol')
return ctx.stylize(value.toString(), 'symbol');
}
}
}
keys.forEach(function(key) {
- if (isSymbol(key) || !key.match(/^\d+$/)) {
+ if (typeof key === 'symbol' || !key.match(/^\d+$/)) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
key, true));
}
}
}
if (!hasOwnProperty(visibleKeys, key)) {
- if (isSymbol(key)) {
+ if (typeof key === 'symbol') {
name = '[' + ctx.stylize(key.toString(), 'symbol') + ']';
} else {
name = '[' + key + ']';
}
if (!str) {
if (ctx.seen.indexOf(desc.value) < 0) {
- if (isNull(recurseTimes)) {
+ if (recurseTimes === null) {
str = formatValue(ctx, desc.value, null);
} else {
str = formatValue(ctx, desc.value, recurseTimes - 1);
str = ctx.stylize('[Circular]', 'special');
}
}
- if (isUndefined(name)) {
+ if (name === undefined) {
if (array && key.match(/^\d+$/)) {
return str;
}
exports.isNull = isNull;
function isNullOrUndefined(arg) {
- return arg == null;
+ return arg === null || arg === undefined;
}
exports.isNullOrUndefined = isNullOrUndefined;
exports.isSymbol = isSymbol;
function isUndefined(arg) {
- return arg === void 0;
+ return arg === undefined;
}
exports.isUndefined = isUndefined;
function isRegExp(re) {
- return isObject(re) && objectToString(re) === '[object RegExp]';
+ return re !== null && typeof re === 'object' &&
+ objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
function isObject(arg) {
- return typeof arg === 'object' && arg !== null;
+ return arg !== null && typeof arg === 'object';
}
exports.isObject = isObject;
function isDate(d) {
- return isObject(d) && objectToString(d) === '[object Date]';
+ return d !== null && typeof d === 'object' &&
+ objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
function isError(e) {
- return isObject(e) &&
+ return e !== null && typeof e === 'object' &&
(objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;
exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
- if (!add || !isObject(add)) return origin;
+ if (add === null || typeof add !== 'object') return origin;
var keys = Object.keys(add);
var i = keys.length;
var uv;
exports._errnoException = function(err, syscall, original) {
- if (isUndefined(uv)) uv = process.binding('uv');
+ if (uv === undefined) uv = process.binding('uv');
var errname = uv.errname(err);
var message = syscall + ' ' + errname;
if (original)
const binding = process.binding('contextify');
const Script = binding.ContextifyScript;
-const util = require('util');
// The binding provides a few useful primitives:
// - ContextifyScript(code, { filename = "evalmachine.anonymous",
};
exports.createContext = function(sandbox) {
- if (util.isUndefined(sandbox)) {
+ if (sandbox === undefined) {
sandbox = {};
} else if (binding.isContext(sandbox)) {
return sandbox;
// Convenience methods.
// compress/decompress a string or buffer in one step.
exports.deflate = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.gzip = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.deflateRaw = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.unzip = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.inflate = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.gunzip = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
};
exports.inflateRaw = function(buffer, opts, callback) {
- if (util.isFunction(opts)) {
+ if (typeof opts === 'function') {
callback = opts;
opts = {};
}
}
function zlibBufferSync(engine, buffer) {
- if (util.isString(buffer))
+ if (typeof buffer === 'string')
buffer = new Buffer(buffer);
- if (!util.isBuffer(buffer))
+ if (!(buffer instanceof Buffer))
throw new TypeError('Not a string or buffer');
var flushFlag = binding.Z_FINISH;
}
if (opts.dictionary) {
- if (!util.isBuffer(opts.dictionary)) {
+ if (!(opts.dictionary instanceof Buffer)) {
throw new Error('Invalid dictionary: it should be a Buffer instance');
}
}
};
var level = exports.Z_DEFAULT_COMPRESSION;
- if (util.isNumber(opts.level)) level = opts.level;
+ if (typeof opts.level === 'number') level = opts.level;
var strategy = exports.Z_DEFAULT_STRATEGY;
- if (util.isNumber(opts.strategy)) strategy = opts.strategy;
+ if (typeof opts.strategy === 'number') strategy = opts.strategy;
this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
level,
Zlib.prototype.flush = function(kind, callback) {
var ws = this._writableState;
- if (util.isFunction(kind) || (util.isUndefined(kind) && !callback)) {
+ if (typeof kind === 'function' || (kind === undefined && !callback)) {
callback = kind;
kind = binding.Z_FULL_FLUSH;
}
var ending = ws.ending || ws.ended;
var last = ending && (!chunk || ws.length === chunk.length);
- if (!util.isNull(chunk) && !util.isBuffer(chunk))
+ if (chunk !== null && !(chunk instanceof Buffer))
return cb(new Error('invalid input'));
if (this._closed)
var self = this;
- var async = util.isFunction(cb);
+ var async = typeof cb === 'function';
if (!async) {
var buffers = [];