diff --git a/.env.example b/.env.example index 8f13de0..6f63386 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ +CREDENTIAL_DAVICAL_USERNAME="" +CREDENTIAL_DAVICAL_PASSWORD="" +CREDENTIAL_DAVICAL_SERVER_URL="" CREDENTIAL_ZOHO_USERNAME="" CREDENTIAL_ZOHO_PASSWORD="" CREDENTIAL_ZOHO_SERVER_URL="" diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 4f7e26c..4275a5a 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -14,6 +14,7 @@ "consts", "copyfiles", "ctag", + "DAVICAL", "DAVV", "displayname", "docusuarus", diff --git a/CHANGELOG.md b/CHANGELOG.md index e73e8b5..97d1c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v2.0.3 + +**improvements** + +- added support for davical +- fixed a bug related to expand #116 +- updated deps + ## v2.0.2 **improvements** diff --git a/dist/package.json b/dist/package.json index 1a48fcf..0010c99 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "tsdav", - "version": "2.0.2", + "version": "2.0.3", "description": "WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser", "keywords": [ "dav", @@ -54,36 +54,36 @@ "xml-js": "1.6.11" }, "devDependencies": { - "@rollup/plugin-commonjs": "21.0.3", + "@rollup/plugin-commonjs": "22.0.1", "@rollup/plugin-node-resolve": "13.1.3", - "@rollup/plugin-typescript": "8.3.1", + "@rollup/plugin-typescript": "8.3.3", "@types/base-64": "1.0.0", "@types/debug": "4.1.7", - "@types/jest": "27.4.1", - "@types/node": "17.0.23", - "@typescript-eslint/eslint-plugin": "5.16.0", - "@typescript-eslint/parser": "5.16.0", + "@types/jest": "28.1.4", + "@types/node": "18.0.0", + "@typescript-eslint/eslint-plugin": "5.30.3", + "@typescript-eslint/parser": "5.18.0", "copyfiles": "2.4.1", "cross-env": "7.0.3", - "dotenv": "16.0.0", - "eslint": "8.12.0", + "dotenv": "16.0.1", + "eslint": "8.19.0", "eslint-config-airbnb": "19.0.4", - "eslint-config-airbnb-typescript": "16.1.4", + "eslint-config-airbnb-typescript": "17.0.0", "eslint-config-prettier": "8.5.0", "eslint-module-utils": "2.7.3", - "eslint-plugin-import": "2.25.4", - "eslint-plugin-prettier": "4.0.0", - "jest": "27.5.1", - "prettier": "2.6.1", + "eslint-plugin-import": "2.26.0", + "eslint-plugin-prettier": "4.2.1", + "jest": "28.1.2", + "prettier": "2.7.1", "rimraf": "3.0.2", - "rollup": "2.70.1", - "rollup-plugin-dts": "4.2.0", + "rollup": "2.75.7", + "rollup-plugin-dts": "4.2.2", "rollup-plugin-node-builtins": "2.1.2", - "rollup-plugin-polyfill-node": "0.8.0", + "rollup-plugin-polyfill-node": "0.9.0", "rollup-plugin-terser": "7.0.2", - "sort-package-json": "1.55.0", - "ts-jest": "27.1.4", - "typescript": "4.6.3" + "sort-package-json": "1.57.0", + "ts-jest": "28.0.5", + "typescript": "4.7.4" }, "engines": { "node": ">=10" diff --git a/dist/tsdav.cjs.js b/dist/tsdav.cjs.js index d4d1d3d..cfd1b48 100644 --- a/dist/tsdav.cjs.js +++ b/dist/tsdav.cjs.js @@ -321,7 +321,7 @@ function hasFields(obj, fields) { } return inObj(obj); } -const findMissingFieldNames = (obj, fields) => fields.reduce((prev, curr) => (obj[curr] ? prev : `${prev.length ? `${prev},` : ''}${curr}`), ''); +const findMissingFieldNames = (obj, fields) => fields.reduce((prev, curr) => (obj[curr] ? prev : `${prev.length ? `${prev},` : ''}${curr.toString()}`), ''); const debug$4 = getLogger__default["default"]('tsdav:collection'); const collectionQuery = (params) => __awaiter(void 0, void 0, void 0, function* () { @@ -878,7 +878,22 @@ const fetchCalendarObjects = (params) => __awaiter(void 0, void 0, void 0, funct (yield calendarQuery({ url: calendar.url, props: { - [`${exports.DAVNamespaceShort.DAV}:getetag`]: {}, + [`${exports.DAVNamespaceShort.DAV}:getetag`]: Object.assign({}, (expand && timeRange + ? { + [`${exports.DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, + }, + } + : {})), }, filters, depth: '1', @@ -887,33 +902,63 @@ const fetchCalendarObjects = (params) => __awaiter(void 0, void 0, void 0, funct .map((url) => (url.startsWith('http') || !url ? url : new URL(url, calendar.url).href)) // patch up to full url if url is not full .filter(urlFilter !== null && urlFilter !== void 0 ? urlFilter : ((url) => Boolean(url === null || url === void 0 ? void 0 : url.includes('.ics')))) // filter out non ics calendar objects since apple calendar might have those .map((url) => new URL(url).pathname); // obtain pathname of the url - const calendarObjectResults = calendarObjectUrls.length > 0 - ? yield calendarMultiGet({ - url: calendar.url, - props: { - [`${exports.DAVNamespaceShort.DAV}:getetag`]: {}, - [`${exports.DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange - ? { - [`${exports.DAVNamespaceShort.CALDAV}:expand`]: { - _attributes: { - start: `${new Date(timeRange.start) - .toISOString() - .slice(0, 19) - .replace(/[-:.]/g, '')}Z`, - end: `${new Date(timeRange.end) - .toISOString() - .slice(0, 19) - .replace(/[-:.]/g, '')}Z`, + let calendarObjectResults = []; + if (calendarObjectUrls.length > 0) { + if (expand) { + calendarObjectResults = yield calendarQuery({ + url: calendar.url, + props: { + [`${exports.DAVNamespaceShort.DAV}:getetag`]: {}, + [`${exports.DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange + ? { + [`${exports.DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, }, - }, - } - : {})), - }, - objectUrls: calendarObjectUrls, - depth: '1', - headers, - }) - : []; + } + : {})), + }, + filters, + depth: '1', + headers, + }); + } + else { + calendarObjectResults = yield calendarMultiGet({ + url: calendar.url, + props: { + [`${exports.DAVNamespaceShort.DAV}:getetag`]: {}, + [`${exports.DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange + ? { + [`${exports.DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, + }, + } + : {})), + }, + objectUrls: calendarObjectUrls, + depth: '1', + headers, + }); + } + } return calendarObjectResults.map((res) => { var _a, _b, _c, _d, _e, _f; return ({ diff --git a/dist/tsdav.d.ts b/dist/tsdav.d.ts index d177fa1..956152d 100644 --- a/dist/tsdav.d.ts +++ b/dist/tsdav.d.ts @@ -183,10 +183,10 @@ declare const addressBookMultiGet: (params: { headers?: Record; }) => Promise; declare const fetchAddressBooks: (params?: { - account?: DAVAccount | undefined; - props?: ElementCompact | undefined; - headers?: Record | undefined; -} | undefined) => Promise; + account?: DAVAccount; + props?: ElementCompact; + headers?: Record; +}) => Promise; declare const fetchVCards: (params: { addressBook: DAVAddressBook; headers?: Record | undefined; @@ -232,10 +232,10 @@ declare const makeCalendar: (params: { headers?: Record; }) => Promise; declare const fetchCalendars: (params?: { - account?: DAVAccount | undefined; - props?: ElementCompact | undefined; - headers?: Record | undefined; -} | undefined) => Promise; + account?: DAVAccount; + props?: ElementCompact; + headers?: Record; +}) => Promise; declare const fetchCalendarObjects: (params: { calendar: DAVCalendar; objectUrls?: string[] | undefined; @@ -588,8 +588,8 @@ declare const getOauthHeaders: (credentials: DAVCredentials) => Promise<{ }; }>; -declare const urlEquals: (urlA?: string | undefined, urlB?: string | undefined) => boolean; -declare const urlContains: (urlA?: string | undefined, urlB?: string | undefined) => boolean; +declare const urlEquals: (urlA?: string, urlB?: string) => boolean; +declare const urlContains: (urlA?: string, urlB?: string) => boolean; declare const getDAVAttribute: (nsArr: DAVNamespace[]) => { [key: string]: DAVNamespace; }; diff --git a/dist/tsdav.esm.js b/dist/tsdav.esm.js index bc6bad3..0873acd 100644 --- a/dist/tsdav.esm.js +++ b/dist/tsdav.esm.js @@ -312,7 +312,7 @@ function hasFields(obj, fields) { } return inObj(obj); } -const findMissingFieldNames = (obj, fields) => fields.reduce((prev, curr) => (obj[curr] ? prev : `${prev.length ? `${prev},` : ''}${curr}`), ''); +const findMissingFieldNames = (obj, fields) => fields.reduce((prev, curr) => (obj[curr] ? prev : `${prev.length ? `${prev},` : ''}${curr.toString()}`), ''); const debug$4 = getLogger('tsdav:collection'); const collectionQuery = (params) => __awaiter(void 0, void 0, void 0, function* () { @@ -869,7 +869,22 @@ const fetchCalendarObjects = (params) => __awaiter(void 0, void 0, void 0, funct (yield calendarQuery({ url: calendar.url, props: { - [`${DAVNamespaceShort.DAV}:getetag`]: {}, + [`${DAVNamespaceShort.DAV}:getetag`]: Object.assign({}, (expand && timeRange + ? { + [`${DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, + }, + } + : {})), }, filters, depth: '1', @@ -878,33 +893,63 @@ const fetchCalendarObjects = (params) => __awaiter(void 0, void 0, void 0, funct .map((url) => (url.startsWith('http') || !url ? url : new URL(url, calendar.url).href)) // patch up to full url if url is not full .filter(urlFilter !== null && urlFilter !== void 0 ? urlFilter : ((url) => Boolean(url === null || url === void 0 ? void 0 : url.includes('.ics')))) // filter out non ics calendar objects since apple calendar might have those .map((url) => new URL(url).pathname); // obtain pathname of the url - const calendarObjectResults = calendarObjectUrls.length > 0 - ? yield calendarMultiGet({ - url: calendar.url, - props: { - [`${DAVNamespaceShort.DAV}:getetag`]: {}, - [`${DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange - ? { - [`${DAVNamespaceShort.CALDAV}:expand`]: { - _attributes: { - start: `${new Date(timeRange.start) - .toISOString() - .slice(0, 19) - .replace(/[-:.]/g, '')}Z`, - end: `${new Date(timeRange.end) - .toISOString() - .slice(0, 19) - .replace(/[-:.]/g, '')}Z`, + let calendarObjectResults = []; + if (calendarObjectUrls.length > 0) { + if (expand) { + calendarObjectResults = yield calendarQuery({ + url: calendar.url, + props: { + [`${DAVNamespaceShort.DAV}:getetag`]: {}, + [`${DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange + ? { + [`${DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, }, - }, - } - : {})), - }, - objectUrls: calendarObjectUrls, - depth: '1', - headers, - }) - : []; + } + : {})), + }, + filters, + depth: '1', + headers, + }); + } + else { + calendarObjectResults = yield calendarMultiGet({ + url: calendar.url, + props: { + [`${DAVNamespaceShort.DAV}:getetag`]: {}, + [`${DAVNamespaceShort.CALDAV}:calendar-data`]: Object.assign({}, (expand && timeRange + ? { + [`${DAVNamespaceShort.CALDAV}:expand`]: { + _attributes: { + start: `${new Date(timeRange.start) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + end: `${new Date(timeRange.end) + .toISOString() + .slice(0, 19) + .replace(/[-:.]/g, '')}Z`, + }, + }, + } + : {})), + }, + objectUrls: calendarObjectUrls, + depth: '1', + headers, + }); + } + } return calendarObjectResults.map((res) => { var _a, _b, _c, _d, _e, _f; return ({ diff --git a/dist/tsdav.js b/dist/tsdav.js index daa21ac..b18db51 100644 --- a/dist/tsdav.js +++ b/dist/tsdav.js @@ -38,8 +38,14 @@ function __awaiter(thisArg, _arguments, P, generator) { var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getAugmentedNamespace(n) { - if (n.__esModule) return n; - var a = Object.defineProperty({}, '__esModule', {value: true}); + var f = n.default; + if (typeof f == "function") { + var a = function () { + return f.apply(this, arguments); + }; + a.prototype = f.prototype; + } else a = {}; + Object.defineProperty(a, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { @@ -55,561 +61,561 @@ function getAugmentedNamespace(n) { var browserPonyfill = {exports: {}}; (function (module, exports) { -var global = typeof self !== 'undefined' ? self : commonjsGlobal; -var __self__ = (function () { -function F() { -this.fetch = false; -this.DOMException = global.DOMException; -} -F.prototype = global; -return new F(); -})(); -(function(self) { - -((function (exports) { - - var support = { - searchParams: 'URLSearchParams' in self, - iterable: 'Symbol' in self && 'iterator' in Symbol, - blob: - 'FileReader' in self && - 'Blob' in self && - (function() { - try { - new Blob(); - return true - } catch (e) { - return false - } - })(), - formData: 'FormData' in self, - arrayBuffer: 'ArrayBuffer' in self - }; - - function isDataView(obj) { - return obj && DataView.prototype.isPrototypeOf(obj) - } - - if (support.arrayBuffer) { - var viewClasses = [ - '[object Int8Array]', - '[object Uint8Array]', - '[object Uint8ClampedArray]', - '[object Int16Array]', - '[object Uint16Array]', - '[object Int32Array]', - '[object Uint32Array]', - '[object Float32Array]', - '[object Float64Array]' - ]; - - var isArrayBufferView = - ArrayBuffer.isView || - function(obj) { - return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 - }; - } - - function normalizeName(name) { - if (typeof name !== 'string') { - name = String(name); - } - if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) { - throw new TypeError('Invalid character in header field name') - } - return name.toLowerCase() - } - - function normalizeValue(value) { - if (typeof value !== 'string') { - value = String(value); - } - return value - } - - // Build a destructive iterator for the value list - function iteratorFor(items) { - var iterator = { - next: function() { - var value = items.shift(); - return {done: value === undefined, value: value} - } - }; - - if (support.iterable) { - iterator[Symbol.iterator] = function() { - return iterator - }; - } - - return iterator - } - - function Headers(headers) { - this.map = {}; - - if (headers instanceof Headers) { - headers.forEach(function(value, name) { - this.append(name, value); - }, this); - } else if (Array.isArray(headers)) { - headers.forEach(function(header) { - this.append(header[0], header[1]); - }, this); - } else if (headers) { - Object.getOwnPropertyNames(headers).forEach(function(name) { - this.append(name, headers[name]); - }, this); - } - } - - Headers.prototype.append = function(name, value) { - name = normalizeName(name); - value = normalizeValue(value); - var oldValue = this.map[name]; - this.map[name] = oldValue ? oldValue + ', ' + value : value; - }; - - Headers.prototype['delete'] = function(name) { - delete this.map[normalizeName(name)]; - }; - - Headers.prototype.get = function(name) { - name = normalizeName(name); - return this.has(name) ? this.map[name] : null - }; - - Headers.prototype.has = function(name) { - return this.map.hasOwnProperty(normalizeName(name)) - }; - - Headers.prototype.set = function(name, value) { - this.map[normalizeName(name)] = normalizeValue(value); - }; - - Headers.prototype.forEach = function(callback, thisArg) { - for (var name in this.map) { - if (this.map.hasOwnProperty(name)) { - callback.call(thisArg, this.map[name], name, this); - } - } - }; - - Headers.prototype.keys = function() { - var items = []; - this.forEach(function(value, name) { - items.push(name); - }); - return iteratorFor(items) - }; - - Headers.prototype.values = function() { - var items = []; - this.forEach(function(value) { - items.push(value); - }); - return iteratorFor(items) - }; - - Headers.prototype.entries = function() { - var items = []; - this.forEach(function(value, name) { - items.push([name, value]); - }); - return iteratorFor(items) - }; - - if (support.iterable) { - Headers.prototype[Symbol.iterator] = Headers.prototype.entries; - } - - function consumed(body) { - if (body.bodyUsed) { - return Promise.reject(new TypeError('Already read')) - } - body.bodyUsed = true; - } - - function fileReaderReady(reader) { - return new Promise(function(resolve, reject) { - reader.onload = function() { - resolve(reader.result); - }; - reader.onerror = function() { - reject(reader.error); - }; - }) - } - - function readBlobAsArrayBuffer(blob) { - var reader = new FileReader(); - var promise = fileReaderReady(reader); - reader.readAsArrayBuffer(blob); - return promise - } - - function readBlobAsText(blob) { - var reader = new FileReader(); - var promise = fileReaderReady(reader); - reader.readAsText(blob); - return promise - } - - function readArrayBufferAsText(buf) { - var view = new Uint8Array(buf); - var chars = new Array(view.length); - - for (var i = 0; i < view.length; i++) { - chars[i] = String.fromCharCode(view[i]); - } - return chars.join('') - } - - function bufferClone(buf) { - if (buf.slice) { - return buf.slice(0) - } else { - var view = new Uint8Array(buf.byteLength); - view.set(new Uint8Array(buf)); - return view.buffer - } - } - - function Body() { - this.bodyUsed = false; - - this._initBody = function(body) { - this._bodyInit = body; - if (!body) { - this._bodyText = ''; - } else if (typeof body === 'string') { - this._bodyText = body; - } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { - this._bodyBlob = body; - } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { - this._bodyFormData = body; - } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { - this._bodyText = body.toString(); - } else if (support.arrayBuffer && support.blob && isDataView(body)) { - this._bodyArrayBuffer = bufferClone(body.buffer); - // IE 10-11 can't handle a DataView body. - this._bodyInit = new Blob([this._bodyArrayBuffer]); - } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { - this._bodyArrayBuffer = bufferClone(body); - } else { - this._bodyText = body = Object.prototype.toString.call(body); - } - - if (!this.headers.get('content-type')) { - if (typeof body === 'string') { - this.headers.set('content-type', 'text/plain;charset=UTF-8'); - } else if (this._bodyBlob && this._bodyBlob.type) { - this.headers.set('content-type', this._bodyBlob.type); - } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { - this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); - } - } - }; - - if (support.blob) { - this.blob = function() { - var rejected = consumed(this); - if (rejected) { - return rejected - } - - if (this._bodyBlob) { - return Promise.resolve(this._bodyBlob) - } else if (this._bodyArrayBuffer) { - return Promise.resolve(new Blob([this._bodyArrayBuffer])) - } else if (this._bodyFormData) { - throw new Error('could not read FormData body as blob') - } else { - return Promise.resolve(new Blob([this._bodyText])) - } - }; - - this.arrayBuffer = function() { - if (this._bodyArrayBuffer) { - return consumed(this) || Promise.resolve(this._bodyArrayBuffer) - } else { - return this.blob().then(readBlobAsArrayBuffer) - } - }; - } - - this.text = function() { - var rejected = consumed(this); - if (rejected) { - return rejected - } - - if (this._bodyBlob) { - return readBlobAsText(this._bodyBlob) - } else if (this._bodyArrayBuffer) { - return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)) - } else if (this._bodyFormData) { - throw new Error('could not read FormData body as text') - } else { - return Promise.resolve(this._bodyText) - } - }; - - if (support.formData) { - this.formData = function() { - return this.text().then(decode) - }; - } - - this.json = function() { - return this.text().then(JSON.parse) - }; - - return this - } - - // HTTP methods whose capitalization should be normalized - var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; - - function normalizeMethod(method) { - var upcased = method.toUpperCase(); - return methods.indexOf(upcased) > -1 ? upcased : method - } - - function Request(input, options) { - options = options || {}; - var body = options.body; - - if (input instanceof Request) { - if (input.bodyUsed) { - throw new TypeError('Already read') - } - this.url = input.url; - this.credentials = input.credentials; - if (!options.headers) { - this.headers = new Headers(input.headers); - } - this.method = input.method; - this.mode = input.mode; - this.signal = input.signal; - if (!body && input._bodyInit != null) { - body = input._bodyInit; - input.bodyUsed = true; - } - } else { - this.url = String(input); - } - - this.credentials = options.credentials || this.credentials || 'same-origin'; - if (options.headers || !this.headers) { - this.headers = new Headers(options.headers); - } - this.method = normalizeMethod(options.method || this.method || 'GET'); - this.mode = options.mode || this.mode || null; - this.signal = options.signal || this.signal; - this.referrer = null; - - if ((this.method === 'GET' || this.method === 'HEAD') && body) { - throw new TypeError('Body not allowed for GET or HEAD requests') - } - this._initBody(body); - } - - Request.prototype.clone = function() { - return new Request(this, {body: this._bodyInit}) - }; - - function decode(body) { - var form = new FormData(); - body - .trim() - .split('&') - .forEach(function(bytes) { - if (bytes) { - var split = bytes.split('='); - var name = split.shift().replace(/\+/g, ' '); - var value = split.join('=').replace(/\+/g, ' '); - form.append(decodeURIComponent(name), decodeURIComponent(value)); - } - }); - return form - } - - function parseHeaders(rawHeaders) { - var headers = new Headers(); - // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space - // https://tools.ietf.org/html/rfc7230#section-3.2 - var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); - preProcessedHeaders.split(/\r?\n/).forEach(function(line) { - var parts = line.split(':'); - var key = parts.shift().trim(); - if (key) { - var value = parts.join(':').trim(); - headers.append(key, value); - } - }); - return headers - } - - Body.call(Request.prototype); - - function Response(bodyInit, options) { - if (!options) { - options = {}; - } - - this.type = 'default'; - this.status = options.status === undefined ? 200 : options.status; - this.ok = this.status >= 200 && this.status < 300; - this.statusText = 'statusText' in options ? options.statusText : 'OK'; - this.headers = new Headers(options.headers); - this.url = options.url || ''; - this._initBody(bodyInit); - } - - Body.call(Response.prototype); - - Response.prototype.clone = function() { - return new Response(this._bodyInit, { - status: this.status, - statusText: this.statusText, - headers: new Headers(this.headers), - url: this.url - }) - }; - - Response.error = function() { - var response = new Response(null, {status: 0, statusText: ''}); - response.type = 'error'; - return response - }; - - var redirectStatuses = [301, 302, 303, 307, 308]; - - Response.redirect = function(url, status) { - if (redirectStatuses.indexOf(status) === -1) { - throw new RangeError('Invalid status code') - } - - return new Response(null, {status: status, headers: {location: url}}) - }; - - exports.DOMException = self.DOMException; - try { - new exports.DOMException(); - } catch (err) { - exports.DOMException = function(message, name) { - this.message = message; - this.name = name; - var error = Error(message); - this.stack = error.stack; - }; - exports.DOMException.prototype = Object.create(Error.prototype); - exports.DOMException.prototype.constructor = exports.DOMException; - } - - function fetch(input, init) { - return new Promise(function(resolve, reject) { - var request = new Request(input, init); - - if (request.signal && request.signal.aborted) { - return reject(new exports.DOMException('Aborted', 'AbortError')) - } - - var xhr = new XMLHttpRequest(); - - function abortXhr() { - xhr.abort(); - } - - xhr.onload = function() { - var options = { - status: xhr.status, - statusText: xhr.statusText, - headers: parseHeaders(xhr.getAllResponseHeaders() || '') - }; - options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); - var body = 'response' in xhr ? xhr.response : xhr.responseText; - resolve(new Response(body, options)); - }; - - xhr.onerror = function() { - reject(new TypeError('Network request failed')); - }; - - xhr.ontimeout = function() { - reject(new TypeError('Network request failed')); - }; - - xhr.onabort = function() { - reject(new exports.DOMException('Aborted', 'AbortError')); - }; - - xhr.open(request.method, request.url, true); - - if (request.credentials === 'include') { - xhr.withCredentials = true; - } else if (request.credentials === 'omit') { - xhr.withCredentials = false; - } - - if ('responseType' in xhr && support.blob) { - xhr.responseType = 'blob'; - } - - request.headers.forEach(function(value, name) { - xhr.setRequestHeader(name, value); - }); - - if (request.signal) { - request.signal.addEventListener('abort', abortXhr); - - xhr.onreadystatechange = function() { - // DONE (success or failure) - if (xhr.readyState === 4) { - request.signal.removeEventListener('abort', abortXhr); - } - }; - } - - xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit); - }) - } - - fetch.polyfill = true; - - if (!self.fetch) { - self.fetch = fetch; - self.Headers = Headers; - self.Request = Request; - self.Response = Response; - } - - exports.Headers = Headers; - exports.Request = Request; - exports.Response = Response; - exports.fetch = fetch; - - Object.defineProperty(exports, '__esModule', { value: true }); - - return exports; - -}))({}); -})(__self__); -__self__.fetch.ponyfill = true; -// Remove "polyfill" property added by whatwg-fetch -delete __self__.fetch.polyfill; -// Choose between native implementation (global) or custom implementation (__self__) -// var ctx = global.fetch ? global : __self__; -var ctx = __self__; // this line disable service worker support temporarily -exports = ctx.fetch; // To enable: import fetch from 'cross-fetch' -exports.default = ctx.fetch; // For TypeScript consumers without esModuleInterop. -exports.fetch = ctx.fetch; // To enable: import {fetch} from 'cross-fetch' -exports.Headers = ctx.Headers; -exports.Request = ctx.Request; -exports.Response = ctx.Response; -module.exports = exports; -}(browserPonyfill, browserPonyfill.exports)); + var global = typeof self !== 'undefined' ? self : commonjsGlobal; + var __self__ = (function () { + function F() { + this.fetch = false; + this.DOMException = global.DOMException; + } + F.prototype = global; + return new F(); + })(); + (function(self) { + + ((function (exports) { + + var support = { + searchParams: 'URLSearchParams' in self, + iterable: 'Symbol' in self && 'iterator' in Symbol, + blob: + 'FileReader' in self && + 'Blob' in self && + (function() { + try { + new Blob(); + return true + } catch (e) { + return false + } + })(), + formData: 'FormData' in self, + arrayBuffer: 'ArrayBuffer' in self + }; + + function isDataView(obj) { + return obj && DataView.prototype.isPrototypeOf(obj) + } + + if (support.arrayBuffer) { + var viewClasses = [ + '[object Int8Array]', + '[object Uint8Array]', + '[object Uint8ClampedArray]', + '[object Int16Array]', + '[object Uint16Array]', + '[object Int32Array]', + '[object Uint32Array]', + '[object Float32Array]', + '[object Float64Array]' + ]; + + var isArrayBufferView = + ArrayBuffer.isView || + function(obj) { + return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 + }; + } + + function normalizeName(name) { + if (typeof name !== 'string') { + name = String(name); + } + if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) { + throw new TypeError('Invalid character in header field name') + } + return name.toLowerCase() + } + + function normalizeValue(value) { + if (typeof value !== 'string') { + value = String(value); + } + return value + } + + // Build a destructive iterator for the value list + function iteratorFor(items) { + var iterator = { + next: function() { + var value = items.shift(); + return {done: value === undefined, value: value} + } + }; + + if (support.iterable) { + iterator[Symbol.iterator] = function() { + return iterator + }; + } + + return iterator + } + + function Headers(headers) { + this.map = {}; + + if (headers instanceof Headers) { + headers.forEach(function(value, name) { + this.append(name, value); + }, this); + } else if (Array.isArray(headers)) { + headers.forEach(function(header) { + this.append(header[0], header[1]); + }, this); + } else if (headers) { + Object.getOwnPropertyNames(headers).forEach(function(name) { + this.append(name, headers[name]); + }, this); + } + } + + Headers.prototype.append = function(name, value) { + name = normalizeName(name); + value = normalizeValue(value); + var oldValue = this.map[name]; + this.map[name] = oldValue ? oldValue + ', ' + value : value; + }; + + Headers.prototype['delete'] = function(name) { + delete this.map[normalizeName(name)]; + }; + + Headers.prototype.get = function(name) { + name = normalizeName(name); + return this.has(name) ? this.map[name] : null + }; + + Headers.prototype.has = function(name) { + return this.map.hasOwnProperty(normalizeName(name)) + }; + + Headers.prototype.set = function(name, value) { + this.map[normalizeName(name)] = normalizeValue(value); + }; + + Headers.prototype.forEach = function(callback, thisArg) { + for (var name in this.map) { + if (this.map.hasOwnProperty(name)) { + callback.call(thisArg, this.map[name], name, this); + } + } + }; + + Headers.prototype.keys = function() { + var items = []; + this.forEach(function(value, name) { + items.push(name); + }); + return iteratorFor(items) + }; + + Headers.prototype.values = function() { + var items = []; + this.forEach(function(value) { + items.push(value); + }); + return iteratorFor(items) + }; + + Headers.prototype.entries = function() { + var items = []; + this.forEach(function(value, name) { + items.push([name, value]); + }); + return iteratorFor(items) + }; + + if (support.iterable) { + Headers.prototype[Symbol.iterator] = Headers.prototype.entries; + } + + function consumed(body) { + if (body.bodyUsed) { + return Promise.reject(new TypeError('Already read')) + } + body.bodyUsed = true; + } + + function fileReaderReady(reader) { + return new Promise(function(resolve, reject) { + reader.onload = function() { + resolve(reader.result); + }; + reader.onerror = function() { + reject(reader.error); + }; + }) + } + + function readBlobAsArrayBuffer(blob) { + var reader = new FileReader(); + var promise = fileReaderReady(reader); + reader.readAsArrayBuffer(blob); + return promise + } + + function readBlobAsText(blob) { + var reader = new FileReader(); + var promise = fileReaderReady(reader); + reader.readAsText(blob); + return promise + } + + function readArrayBufferAsText(buf) { + var view = new Uint8Array(buf); + var chars = new Array(view.length); + + for (var i = 0; i < view.length; i++) { + chars[i] = String.fromCharCode(view[i]); + } + return chars.join('') + } + + function bufferClone(buf) { + if (buf.slice) { + return buf.slice(0) + } else { + var view = new Uint8Array(buf.byteLength); + view.set(new Uint8Array(buf)); + return view.buffer + } + } + + function Body() { + this.bodyUsed = false; + + this._initBody = function(body) { + this._bodyInit = body; + if (!body) { + this._bodyText = ''; + } else if (typeof body === 'string') { + this._bodyText = body; + } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { + this._bodyBlob = body; + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { + this._bodyFormData = body; + } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { + this._bodyText = body.toString(); + } else if (support.arrayBuffer && support.blob && isDataView(body)) { + this._bodyArrayBuffer = bufferClone(body.buffer); + // IE 10-11 can't handle a DataView body. + this._bodyInit = new Blob([this._bodyArrayBuffer]); + } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { + this._bodyArrayBuffer = bufferClone(body); + } else { + this._bodyText = body = Object.prototype.toString.call(body); + } + + if (!this.headers.get('content-type')) { + if (typeof body === 'string') { + this.headers.set('content-type', 'text/plain;charset=UTF-8'); + } else if (this._bodyBlob && this._bodyBlob.type) { + this.headers.set('content-type', this._bodyBlob.type); + } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { + this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); + } + } + }; + + if (support.blob) { + this.blob = function() { + var rejected = consumed(this); + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return Promise.resolve(this._bodyBlob) + } else if (this._bodyArrayBuffer) { + return Promise.resolve(new Blob([this._bodyArrayBuffer])) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as blob') + } else { + return Promise.resolve(new Blob([this._bodyText])) + } + }; + + this.arrayBuffer = function() { + if (this._bodyArrayBuffer) { + return consumed(this) || Promise.resolve(this._bodyArrayBuffer) + } else { + return this.blob().then(readBlobAsArrayBuffer) + } + }; + } + + this.text = function() { + var rejected = consumed(this); + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return readBlobAsText(this._bodyBlob) + } else if (this._bodyArrayBuffer) { + return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as text') + } else { + return Promise.resolve(this._bodyText) + } + }; + + if (support.formData) { + this.formData = function() { + return this.text().then(decode) + }; + } + + this.json = function() { + return this.text().then(JSON.parse) + }; + + return this + } + + // HTTP methods whose capitalization should be normalized + var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; + + function normalizeMethod(method) { + var upcased = method.toUpperCase(); + return methods.indexOf(upcased) > -1 ? upcased : method + } + + function Request(input, options) { + options = options || {}; + var body = options.body; + + if (input instanceof Request) { + if (input.bodyUsed) { + throw new TypeError('Already read') + } + this.url = input.url; + this.credentials = input.credentials; + if (!options.headers) { + this.headers = new Headers(input.headers); + } + this.method = input.method; + this.mode = input.mode; + this.signal = input.signal; + if (!body && input._bodyInit != null) { + body = input._bodyInit; + input.bodyUsed = true; + } + } else { + this.url = String(input); + } + + this.credentials = options.credentials || this.credentials || 'same-origin'; + if (options.headers || !this.headers) { + this.headers = new Headers(options.headers); + } + this.method = normalizeMethod(options.method || this.method || 'GET'); + this.mode = options.mode || this.mode || null; + this.signal = options.signal || this.signal; + this.referrer = null; + + if ((this.method === 'GET' || this.method === 'HEAD') && body) { + throw new TypeError('Body not allowed for GET or HEAD requests') + } + this._initBody(body); + } + + Request.prototype.clone = function() { + return new Request(this, {body: this._bodyInit}) + }; + + function decode(body) { + var form = new FormData(); + body + .trim() + .split('&') + .forEach(function(bytes) { + if (bytes) { + var split = bytes.split('='); + var name = split.shift().replace(/\+/g, ' '); + var value = split.join('=').replace(/\+/g, ' '); + form.append(decodeURIComponent(name), decodeURIComponent(value)); + } + }); + return form + } + + function parseHeaders(rawHeaders) { + var headers = new Headers(); + // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space + // https://tools.ietf.org/html/rfc7230#section-3.2 + var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); + preProcessedHeaders.split(/\r?\n/).forEach(function(line) { + var parts = line.split(':'); + var key = parts.shift().trim(); + if (key) { + var value = parts.join(':').trim(); + headers.append(key, value); + } + }); + return headers + } + + Body.call(Request.prototype); + + function Response(bodyInit, options) { + if (!options) { + options = {}; + } + + this.type = 'default'; + this.status = options.status === undefined ? 200 : options.status; + this.ok = this.status >= 200 && this.status < 300; + this.statusText = 'statusText' in options ? options.statusText : 'OK'; + this.headers = new Headers(options.headers); + this.url = options.url || ''; + this._initBody(bodyInit); + } + + Body.call(Response.prototype); + + Response.prototype.clone = function() { + return new Response(this._bodyInit, { + status: this.status, + statusText: this.statusText, + headers: new Headers(this.headers), + url: this.url + }) + }; + + Response.error = function() { + var response = new Response(null, {status: 0, statusText: ''}); + response.type = 'error'; + return response + }; + + var redirectStatuses = [301, 302, 303, 307, 308]; + + Response.redirect = function(url, status) { + if (redirectStatuses.indexOf(status) === -1) { + throw new RangeError('Invalid status code') + } + + return new Response(null, {status: status, headers: {location: url}}) + }; + + exports.DOMException = self.DOMException; + try { + new exports.DOMException(); + } catch (err) { + exports.DOMException = function(message, name) { + this.message = message; + this.name = name; + var error = Error(message); + this.stack = error.stack; + }; + exports.DOMException.prototype = Object.create(Error.prototype); + exports.DOMException.prototype.constructor = exports.DOMException; + } + + function fetch(input, init) { + return new Promise(function(resolve, reject) { + var request = new Request(input, init); + + if (request.signal && request.signal.aborted) { + return reject(new exports.DOMException('Aborted', 'AbortError')) + } + + var xhr = new XMLHttpRequest(); + + function abortXhr() { + xhr.abort(); + } + + xhr.onload = function() { + var options = { + status: xhr.status, + statusText: xhr.statusText, + headers: parseHeaders(xhr.getAllResponseHeaders() || '') + }; + options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); + var body = 'response' in xhr ? xhr.response : xhr.responseText; + resolve(new Response(body, options)); + }; + + xhr.onerror = function() { + reject(new TypeError('Network request failed')); + }; + + xhr.ontimeout = function() { + reject(new TypeError('Network request failed')); + }; + + xhr.onabort = function() { + reject(new exports.DOMException('Aborted', 'AbortError')); + }; + + xhr.open(request.method, request.url, true); + + if (request.credentials === 'include') { + xhr.withCredentials = true; + } else if (request.credentials === 'omit') { + xhr.withCredentials = false; + } + + if ('responseType' in xhr && support.blob) { + xhr.responseType = 'blob'; + } + + request.headers.forEach(function(value, name) { + xhr.setRequestHeader(name, value); + }); + + if (request.signal) { + request.signal.addEventListener('abort', abortXhr); + + xhr.onreadystatechange = function() { + // DONE (success or failure) + if (xhr.readyState === 4) { + request.signal.removeEventListener('abort', abortXhr); + } + }; + } + + xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit); + }) + } + + fetch.polyfill = true; + + if (!self.fetch) { + self.fetch = fetch; + self.Headers = Headers; + self.Request = Request; + self.Response = Response; + } + + exports.Headers = Headers; + exports.Request = Request; + exports.Response = Response; + exports.fetch = fetch; + + Object.defineProperty(exports, '__esModule', { value: true }); + + return exports; + + }))({}); + })(__self__); + __self__.fetch.ponyfill = true; + // Remove "polyfill" property added by whatwg-fetch + delete __self__.fetch.polyfill; + // Choose between native implementation (global) or custom implementation (__self__) + // var ctx = global.fetch ? global : __self__; + var ctx = __self__; // this line disable service worker support temporarily + exports = ctx.fetch; // To enable: import fetch from 'cross-fetch' + exports.default = ctx.fetch; // For TypeScript consumers without esModuleInterop. + exports.fetch = ctx.fetch; // To enable: import {fetch} from 'cross-fetch' + exports.Headers = ctx.Headers; + exports.Request = ctx.Request; + exports.Response = ctx.Response; + module.exports = exports; +} (browserPonyfill, browserPonyfill.exports)); var global$1 = (typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : @@ -843,163 +849,171 @@ var browser = {exports: {}}; * Helpers. */ -var s = 1000; -var m = s * 60; -var h = m * 60; -var d = h * 24; -var w = d * 7; -var y = d * 365.25; - -/** - * Parse or format the given `val`. - * - * Options: - * - * - `long` verbose formatting [false] - * - * @param {String|Number} val - * @param {Object} [options] - * @throws {Error} throw an error if val is not a non-empty string or a number - * @return {String|Number} - * @api public - */ - -var ms = function(val, options) { - options = options || {}; - var type = typeof val; - if (type === 'string' && val.length > 0) { - return parse(val); - } else if (type === 'number' && isFinite(val)) { - return options.long ? fmtLong(val) : fmtShort(val); - } - throw new Error( - 'val is not a non-empty string or a valid number. val=' + - JSON.stringify(val) - ); -}; - -/** - * Parse the given `str` and return milliseconds. - * - * @param {String} str - * @return {Number} - * @api private - */ +var ms; +var hasRequiredMs; -function parse(str) { - str = String(str); - if (str.length > 100) { - return; - } - var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( - str - ); - if (!match) { - return; - } - var n = parseFloat(match[1]); - var type = (match[2] || 'ms').toLowerCase(); - switch (type) { - case 'years': - case 'year': - case 'yrs': - case 'yr': - case 'y': - return n * y; - case 'weeks': - case 'week': - case 'w': - return n * w; - case 'days': - case 'day': - case 'd': - return n * d; - case 'hours': - case 'hour': - case 'hrs': - case 'hr': - case 'h': - return n * h; - case 'minutes': - case 'minute': - case 'mins': - case 'min': - case 'm': - return n * m; - case 'seconds': - case 'second': - case 'secs': - case 'sec': - case 's': - return n * s; - case 'milliseconds': - case 'millisecond': - case 'msecs': - case 'msec': - case 'ms': - return n; - default: - return undefined; - } -} +function requireMs () { + if (hasRequiredMs) return ms; + hasRequiredMs = 1; + var s = 1000; + var m = s * 60; + var h = m * 60; + var d = h * 24; + var w = d * 7; + var y = d * 365.25; -/** - * Short format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ + /** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} [options] + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + + ms = function(val, options) { + options = options || {}; + var type = typeof val; + if (type === 'string' && val.length > 0) { + return parse(val); + } else if (type === 'number' && isFinite(val)) { + return options.long ? fmtLong(val) : fmtShort(val); + } + throw new Error( + 'val is not a non-empty string or a valid number. val=' + + JSON.stringify(val) + ); + }; -function fmtShort(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return Math.round(ms / d) + 'd'; - } - if (msAbs >= h) { - return Math.round(ms / h) + 'h'; - } - if (msAbs >= m) { - return Math.round(ms / m) + 'm'; - } - if (msAbs >= s) { - return Math.round(ms / s) + 's'; - } - return ms + 'ms'; -} + /** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + + function parse(str) { + str = String(str); + if (str.length > 100) { + return; + } + var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + str + ); + if (!match) { + return; + } + var n = parseFloat(match[1]); + var type = (match[2] || 'ms').toLowerCase(); + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y; + case 'weeks': + case 'week': + case 'w': + return n * w; + case 'days': + case 'day': + case 'd': + return n * d; + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h; + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m; + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s; + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n; + default: + return undefined; + } + } -/** - * Long format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ + /** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + + function fmtShort(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return Math.round(ms / d) + 'd'; + } + if (msAbs >= h) { + return Math.round(ms / h) + 'h'; + } + if (msAbs >= m) { + return Math.round(ms / m) + 'm'; + } + if (msAbs >= s) { + return Math.round(ms / s) + 's'; + } + return ms + 'ms'; + } -function fmtLong(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return plural(ms, msAbs, d, 'day'); - } - if (msAbs >= h) { - return plural(ms, msAbs, h, 'hour'); - } - if (msAbs >= m) { - return plural(ms, msAbs, m, 'minute'); - } - if (msAbs >= s) { - return plural(ms, msAbs, s, 'second'); - } - return ms + ' ms'; -} + /** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + + function fmtLong(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return plural(ms, msAbs, d, 'day'); + } + if (msAbs >= h) { + return plural(ms, msAbs, h, 'hour'); + } + if (msAbs >= m) { + return plural(ms, msAbs, m, 'minute'); + } + if (msAbs >= s) { + return plural(ms, msAbs, s, 'second'); + } + return ms + ' ms'; + } -/** - * Pluralization helper. - */ + /** + * Pluralization helper. + */ -function plural(ms, msAbs, n, name) { - var isPlural = msAbs >= n * 1.5; - return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); + function plural(ms, msAbs, n, name) { + var isPlural = msAbs >= n * 1.5; + return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); + } + return ms; } /** @@ -1014,7 +1028,7 @@ function setup(env) { createDebug.disable = disable; createDebug.enable = enable; createDebug.enabled = enabled; - createDebug.humanize = ms; + createDebug.humanize = requireMs(); createDebug.destroy = destroy; Object.keys(env).forEach(key => { @@ -1277,274 +1291,274 @@ function setup(env) { var common = setup; (function (module, exports) { -/** - * This is the web browser implementation of `debug()`. - */ + /** + * This is the web browser implementation of `debug()`. + */ + + exports.formatArgs = formatArgs; + exports.save = save; + exports.load = load; + exports.useColors = useColors; + exports.storage = localstorage(); + exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; + })(); + + /** + * Colors. + */ + + exports.colors = [ + '#0000CC', + '#0000FF', + '#0033CC', + '#0033FF', + '#0066CC', + '#0066FF', + '#0099CC', + '#0099FF', + '#00CC00', + '#00CC33', + '#00CC66', + '#00CC99', + '#00CCCC', + '#00CCFF', + '#3300CC', + '#3300FF', + '#3333CC', + '#3333FF', + '#3366CC', + '#3366FF', + '#3399CC', + '#3399FF', + '#33CC00', + '#33CC33', + '#33CC66', + '#33CC99', + '#33CCCC', + '#33CCFF', + '#6600CC', + '#6600FF', + '#6633CC', + '#6633FF', + '#66CC00', + '#66CC33', + '#9900CC', + '#9900FF', + '#9933CC', + '#9933FF', + '#99CC00', + '#99CC33', + '#CC0000', + '#CC0033', + '#CC0066', + '#CC0099', + '#CC00CC', + '#CC00FF', + '#CC3300', + '#CC3333', + '#CC3366', + '#CC3399', + '#CC33CC', + '#CC33FF', + '#CC6600', + '#CC6633', + '#CC9900', + '#CC9933', + '#CCCC00', + '#CCCC33', + '#FF0000', + '#FF0033', + '#FF0066', + '#FF0099', + '#FF00CC', + '#FF00FF', + '#FF3300', + '#FF3333', + '#FF3366', + '#FF3399', + '#FF33CC', + '#FF33FF', + '#FF6600', + '#FF6633', + '#FF9900', + '#FF9933', + '#FFCC00', + '#FFCC33' + ]; -exports.formatArgs = formatArgs; -exports.save = save; -exports.load = load; -exports.useColors = useColors; -exports.storage = localstorage(); -exports.destroy = (() => { - let warned = false; - - return () => { - if (!warned) { - warned = true; - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + /** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ + + // eslint-disable-next-line complexity + function useColors() { + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { + return true; } - }; -})(); -/** - * Colors. - */ + // Internet Explorer and Edge do not support colors. + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } + + // Is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || + // Is firebug? http://stackoverflow.com/a/398120/376773 + (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || + // Is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + // Double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); + } -exports.colors = [ - '#0000CC', - '#0000FF', - '#0033CC', - '#0033FF', - '#0066CC', - '#0066FF', - '#0099CC', - '#0099FF', - '#00CC00', - '#00CC33', - '#00CC66', - '#00CC99', - '#00CCCC', - '#00CCFF', - '#3300CC', - '#3300FF', - '#3333CC', - '#3333FF', - '#3366CC', - '#3366FF', - '#3399CC', - '#3399FF', - '#33CC00', - '#33CC33', - '#33CC66', - '#33CC99', - '#33CCCC', - '#33CCFF', - '#6600CC', - '#6600FF', - '#6633CC', - '#6633FF', - '#66CC00', - '#66CC33', - '#9900CC', - '#9900FF', - '#9933CC', - '#9933FF', - '#99CC00', - '#99CC33', - '#CC0000', - '#CC0033', - '#CC0066', - '#CC0099', - '#CC00CC', - '#CC00FF', - '#CC3300', - '#CC3333', - '#CC3366', - '#CC3399', - '#CC33CC', - '#CC33FF', - '#CC6600', - '#CC6633', - '#CC9900', - '#CC9933', - '#CCCC00', - '#CCCC33', - '#FF0000', - '#FF0033', - '#FF0066', - '#FF0099', - '#FF00CC', - '#FF00FF', - '#FF3300', - '#FF3333', - '#FF3366', - '#FF3399', - '#FF33CC', - '#FF33FF', - '#FF6600', - '#FF6633', - '#FF9900', - '#FF9933', - '#FFCC00', - '#FFCC33' -]; + /** + * Colorize log arguments if enabled. + * + * @api public + */ + + function formatArgs(args) { + args[0] = (this.useColors ? '%c' : '') + + this.namespace + + (this.useColors ? ' %c' : ' ') + + args[0] + + (this.useColors ? '%c ' : ' ') + + '+' + module.exports.humanize(this.diff); + + if (!this.useColors) { + return; + } -/** - * Currently only WebKit-based Web Inspectors, Firefox >= v31, - * and the Firebug extension (any Firefox version) are known - * to support "%c" CSS customizations. - * - * TODO: add a `localStorage` variable to explicitly enable/disable colors - */ + const c = 'color: ' + this.color; + args.splice(1, 0, c, 'color: inherit'); -// eslint-disable-next-line complexity -function useColors() { - // NB: In an Electron preload script, document will be defined but not fully - // initialized. Since we know we're in Chrome, we'll just detect this case - // explicitly - if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { - return true; - } + // The final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + let index = 0; + let lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, match => { + if (match === '%%') { + return; + } + index++; + if (match === '%c') { + // We only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); - // Internet Explorer and Edge do not support colors. - if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { - return false; + args.splice(lastC, 0, c); } - // Is webkit? http://stackoverflow.com/a/16459606/376773 - // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 - return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || - // Is firebug? http://stackoverflow.com/a/398120/376773 - (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || - // Is firefox >= v31? - // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || - // Double check webkit in userAgent just in case we are in a worker - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); -} + /** + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. + * + * @api public + */ + exports.log = console.debug || console.log || (() => {}); -/** - * Colorize log arguments if enabled. - * - * @api public - */ - -function formatArgs(args) { - args[0] = (this.useColors ? '%c' : '') + - this.namespace + - (this.useColors ? ' %c' : ' ') + - args[0] + - (this.useColors ? '%c ' : ' ') + - '+' + module.exports.humanize(this.diff); - - if (!this.useColors) { - return; + /** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + function save(namespaces) { + try { + if (namespaces) { + exports.storage.setItem('debug', namespaces); + } else { + exports.storage.removeItem('debug'); + } + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } } - const c = 'color: ' + this.color; - args.splice(1, 0, c, 'color: inherit'); - - // The final "%c" is somewhat tricky, because there could be other - // arguments passed either before or after the %c, so we need to - // figure out the correct index to insert the CSS into - let index = 0; - let lastC = 0; - args[0].replace(/%[a-zA-Z%]/g, match => { - if (match === '%%') { - return; - } - index++; - if (match === '%c') { - // We only are interested in the *last* %c - // (the user may have provided their own) - lastC = index; + /** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + function load() { + let r; + try { + r = exports.storage.getItem('debug'); + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? } - }); - - args.splice(lastC, 0, c); -} - -/** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. - * - * @api public - */ -exports.log = console.debug || console.log || (() => {}); -/** - * Save `namespaces`. - * - * @param {String} namespaces - * @api private - */ -function save(namespaces) { - try { - if (namespaces) { - exports.storage.setItem('debug', namespaces); - } else { - exports.storage.removeItem('debug'); + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (!r && typeof browser$1$1 !== 'undefined' && 'env' in browser$1$1) { + r = browser$1$1.env.DEBUG; } - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } -} -/** - * Load `namespaces`. - * - * @return {String} returns the previously persisted debug modes - * @api private - */ -function load() { - let r; - try { - r = exports.storage.getItem('debug'); - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } - - // If debug isn't set in LS, and we're in Electron, try to load $DEBUG - if (!r && typeof browser$1$1 !== 'undefined' && 'env' in browser$1$1) { - r = browser$1$1.env.DEBUG; + return r; } - return r; -} - -/** - * Localstorage attempts to return the localstorage. - * - * This is necessary because safari throws - * when a user disables cookies/localstorage - * and you attempt to access it. - * - * @return {LocalStorage} - * @api private - */ - -function localstorage() { - try { - // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context - // The Browser also has localStorage in the global context. - return localStorage; - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? + /** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + + function localstorage() { + try { + // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context + // The Browser also has localStorage in the global context. + return localStorage; + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } } -} - -module.exports = common(exports); -const {formatters} = module.exports; + module.exports = common(exports); -/** - * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. - */ + const {formatters} = module.exports; -formatters.j = function (v) { - try { - return JSON.stringify(v); - } catch (error) { - return '[UnexpectedJSONParseError]: ' + error.message; - } -}; -}(browser, browser.exports)); + /** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + + formatters.j = function (v) { + try { + return JSON.stringify(v); + } catch (error) { + return '[UnexpectedJSONParseError]: ' + error.message; + } + }; +} (browser, browser.exports)); var getLogger = browser.exports; @@ -1778,7 +1792,7 @@ function write (buffer, value, offset, isLE, mLen, nBytes) { var toString = {}.toString; -var isArray$3 = Array.isArray || function (arr) { +var isArray$4 = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; @@ -1815,7 +1829,7 @@ var INSPECT_MAX_BYTES = 50; * 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$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined +Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined ? global$1.TYPED_ARRAY_SUPPORT : true; @@ -1825,7 +1839,7 @@ Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined var _kMaxLength = kMaxLength(); function kMaxLength () { - return Buffer$1.TYPED_ARRAY_SUPPORT + return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff } @@ -1834,14 +1848,14 @@ function createBuffer (that, length) { if (kMaxLength() < length) { throw new RangeError('Invalid typed array length') } - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = new Uint8Array(length); - that.__proto__ = Buffer$1.prototype; + that.__proto__ = Buffer.prototype; } else { // Fallback: Return an object instance of the Buffer class if (that === null) { - that = new Buffer$1(length); + that = new Buffer(length); } that.length = length; } @@ -1859,9 +1873,9 @@ function createBuffer (that, length) { * The `Uint8Array` prototype remains unmodified. */ -function Buffer$1 (arg, encodingOrOffset, length) { - if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) { - return new Buffer$1(arg, encodingOrOffset, length) +function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) } // Common case. @@ -1876,11 +1890,11 @@ function Buffer$1 (arg, encodingOrOffset, length) { return from(this, arg, encodingOrOffset, length) } -Buffer$1.poolSize = 8192; // not used by this implementation +Buffer.poolSize = 8192; // not used by this implementation // TODO: Legacy, not needed anymore. Remove in next major version. -Buffer$1._augment = function (arr) { - arr.__proto__ = Buffer$1.prototype; +Buffer._augment = function (arr) { + arr.__proto__ = Buffer.prototype; return arr }; @@ -1908,13 +1922,13 @@ function from (that, value, encodingOrOffset, length) { * Buffer.from(buffer) * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ -Buffer$1.from = function (value, encodingOrOffset, length) { +Buffer.from = function (value, encodingOrOffset, length) { return from(null, value, encodingOrOffset, length) }; -if (Buffer$1.TYPED_ARRAY_SUPPORT) { - Buffer$1.prototype.__proto__ = Uint8Array.prototype; - Buffer$1.__proto__ = Uint8Array; +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype; + Buffer.__proto__ = Uint8Array; } function assertSize (size) { @@ -1945,14 +1959,14 @@ function alloc (that, size, fill, encoding) { * Creates a new filled Buffer instance. * alloc(size[, fill[, encoding]]) **/ -Buffer$1.alloc = function (size, fill, encoding) { +Buffer.alloc = function (size, fill, encoding) { return alloc(null, size, fill, encoding) }; function allocUnsafe (that, size) { assertSize(size); that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); - if (!Buffer$1.TYPED_ARRAY_SUPPORT) { + if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < size; ++i) { that[i] = 0; } @@ -1963,13 +1977,13 @@ function allocUnsafe (that, size) { /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ -Buffer$1.allocUnsafe = function (size) { +Buffer.allocUnsafe = function (size) { return allocUnsafe(null, size) }; /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ -Buffer$1.allocUnsafeSlow = function (size) { +Buffer.allocUnsafeSlow = function (size) { return allocUnsafe(null, size) }; @@ -1978,7 +1992,7 @@ function fromString (that, string, encoding) { encoding = 'utf8'; } - if (!Buffer$1.isEncoding(encoding)) { + if (!Buffer.isEncoding(encoding)) { throw new TypeError('"encoding" must be a valid string encoding') } @@ -2025,10 +2039,10 @@ function fromArrayBuffer (that, array, byteOffset, length) { array = new Uint8Array(array, byteOffset, length); } - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = array; - that.__proto__ = Buffer$1.prototype; + that.__proto__ = Buffer.prototype; } else { // Fallback: Return an object instance of the Buffer class that = fromArrayLike(that, array); @@ -2058,7 +2072,7 @@ function fromObject (that, obj) { return fromArrayLike(that, obj) } - if (obj.type === 'Buffer' && isArray$3(obj.data)) { + if (obj.type === 'Buffer' && isArray$4(obj.data)) { return fromArrayLike(that, obj.data) } } @@ -2080,14 +2094,14 @@ function SlowBuffer (length) { if (+length != length) { // eslint-disable-line eqeqeq length = 0; } - return Buffer$1.alloc(+length) + return Buffer.alloc(+length) } -Buffer$1.isBuffer = isBuffer; +Buffer.isBuffer = isBuffer; function internalIsBuffer (b) { return !!(b != null && b._isBuffer) } -Buffer$1.compare = function compare (a, b) { +Buffer.compare = function compare (a, b) { if (!internalIsBuffer(a) || !internalIsBuffer(b)) { throw new TypeError('Arguments must be Buffers') } @@ -2110,7 +2124,7 @@ Buffer$1.compare = function compare (a, b) { return 0 }; -Buffer$1.isEncoding = function isEncoding (encoding) { +Buffer.isEncoding = function isEncoding (encoding) { switch (String(encoding).toLowerCase()) { case 'hex': case 'utf8': @@ -2129,13 +2143,13 @@ Buffer$1.isEncoding = function isEncoding (encoding) { } }; -Buffer$1.concat = function concat (list, length) { - if (!isArray$3(list)) { +Buffer.concat = function concat (list, length) { + if (!isArray$4(list)) { throw new TypeError('"list" argument must be an Array of Buffers') } if (list.length === 0) { - return Buffer$1.alloc(0) + return Buffer.alloc(0) } var i; @@ -2146,7 +2160,7 @@ Buffer$1.concat = function concat (list, length) { } } - var buffer = Buffer$1.allocUnsafe(length); + var buffer = Buffer.allocUnsafe(length); var pos = 0; for (i = 0; i < list.length; ++i) { var buf = list[i]; @@ -2202,7 +2216,7 @@ function byteLength (string, encoding) { } } } -Buffer$1.byteLength = byteLength; +Buffer.byteLength = byteLength; function slowToString (encoding, start, end) { var loweredCase = false; @@ -2276,7 +2290,7 @@ function slowToString (encoding, start, end) { // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect // Buffer instances. -Buffer$1.prototype._isBuffer = true; +Buffer.prototype._isBuffer = true; function swap (b, n, m) { var i = b[n]; @@ -2284,7 +2298,7 @@ function swap (b, n, m) { b[m] = i; } -Buffer$1.prototype.swap16 = function swap16 () { +Buffer.prototype.swap16 = function swap16 () { var len = this.length; if (len % 2 !== 0) { throw new RangeError('Buffer size must be a multiple of 16-bits') @@ -2295,7 +2309,7 @@ Buffer$1.prototype.swap16 = function swap16 () { return this }; -Buffer$1.prototype.swap32 = function swap32 () { +Buffer.prototype.swap32 = function swap32 () { var len = this.length; if (len % 4 !== 0) { throw new RangeError('Buffer size must be a multiple of 32-bits') @@ -2307,7 +2321,7 @@ Buffer$1.prototype.swap32 = function swap32 () { return this }; -Buffer$1.prototype.swap64 = function swap64 () { +Buffer.prototype.swap64 = function swap64 () { var len = this.length; if (len % 8 !== 0) { throw new RangeError('Buffer size must be a multiple of 64-bits') @@ -2321,20 +2335,20 @@ Buffer$1.prototype.swap64 = function swap64 () { return this }; -Buffer$1.prototype.toString = function toString () { +Buffer.prototype.toString = function toString () { var length = this.length | 0; if (length === 0) return '' if (arguments.length === 0) return utf8Slice(this, 0, length) return slowToString.apply(this, arguments) }; -Buffer$1.prototype.equals = function equals (b) { +Buffer.prototype.equals = function equals (b) { if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true - return Buffer$1.compare(this, b) === 0 + return Buffer.compare(this, b) === 0 }; -Buffer$1.prototype.inspect = function inspect () { +Buffer.prototype.inspect = function inspect () { var str = ''; var max = INSPECT_MAX_BYTES; if (this.length > 0) { @@ -2344,7 +2358,7 @@ Buffer$1.prototype.inspect = function inspect () { return '' }; -Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { if (!internalIsBuffer(target)) { throw new TypeError('Argument must be a Buffer') } @@ -2443,7 +2457,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { // Normalize val if (typeof val === 'string') { - val = Buffer$1.from(val, encoding); + val = Buffer.from(val, encoding); } // Finally, search either indexOf (if dir is true) or lastIndexOf @@ -2455,7 +2469,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return arrayIndexOf(buffer, val, byteOffset, encoding, dir) } else if (typeof val === 'number') { val = val & 0xFF; // Search for a byte value [0-255] - if (Buffer$1.TYPED_ARRAY_SUPPORT && + if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) @@ -2525,15 +2539,15 @@ function arrayIndexOf (arr, val, byteOffset, encoding, dir) { return -1 } -Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) { +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { return this.indexOf(val, byteOffset, encoding) !== -1 }; -Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) { +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, true) }; -Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false) }; @@ -2584,7 +2598,7 @@ function ucs2Write (buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) } -Buffer$1.prototype.write = function write (string, offset, length, encoding) { +Buffer.prototype.write = function write (string, offset, length, encoding) { // Buffer#write(string) if (offset === undefined) { encoding = 'utf8'; @@ -2656,7 +2670,7 @@ Buffer$1.prototype.write = function write (string, offset, length, encoding) { } }; -Buffer$1.prototype.toJSON = function toJSON () { +Buffer.prototype.toJSON = function toJSON () { return { type: 'Buffer', data: Array.prototype.slice.call(this._arr || this, 0) @@ -2809,7 +2823,7 @@ function utf16leSlice (buf, start, end) { return res } -Buffer$1.prototype.slice = function slice (start, end) { +Buffer.prototype.slice = function slice (start, end) { var len = this.length; start = ~~start; end = end === undefined ? len : ~~end; @@ -2831,12 +2845,12 @@ Buffer$1.prototype.slice = function slice (start, end) { if (end < start) end = start; var newBuf; - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { newBuf = this.subarray(start, end); - newBuf.__proto__ = Buffer$1.prototype; + newBuf.__proto__ = Buffer.prototype; } else { var sliceLen = end - start; - newBuf = new Buffer$1(sliceLen, undefined); + newBuf = new Buffer(sliceLen, undefined); for (var i = 0; i < sliceLen; ++i) { newBuf[i] = this[i + start]; } @@ -2853,7 +2867,7 @@ function checkOffset (offset, ext, length) { if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') } -Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); @@ -2868,7 +2882,7 @@ Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAsser return val }; -Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) { @@ -2884,22 +2898,22 @@ Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAsser return val }; -Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) { +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); return this[offset] }; -Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] | (this[offset + 1] << 8) }; -Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); return (this[offset] << 8) | this[offset + 1] }; -Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return ((this[offset]) | @@ -2908,7 +2922,7 @@ Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { (this[offset + 3] * 0x1000000) }; -Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] * 0x1000000) + @@ -2917,7 +2931,7 @@ Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { this[offset + 3]) }; -Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); @@ -2935,7 +2949,7 @@ Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) return val }; -Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); @@ -2953,25 +2967,25 @@ Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) return val }; -Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) { +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { if (!noAssert) checkOffset(offset, 1, this.length); if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) }; -Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) { +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset] | (this[offset + 1] << 8); return (val & 0x8000) ? val | 0xFFFF0000 : val }; -Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) { +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset + 1] | (this[offset] << 8); return (val & 0x8000) ? val | 0xFFFF0000 : val }; -Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) { +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset]) | @@ -2980,7 +2994,7 @@ Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) { (this[offset + 3] << 24) }; -Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) { +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] << 24) | @@ -2989,22 +3003,22 @@ Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) { (this[offset + 3]) }; -Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) { +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, true, 23, 4) }; -Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) { +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { if (!noAssert) checkOffset(offset, 4, this.length); return read(this, offset, false, 23, 4) }; -Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, true, 52, 8) }; -Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { if (!noAssert) checkOffset(offset, 8, this.length); return read(this, offset, false, 52, 8) }; @@ -3015,7 +3029,7 @@ function checkInt (buf, value, offset, ext, max, min) { if (offset + ext > buf.length) throw new RangeError('Index out of range') } -Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; byteLength = byteLength | 0; @@ -3034,7 +3048,7 @@ Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength return offset + byteLength }; -Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; byteLength = byteLength | 0; @@ -3053,11 +3067,11 @@ Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength return offset + byteLength }; -Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); - if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value); + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); this[offset] = (value & 0xff); return offset + 1 }; @@ -3070,11 +3084,11 @@ function objectWriteUInt16 (buf, value, offset, littleEndian) { } } -Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value & 0xff); this[offset + 1] = (value >>> 8); } else { @@ -3083,11 +3097,11 @@ Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAsse return offset + 2 }; -Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8); this[offset + 1] = (value & 0xff); } else { @@ -3103,11 +3117,11 @@ function objectWriteUInt32 (buf, value, offset, littleEndian) { } } -Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset + 3] = (value >>> 24); this[offset + 2] = (value >>> 16); this[offset + 1] = (value >>> 8); @@ -3118,11 +3132,11 @@ Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAsse return offset + 4 }; -Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 24); this[offset + 1] = (value >>> 16); this[offset + 2] = (value >>> 8); @@ -3133,7 +3147,7 @@ Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAsse return offset + 4 }; -Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { @@ -3156,7 +3170,7 @@ Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, return offset + byteLength }; -Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value; offset = offset | 0; if (!noAssert) { @@ -3179,21 +3193,21 @@ Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, return offset + byteLength }; -Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); - if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value); + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); if (value < 0) value = 0xff + value + 1; this[offset] = (value & 0xff); return offset + 1 }; -Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value & 0xff); this[offset + 1] = (value >>> 8); } else { @@ -3202,11 +3216,11 @@ Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert return offset + 2 }; -Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8); this[offset + 1] = (value & 0xff); } else { @@ -3215,11 +3229,11 @@ Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert return offset + 2 }; -Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value & 0xff); this[offset + 1] = (value >>> 8); this[offset + 2] = (value >>> 16); @@ -3230,12 +3244,12 @@ Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert return offset + 4 }; -Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value; offset = offset | 0; if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); if (value < 0) value = 0xffffffff + value + 1; - if (Buffer$1.TYPED_ARRAY_SUPPORT) { + if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 24); this[offset + 1] = (value >>> 16); this[offset + 2] = (value >>> 8); @@ -3259,11 +3273,11 @@ function writeFloat (buf, value, offset, littleEndian, noAssert) { return offset + 4 } -Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { return writeFloat(this, value, offset, true, noAssert) }; -Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { return writeFloat(this, value, offset, false, noAssert) }; @@ -3275,16 +3289,16 @@ function writeDouble (buf, value, offset, littleEndian, noAssert) { return offset + 8 } -Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { return writeDouble(this, value, offset, true, noAssert) }; -Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { return writeDouble(this, value, offset, false, noAssert) }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer$1.prototype.copy = function copy (target, targetStart, start, end) { +Buffer.prototype.copy = function copy (target, targetStart, start, end) { if (!start) start = 0; if (!end && end !== 0) end = this.length; if (targetStart >= target.length) targetStart = target.length; @@ -3316,7 +3330,7 @@ Buffer$1.prototype.copy = function copy (target, targetStart, start, end) { for (i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start]; } - } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) { + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { // ascending copy from start for (i = 0; i < len; ++i) { target[i + targetStart] = this[i + start]; @@ -3336,7 +3350,7 @@ Buffer$1.prototype.copy = function copy (target, targetStart, start, end) { // buffer.fill(number[, offset[, end]]) // buffer.fill(buffer[, offset[, end]]) // buffer.fill(string[, offset[, end]][, encoding]) -Buffer$1.prototype.fill = function fill (val, start, end, encoding) { +Buffer.prototype.fill = function fill (val, start, end, encoding) { // Handle string cases: if (typeof val === 'string') { if (typeof start === 'string') { @@ -3356,7 +3370,7 @@ Buffer$1.prototype.fill = function fill (val, start, end, encoding) { if (encoding !== undefined && typeof encoding !== 'string') { throw new TypeError('encoding must be a string') } - if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) { + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { throw new TypeError('Unknown encoding: ' + encoding) } } else if (typeof val === 'number') { @@ -3385,7 +3399,7 @@ Buffer$1.prototype.fill = function fill (val, start, end, encoding) { } else { var bytes = internalIsBuffer(val) ? val - : utf8ToBytes(new Buffer$1(val, encoding).toString()); + : utf8ToBytes(new Buffer(val, encoding).toString()); var len = bytes.length; for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len]; @@ -3563,7 +3577,7 @@ function isSlowBuffer (obj) { var _polyfillNode_buffer = /*#__PURE__*/Object.freeze({ __proto__: null, - Buffer: Buffer$1, + Buffer: Buffer, INSPECT_MAX_BYTES: INSPECT_MAX_BYTES, SlowBuffer: SlowBuffer, isBuffer: isBuffer, @@ -3572,1797 +3586,4494 @@ var _polyfillNode_buffer = /*#__PURE__*/Object.freeze({ var sax$1 = {}; -var string_decoder = {}; +var domain; -var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_buffer); +// This constructor is used to store event handlers. Instantiating this is +// faster than explicitly calling `Object.create(null)` to get a "clean" empty +// object (tested with v8 v4.9). +function EventHandlers() {} +EventHandlers.prototype = Object.create(null); -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +function EventEmitter() { + EventEmitter.init.call(this); +} -var Buffer = require$$0.Buffer; +// nodejs oddity +// require('events') === require('events').EventEmitter +EventEmitter.EventEmitter = EventEmitter; -var isBufferEncoding = Buffer.isEncoding - || function(encoding) { - switch (encoding && encoding.toLowerCase()) { - case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; - default: return false; - } - }; +EventEmitter.usingDomains = false; +EventEmitter.prototype.domain = undefined; +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; -function assertEncoding(encoding) { - if (encoding && !isBufferEncoding(encoding)) { - throw new Error('Unknown encoding: ' + encoding); +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +EventEmitter.defaultMaxListeners = 10; + +EventEmitter.init = function() { + this.domain = null; + if (EventEmitter.usingDomains) { + // if there is an active domain, then attach to it. + if (domain.active ) ; } -} -// StringDecoder provides an interface for efficiently splitting a series of -// buffers into a series of JS strings without breaking apart multi-byte -// characters. CESU-8 is handled as part of the UTF-8 encoding. -// -// @TODO Handling all encodings inside a single object makes it very difficult -// to reason about this code, so it should be split up in the future. -// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code -// points as used by CESU-8. -var StringDecoder = string_decoder.StringDecoder = function(encoding) { - this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); - assertEncoding(encoding); - switch (this.encoding) { - case 'utf8': - // CESU-8 represents each of Surrogate Pair by 3-bytes - this.surrogateSize = 3; - break; - case 'ucs2': - case 'utf16le': - // UTF-16 represents each of Surrogate Pair by 2-bytes - this.surrogateSize = 2; - this.detectIncompleteChar = utf16DetectIncompleteChar; - break; - case 'base64': - // Base-64 stores 3 bytes in 4 chars, and pads the remainder. - this.surrogateSize = 3; - this.detectIncompleteChar = base64DetectIncompleteChar; - break; - default: - this.write = passThroughWrite; - return; + if (!this._events || this._events === Object.getPrototypeOf(this)._events) { + this._events = new EventHandlers(); + this._eventsCount = 0; } - // Enough space to store all bytes of a single character. UTF-8 needs 4 - // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). - this.charBuffer = new Buffer(6); - // Number of bytes received for the current incomplete multi-byte character. - this.charReceived = 0; - // Number of bytes expected for the current incomplete multi-byte character. - this.charLength = 0; + this._maxListeners = this._maxListeners || undefined; }; +// 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 (typeof n !== 'number' || n < 0 || isNaN(n)) + throw new TypeError('"n" argument must be a positive number'); + this._maxListeners = n; + return this; +}; -// write decodes the given buffer and returns it as JS string that is -// guaranteed to not contain any partial multi-byte characters. Any partial -// character found at the end of the buffer is buffered up, and will be -// returned when calling write again with the remaining bytes. -// -// Note: Converting a Buffer containing an orphan surrogate to a String -// currently works, but converting a String to a Buffer (via `new Buffer`, or -// Buffer#write) will replace incomplete surrogates with the unicode -// replacement character. See https://codereview.chromium.org/121173009/ . -StringDecoder.prototype.write = function(buffer) { - var charStr = ''; - // if our last write ended with an incomplete multibyte character - while (this.charLength) { - // determine how many remaining bytes this buffer has to offer for this char - var available = (buffer.length >= this.charLength - this.charReceived) ? - this.charLength - this.charReceived : - buffer.length; +function $getMaxListeners(that) { + if (that._maxListeners === undefined) + return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} - // add the new bytes to the char buffer - buffer.copy(this.charBuffer, this.charReceived, 0, available); - this.charReceived += available; +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return $getMaxListeners(this); +}; - if (this.charReceived < this.charLength) { - // still not enough chars in this buffer? wait for more ... - return ''; - } +// These standalone emit* functions are used to optimize calling of event +// handlers for fast cases because emit() itself often has a variable number of +// arguments and can be deoptimized because of that. These functions always have +// the same number of arguments and thus do not get deoptimized, so the code +// inside them can execute faster. +function emitNone(handler, isFn, self) { + if (isFn) + handler.call(self); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self); + } +} +function emitOne(handler, isFn, self, arg1) { + if (isFn) + handler.call(self, arg1); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1); + } +} +function emitTwo(handler, isFn, self, arg1, arg2) { + if (isFn) + handler.call(self, arg1, arg2); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2); + } +} +function emitThree(handler, isFn, self, arg1, arg2, arg3) { + if (isFn) + handler.call(self, arg1, arg2, arg3); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2, arg3); + } +} - // remove bytes belonging to the current character from the buffer - buffer = buffer.slice(available, buffer.length); +function emitMany(handler, isFn, self, args) { + if (isFn) + handler.apply(self, args); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].apply(self, args); + } +} - // get the character that was split - charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); +EventEmitter.prototype.emit = function emit(type) { + var er, handler, len, args, i, events, domain; + var doError = (type === 'error'); - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - var charCode = charStr.charCodeAt(charStr.length - 1); - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - this.charLength += this.surrogateSize; - charStr = ''; - continue; - } - this.charReceived = this.charLength = 0; + events = this._events; + if (events) + doError = (doError && events.error == null); + else if (!doError) + return false; - // if there are no more bytes in this buffer, just emit our char - if (buffer.length === 0) { - return charStr; + domain = this.domain; + + // If there is no 'error' event listener then throw. + if (doError) { + er = arguments[1]; + if (domain) { + if (!er) + er = new Error('Uncaught, unspecified "error" event'); + er.domainEmitter = this; + er.domain = domain; + er.domainThrown = false; + domain.emit('error', er); + } else if (er instanceof Error) { + throw er; // Unhandled 'error' event + } else { + // At least give some kind of context to the user + var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); + err.context = er; + throw err; } - break; + return false; } - // determine and set charLength / charReceived - this.detectIncompleteChar(buffer); - - var end = buffer.length; - if (this.charLength) { - // buffer the incomplete character bytes we got - buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); - end -= this.charReceived; - } + handler = events[type]; - charStr += buffer.toString(this.encoding, 0, end); + if (!handler) + return false; - var end = charStr.length - 1; - var charCode = charStr.charCodeAt(end); - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - var size = this.surrogateSize; - this.charLength += size; - this.charReceived += size; - this.charBuffer.copy(this.charBuffer, size, 0, size); - buffer.copy(this.charBuffer, 0, 0, size); - return charStr.substring(0, end); + var isFn = typeof handler === 'function'; + len = arguments.length; + switch (len) { + // fast cases + case 1: + emitNone(handler, isFn, this); + break; + case 2: + emitOne(handler, isFn, this, arguments[1]); + break; + case 3: + emitTwo(handler, isFn, this, arguments[1], arguments[2]); + break; + case 4: + emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); + break; + // slower + default: + args = new Array(len - 1); + for (i = 1; i < len; i++) + args[i - 1] = arguments[i]; + emitMany(handler, isFn, this, args); } - // or just emit the charStr - return charStr; + return true; }; -// detectIncompleteChar determines if there is an incomplete UTF-8 character at -// the end of the given buffer. If so, it sets this.charLength to the byte -// length that character, and sets this.charReceived to the number of bytes -// that are available for this character. -StringDecoder.prototype.detectIncompleteChar = function(buffer) { - // determine how many bytes we have to check at the end of this buffer - var i = (buffer.length >= 3) ? 3 : buffer.length; +function _addListener(target, type, listener, prepend) { + var m; + var events; + var existing; - // Figure out if one of the last i bytes of our buffer announces an - // incomplete char. - for (; i > 0; i--) { - var c = buffer[buffer.length - i]; + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); - // See http://en.wikipedia.org/wiki/UTF-8#Description + events = target._events; + if (!events) { + events = target._events = new EventHandlers(); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener) { + target.emit('newListener', type, + listener.listener ? listener.listener : listener); - // 110XXXXX - if (i == 1 && c >> 5 == 0x06) { - this.charLength = 2; - break; + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; } + existing = events[type]; + } - // 1110XXXX - if (i <= 2 && c >> 4 == 0x0E) { - this.charLength = 3; - break; + if (!existing) { + // Optimize the case of one listener. Don't need the extra array object. + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === 'function') { + // Adding the second element, need to change to array. + existing = events[type] = prepend ? [listener, existing] : + [existing, listener]; + } else { + // If we've already got an array, just append. + if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } } - // 11110XXX - if (i <= 3 && c >> 3 == 0x1E) { - this.charLength = 4; - break; + // Check for listener leak + if (!existing.warned) { + m = $getMaxListeners(target); + if (m && m > 0 && existing.length > m) { + existing.warned = true; + var w = new Error('Possible EventEmitter memory leak detected. ' + + existing.length + ' ' + type + ' listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit'); + w.name = 'MaxListenersExceededWarning'; + w.emitter = target; + w.type = type; + w.count = existing.length; + emitWarning(w); + } } } - this.charReceived = i; + + return target; +} +function emitWarning(e) { + typeof console.warn === 'function' ? console.warn(e) : console.log(e); +} +EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); }; -StringDecoder.prototype.end = function(buffer) { - var res = ''; - if (buffer && buffer.length) - res = this.write(buffer); +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.prependListener = + function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; - if (this.charReceived) { - var cr = this.charReceived; - var buf = this.charBuffer; - var enc = this.encoding; - res += buf.slice(0, cr).toString(enc); +function _onceWrap(target, type, listener) { + var fired = false; + function g() { + target.removeListener(type, g); + if (!fired) { + fired = true; + listener.apply(target, arguments); + } } + g.listener = listener; + return g; +} - return res; +EventEmitter.prototype.once = function once(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.on(type, _onceWrap(this, type, listener)); + return this; }; -function passThroughWrite(buffer) { - return buffer.toString(this.encoding); -} +EventEmitter.prototype.prependOnceListener = + function prependOnceListener(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; -function utf16DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 2; - this.charLength = this.charReceived ? 2 : 0; -} +// emits a 'removeListener' event iff the listener was removed +EventEmitter.prototype.removeListener = + function removeListener(type, listener) { + var list, events, position, i, originalListener; + + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + + events = this._events; + if (!events) + return this; + + list = events[type]; + if (!list) + return this; + + if (list === listener || (list.listener && list.listener === listener)) { + if (--this._eventsCount === 0) + this._events = new EventHandlers(); + else { + delete events[type]; + if (events.removeListener) + this.emit('removeListener', type, list.listener || listener); + } + } else if (typeof list !== 'function') { + position = -1; + + for (i = list.length; i-- > 0;) { + if (list[i] === listener || + (list[i].listener && list[i].listener === listener)) { + originalListener = list[i].listener; + position = i; + break; + } + } -function base64DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 3; - this.charLength = this.charReceived ? 3 : 0; -} + if (position < 0) + return this; -(function (exports) { -(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 = [ - 'text', - 'processinginstruction', - 'sgmldeclaration', - 'doctype', - 'comment', - 'opentagstart', - '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.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'); - } - - if (!Object.create) { - Object.create = function (o) { - function F () {} - F.prototype = o; - var newf = new F(); - return newf - }; - } + if (list.length === 1) { + list[0] = undefined; + if (--this._eventsCount === 0) { + this._events = new EventHandlers(); + return this; + } else { + delete events[type]; + } + } else { + spliceOne(list, position); + } + + if (events.removeListener) + this.emit('removeListener', type, originalListener || listener); + } - if (!Object.keys) { - Object.keys = function (o) { - var a = []; - for (var i in o) if (o.hasOwnProperty(i)) a.push(i); - return a + return this; }; - } + +// Alias for removeListener added in NodeJS 10.0 +// https://nodejs.org/api/events.html#events_emitter_off_eventname_listener +EventEmitter.prototype.off = function(type, listener){ + return this.removeListener(type, listener); +}; - 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]); +EventEmitter.prototype.removeAllListeners = + function removeAllListeners(type) { + var listeners, events; + + events = this._events; + if (!events) + return this; + + // not listening for removeListener, no need to emit + if (!events.removeListener) { + if (arguments.length === 0) { + this._events = new EventHandlers(); + this._eventsCount = 0; + } else if (events[type]) { + if (--this._eventsCount === 0) + this._events = new EventHandlers(); + else + delete events[type]; } + return this; } - 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; - } - function clearBuffers (parser) { - for (var i = 0, l = buffers.length; i < l; i++) { - parser[buffers[i]] = ''; - } - } + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = Object.keys(events); + for (var i = 0, key; i < keys.length; ++i) { + key = keys[i]; + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = new EventHandlers(); + this._eventsCount = 0; + return this; + } - 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 = ''; - } - } + listeners = events[type]; - 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); } - }; + if (typeof listeners === 'function') { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + do { + this.removeListener(type, listeners[listeners.length - 1]); + } while (listeners[0]); + } - var Stream; - try { - Stream = require('stream').Stream; - } catch (ex) { - Stream = function () {}; - } + return this; + }; - var streamWraps = sax.EVENTS.filter(function (ev) { - return ev !== 'error' && ev !== 'end' - }); +EventEmitter.prototype.listeners = function listeners(type) { + var evlistener; + var ret; + var events = this._events; - function createStream (strict, opt) { - return new SAXStream(strict, opt) + if (!events) + ret = []; + else { + evlistener = events[type]; + if (!evlistener) + ret = []; + else if (typeof evlistener === 'function') + ret = [evlistener.listener || evlistener]; + else + ret = unwrapListeners(evlistener); } - function SAXStream (strict, opt) { - if (!(this instanceof SAXStream)) { - return new SAXStream(strict, opt) - } + return ret; +}; - Stream.apply(this); +EventEmitter.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === 'function') { + return emitter.listenerCount(type); + } else { + return listenerCount$1.call(emitter, type); + } +}; - this._parser = new SAXParser(strict, opt); - this.writable = true; - this.readable = true; +EventEmitter.prototype.listenerCount = listenerCount$1; +function listenerCount$1(type) { + var events = this._events; - var me = this; + if (events) { + var evlistener = events[type]; - this._parser.onend = function () { - me.emit('end'); - }; + if (typeof evlistener === 'function') { + return 1; + } else if (evlistener) { + return evlistener.length; + } + } - this._parser.onerror = function (er) { - me.emit('error', er); + return 0; +} - // if didn't throw, then means error was handled. - // go ahead and clear error, so we can write again. - me._parser.error = null; - }; +EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; +}; - this._decoder = null; +// About 1.5x faster than the two-arg version of Array#splice(). +function spliceOne(list, index) { + for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) + list[i] = list[k]; + list.pop(); +} - 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 - }); - }); +function arrayClone(arr, i) { + var copy = new Array(i); + while (i--) + copy[i] = arr[i]; + return copy; +} + +function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; } + return ret; +} - SAXStream.prototype = Object.create(Stream.prototype, { - constructor: { - value: SAXStream +var inherits; +if (typeof Object.create === 'function'){ + inherits = function inherits(ctor, superCtor) { + // implementation from standard node.js 'util' module + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + inherits = function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + var TempCtor = function () {}; + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + }; +} +var inherits$1 = inherits; + +var formatRegExp = /%[sdj%]/g; +function format(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; } }); - - SAXStream.prototype.write = function (data) { - if (typeof Buffer$1 === 'function' && - typeof Buffer$1.isBuffer === 'function' && - Buffer$1.isBuffer(data)) { - if (!this._decoder) { - var SD = string_decoder.StringDecoder; - this._decoder = new SD('utf8'); - } - data = this._decoder.write(data); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); } + } + return str; +} - this._parser.write(data.toString()); - this.emit('data', data); - return true - }; +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +function deprecate(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global$1.process)) { + return function() { + return deprecate(fn, msg).apply(this, arguments); + }; + } - SAXStream.prototype.end = function (chunk) { - if (chunk && chunk.length) { - this.write(chunk); + if (browser$1$1.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (browser$1$1.throwDeprecation) { + throw new Error(msg); + } else if (browser$1$1.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; } - this._parser.end(); - return true - }; + return fn.apply(this, arguments); + } + + return deprecated; +} - 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); +var debugs = {}; +var debugEnviron; +function debuglog(set) { + if (isUndefined(debugEnviron)) + debugEnviron = browser$1$1.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = 0; + debugs[set] = function() { + var msg = format.apply(null, arguments); + console.error('%s %d: %s', set, pid, msg); }; + } else { + debugs[set] = function() {}; } + } + return debugs[set]; +} - return Stream.prototype.on.call(me, ev, handler) +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + _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.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} - // this really needs to be replaced with character classes. - // XML allows all manner of ridiculous numbers and digits. - var CDATA = '[CDATA['; - var DOCTYPE = 'DOCTYPE'; - var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'; - var XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/'; - var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE }; - - // 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-]/; - - var entityStart = /[#:_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 entityBody = /[#:_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-]/; - - function isWhitespace (c) { - return c === ' ' || c === '\n' || c === '\r' || c === '\t' - } - - function isQuote (c) { - return c === '"' || c === '\'' - } - - function isAttribEnd (c) { - return c === '>' || isWhitespace(c) - } - - function isMatch (regex, c) { - return regex.test(c) - } - - function notMatch (regex, c) { - return !isMatch(regex, c) - } - - var S = 0; - sax.STATE = { - BEGIN: S++, // leading byte order mark or whitespace - BEGIN_WHITESPACE: S++, // leading whitespace - TEXT: S++, // general stuff - TEXT_ENTITY: S++, // & and such. - OPEN_WAKA: S++, // < - SGML_DECL: S++, // - SCRIPT: S++, //