diff --git a/binary.js b/binary.js index b31f40c..d2c6d69 100644 --- a/binary.js +++ b/binary.js @@ -34,7 +34,7 @@ exports.deconstructPacket = function(packet){ newData[i] = _deconstructPacket(data[i]); } return newData; - } else if ('object' == typeof data && !(data instanceof Date)) { + } else if (typeof data === 'object' && !(data instanceof Date)) { var newData = {}; for (var key in data) { newData[key] = _deconstructPacket(data[key]); @@ -71,7 +71,7 @@ exports.reconstructPacket = function(packet, buffers) { data[i] = _reconstructPacket(data[i]); } return data; - } else if (data && 'object' == typeof data) { + } else if (data && 'object' === typeof data) { for (var key in data) { data[key] = _reconstructPacket(data[key]); } @@ -125,7 +125,7 @@ exports.removeBlobs = function(data, callback) { for (var i = 0; i < obj.length; i++) { _removeBlobs(obj[i], i, obj); } - } else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object + } else if (obj && 'object' === typeof obj && !isBuf(obj)) { // and object for (var key in obj) { _removeBlobs(obj[key], key, obj); } diff --git a/index.js b/index.js index 165a4a6..f453c0e 100644 --- a/index.js +++ b/index.js @@ -126,7 +126,7 @@ function Encoder() {} Encoder.prototype.encode = function(obj, callback){ debug('encoding packet %j', obj); - if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) { + if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) { encodeAsBinary(obj, callback); } else { @@ -151,14 +151,14 @@ function encodeAsString(obj) { str += obj.type; // attachments if we have them - if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) { + if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) { str += obj.attachments; str += '-'; } // if we have a namespace other than `/` // we append it followed by a comma `,` - if (obj.nsp && '/' != obj.nsp) { + if (obj.nsp && '/' !== obj.nsp) { nsp = true; str += obj.nsp; } @@ -233,9 +233,9 @@ Emitter(Decoder.prototype); Decoder.prototype.add = function(obj) { var packet; - if ('string' == typeof obj) { + if (typeof obj === 'string') { packet = decodeString(obj); - if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json + if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json this.reconstructor = new BinaryReconstructor(packet); // no attachments, labeled binary but no binary data to follow @@ -281,24 +281,24 @@ function decodeString(str) { // look up attachments if type binary if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) { var buf = ''; - while (str.charAt(++i) != '-') { + while (str.charAt(++i) !== '-') { buf += str.charAt(i); if (i == str.length) break; } - if (buf != Number(buf) || str.charAt(i) != '-') { + if (buf != Number(buf) || str.charAt(i) !== '-') { throw new Error('Illegal attachments'); } p.attachments = Number(buf); } // look up namespace (if any) - if ('/' == str.charAt(i + 1)) { + if ('/' === str.charAt(i + 1)) { p.nsp = ''; while (++i) { var c = str.charAt(i); - if (',' == c) break; + if (',' === c) break; p.nsp += c; - if (i == str.length) break; + if (i === str.length) break; } } else { p.nsp = '/'; @@ -315,7 +315,7 @@ function decodeString(str) { break; } p.id += str.charAt(i); - if (i == str.length) break; + if (i === str.length) break; } p.id = Number(p.id); } @@ -336,7 +336,7 @@ function tryParse(p, str) { return error(); } return p; -}; +} /** * Deallocates a parser's resources @@ -377,7 +377,7 @@ function BinaryReconstructor(packet) { BinaryReconstructor.prototype.takeBinaryData = function(binData) { this.buffers.push(binData); - if (this.buffers.length == this.reconPack.attachments) { // done with buffer list + if (this.buffers.length === this.reconPack.attachments) { // done with buffer list var packet = binary.reconstructPacket(this.reconPack, this.buffers); this.finishedReconstruction(); return packet;