diff --git a/.travis.yml b/.travis.yml index ddf8173..d01efa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,8 @@ language: node_js sudo: false node_js: - - '4' - - '6' - '8' - - node -notifications: - irc: 'irc.freenode.org##socket.io' + - '10' git: depth: 1 matrix: diff --git a/Makefile b/Makefile index 2942f60..5bbd22a 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,14 @@ -REPORTER = dot +help: ## print this message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' -test: +test: ## run tests either in the browser or in Node.js, based on the `BROWSERS` variable @if [ "x$(BROWSERS)" = "x" ]; then make test-node; else make test-zuul; fi -test-node: - @./node_modules/.bin/mocha \ - --reporter $(REPORTER) \ - --bail \ - test/index.js +test-node: ## run tests in Node.js + @./node_modules/.bin/mocha --reporter dot --bail test/index.js -test-zuul: - @./node_modules/zuul/bin/zuul \ - test/index.js +test-zuul: ## run tests in the browser + @./node_modules/zuul/bin/zuul test/index.js -.PHONY: test +.PHONY: help test test-node test-zuul diff --git a/Readme.md b/Readme.md index 2463bc7..ac22117 100644 --- a/Readme.md +++ b/Readme.md @@ -54,7 +54,7 @@ var packet = { encoder.encode(packet, function(encodedPackets) { var decoder = new parser.Decoder(); decoder.on('decoded', function(decodedPacket) { - // decodedPacket.type == parser.BINARY_EVENTEVENT + // decodedPacket.type == parser.BINARY_EVENT // Buffer.isBuffer(decodedPacket.data.i) == true // Buffer.isBuffer(decodedPacket.data.j) == true // decodedPacket.id == 15 diff --git a/binary.js b/binary.js index 1a530c7..3e2347d 100644 --- a/binary.js +++ b/binary.js @@ -7,8 +7,8 @@ var isArray = require('isarray'); var isBuf = require('./is-buffer'); var toString = Object.prototype.toString; -var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]'; -var withNativeFile = typeof global.File === 'function' || toString.call(global.File) === '[object FileConstructor]'; +var withNativeBlob = typeof Blob === 'function' || (typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]'); +var withNativeFile = typeof File === 'function' || (typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]'); /** * Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder. diff --git a/index.js b/index.js index daa242c..102615a 100644 --- a/index.js +++ b/index.js @@ -229,7 +229,7 @@ function Decoder() { Emitter(Decoder.prototype); /** - * Decodes an ecoded packet string into packet JSON. + * Decodes an encoded packet string into packet JSON. * * @param {String} obj - encoded packet * @return {Object} packet @@ -250,8 +250,7 @@ Decoder.prototype.add = function(obj) { } else { // non-binary full packet this.emit('decoded', packet); } - } - else if (isBuf(obj) || obj.base64) { // raw binary data + } else if (isBuf(obj) || obj.base64) { // raw binary data if (!this.reconstructor) { throw new Error('got binary data when not reconstructing a packet'); } else { @@ -261,8 +260,7 @@ Decoder.prototype.add = function(obj) { this.emit('decoded', packet); } } - } - else { + } else { throw new Error('Unknown type: ' + obj); } }; diff --git a/is-buffer.js b/is-buffer.js index 9f451a4..c833865 100644 --- a/is-buffer.js +++ b/is-buffer.js @@ -1,16 +1,12 @@ module.exports = isBuf; -var withNativeBuffer = typeof global.Buffer === 'function' && typeof global.Buffer.isBuffer === 'function'; -var withNativeArrayBuffer = typeof global.ArrayBuffer === 'function'; +var withNativeBuffer = typeof Buffer === 'function' && typeof Buffer.isBuffer === 'function'; +var withNativeArrayBuffer = typeof ArrayBuffer === 'function'; -var isView = (function () { - if (withNativeArrayBuffer && typeof global.ArrayBuffer.isView === 'function') { - return global.ArrayBuffer.isView; - } else { - return function (obj) { return obj.buffer instanceof global.ArrayBuffer; }; - } -})(); +var isView = function (obj) { + return typeof ArrayBuffer.isView === 'function' ? ArrayBuffer.isView(obj) : (obj.buffer instanceof ArrayBuffer); +}; /** * Returns true if obj is a buffer or an arraybuffer. @@ -19,6 +15,6 @@ var isView = (function () { */ function isBuf(obj) { - return (withNativeBuffer && global.Buffer.isBuffer(obj)) || - (withNativeArrayBuffer && (obj instanceof global.ArrayBuffer || isView(obj))); + return (withNativeBuffer && Buffer.isBuffer(obj)) || + (withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))); } diff --git a/package.json b/package.json index ba5067a..f95861d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "socket.io-parser", - "version": "3.2.0", + "version": "3.3.0", "description": "socket.io protocol parser", "repository": { "type": "git", diff --git a/test/blob.js b/test/blob.js index 31d4b24..4e101fe 100644 --- a/test/blob.js +++ b/test/blob.js @@ -1,10 +1,10 @@ var parser = require('../index.js'); -var expect = require('expect.js'); var helpers = require('./helpers.js'); -var encode = parser.encode; -var decode = parser.decode; -var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder || global.MozBlobBuilder; +var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : + typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder : + typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : + typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : false; describe('parser', function() { it('encodes a Blob', function() { diff --git a/test/index.js b/test/index.js index ba6ce75..9d4a1cb 100644 --- a/test/index.js +++ b/test/index.js @@ -12,7 +12,10 @@ var blobSupported = (function() { * Create a blob builder even when vendor prefixes exist */ -var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder || global.MozBlobBuilder; +var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : + typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder : + typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : + typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : false; var blobBuilderSupported = !!BlobBuilder && !!BlobBuilder.prototype.append && !!BlobBuilder.prototype.getBlob; require('./parser.js'); @@ -21,7 +24,7 @@ if (!env.browser) { require('./buffer.js'); } -if (global.ArrayBuffer) { +if (typeof ArrayBuffer !== 'undefined') { require('./arraybuffer.js'); } diff --git a/test/support/env.js b/test/support/env.js index c1d494e..0b4873d 100644 --- a/test/support/env.js +++ b/test/support/env.js @@ -2,4 +2,4 @@ // we only do this in our tests because we need to test engine.io-client // support in browsers and in node.js // some tests do not yet work in both -module.exports.browser = !!global.window; +module.exports.browser = typeof window !== 'undefined';
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: