diff --git a/dist/gpx-parse-browser.js b/dist/gpx-parse-browser.js index 11733be..5152aed 100644 --- a/dist/gpx-parse-browser.js +++ b/dist/gpx-parse-browser.js @@ -6,7 +6,7 @@ exports.empty = null; module.exports = process.env.GPXPARSE_COV ? require('./lib-cov/gpx-parse') : require('./lib/gpx-parse'); }).call(this,require('_process')) -},{"./lib-cov/gpx-parse":"./lib-cov/gpx-parse","./lib/gpx-parse":3,"_process":21}],2:[function(require,module,exports){ +},{"./lib-cov/gpx-parse":"./lib-cov/gpx-parse","./lib/gpx-parse":3,"_process":22}],2:[function(require,module,exports){ /** * Contians utility functions for calculating values on geometries * @module geomutils @@ -43,7 +43,7 @@ exports.calculateDistance = function(lat1, lon1, lat2, lon2) { var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - return greatCircleRadius.miles * c; + return greatCircleRadius.km * c; }; /** @@ -308,7 +308,7 @@ exports.utils = geomUtils; * @param {GpxResult} response The parsed gpx file object */ -},{"./geomUtils":2,"./gpxExtent":4,"./gpxMetaData":5,"./gpxResult":6,"./gpxRoute":7,"./gpxTrack":8,"./gpxWaypoint":9,"assert":11,"fs":10,"http":40,"https":18,"url":50,"xml2js":56}],4:[function(require,module,exports){ +},{"./geomUtils":2,"./gpxExtent":4,"./gpxMetaData":5,"./gpxResult":6,"./gpxRoute":7,"./gpxTrack":8,"./gpxWaypoint":9,"assert":11,"fs":10,"http":41,"https":18,"url":52,"xml2js":58}],4:[function(require,module,exports){ /** * Contructor for gpx extent * @classdesc Stores an extent. @@ -1032,15 +1032,17 @@ var objectKeys = Object.keys || function (obj) { return keys; }; -},{"util/":52}],12:[function(require,module,exports){ +},{"util/":54}],12:[function(require,module,exports){ arguments[4][10][0].apply(exports,arguments) },{"dup":10}],13:[function(require,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ +/* eslint-disable no-proto */ var base64 = require('base64-js') var ieee754 = require('ieee754') @@ -1080,7 +1082,11 @@ var rootParent = {} * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they * get the Object implementation, which is slower but behaves correctly. */ -Buffer.TYPED_ARRAY_SUPPORT = (function () { +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { function Bar () {} try { var arr = new Uint8Array(1) @@ -1093,7 +1099,7 @@ Buffer.TYPED_ARRAY_SUPPORT = (function () { } catch (e) { return false } -})() +} function kMaxLength () { return Buffer.TYPED_ARRAY_SUPPORT @@ -1249,10 +1255,16 @@ function fromJsonObject (that, object) { return that } +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} + function allocate (that, length) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class that.length = length @@ -1660,20 +1672,99 @@ function base64Slice (buf, start, end) { } function utf8Slice (buf, start, end) { - var res = '' - var tmp = '' end = Math.min(buf.length, end) + var res = [] + + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } + } - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF } + + res.push(codePoint) + i += bytesPerSequence + } + + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() } - return res + decodeUtf8Char(tmp) + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res } function asciiSlice (buf, start, end) { @@ -1962,7 +2053,7 @@ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -1979,7 +2070,7 @@ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -1993,7 +2084,7 @@ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -2015,7 +2106,7 @@ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert this[offset + 3] = (value >>> 24) this[offset + 2] = (value >>> 16) this[offset + 1] = (value >>> 8) - this[offset] = value + this[offset] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, true) } @@ -2030,7 +2121,7 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -2083,7 +2174,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 - this[offset] = value + this[offset] = (value & 0xff) return offset + 1 } @@ -2092,7 +2183,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) } else { objectWriteUInt16(this, value, offset, true) @@ -2106,7 +2197,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) - this[offset + 1] = value + this[offset + 1] = (value & 0xff) } else { objectWriteUInt16(this, value, offset, false) } @@ -2118,7 +2209,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = value + this[offset] = (value & 0xff) this[offset + 1] = (value >>> 8) this[offset + 2] = (value >>> 16) this[offset + 3] = (value >>> 24) @@ -2137,7 +2228,7 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) this[offset] = (value >>> 24) this[offset + 1] = (value >>> 16) this[offset + 2] = (value >>> 8) - this[offset + 3] = value + this[offset + 3] = (value & 0xff) } else { objectWriteUInt32(this, value, offset, false) } @@ -2379,28 +2470,15 @@ function utf8ToBytes (string, units) { var length = string.length var leadSurrogate = null var bytes = [] - var i = 0 - for (; i < length; i++) { + for (var i = 0; i < length; i++) { codePoint = string.charCodeAt(i) // is surrogate component if (codePoint > 0xD7FF && codePoint < 0xE000) { // last char was a lead - if (leadSurrogate) { - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } else { - // valid surrogate pair - codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 - leadSurrogate = null - } - } else { + if (!leadSurrogate) { // no lead yet - if (codePoint > 0xDBFF) { // unexpected trail if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) @@ -2409,18 +2487,30 @@ function utf8ToBytes (string, units) { // unpaired lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) continue - } else { - // valid lead - leadSurrogate = codePoint - continue } + + // valid lead + leadSurrogate = codePoint + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue } + + // valid surrogate pair + codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 } else if (leadSurrogate) { // valid bmp char, but last char was a lead if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = null } + leadSurrogate = null + // encode utf8 if (codePoint < 0x80) { if ((units -= 1) < 0) break @@ -2438,7 +2528,7 @@ function utf8ToBytes (string, units) { codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80 ) - } else if (codePoint < 0x200000) { + } else if (codePoint < 0x110000) { if ((units -= 4) < 0) break bytes.push( codePoint >> 0x12 | 0xF0, @@ -2491,14 +2581,7 @@ function blitBuffer (src, dst, offset, length) { return i } -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} - +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"base64-js":14,"ieee754":15,"is-array":16}],14:[function(require,module,exports){ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; @@ -3061,10 +3144,11 @@ for (var key in http) { https.request = function (params, cb) { if (!params) params = {}; params.scheme = 'https'; + params.protocol = 'https:'; return http.request.call(this, params, cb); } -},{"http":40}],19:[function(require,module,exports){ +},{"http":41}],19:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -3090,11 +3174,30 @@ if (typeof Object.create === 'function') { } },{}],20:[function(require,module,exports){ +/** + * Determine if an object is Buffer + * + * Author: Feross Aboukhadijeh + * License: MIT + * + * `npm install is-buffer` + */ + +module.exports = function (obj) { + return !!(obj != null && + (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor) + (obj.constructor && + typeof obj.constructor.isBuffer === 'function' && + obj.constructor.isBuffer(obj)) + )) +} + +},{}],21:[function(require,module,exports){ module.exports = Array.isArray || function (arr) { return Object.prototype.toString.call(arr) == '[object Array]'; }; -},{}],21:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -3127,7 +3230,9 @@ function drainQueue() { currentQueue = queue; queue = []; while (++queueIndex < len) { - currentQueue[queueIndex].run(); + if (currentQueue) { + currentQueue[queueIndex].run(); + } } queueIndex = -1; len = queue.length; @@ -3179,14 +3284,13 @@ process.binding = function (name) { throw new Error('process.binding is not supported'); }; -// TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; -},{}],22:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ (function (global){ /*! https://mths.be/punycode v1.3.2 by @mathias */ ;(function(root) { @@ -3720,7 +3824,7 @@ process.umask = function() { return 0; }; }(this)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],23:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -3806,7 +3910,7 @@ var isArray = Array.isArray || function (xs) { return Object.prototype.toString.call(xs) === '[object Array]'; }; -},{}],24:[function(require,module,exports){ +},{}],25:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -3893,16 +3997,16 @@ var objectKeys = Object.keys || function (obj) { return res; }; -},{}],25:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ 'use strict'; exports.decode = exports.parse = require('./decode'); exports.encode = exports.stringify = require('./encode'); -},{"./decode":23,"./encode":24}],26:[function(require,module,exports){ +},{"./decode":24,"./encode":25}],27:[function(require,module,exports){ module.exports = require("./lib/_stream_duplex.js") -},{"./lib/_stream_duplex.js":27}],27:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":28}],28:[function(require,module,exports){ // a duplex stream is just a stream that is both readable and writable. // Since JS doesn't have multiple prototypal inheritance, this class // prototypally inherits from Readable, and then parasitically from @@ -3986,7 +4090,7 @@ function forEach (xs, f) { } } -},{"./_stream_readable":29,"./_stream_writable":31,"core-util-is":32,"inherits":19,"process-nextick-args":33}],28:[function(require,module,exports){ +},{"./_stream_readable":30,"./_stream_writable":32,"core-util-is":33,"inherits":19,"process-nextick-args":34}],29:[function(require,module,exports){ // a passthrough stream. // basically just the most minimal sort of Transform stream. // Every written chunk gets output as-is. @@ -4015,7 +4119,7 @@ PassThrough.prototype._transform = function(chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":30,"core-util-is":32,"inherits":19}],29:[function(require,module,exports){ +},{"./_stream_transform":31,"core-util-is":33,"inherits":19}],30:[function(require,module,exports){ (function (process){ 'use strict'; @@ -4037,10 +4141,10 @@ var Buffer = require('buffer').Buffer; Readable.ReadableState = ReadableState; -var EE = require('events').EventEmitter; +var EE = require('events'); /**/ -if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { +var EElistenerCount = function(emitter, type) { return emitter.listeners(type).length; }; /**/ @@ -4067,9 +4171,10 @@ util.inherits = require('inherits'); /**/ -var debug = require('util'); -if (debug && debug.debuglog) { - debug = debug.debuglog('stream'); +var debugUtil = require('util'); +var debug; +if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); } else { debug = function () {}; } @@ -4238,7 +4343,6 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { } - // if it's past the high water mark, we can push in some more. // Also, if we have no data yet, we can stand some // more bytes. This is to work around cases where hwm=0, @@ -4262,15 +4366,19 @@ Readable.prototype.setEncoding = function(enc) { return this; }; -// Don't raise the hwm > 128MB +// Don't raise the hwm > 8MB var MAX_HWM = 0x800000; -function roundUpToNextPowerOf2(n) { +function computeNewHighWaterMark(n) { if (n >= MAX_HWM) { n = MAX_HWM; } else { // Get the next highest power of 2 n--; - for (var p = 1; p < 32; p <<= 1) n |= n >> p; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; n++; } return n; @@ -4299,7 +4407,7 @@ function howMuchToRead(n, state) { // power of 2, to prevent increasing it excessively in tiny // amounts. if (n > state.highWaterMark) - state.highWaterMark = roundUpToNextPowerOf2(n); + state.highWaterMark = computeNewHighWaterMark(n); // don't have that much. return null, unless we've ended. if (n > state.length) { @@ -4605,7 +4713,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { debug('onerror', er); unpipe(); dest.removeListener('error', onerror); - if (EE.listenerCount(dest, 'error') === 0) + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); } // This is a brutally ugly hack to make sure that our error handler @@ -4618,7 +4726,6 @@ Readable.prototype.pipe = function(dest, pipeOpts) { dest._events.error = [onerror, dest._events.error]; - // Both close and finish should trigger unpipe, but only once. function onclose() { dest.removeListener('finish', onfinish); @@ -4655,7 +4762,7 @@ function pipeOnDrain(src) { debug('pipeOnDrain', state.awaitDrain); if (state.awaitDrain) state.awaitDrain--; - if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) { + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { state.flowing = true; flow(src); } @@ -4871,7 +4978,6 @@ Readable.prototype.wrap = function(stream) { }; - // exposed for testing purposes only. Readable._fromList = fromList; @@ -4978,7 +5084,7 @@ function indexOf (xs, x) { } }).call(this,require('_process')) -},{"./_stream_duplex":27,"_process":21,"buffer":13,"core-util-is":32,"events":17,"inherits":19,"isarray":20,"process-nextick-args":33,"string_decoder/":49,"util":12}],30:[function(require,module,exports){ +},{"./_stream_duplex":28,"_process":22,"buffer":13,"core-util-is":33,"events":17,"inherits":19,"isarray":21,"process-nextick-args":34,"string_decoder/":50,"util":12}],31:[function(require,module,exports){ // a transform stream is a readable/writable stream where you do // something with the data. Sometimes it's called a "filter", // but that's not a great name for it, since that implies a thing where @@ -5177,7 +5283,7 @@ function done(stream, er) { return stream.push(null); } -},{"./_stream_duplex":27,"core-util-is":32,"inherits":19}],31:[function(require,module,exports){ +},{"./_stream_duplex":28,"core-util-is":33,"inherits":19}],32:[function(require,module,exports){ // A bit simpler than readable streams. // Implement an async ._write(chunk, cb), and it'll handle all // the drain event emission and buffering. @@ -5204,6 +5310,13 @@ util.inherits = require('inherits'); /**/ +/**/ +var internalUtil = { + deprecate: require('util-deprecate') +}; +/**/ + + /**/ var Stream; @@ -5329,10 +5442,10 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() { (function (){try { Object.defineProperty(WritableState.prototype, 'buffer', { - get: require('util-deprecate')(function() { + get: internalUtil.deprecate(function() { return this.getBuffer(); - }, '_writableState.buffer is deprecated. Use ' + - '_writableState.getBuffer() instead.') + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + + 'instead.') }); }catch(_){}}()); @@ -5699,7 +5812,7 @@ function endWritable(stream, state, cb) { state.ended = true; } -},{"./_stream_duplex":27,"buffer":13,"core-util-is":32,"events":17,"inherits":19,"process-nextick-args":33,"util-deprecate":34}],32:[function(require,module,exports){ +},{"./_stream_duplex":28,"buffer":13,"core-util-is":33,"events":17,"inherits":19,"process-nextick-args":34,"util-deprecate":35}],33:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -5808,8 +5921,8 @@ exports.isBuffer = isBuffer; function objectToString(o) { return Object.prototype.toString.call(o); } -}).call(this,require("buffer").Buffer) -},{"buffer":13}],33:[function(require,module,exports){ +}).call(this,{"isBuffer":require("../../../../insert-module-globals/node_modules/is-buffer/index.js")}) +},{"../../../../insert-module-globals/node_modules/is-buffer/index.js":20}],34:[function(require,module,exports){ (function (process){ 'use strict'; module.exports = nextTick; @@ -5817,7 +5930,7 @@ module.exports = nextTick; function nextTick(fn) { var args = new Array(arguments.length - 1); var i = 0; - while (i < arguments.length) { + while (i < args.length) { args[i++] = arguments[i]; } process.nextTick(function afterTick() { @@ -5826,7 +5939,7 @@ function nextTick(fn) { } }).call(this,require('_process')) -},{"_process":21}],34:[function(require,module,exports){ +},{"_process":22}],35:[function(require,module,exports){ (function (global){ /** @@ -5885,17 +5998,22 @@ function deprecate (fn, msg) { */ function config (name) { - if (!global.localStorage) return false; + // accessing global.localStorage can trigger a DOMException in sandboxed iframes + try { + if (!global.localStorage) return false; + } catch (_) { + return false; + } var val = global.localStorage[name]; if (null == val) return false; return String(val).toLowerCase() === 'true'; } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],35:[function(require,module,exports){ +},{}],36:[function(require,module,exports){ module.exports = require("./lib/_stream_passthrough.js") -},{"./lib/_stream_passthrough.js":28}],36:[function(require,module,exports){ +},{"./lib/_stream_passthrough.js":29}],37:[function(require,module,exports){ var Stream = (function (){ try { return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify @@ -5909,13 +6027,13 @@ exports.Duplex = require('./lib/_stream_duplex.js'); exports.Transform = require('./lib/_stream_transform.js'); exports.PassThrough = require('./lib/_stream_passthrough.js'); -},{"./lib/_stream_duplex.js":27,"./lib/_stream_passthrough.js":28,"./lib/_stream_readable.js":29,"./lib/_stream_transform.js":30,"./lib/_stream_writable.js":31}],37:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":28,"./lib/_stream_passthrough.js":29,"./lib/_stream_readable.js":30,"./lib/_stream_transform.js":31,"./lib/_stream_writable.js":32}],38:[function(require,module,exports){ module.exports = require("./lib/_stream_transform.js") -},{"./lib/_stream_transform.js":30}],38:[function(require,module,exports){ +},{"./lib/_stream_transform.js":31}],39:[function(require,module,exports){ module.exports = require("./lib/_stream_writable.js") -},{"./lib/_stream_writable.js":31}],39:[function(require,module,exports){ +},{"./lib/_stream_writable.js":32}],40:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -6044,7 +6162,7 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"events":17,"inherits":19,"readable-stream/duplex.js":26,"readable-stream/passthrough.js":35,"readable-stream/readable.js":36,"readable-stream/transform.js":37,"readable-stream/writable.js":38}],40:[function(require,module,exports){ +},{"events":17,"inherits":19,"readable-stream/duplex.js":27,"readable-stream/passthrough.js":36,"readable-stream/readable.js":37,"readable-stream/transform.js":38,"readable-stream/writable.js":39}],41:[function(require,module,exports){ var ClientRequest = require('./lib/request') var extend = require('xtend') var statusCodes = require('builtin-status-codes') @@ -6058,19 +6176,19 @@ http.request = function (opts, cb) { else opts = extend(opts) - // Split opts.host into its components - var hostHostname = opts.host ? opts.host.split(':')[0] : null - var hostPort = opts.host ? parseInt(opts.host.split(':')[1], 10) : null + var protocol = opts.protocol || '' + var host = opts.hostname || opts.host + var port = opts.port + var path = opts.path || '/' + + // Necessary for IPv6 addresses + if (host && host.indexOf(':') !== -1) + host = '[' + host + ']' - opts.method = opts.method || 'GET' + // This may be a relative url. The browser should always be able to interpret it correctly. + opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path + opts.method = (opts.method || 'GET').toUpperCase() opts.headers = opts.headers || {} - opts.path = opts.path || '/' - opts.protocol = opts.protocol || window.location.protocol - // If the hostname is provided, use the default port for the protocol. If - // the url is instead relative, use window.location.port - var defaultPort = (opts.hostname || hostHostname) ? (opts.protocol === 'https:' ? 443 : 80) : window.location.port - opts.hostname = opts.hostname || hostHostname || window.location.hostname - opts.port = opts.port || hostPort || defaultPort // Also valid opts.auth, opts.mode @@ -6092,14 +6210,36 @@ http.Agent.defaultMaxSockets = 4 http.STATUS_CODES = statusCodes http.METHODS = [ + 'CHECKOUT', + 'CONNECT', + 'COPY', + 'DELETE', 'GET', + 'HEAD', + 'LOCK', + 'M-SEARCH', + 'MERGE', + 'MKACTIVITY', + 'MKCOL', + 'MOVE', + 'NOTIFY', + 'OPTIONS', + 'PATCH', 'POST', + 'PROPFIND', + 'PROPPATCH', + 'PURGE', 'PUT', - 'DELETE' // TODO: include the methods from RFC 2616 and 2518? + 'REPORT', + 'SEARCH', + 'SUBSCRIBE', + 'TRACE', + 'UNLOCK', + 'UNSUBSCRIBE' ] - -},{"./lib/request":42,"builtin-status-codes":44,"url":50,"xtend":53}],41:[function(require,module,exports){ -exports.fetch = isFunction(window.fetch) && isFunction(window.ReadableByteStream) +},{"./lib/request":43,"builtin-status-codes":45,"url":52,"xtend":55}],42:[function(require,module,exports){ +(function (global){ +exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream) exports.blobConstructor = false try { @@ -6107,8 +6247,10 @@ try { exports.blobConstructor = true } catch (e) {} -var xhr = new window.XMLHttpRequest() -xhr.open('GET', '/') +var xhr = new global.XMLHttpRequest() +// If location.host is empty, e.g. if this page/worker was loaded +// from a Blob, then use example.com to avoid an error +xhr.open('GET', global.location.host ? '/' : 'https://example.com') function checkTypeSupport (type) { try { @@ -6118,14 +6260,19 @@ function checkTypeSupport (type) { return false } -var haveArrayBuffer = isFunction(window.ArrayBuffer) -var haveSlice = haveArrayBuffer && isFunction(window.ArrayBuffer.prototype.slice) +// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'. +// Safari 7.1 appears to have fixed this bug. +var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined' +var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice) exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer') -exports.msstream = haveSlice && checkTypeSupport('ms-stream') -exports.mozchunkedarraybuffer = haveArrayBuffer && checkTypeSupport('moz-chunked-arraybuffer') +// These next two tests unavoidably show warnings in Chrome. Since fetch will always +// be used if it's available, just return false for these to avoid the warnings. +exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream') +exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer && + checkTypeSupport('moz-chunked-arraybuffer') exports.overrideMimeType = isFunction(xhr.overrideMimeType) -exports.vbArray = isFunction(window.VBArray) +exports.vbArray = isFunction(global.VBArray) function isFunction (value) { return typeof value === 'function' @@ -6133,8 +6280,9 @@ function isFunction (value) { xhr = null // Help gc -},{}],42:[function(require,module,exports){ -(function (process,Buffer){ +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],43:[function(require,module,exports){ +(function (process,global,Buffer){ // var Base64 = require('Base64') var capability = require('./capability') var foreach = require('foreach') @@ -6168,7 +6316,6 @@ var ClientRequest = module.exports = function (opts) { stream.Writable.call(self) self._opts = opts - self._url = opts.protocol + '//' + opts.hostname + ':' + opts.port + opts.path self._body = [] self._headers = {} if (opts.auth) @@ -6179,14 +6326,15 @@ var ClientRequest = module.exports = function (opts) { var preferBinary if (opts.mode === 'prefer-streaming') { - // If streaming is a high priority but binary compatibility isn't + // If streaming is a high priority but binary compatibility and + // the accuracy of the 'content-type' header aren't preferBinary = false - } else if (opts.mode === 'prefer-fast') { - // If binary is preferred for speed - preferBinary = true - } else if (!opts.mode || opts.mode === 'default') { - // By default, use binary if text streaming may corrupt data + } else if (opts.mode === 'allow-wrong-content-type') { + // If streaming is more important than preserving the 'content-type' header preferBinary = !capability.overrideMimeType + } else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') { + // Use binary if text streaming may corrupt data or the content-type header, or for speed + preferBinary = true } else { throw new Error('Invalid value for opts.mode') } @@ -6235,7 +6383,7 @@ ClientRequest.prototype._onFinish = function () { var body if (opts.method === 'POST' || opts.method === 'PUT') { if (capability.blobConstructor) { - body = new window.Blob(self._body.map(function (buffer) { + body = new global.Blob(self._body.map(function (buffer) { return buffer.toArrayBuffer() }), { type: (headersObj['content-type'] || {}).value || '' @@ -6251,7 +6399,7 @@ ClientRequest.prototype._onFinish = function () { return [headersObj[name].name, headersObj[name].value] }) - window.fetch(self._url, { + global.fetch(self._opts.url, { method: self._opts.method, headers: headers, body: body, @@ -6264,9 +6412,9 @@ ClientRequest.prototype._onFinish = function () { self.emit('error', reason) }) } else { - var xhr = self._xhr = new window.XMLHttpRequest() + var xhr = self._xhr = new global.XMLHttpRequest() try { - xhr.open(self._opts.method, self._url, true) + xhr.open(self._opts.method, self._opts.url, true) } catch (err) { process.nextTick(function () { self.emit('error', err) @@ -6381,10 +6529,7 @@ ClientRequest.prototype.end = function (data, encoding, cb) { data = undefined } - if (data) - stream.Writable.push.call(self, data, encoding) - - stream.Writable.prototype.end.call(self, cb) + stream.Writable.prototype.end.call(self, data, encoding, cb) } ClientRequest.prototype.flushHeaders = function () {} @@ -6417,9 +6562,9 @@ var unsafeHeaders = [ 'via' ] -}).call(this,require('_process'),require("buffer").Buffer) -},{"./capability":41,"./response":43,"_process":21,"buffer":13,"foreach":45,"indexof":46,"inherits":19,"object-keys":47,"stream":39}],43:[function(require,module,exports){ -(function (process,Buffer){ +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) +},{"./capability":42,"./response":44,"_process":22,"buffer":13,"foreach":46,"indexof":47,"inherits":19,"object-keys":48,"stream":40}],44:[function(require,module,exports){ +(function (process,global,Buffer){ var capability = require('./capability') var foreach = require('foreach') var inherits = require('inherits') @@ -6529,7 +6674,7 @@ IncomingMessage.prototype._onXHRProgress = function () { break try { // This fails in IE8 - response = new window.VBArray(xhr.responseBody).toArray() + response = new global.VBArray(xhr.responseBody).toArray() } catch (e) {} if (response !== null) { self.push(new Buffer(response)) @@ -6573,7 +6718,7 @@ IncomingMessage.prototype._onXHRProgress = function () { response = xhr.response if (xhr.readyState !== rStates.LOADING) break - var reader = new window.MSStreamReader() + var reader = new global.MSStreamReader() reader.onprogress = function () { if (reader.result.byteLength > self._pos) { self.push(new Buffer(new Uint8Array(reader.result.slice(self._pos)))) @@ -6594,8 +6739,8 @@ IncomingMessage.prototype._onXHRProgress = function () { } } -}).call(this,require('_process'),require("buffer").Buffer) -},{"./capability":41,"_process":21,"buffer":13,"foreach":45,"inherits":19,"stream":39}],44:[function(require,module,exports){ +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) +},{"./capability":42,"_process":22,"buffer":13,"foreach":46,"inherits":19,"stream":40}],45:[function(require,module,exports){ module.exports = { "100": "Continue", "101": "Switching Protocols", @@ -6656,7 +6801,7 @@ module.exports = { "511": "Network Authentication Required" } -},{}],45:[function(require,module,exports){ +},{}],46:[function(require,module,exports){ var hasOwn = Object.prototype.hasOwnProperty; var toString = Object.prototype.toString; @@ -6680,7 +6825,7 @@ module.exports = function forEach (obj, fn, ctx) { }; -},{}],46:[function(require,module,exports){ +},{}],47:[function(require,module,exports){ var indexOf = [].indexOf; @@ -6691,7 +6836,7 @@ module.exports = function(arr, obj){ } return -1; }; -},{}],47:[function(require,module,exports){ +},{}],48:[function(require,module,exports){ 'use strict'; // modified from https://github.com/es-shims/es5-shim @@ -6699,7 +6844,7 @@ var has = Object.prototype.hasOwnProperty; var toStr = Object.prototype.toString; var slice = Array.prototype.slice; var isArgs = require('./isArguments'); -var hasDontEnumBug = !({ 'toString': null }).propertyIsEnumerable('toString'); +var hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'); var hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype'); var dontEnums = [ 'toString', @@ -6710,6 +6855,50 @@ var dontEnums = [ 'propertyIsEnumerable', 'constructor' ]; +var equalsConstructorPrototype = function (o) { + var ctor = o.constructor; + return ctor && ctor.prototype === o; +}; +var blacklistedKeys = { + $console: true, + $frame: true, + $frameElement: true, + $frames: true, + $parent: true, + $self: true, + $webkitIndexedDB: true, + $webkitStorageInfo: true, + $window: true +}; +var hasAutomationEqualityBug = (function () { + /* global window */ + if (typeof window === 'undefined') { return false; } + for (var k in window) { + try { + if (!blacklistedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { + try { + equalsConstructorPrototype(window[k]); + } catch (e) { + return true; + } + } + } catch (e) { + return true; + } + } + return false; +}()); +var equalsConstructorPrototypeIfNotBuggy = function (o) { + /* global window */ + if (typeof window === 'undefined' || !hasAutomationEqualityBug) { + return equalsConstructorPrototype(o); + } + try { + return equalsConstructorPrototype(o); + } catch (e) { + return false; + } +}; var keysShim = function keys(object) { var isObject = object !== null && typeof object === 'object'; @@ -6742,8 +6931,7 @@ var keysShim = function keys(object) { } if (hasDontEnumBug) { - var ctor = object.constructor; - var skipConstructor = ctor && ctor.prototype === object; + var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); for (var k = 0; k < dontEnums.length; ++k) { if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { @@ -6755,9 +6943,7 @@ var keysShim = function keys(object) { }; keysShim.shim = function shimObjectKeys() { - if (!Object.keys) { - Object.keys = keysShim; - } else { + if (Object.keys) { var keysWorksWithArguments = (function () { // Safari 5.0 bug return (Object.keys(arguments) || '').length === 2; @@ -6772,13 +6958,15 @@ keysShim.shim = function shimObjectKeys() { } }; } + } else { + Object.keys = keysShim; } return Object.keys || keysShim; }; module.exports = keysShim; -},{"./isArguments":48}],48:[function(require,module,exports){ +},{"./isArguments":49}],49:[function(require,module,exports){ 'use strict'; var toStr = Object.prototype.toString; @@ -6797,7 +6985,7 @@ module.exports = function isArguments(value) { return isArgs; }; -},{}],49:[function(require,module,exports){ +},{}],50:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -7020,7 +7208,84 @@ function base64DetectIncompleteChar(buffer) { this.charLength = this.charReceived ? 3 : 0; } -},{"buffer":13}],50:[function(require,module,exports){ +},{"buffer":13}],51:[function(require,module,exports){ +var nextTick = require('process/browser.js').nextTick; +var apply = Function.prototype.apply; +var slice = Array.prototype.slice; +var immediateIds = {}; +var nextImmediateId = 0; + +// DOM APIs, for completeness + +exports.setTimeout = function() { + return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout); +}; +exports.setInterval = function() { + return new Timeout(apply.call(setInterval, window, arguments), clearInterval); +}; +exports.clearTimeout = +exports.clearInterval = function(timeout) { timeout.close(); }; + +function Timeout(id, clearFn) { + this._id = id; + this._clearFn = clearFn; +} +Timeout.prototype.unref = Timeout.prototype.ref = function() {}; +Timeout.prototype.close = function() { + this._clearFn.call(window, this._id); +}; + +// Does not start the time, just sets up the members needed. +exports.enroll = function(item, msecs) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = msecs; +}; + +exports.unenroll = function(item) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = -1; +}; + +exports._unrefActive = exports.active = function(item) { + clearTimeout(item._idleTimeoutId); + + var msecs = item._idleTimeout; + if (msecs >= 0) { + item._idleTimeoutId = setTimeout(function onTimeout() { + if (item._onTimeout) + item._onTimeout(); + }, msecs); + } +}; + +// That's not how node.js implements it but the exposed api is the same. +exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) { + var id = nextImmediateId++; + var args = arguments.length < 2 ? false : slice.call(arguments, 1); + + immediateIds[id] = true; + + nextTick(function onNextTick() { + if (immediateIds[id]) { + // fn.call() is faster so we optimize for the common use-case + // @see http://jsperf.com/call-apply-segu + if (args) { + fn.apply(null, args); + } else { + fn.call(null); + } + // Prevent ids from leaking + exports.clearImmediate(id); + } + }); + + return id; +}; + +exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) { + delete immediateIds[id]; +}; +},{"process/browser.js":22}],52:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -7729,14 +7994,14 @@ function isNullOrUndefined(arg) { return arg == null; } -},{"punycode":22,"querystring":25}],51:[function(require,module,exports){ +},{"punycode":23,"querystring":26}],53:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],52:[function(require,module,exports){ +},{}],54:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -8326,7 +8591,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":51,"_process":21,"inherits":19}],53:[function(require,module,exports){ +},{"./support/isBuffer":53,"_process":22,"inherits":19}],55:[function(require,module,exports){ module.exports = extend function extend() { @@ -8345,9 +8610,10 @@ function extend() { return target } -},{}],54:[function(require,module,exports){ -// Generated by CoffeeScript 1.9.2 +},{}],56:[function(require,module,exports){ +// Generated by CoffeeScript 1.10.0 (function() { + "use strict"; var xml2js; xml2js = require('../lib/xml2js'); @@ -8362,9 +8628,10 @@ function extend() { }).call(this); -},{"../lib/xml2js":56}],55:[function(require,module,exports){ -// Generated by CoffeeScript 1.9.2 +},{"../lib/xml2js":58}],57:[function(require,module,exports){ +// Generated by CoffeeScript 1.10.0 (function() { + "use strict"; var prefixMatch; prefixMatch = new RegExp(/(?!xmlns)^.*:/); @@ -8388,12 +8655,20 @@ function extend() { return str; }; + exports.parseBooleans = function(str) { + if (/^(?:true|false)$/i.test(str)) { + str = str.toLowerCase() === 'true'; + } + return str; + }; + }).call(this); -},{}],56:[function(require,module,exports){ -// Generated by CoffeeScript 1.9.2 +},{}],58:[function(require,module,exports){ +// Generated by CoffeeScript 1.10.0 (function() { - var bom, builder, escapeCDATA, events, isEmpty, processName, processors, requiresCDATA, sax, wrapCDATA, + "use strict"; + var bom, builder, escapeCDATA, events, isEmpty, processName, processors, requiresCDATA, sax, setImmediate, wrapCDATA, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; @@ -8408,6 +8683,8 @@ function extend() { processors = require('./processors'); + setImmediate = require('timers').setImmediate; + isEmpty = function(thing) { return typeof thing === "object" && (thing != null) && Object.keys(thing).length === 0; }; @@ -8575,11 +8852,11 @@ function extend() { element = element.ele(key, entry).up(); } } else { - element = arguments.callee(element.ele(key), entry).up(); + element = render(element.ele(key), entry).up(); } } } else if (typeof child === "object") { - element = arguments.callee(element.ele(key), child).up(); + element = render(element.ele(key), child).up(); } else { if (typeof child === 'string' && _this.options.cdata && requiresCDATA(child)) { element = element.ele(key).raw(wrapCDATA(child)).up(); @@ -8639,17 +8916,25 @@ function extend() { } Parser.prototype.processAsync = function() { - var chunk; - if (this.remaining.length <= this.options.chunkSize) { - chunk = this.remaining; - this.remaining = ''; - this.saxParser = this.saxParser.write(chunk); - return this.saxParser.close(); - } else { - chunk = this.remaining.substr(0, this.options.chunkSize); - this.remaining = this.remaining.substr(this.options.chunkSize, this.remaining.length); - this.saxParser = this.saxParser.write(chunk); - return setImmediate(this.processAsync); + var chunk, err, error1; + try { + if (this.remaining.length <= this.options.chunkSize) { + chunk = this.remaining; + this.remaining = ''; + this.saxParser = this.saxParser.write(chunk); + return this.saxParser.close(); + } else { + chunk = this.remaining.substr(0, this.options.chunkSize); + this.remaining = this.remaining.substr(this.options.chunkSize, this.remaining.length); + this.saxParser = this.saxParser.write(chunk); + return setImmediate(this.processAsync); + } + } catch (error1) { + err = error1; + if (!this.saxParser.errThrown) { + this.saxParser.errThrown = true; + return this.emit(err); + } } }; @@ -8686,6 +8971,14 @@ function extend() { } }; })(this); + this.saxParser.onend = (function(_this) { + return function() { + if (!_this.saxParser.ended) { + _this.saxParser.ended = true; + return _this.emit("end", _this.resultObject); + } + }; + })(this); this.saxParser.ended = false; this.EXPLICIT_CHARKEY = this.options.explicitCharkey; this.resultObject = null; @@ -8725,7 +9018,7 @@ function extend() { })(this); this.saxParser.onclosetag = (function(_this) { return function() { - var cdata, emptyStr, err, key, node, nodeName, obj, objClone, old, s, xpath; + var cdata, emptyStr, err, error1, key, node, nodeName, obj, objClone, old, s, xpath; obj = stack.pop(); nodeName = obj["#name"]; if (!_this.options.explicitChildren || !_this.options.preserveChildrenOrder) { @@ -8766,8 +9059,8 @@ function extend() { })()).concat(nodeName).join("/"); try { obj = _this.options.validator(xpath, s && s[nodeName], obj); - } catch (_error) { - err = _error; + } catch (error1) { + err = error1; _this.emit("error", err); } } @@ -8845,7 +9138,7 @@ function extend() { }; Parser.prototype.parseString = function(str, cb) { - var err; + var err, error1; if ((cb != null) && typeof cb === "function") { this.on("end", function(result) { this.reset(); @@ -8856,21 +9149,21 @@ function extend() { return cb(err); }); } - str = str.toString(); - if (str.trim() === '') { - this.emit("end", null); - return true; - } try { + str = str.toString(); + if (str.trim() === '') { + this.emit("end", null); + return true; + } str = bom.stripBOM(str); if (this.options.async) { this.remaining = str; setImmediate(this.processAsync); - this.saxParser; + return this.saxParser; } return this.saxParser.write(str).close(); - } catch (_error) { - err = _error; + } catch (error1) { + err = error1; if (!(this.saxParser.errThrown || this.saxParser.ended)) { this.emit('error', err); return this.saxParser.errThrown = true; @@ -8905,1421 +9198,1574 @@ function extend() { }).call(this); -},{"./bom":54,"./processors":55,"events":17,"sax":57,"xmlbuilder":74}],57:[function(require,module,exports){ +},{"./bom":56,"./processors":57,"events":17,"sax":59,"timers":51,"xmlbuilder":76}],59:[function(require,module,exports){ (function (Buffer){ -// wrapper for non-node envs -;(function (sax) { - -sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } -sax.SAXParser = SAXParser -sax.SAXStream = SAXStream -sax.createStream = createStream - -// When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns. -// When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)), -// since that's the earliest that a buffer overrun could occur. This way, checks are -// as rare as required, but as often as necessary to ensure never crossing this bound. -// Furthermore, buffers are only tested at most once per write(), so passing a very -// large string into write() might have undesirable effects, but this is manageable by -// the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme -// edge case, result in creating at most one complete copy of the string passed in. -// Set to Infinity to have unlimited buffers. -sax.MAX_BUFFER_LENGTH = 64 * 1024 - -var buffers = [ - "comment", "sgmlDecl", "textNode", "tagName", "doctype", - "procInstName", "procInstBody", "entity", "attribName", - "attribValue", "cdata", "script" -] +;(function (sax) { // wrapper for non-node envs + sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } + sax.SAXParser = SAXParser + sax.SAXStream = SAXStream + sax.createStream = createStream + + // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns. + // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)), + // since that's the earliest that a buffer overrun could occur. This way, checks are + // as rare as required, but as often as necessary to ensure never crossing this bound. + // Furthermore, buffers are only tested at most once per write(), so passing a very + // large string into write() might have undesirable effects, but this is manageable by + // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme + // edge case, result in creating at most one complete copy of the string passed in. + // Set to Infinity to have unlimited buffers. + sax.MAX_BUFFER_LENGTH = 64 * 1024 + + var buffers = [ + 'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', + 'procInstName', 'procInstBody', 'entity', 'attribName', + 'attribValue', 'cdata', 'script' + ] -sax.EVENTS = // for discoverability. - [ "text" - , "processinginstruction" - , "sgmldeclaration" - , "doctype" - , "comment" - , "attribute" - , "opentag" - , "closetag" - , "opencdata" - , "cdata" - , "closecdata" - , "error" - , "end" - , "ready" - , "script" - , "opennamespace" - , "closenamespace" + sax.EVENTS = [ + 'text', + 'processinginstruction', + 'sgmldeclaration', + 'doctype', + 'comment', + 'attribute', + 'opentag', + 'closetag', + 'opencdata', + 'cdata', + 'closecdata', + 'error', + 'end', + 'ready', + 'script', + 'opennamespace', + 'closenamespace' ] -function SAXParser (strict, opt) { - if (!(this instanceof SAXParser)) return new SAXParser(strict, opt) - - var parser = this - clearBuffers(parser) - parser.q = parser.c = "" - parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH - parser.opt = opt || {} - parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags - parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase" - parser.tags = [] - parser.closed = parser.closedRoot = parser.sawRoot = false - parser.tag = parser.error = null - parser.strict = !!strict - parser.noscript = !!(strict || parser.opt.noscript) - parser.state = S.BEGIN - parser.ENTITIES = Object.create(sax.ENTITIES) - parser.attribList = [] - - // namespaces form a prototype chain. - // it always points at the current tag, - // which protos to its parent tag. - if (parser.opt.xmlns) parser.ns = Object.create(rootNS) - - // mostly just for error reporting - parser.trackPosition = parser.opt.position !== false - if (parser.trackPosition) { - parser.position = parser.line = parser.column = 0 - } - emit(parser, "onready") -} - -if (!Object.create) Object.create = function (o) { - function f () { this.__proto__ = o } - f.prototype = o - return new f -} - -if (!Object.getPrototypeOf) Object.getPrototypeOf = function (o) { - return o.__proto__ -} - -if (!Object.keys) Object.keys = function (o) { - var a = [] - for (var i in o) if (o.hasOwnProperty(i)) a.push(i) - return a -} - -function checkBufferLength (parser) { - var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10) - , maxActual = 0 - for (var i = 0, l = buffers.length; i < l; i ++) { - var len = parser[buffers[i]].length - if (len > maxAllowed) { - // Text/cdata nodes can get big, and since they're buffered, - // we can get here under normal conditions. - // Avoid issues by emitting the text node now, - // so at least it won't get any bigger. - switch (buffers[i]) { - case "textNode": - closeText(parser) - break + function SAXParser (strict, opt) { + if (!(this instanceof SAXParser)) { + return new SAXParser(strict, opt) + } + + var parser = this + clearBuffers(parser) + parser.q = parser.c = '' + parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH + parser.opt = opt || {} + parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags + parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase' + parser.tags = [] + parser.closed = parser.closedRoot = parser.sawRoot = false + parser.tag = parser.error = null + parser.strict = !!strict + parser.noscript = !!(strict || parser.opt.noscript) + parser.state = S.BEGIN + parser.strictEntities = parser.opt.strictEntities + parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES) + parser.attribList = [] + + // namespaces form a prototype chain. + // it always points at the current tag, + // which protos to its parent tag. + if (parser.opt.xmlns) { + parser.ns = Object.create(rootNS) + } + + // mostly just for error reporting + parser.trackPosition = parser.opt.position !== false + if (parser.trackPosition) { + parser.position = parser.line = parser.column = 0 + } + emit(parser, 'onready') + } - case "cdata": - emitNode(parser, "oncdata", parser.cdata) - parser.cdata = "" - break + if (!Object.create) { + Object.create = function (o) { + function F () {} + F.prototype = o + var newf = new F() + return newf + } + } - case "script": - emitNode(parser, "onscript", parser.script) - parser.script = "" - break + if (!Object.keys) { + Object.keys = function (o) { + var a = [] + for (var i in o) if (o.hasOwnProperty(i)) a.push(i) + return a + } + } - default: - error(parser, "Max buffer length exceeded: "+buffers[i]) + function checkBufferLength (parser) { + var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10) + var maxActual = 0 + for (var i = 0, l = buffers.length; i < l; i++) { + var len = parser[buffers[i]].length + if (len > maxAllowed) { + // Text/cdata nodes can get big, and since they're buffered, + // we can get here under normal conditions. + // Avoid issues by emitting the text node now, + // so at least it won't get any bigger. + switch (buffers[i]) { + case 'textNode': + closeText(parser) + break + + case 'cdata': + emitNode(parser, 'oncdata', parser.cdata) + parser.cdata = '' + break + + case 'script': + emitNode(parser, 'onscript', parser.script) + parser.script = '' + break + + default: + error(parser, 'Max buffer length exceeded: ' + buffers[i]) + } } + maxActual = Math.max(maxActual, len) } - maxActual = Math.max(maxActual, len) + // schedule the next check for the earliest possible buffer overrun. + var m = sax.MAX_BUFFER_LENGTH - maxActual + parser.bufferCheckPosition = m + parser.position } - // schedule the next check for the earliest possible buffer overrun. - parser.bufferCheckPosition = (sax.MAX_BUFFER_LENGTH - maxActual) - + parser.position -} -function clearBuffers (parser) { - for (var i = 0, l = buffers.length; i < l; i ++) { - parser[buffers[i]] = "" + function clearBuffers (parser) { + for (var i = 0, l = buffers.length; i < l; i++) { + parser[buffers[i]] = '' + } } -} -function flushBuffers (parser) { - closeText(parser) - if (parser.cdata !== "") { - emitNode(parser, "oncdata", parser.cdata) - parser.cdata = "" - } - if (parser.script !== "") { - emitNode(parser, "onscript", parser.script) - parser.script = "" + function flushBuffers (parser) { + closeText(parser) + if (parser.cdata !== '') { + emitNode(parser, 'oncdata', parser.cdata) + parser.cdata = '' + } + if (parser.script !== '') { + emitNode(parser, 'onscript', parser.script) + parser.script = '' + } } -} -SAXParser.prototype = - { end: function () { end(this) } - , write: write - , resume: function () { this.error = null; return this } - , close: function () { return this.write(null) } - , flush: function () { flushBuffers(this) } + SAXParser.prototype = { + end: function () { end(this) }, + write: write, + resume: function () { this.error = null; return this }, + close: function () { return this.write(null) }, + flush: function () { flushBuffers(this) } } -try { - var Stream = require("stream").Stream -} catch (ex) { - var Stream = function () {} -} + var Stream + try { + Stream = require('stream').Stream + } catch (ex) { + Stream = function () {} + } + var streamWraps = sax.EVENTS.filter(function (ev) { + return ev !== 'error' && ev !== 'end' + }) -var streamWraps = sax.EVENTS.filter(function (ev) { - return ev !== "error" && ev !== "end" -}) + function createStream (strict, opt) { + return new SAXStream(strict, opt) + } -function createStream (strict, opt) { - return new SAXStream(strict, opt) -} + function SAXStream (strict, opt) { + if (!(this instanceof SAXStream)) { + return new SAXStream(strict, opt) + } -function SAXStream (strict, opt) { - if (!(this instanceof SAXStream)) return new SAXStream(strict, opt) + Stream.apply(this) - Stream.apply(this) + this._parser = new SAXParser(strict, opt) + this.writable = true + this.readable = true - this._parser = new SAXParser(strict, opt) - this.writable = true - this.readable = true + var me = this + this._parser.onend = function () { + me.emit('end') + } - var me = this + this._parser.onerror = function (er) { + me.emit('error', er) - this._parser.onend = function () { - me.emit("end") - } + // if didn't throw, then means error was handled. + // go ahead and clear error, so we can write again. + me._parser.error = null + } - this._parser.onerror = function (er) { - me.emit("error", er) + this._decoder = null - // if didn't throw, then means error was handled. - // go ahead and clear error, so we can write again. - me._parser.error = null + streamWraps.forEach(function (ev) { + Object.defineProperty(me, 'on' + ev, { + get: function () { + return me._parser['on' + ev] + }, + set: function (h) { + if (!h) { + me.removeAllListeners(ev) + me._parser['on' + ev] = h + return h + } + me.on(ev, h) + }, + enumerable: true, + configurable: false + }) + }) } - this._decoder = null; - - streamWraps.forEach(function (ev) { - Object.defineProperty(me, "on" + ev, { - get: function () { return me._parser["on" + ev] }, - set: function (h) { - if (!h) { - me.removeAllListeners(ev) - return me._parser["on"+ev] = h - } - me.on(ev, h) - }, - enumerable: true, - configurable: false - }) + SAXStream.prototype = Object.create(Stream.prototype, { + constructor: { + value: SAXStream + } }) -} -SAXStream.prototype = Object.create(Stream.prototype, - { constructor: { value: SAXStream } }) - -SAXStream.prototype.write = function (data) { - if (typeof Buffer === 'function' && + SAXStream.prototype.write = function (data) { + if (typeof Buffer === 'function' && typeof Buffer.isBuffer === 'function' && Buffer.isBuffer(data)) { - if (!this._decoder) { - var SD = require('string_decoder').StringDecoder - this._decoder = new SD('utf8') + if (!this._decoder) { + var SD = require('string_decoder').StringDecoder + this._decoder = new SD('utf8') + } + data = this._decoder.write(data) } - data = this._decoder.write(data); - } - - this._parser.write(data.toString()) - this.emit("data", data) - return true -} -SAXStream.prototype.end = function (chunk) { - if (chunk && chunk.length) this.write(chunk) - this._parser.end() - return true -} + this._parser.write(data.toString()) + this.emit('data', data) + return true + } -SAXStream.prototype.on = function (ev, handler) { - var me = this - if (!me._parser["on"+ev] && streamWraps.indexOf(ev) !== -1) { - me._parser["on"+ev] = function () { - var args = arguments.length === 1 ? [arguments[0]] - : Array.apply(null, arguments) - args.splice(0, 0, ev) - me.emit.apply(me, args) + SAXStream.prototype.end = function (chunk) { + if (chunk && chunk.length) { + this.write(chunk) } + this._parser.end() + return true } - return Stream.prototype.on.call(me, ev, handler) -} + SAXStream.prototype.on = function (ev, handler) { + var me = this + if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) { + me._parser['on' + ev] = function () { + var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments) + args.splice(0, 0, ev) + me.emit.apply(me, args) + } + } + return Stream.prototype.on.call(me, ev, handler) + } + // character classes and tokens + var whitespace = '\r\n\t ' -// character classes and tokens -var whitespace = "\r\n\t " // this really needs to be replaced with character classes. // XML allows all manner of ridiculous numbers and digits. - , number = "0124356789" - , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + var number = '0124356789' + var letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + // (Letter | "_" | ":") - , quote = "'\"" - , entity = number+letter+"#" - , attribEnd = whitespace + ">" - , CDATA = "[CDATA[" - , DOCTYPE = "DOCTYPE" - , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace" - , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/" - , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } - -// turn all the string character sets into character class objects. -whitespace = charClass(whitespace) -number = charClass(number) -letter = charClass(letter) - -// http://www.w3.org/TR/REC-xml/#NT-NameStartChar -// This implementation works on strings, a single character at a time -// as such, it cannot ever support astral-plane characters (10000-EFFFF) -// without a significant breaking change to either this parser, or the -// JavaScript language. Implementation of an emoji-capable xml parser -// is left as an exercise for the reader. -var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/ - -var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/ - -quote = charClass(quote) -entity = charClass(entity) -attribEnd = charClass(attribEnd) - -function charClass (str) { - return str.split("").reduce(function (s, c) { - s[c] = true - return s - }, {}) -} - -function isRegExp (c) { - return Object.prototype.toString.call(c) === '[object RegExp]' -} - -function is (charclass, c) { - return isRegExp(charclass) ? !!c.match(charclass) : charclass[c] -} - -function not (charclass, c) { - return !is(charclass, c) -} - -var S = 0 -sax.STATE = -{ BEGIN : S++ -, TEXT : S++ // general stuff -, TEXT_ENTITY : S++ // & and such. -, OPEN_WAKA : S++ // < -, SGML_DECL : S++ // -, SCRIPT : S++ //