You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25426 lines
1.2 MiB

'use strict';
var obsidian = require('obsidian');
3 years ago
var require$$1$4 = require('path');
var require$$0$5 = require('url');
var require$$0$4 = require('events');
var require$$1 = require('util');
var require$$0$2 = require('stream');
var require$$2$1 = require('fs');
var require$$4 = require('http');
var require$$1$3 = require('https');
var require$$0$1 = require('dns');
var require$$2 = require('os');
var require$$0$3 = require('buffer');
var require$$1$1 = require('zlib');
var require$$0$6 = require('http2');
var require$$1$2 = require('tls');
var require$$0$7 = require('net');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
3 years ago
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function commonjsRequire (path) {
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var source$4 = {exports: {}};
var create = {};
var dist$1 = {exports: {}};
(function (module, exports) {
/// <reference lib="es2018"/>
/// <reference lib="dom"/>
/// <reference types="node"/>
Object.defineProperty(exports, "__esModule", { value: true });
const typedArrayTypeNames = [
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'BigInt64Array',
'BigUint64Array'
];
function isTypedArrayName(name) {
return typedArrayTypeNames.includes(name);
}
const objectTypeNames = [
'Function',
'Generator',
'AsyncGenerator',
'GeneratorFunction',
'AsyncGeneratorFunction',
'AsyncFunction',
'Observable',
'Array',
'Buffer',
'Blob',
'Object',
'RegExp',
'Date',
'Error',
'Map',
'Set',
'WeakMap',
'WeakSet',
'ArrayBuffer',
'SharedArrayBuffer',
'DataView',
'Promise',
'URL',
'FormData',
'URLSearchParams',
'HTMLElement',
...typedArrayTypeNames
];
function isObjectTypeName(name) {
return objectTypeNames.includes(name);
}
const primitiveTypeNames = [
'null',
'undefined',
'string',
'number',
'bigint',
'boolean',
'symbol'
];
function isPrimitiveTypeName(name) {
return primitiveTypeNames.includes(name);
}
// eslint-disable-next-line @typescript-eslint/ban-types
function isOfType(type) {
return (value) => typeof value === type;
}
const { toString } = Object.prototype;
const getObjectType = (value) => {
const objectTypeName = toString.call(value).slice(8, -1);
if (/HTML\w+Element/.test(objectTypeName) && is.domElement(value)) {
return 'HTMLElement';
}
3 years ago
if (isObjectTypeName(objectTypeName)) {
return objectTypeName;
}
return undefined;
};
const isObjectOfType = (type) => (value) => getObjectType(value) === type;
function is(value) {
if (value === null) {
return 'null';
}
switch (typeof value) {
case 'undefined':
return 'undefined';
case 'string':
return 'string';
case 'number':
return 'number';
case 'boolean':
return 'boolean';
case 'function':
return 'Function';
case 'bigint':
return 'bigint';
case 'symbol':
return 'symbol';
}
if (is.observable(value)) {
return 'Observable';
}
if (is.array(value)) {
return 'Array';
}
if (is.buffer(value)) {
return 'Buffer';
}
const tagType = getObjectType(value);
if (tagType) {
return tagType;
}
if (value instanceof String || value instanceof Boolean || value instanceof Number) {
throw new TypeError('Please don\'t use object wrappers for primitive types');
}
return 'Object';
}
is.undefined = isOfType('undefined');
is.string = isOfType('string');
const isNumberType = isOfType('number');
is.number = (value) => isNumberType(value) && !is.nan(value);
is.bigint = isOfType('bigint');
// eslint-disable-next-line @typescript-eslint/ban-types
is.function_ = isOfType('function');
is.null_ = (value) => value === null;
is.class_ = (value) => is.function_(value) && value.toString().startsWith('class ');
is.boolean = (value) => value === true || value === false;
is.symbol = isOfType('symbol');
is.numericString = (value) => is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
is.array = (value, assertion) => {
if (!Array.isArray(value)) {
return false;
}
if (!is.function_(assertion)) {
return true;
}
return value.every(assertion);
};
is.buffer = (value) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = value) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.isBuffer) === null || _c === void 0 ? void 0 : _c.call(_b, value)) !== null && _d !== void 0 ? _d : false; };
is.blob = (value) => isObjectOfType('Blob')(value);
is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value);
is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value));
is.iterable = (value) => { var _a; return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a[Symbol.iterator]); };
is.asyncIterable = (value) => { var _a; return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a[Symbol.asyncIterator]); };
is.generator = (value) => { var _a, _b; return is.iterable(value) && is.function_((_a = value) === null || _a === void 0 ? void 0 : _a.next) && is.function_((_b = value) === null || _b === void 0 ? void 0 : _b.throw); };
is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
is.nativePromise = (value) => isObjectOfType('Promise')(value);
const hasPromiseAPI = (value) => {
var _a, _b;
return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a.then) &&
is.function_((_b = value) === null || _b === void 0 ? void 0 : _b.catch);
};
is.promise = (value) => is.nativePromise(value) || hasPromiseAPI(value);
is.generatorFunction = isObjectOfType('GeneratorFunction');
is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
is.asyncFunction = (value) => getObjectType(value) === 'AsyncFunction';
// eslint-disable-next-line no-prototype-builtins, @typescript-eslint/ban-types
is.boundFunction = (value) => is.function_(value) && !value.hasOwnProperty('prototype');
is.regExp = isObjectOfType('RegExp');
is.date = isObjectOfType('Date');
is.error = isObjectOfType('Error');
is.map = (value) => isObjectOfType('Map')(value);
is.set = (value) => isObjectOfType('Set')(value);
is.weakMap = (value) => isObjectOfType('WeakMap')(value);
is.weakSet = (value) => isObjectOfType('WeakSet')(value);
is.int8Array = isObjectOfType('Int8Array');
is.uint8Array = isObjectOfType('Uint8Array');
is.uint8ClampedArray = isObjectOfType('Uint8ClampedArray');
is.int16Array = isObjectOfType('Int16Array');
is.uint16Array = isObjectOfType('Uint16Array');
is.int32Array = isObjectOfType('Int32Array');
is.uint32Array = isObjectOfType('Uint32Array');
is.float32Array = isObjectOfType('Float32Array');
is.float64Array = isObjectOfType('Float64Array');
is.bigInt64Array = isObjectOfType('BigInt64Array');
is.bigUint64Array = isObjectOfType('BigUint64Array');
is.arrayBuffer = isObjectOfType('ArrayBuffer');
is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer');
is.dataView = isObjectOfType('DataView');
is.enumCase = (value, targetEnum) => Object.values(targetEnum).includes(value);
is.directInstanceOf = (instance, class_) => Object.getPrototypeOf(instance) === class_.prototype;
is.urlInstance = (value) => isObjectOfType('URL')(value);
is.urlString = (value) => {
if (!is.string(value)) {
return false;
}
try {
new URL(value); // eslint-disable-line no-new
return true;
}
catch (_a) {
return false;
}
};
// Example: `is.truthy = (value: unknown): value is (not false | not 0 | not '' | not undefined | not null) => Boolean(value);`
is.truthy = (value) => Boolean(value);
// Example: `is.falsy = (value: unknown): value is (not true | 0 | '' | undefined | null) => Boolean(value);`
is.falsy = (value) => !value;
is.nan = (value) => Number.isNaN(value);
is.primitive = (value) => is.null_(value) || isPrimitiveTypeName(typeof value);
is.integer = (value) => Number.isInteger(value);
is.safeInteger = (value) => Number.isSafeInteger(value);
is.plainObject = (value) => {
// From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
if (toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.getPrototypeOf({});
};
is.typedArray = (value) => isTypedArrayName(getObjectType(value));
const isValidLength = (value) => is.safeInteger(value) && value >= 0;
is.arrayLike = (value) => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength(value.length);
is.inRange = (value, range) => {
if (is.number(range)) {
return value >= Math.min(0, range) && value <= Math.max(range, 0);
}
if (is.array(range) && range.length === 2) {
return value >= Math.min(...range) && value <= Math.max(...range);
}
throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
};
const NODE_TYPE_ELEMENT = 1;
const DOM_PROPERTIES_TO_CHECK = [
'innerHTML',
'ownerDocument',
'style',
'attributes',
'nodeValue'
];
is.domElement = (value) => {
return is.object(value) &&
value.nodeType === NODE_TYPE_ELEMENT &&
is.string(value.nodeName) &&
!is.plainObject(value) &&
DOM_PROPERTIES_TO_CHECK.every(property => property in value);
};
is.observable = (value) => {
var _a, _b, _c, _d;
if (!value) {
return false;
}
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
if (value === ((_b = (_a = value)[Symbol.observable]) === null || _b === void 0 ? void 0 : _b.call(_a))) {
return true;
}
if (value === ((_d = (_c = value)['@@observable']) === null || _d === void 0 ? void 0 : _d.call(_c))) {
return true;
}
return false;
};
is.nodeStream = (value) => is.object(value) && is.function_(value.pipe) && !is.observable(value);
is.infinite = (value) => value === Infinity || value === -Infinity;
const isAbsoluteMod2 = (remainder) => (value) => is.integer(value) && Math.abs(value % 2) === remainder;
is.evenInteger = isAbsoluteMod2(0);
is.oddInteger = isAbsoluteMod2(1);
is.emptyArray = (value) => is.array(value) && value.length === 0;
is.nonEmptyArray = (value) => is.array(value) && value.length > 0;
is.emptyString = (value) => is.string(value) && value.length === 0;
const isWhiteSpaceString = (value) => is.string(value) && !/\S/.test(value);
is.emptyStringOrWhitespace = (value) => is.emptyString(value) || isWhiteSpaceString(value);
// TODO: Use `not ''` when the `not` operator is available.
is.nonEmptyString = (value) => is.string(value) && value.length > 0;
// TODO: Use `not ''` when the `not` operator is available.
is.nonEmptyStringAndNotWhitespace = (value) => is.string(value) && !is.emptyStringOrWhitespace(value);
is.emptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length === 0;
// TODO: Use `not` operator here to remove `Map` and `Set` from type guard:
// - https://github.com/Microsoft/TypeScript/pull/29317
is.nonEmptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length > 0;
is.emptySet = (value) => is.set(value) && value.size === 0;
is.nonEmptySet = (value) => is.set(value) && value.size > 0;
is.emptyMap = (value) => is.map(value) && value.size === 0;
is.nonEmptyMap = (value) => is.map(value) && value.size > 0;
// `PropertyKey` is any value that can be used as an object key (string, number, or symbol)
is.propertyKey = (value) => is.any([is.string, is.number, is.symbol], value);
is.formData = (value) => isObjectOfType('FormData')(value);
is.urlSearchParams = (value) => isObjectOfType('URLSearchParams')(value);
const predicateOnArray = (method, predicate, values) => {
if (!is.function_(predicate)) {
throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
}
if (values.length === 0) {
throw new TypeError('Invalid number of values');
}
return method.call(values, predicate);
};
is.any = (predicate, ...values) => {
const predicates = is.array(predicate) ? predicate : [predicate];
return predicates.some(singlePredicate => predicateOnArray(Array.prototype.some, singlePredicate, values));
};
is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values);
const assertType = (condition, description, value, options = {}) => {
if (!condition) {
const { multipleValues } = options;
const valuesMessage = multipleValues ?
`received values of types ${[
...new Set(value.map(singleValue => `\`${is(singleValue)}\``))
].join(', ')}` :
`received value of type \`${is(value)}\``;
throw new TypeError(`Expected value which is \`${description}\`, ${valuesMessage}.`);
}
};
exports.assert = {
// Unknowns.
undefined: (value) => assertType(is.undefined(value), 'undefined', value),
string: (value) => assertType(is.string(value), 'string', value),
number: (value) => assertType(is.number(value), 'number', value),
bigint: (value) => assertType(is.bigint(value), 'bigint', value),
// eslint-disable-next-line @typescript-eslint/ban-types
function_: (value) => assertType(is.function_(value), 'Function', value),
null_: (value) => assertType(is.null_(value), 'null', value),
class_: (value) => assertType(is.class_(value), "Class" /* class_ */, value),
boolean: (value) => assertType(is.boolean(value), 'boolean', value),
symbol: (value) => assertType(is.symbol(value), 'symbol', value),
numericString: (value) => assertType(is.numericString(value), "string with a number" /* numericString */, value),
array: (value, assertion) => {
const assert = assertType;
assert(is.array(value), 'Array', value);
if (assertion) {
value.forEach(assertion);
}
3 years ago
},
buffer: (value) => assertType(is.buffer(value), 'Buffer', value),
blob: (value) => assertType(is.blob(value), 'Blob', value),
nullOrUndefined: (value) => assertType(is.nullOrUndefined(value), "null or undefined" /* nullOrUndefined */, value),
object: (value) => assertType(is.object(value), 'Object', value),
iterable: (value) => assertType(is.iterable(value), "Iterable" /* iterable */, value),
asyncIterable: (value) => assertType(is.asyncIterable(value), "AsyncIterable" /* asyncIterable */, value),
generator: (value) => assertType(is.generator(value), 'Generator', value),
asyncGenerator: (value) => assertType(is.asyncGenerator(value), 'AsyncGenerator', value),
nativePromise: (value) => assertType(is.nativePromise(value), "native Promise" /* nativePromise */, value),
promise: (value) => assertType(is.promise(value), 'Promise', value),
generatorFunction: (value) => assertType(is.generatorFunction(value), 'GeneratorFunction', value),
asyncGeneratorFunction: (value) => assertType(is.asyncGeneratorFunction(value), 'AsyncGeneratorFunction', value),
// eslint-disable-next-line @typescript-eslint/ban-types
asyncFunction: (value) => assertType(is.asyncFunction(value), 'AsyncFunction', value),
// eslint-disable-next-line @typescript-eslint/ban-types
boundFunction: (value) => assertType(is.boundFunction(value), 'Function', value),
regExp: (value) => assertType(is.regExp(value), 'RegExp', value),
date: (value) => assertType(is.date(value), 'Date', value),
error: (value) => assertType(is.error(value), 'Error', value),
map: (value) => assertType(is.map(value), 'Map', value),
set: (value) => assertType(is.set(value), 'Set', value),
weakMap: (value) => assertType(is.weakMap(value), 'WeakMap', value),
weakSet: (value) => assertType(is.weakSet(value), 'WeakSet', value),
int8Array: (value) => assertType(is.int8Array(value), 'Int8Array', value),
uint8Array: (value) => assertType(is.uint8Array(value), 'Uint8Array', value),
uint8ClampedArray: (value) => assertType(is.uint8ClampedArray(value), 'Uint8ClampedArray', value),
int16Array: (value) => assertType(is.int16Array(value), 'Int16Array', value),
uint16Array: (value) => assertType(is.uint16Array(value), 'Uint16Array', value),
int32Array: (value) => assertType(is.int32Array(value), 'Int32Array', value),
uint32Array: (value) => assertType(is.uint32Array(value), 'Uint32Array', value),
float32Array: (value) => assertType(is.float32Array(value), 'Float32Array', value),
float64Array: (value) => assertType(is.float64Array(value), 'Float64Array', value),
bigInt64Array: (value) => assertType(is.bigInt64Array(value), 'BigInt64Array', value),
bigUint64Array: (value) => assertType(is.bigUint64Array(value), 'BigUint64Array', value),
arrayBuffer: (value) => assertType(is.arrayBuffer(value), 'ArrayBuffer', value),
sharedArrayBuffer: (value) => assertType(is.sharedArrayBuffer(value), 'SharedArrayBuffer', value),
dataView: (value) => assertType(is.dataView(value), 'DataView', value),
enumCase: (value, targetEnum) => assertType(is.enumCase(value, targetEnum), 'EnumCase', value),
urlInstance: (value) => assertType(is.urlInstance(value), 'URL', value),
urlString: (value) => assertType(is.urlString(value), "string with a URL" /* urlString */, value),
truthy: (value) => assertType(is.truthy(value), "truthy" /* truthy */, value),
falsy: (value) => assertType(is.falsy(value), "falsy" /* falsy */, value),
nan: (value) => assertType(is.nan(value), "NaN" /* nan */, value),
primitive: (value) => assertType(is.primitive(value), "primitive" /* primitive */, value),
integer: (value) => assertType(is.integer(value), "integer" /* integer */, value),
safeInteger: (value) => assertType(is.safeInteger(value), "integer" /* safeInteger */, value),
plainObject: (value) => assertType(is.plainObject(value), "plain object" /* plainObject */, value),
typedArray: (value) => assertType(is.typedArray(value), "TypedArray" /* typedArray */, value),
arrayLike: (value) => assertType(is.arrayLike(value), "array-like" /* arrayLike */, value),
domElement: (value) => assertType(is.domElement(value), "HTMLElement" /* domElement */, value),
observable: (value) => assertType(is.observable(value), 'Observable', value),
nodeStream: (value) => assertType(is.nodeStream(value), "Node.js Stream" /* nodeStream */, value),
infinite: (value) => assertType(is.infinite(value), "infinite number" /* infinite */, value),
emptyArray: (value) => assertType(is.emptyArray(value), "empty array" /* emptyArray */, value),
nonEmptyArray: (value) => assertType(is.nonEmptyArray(value), "non-empty array" /* nonEmptyArray */, value),
emptyString: (value) => assertType(is.emptyString(value), "empty string" /* emptyString */, value),
emptyStringOrWhitespace: (value) => assertType(is.emptyStringOrWhitespace(value), "empty string or whitespace" /* emptyStringOrWhitespace */, value),
nonEmptyString: (value) => assertType(is.nonEmptyString(value), "non-empty string" /* nonEmptyString */, value),
nonEmptyStringAndNotWhitespace: (value) => assertType(is.nonEmptyStringAndNotWhitespace(value), "non-empty string and not whitespace" /* nonEmptyStringAndNotWhitespace */, value),
emptyObject: (value) => assertType(is.emptyObject(value), "empty object" /* emptyObject */, value),
nonEmptyObject: (value) => assertType(is.nonEmptyObject(value), "non-empty object" /* nonEmptyObject */, value),
emptySet: (value) => assertType(is.emptySet(value), "empty set" /* emptySet */, value),
nonEmptySet: (value) => assertType(is.nonEmptySet(value), "non-empty set" /* nonEmptySet */, value),
emptyMap: (value) => assertType(is.emptyMap(value), "empty map" /* emptyMap */, value),
nonEmptyMap: (value) => assertType(is.nonEmptyMap(value), "non-empty map" /* nonEmptyMap */, value),
propertyKey: (value) => assertType(is.propertyKey(value), 'PropertyKey', value),
formData: (value) => assertType(is.formData(value), 'FormData', value),
urlSearchParams: (value) => assertType(is.urlSearchParams(value), 'URLSearchParams', value),
// Numbers.
evenInteger: (value) => assertType(is.evenInteger(value), "even integer" /* evenInteger */, value),
oddInteger: (value) => assertType(is.oddInteger(value), "odd integer" /* oddInteger */, value),
// Two arguments.
directInstanceOf: (instance, class_) => assertType(is.directInstanceOf(instance, class_), "T" /* directInstanceOf */, instance),
inRange: (value, range) => assertType(is.inRange(value, range), "in range" /* inRange */, value),
// Variadic functions.
any: (predicate, ...values) => {
return assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* any */, values, { multipleValues: true });
},
all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* all */, values, { multipleValues: true })
};
// Some few keywords are reserved, but we'll populate them for Node.js users
// See https://github.com/Microsoft/TypeScript/issues/2536
Object.defineProperties(is, {
class: {
value: is.class_
},
function: {
value: is.function_
},
null: {
value: is.null_
}
});
Object.defineProperties(exports.assert, {
class: {
value: exports.assert.class_
},
function: {
value: exports.assert.function_
},
null: {
value: exports.assert.null_
}
3 years ago
});
exports.default = is;
// For CommonJS default export support
module.exports = is;
module.exports.default = is;
module.exports.assert = exports.assert;
}(dist$1, dist$1.exports));
var asPromise = {};
var pCancelable = {exports: {}};
class CancelError extends Error {
constructor(reason) {
super(reason || 'Promise was canceled');
this.name = 'CancelError';
}
get isCanceled() {
return true;
}
}
3 years ago
class PCancelable {
static fn(userFn) {
return (...arguments_) => {
return new PCancelable((resolve, reject, onCancel) => {
arguments_.push(onCancel);
// eslint-disable-next-line promise/prefer-await-to-then
userFn(...arguments_).then(resolve, reject);
});
};
}
constructor(executor) {
this._cancelHandlers = [];
this._isPending = true;
this._isCanceled = false;
this._rejectOnCancel = true;
this._promise = new Promise((resolve, reject) => {
this._reject = reject;
const onResolve = value => {
if (!this._isCanceled || !onCancel.shouldReject) {
this._isPending = false;
resolve(value);
}
};
const onReject = error => {
this._isPending = false;
reject(error);
};
const onCancel = handler => {
if (!this._isPending) {
throw new Error('The `onCancel` handler was attached after the promise settled.');
}
this._cancelHandlers.push(handler);
};
Object.defineProperties(onCancel, {
shouldReject: {
get: () => this._rejectOnCancel,
set: boolean => {
this._rejectOnCancel = boolean;
}
}
});
return executor(onResolve, onReject, onCancel);
});
}
then(onFulfilled, onRejected) {
// eslint-disable-next-line promise/prefer-await-to-then
return this._promise.then(onFulfilled, onRejected);
}
catch(onRejected) {
return this._promise.catch(onRejected);
}
finally(onFinally) {
return this._promise.finally(onFinally);
}
cancel(reason) {
if (!this._isPending || this._isCanceled) {
return;
}
this._isCanceled = true;
if (this._cancelHandlers.length > 0) {
try {
for (const handler of this._cancelHandlers) {
handler();
}
} catch (error) {
this._reject(error);
return;
}
}
if (this._rejectOnCancel) {
this._reject(new CancelError(reason));
}
}
get isCanceled() {
return this._isCanceled;
}
}
Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
pCancelable.exports = PCancelable;
pCancelable.exports.CancelError = CancelError;
var types$1 = {};
var core = {};
var source$3 = {exports: {}};
var source$2 = {exports: {}};
(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function isTLSSocket(socket) {
return socket.encrypted;
}
const deferToConnect = (socket, fn) => {
let listeners;
if (typeof fn === 'function') {
const connect = fn;
listeners = { connect };
}
else {
listeners = fn;
}
const hasConnectListener = typeof listeners.connect === 'function';
const hasSecureConnectListener = typeof listeners.secureConnect === 'function';
const hasCloseListener = typeof listeners.close === 'function';
const onConnect = () => {
if (hasConnectListener) {
listeners.connect();
}
if (isTLSSocket(socket) && hasSecureConnectListener) {
if (socket.authorized) {
listeners.secureConnect();
}
else if (!socket.authorizationError) {
socket.once('secureConnect', listeners.secureConnect);
}
}
if (hasCloseListener) {
socket.once('close', listeners.close);
}
};
if (socket.writable && !socket.connecting) {
onConnect();
}
else if (socket.connecting) {
socket.once('connect', onConnect);
}
else if (socket.destroyed && hasCloseListener) {
listeners.close(socket._hadError);
}
};
exports.default = deferToConnect;
// For CommonJS default export support
module.exports = deferToConnect;
module.exports.default = deferToConnect;
}(source$2, source$2.exports));
(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
const defer_to_connect_1 = source$2.exports;
const util_1 = require$$1__default["default"];
const nodejsMajorVersion = Number(process.versions.node.split('.')[0]);
const timer = (request) => {
if (request.timings) {
return request.timings;
}
const timings = {
start: Date.now(),
socket: undefined,
lookup: undefined,
connect: undefined,
secureConnect: undefined,
upload: undefined,
response: undefined,
end: undefined,
error: undefined,
abort: undefined,
phases: {
wait: undefined,
dns: undefined,
tcp: undefined,
tls: undefined,
request: undefined,
firstByte: undefined,
download: undefined,
total: undefined
}
};
request.timings = timings;
const handleError = (origin) => {
const emit = origin.emit.bind(origin);
origin.emit = (event, ...args) => {
// Catches the `error` event
if (event === 'error') {
timings.error = Date.now();
timings.phases.total = timings.error - timings.start;
origin.emit = emit;
}
// Saves the original behavior
return emit(event, ...args);
};
};
handleError(request);
const onAbort = () => {
timings.abort = Date.now();
// Let the `end` response event be responsible for setting the total phase,
// unless the Node.js major version is >= 13.
if (!timings.response || nodejsMajorVersion >= 13) {
timings.phases.total = Date.now() - timings.start;
}
};
request.prependOnceListener('abort', onAbort);
const onSocket = (socket) => {
timings.socket = Date.now();
timings.phases.wait = timings.socket - timings.start;
if (util_1.types.isProxy(socket)) {
return;
}
const lookupListener = () => {
timings.lookup = Date.now();
timings.phases.dns = timings.lookup - timings.socket;
};
socket.prependOnceListener('lookup', lookupListener);
defer_to_connect_1.default(socket, {
connect: () => {
timings.connect = Date.now();
if (timings.lookup === undefined) {
socket.removeListener('lookup', lookupListener);
timings.lookup = timings.connect;
timings.phases.dns = timings.lookup - timings.socket;
}
timings.phases.tcp = timings.connect - timings.lookup;
// This callback is called before flushing any data,
// so we don't need to set `timings.phases.request` here.
},
secureConnect: () => {
timings.secureConnect = Date.now();
timings.phases.tls = timings.secureConnect - timings.connect;
}
});
3 years ago
};
if (request.socket) {
onSocket(request.socket);
}
else {
3 years ago
request.prependOnceListener('socket', onSocket);
}
const onUpload = () => {
var _a;
timings.upload = Date.now();
timings.phases.request = timings.upload - ((_a = timings.secureConnect) !== null && _a !== void 0 ? _a : timings.connect);
};
const writableFinished = () => {
if (typeof request.writableFinished === 'boolean') {
return request.writableFinished;
}
// Node.js doesn't have `request.writableFinished` property
return request.finished && request.outputSize === 0 && (!request.socket || request.socket.writableLength === 0);
};
if (writableFinished()) {
onUpload();
}
else {
request.prependOnceListener('finish', onUpload);
}
3 years ago
request.prependOnceListener('response', (response) => {
timings.response = Date.now();
timings.phases.firstByte = timings.response - timings.upload;
response.timings = timings;
handleError(response);
response.prependOnceListener('end', () => {
timings.end = Date.now();
timings.phases.download = timings.end - timings.response;
timings.phases.total = timings.end - timings.start;
});
response.prependOnceListener('aborted', onAbort);
});
return timings;
};
exports.default = timer;
// For CommonJS default export support
module.exports = timer;
module.exports.default = timer;
}(source$3, source$3.exports));
var source$1 = {exports: {}};
const {
V4MAPPED,
ADDRCONFIG,
ALL,
promises: {
Resolver: AsyncResolver
},
lookup: dnsLookup
} = require$$0__default["default"];
const {promisify} = require$$1__default["default"];
const os = require$$2__default["default"];
const kCacheableLookupCreateConnection = Symbol('cacheableLookupCreateConnection');
const kCacheableLookupInstance = Symbol('cacheableLookupInstance');
const kExpires = Symbol('expires');
const supportsALL = typeof ALL === 'number';
const verifyAgent = agent => {
if (!(agent && typeof agent.createConnection === 'function')) {
throw new Error('Expected an Agent instance as the first argument');
}
};
const map4to6 = entries => {
for (const entry of entries) {
if (entry.family === 6) {
continue;
}
entry.address = `::ffff:${entry.address}`;
entry.family = 6;
}
};
const getIfaceInfo = () => {
let has4 = false;
let has6 = false;
for (const device of Object.values(os.networkInterfaces())) {
for (const iface of device) {
if (iface.internal) {
continue;
}
if (iface.family === 'IPv6') {
has6 = true;
} else {
has4 = true;
}
if (has4 && has6) {
return {has4, has6};
}
}
}
return {has4, has6};
};
const isIterable = map => {
return Symbol.iterator in map;
};
const ttl = {ttl: true};
const all = {all: true};
class CacheableLookup {
constructor({
cache = new Map(),
maxTtl = Infinity,
fallbackDuration = 3600,
errorTtl = 0.15,
resolver = new AsyncResolver(),
lookup = dnsLookup
} = {}) {
this.maxTtl = maxTtl;
this.errorTtl = errorTtl;
this._cache = cache;
this._resolver = resolver;
this._dnsLookup = promisify(lookup);
if (this._resolver instanceof AsyncResolver) {
this._resolve4 = this._resolver.resolve4.bind(this._resolver);
this._resolve6 = this._resolver.resolve6.bind(this._resolver);
} else {
this._resolve4 = promisify(this._resolver.resolve4.bind(this._resolver));
this._resolve6 = promisify(this._resolver.resolve6.bind(this._resolver));
}
this._iface = getIfaceInfo();
this._pending = {};
this._nextRemovalTime = false;
this._hostnamesToFallback = new Set();
if (fallbackDuration < 1) {
this._fallback = false;
} else {
this._fallback = true;
const interval = setInterval(() => {
this._hostnamesToFallback.clear();
}, fallbackDuration * 1000);
/* istanbul ignore next: There is no `interval.unref()` when running inside an Electron renderer */
if (interval.unref) {
interval.unref();
}
}
this.lookup = this.lookup.bind(this);
this.lookupAsync = this.lookupAsync.bind(this);
}
set servers(servers) {
this.clear();
this._resolver.setServers(servers);
}
get servers() {
return this._resolver.getServers();
}
lookup(hostname, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
} else if (typeof options === 'number') {
options = {
family: options
};
}
if (!callback) {
throw new Error('Callback must be a function.');
}
// eslint-disable-next-line promise/prefer-await-to-then
this.lookupAsync(hostname, options).then(result => {
if (options.all) {
callback(null, result);
} else {
callback(null, result.address, result.family, result.expires, result.ttl);
}
}, callback);
}
async lookupAsync(hostname, options = {}) {
if (typeof options === 'number') {
options = {
family: options
};
}
let cached = await this.query(hostname);
if (options.family === 6) {
const filtered = cached.filter(entry => entry.family === 6);
if (options.hints & V4MAPPED) {
if ((supportsALL && options.hints & ALL) || filtered.length === 0) {
map4to6(cached);
} else {
cached = filtered;
}
} else {
cached = filtered;
}
} else if (options.family === 4) {
cached = cached.filter(entry => entry.family === 4);
}
if (options.hints & ADDRCONFIG) {
const {_iface} = this;
cached = cached.filter(entry => entry.family === 6 ? _iface.has6 : _iface.has4);
}
if (cached.length === 0) {
const error = new Error(`cacheableLookup ENOTFOUND ${hostname}`);
error.code = 'ENOTFOUND';
error.hostname = hostname;
throw error;
}
if (options.all) {
return cached;
}
return cached[0];
}
async query(hostname) {
let cached = await this._cache.get(hostname);
if (!cached) {
const pending = this._pending[hostname];
if (pending) {
cached = await pending;
} else {
const newPromise = this.queryAndCache(hostname);
this._pending[hostname] = newPromise;
try {
cached = await newPromise;
} finally {
delete this._pending[hostname];
}
}
}
cached = cached.map(entry => {
return {...entry};
});
return cached;
}
async _resolve(hostname) {
const wrap = async promise => {
try {
return await promise;
} catch (error) {
if (error.code === 'ENODATA' || error.code === 'ENOTFOUND') {
return [];
}
throw error;
}
};
// ANY is unsafe as it doesn't trigger new queries in the underlying server.
const [A, AAAA] = await Promise.all([
this._resolve4(hostname, ttl),
this._resolve6(hostname, ttl)
].map(promise => wrap(promise)));
let aTtl = 0;
let aaaaTtl = 0;
let cacheTtl = 0;
const now = Date.now();
for (const entry of A) {
entry.family = 4;
entry.expires = now + (entry.ttl * 1000);
aTtl = Math.max(aTtl, entry.ttl);
}
for (const entry of AAAA) {
entry.family = 6;
entry.expires = now + (entry.ttl * 1000);
aaaaTtl = Math.max(aaaaTtl, entry.ttl);
}
if (A.length > 0) {
if (AAAA.length > 0) {
cacheTtl = Math.min(aTtl, aaaaTtl);
} else {
cacheTtl = aTtl;
}
} else {
cacheTtl = aaaaTtl;
}
return {
entries: [
...A,
...AAAA
],
cacheTtl
};
}
async _lookup(hostname) {
try {
const entries = await this._dnsLookup(hostname, {
all: true
});
return {
entries,
cacheTtl: 0
};
} catch (_) {
return {
entries: [],
cacheTtl: 0
};
}
}
async _set(hostname, data, cacheTtl) {
if (this.maxTtl > 0 && cacheTtl > 0) {
cacheTtl = Math.min(cacheTtl, this.maxTtl) * 1000;
data[kExpires] = Date.now() + cacheTtl;
try {
await this._cache.set(hostname, data, cacheTtl);
} catch (error) {
this.lookupAsync = async () => {
const cacheError = new Error('Cache Error. Please recreate the CacheableLookup instance.');
cacheError.cause = error;
throw cacheError;
};
}
if (isIterable(this._cache)) {
this._tick(cacheTtl);
}
}
}
async queryAndCache(hostname) {
if (this._hostnamesToFallback.has(hostname)) {
return this._dnsLookup(hostname, all);
}
let query = await this._resolve(hostname);
if (query.entries.length === 0 && this._fallback) {
query = await this._lookup(hostname);
if (query.entries.length !== 0) {
// Use `dns.lookup(...)` for that particular hostname
this._hostnamesToFallback.add(hostname);
}
}
const cacheTtl = query.entries.length === 0 ? this.errorTtl : query.cacheTtl;
await this._set(hostname, query.entries, cacheTtl);
return query.entries;
}
_tick(ms) {
const nextRemovalTime = this._nextRemovalTime;
if (!nextRemovalTime || ms < nextRemovalTime) {
clearTimeout(this._removalTimeout);
this._nextRemovalTime = ms;
this._removalTimeout = setTimeout(() => {
this._nextRemovalTime = false;
let nextExpiry = Infinity;
const now = Date.now();
for (const [hostname, entries] of this._cache) {
const expires = entries[kExpires];
if (now >= expires) {
this._cache.delete(hostname);
} else if (expires < nextExpiry) {
nextExpiry = expires;
}
}
if (nextExpiry !== Infinity) {
this._tick(nextExpiry - now);
}
}, ms);
/* istanbul ignore next: There is no `timeout.unref()` when running inside an Electron renderer */
if (this._removalTimeout.unref) {
this._removalTimeout.unref();
}
}
}
install(agent) {
verifyAgent(agent);
if (kCacheableLookupCreateConnection in agent) {
throw new Error('CacheableLookup has been already installed');
}
agent[kCacheableLookupCreateConnection] = agent.createConnection;
agent[kCacheableLookupInstance] = this;
agent.createConnection = (options, callback) => {
if (!('lookup' in options)) {
options.lookup = this.lookup;
}
return agent[kCacheableLookupCreateConnection](options, callback);
};
}
uninstall(agent) {
verifyAgent(agent);
if (agent[kCacheableLookupCreateConnection]) {
if (agent[kCacheableLookupInstance] !== this) {
throw new Error('The agent is not owned by this CacheableLookup instance');
}
agent.createConnection = agent[kCacheableLookupCreateConnection];
delete agent[kCacheableLookupCreateConnection];
delete agent[kCacheableLookupInstance];
}
}
updateInterfaceInfo() {
const {_iface} = this;
this._iface = getIfaceInfo();
if ((_iface.has4 && !this._iface.has4) || (_iface.has6 && !this._iface.has6)) {
this._cache.clear();
}
}
clear(hostname) {
if (hostname) {
this._cache.delete(hostname);
return;
}
this._cache.clear();
}
}
3 years ago
source$1.exports = CacheableLookup;
source$1.exports.default = CacheableLookup;
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
const testParameter = (name, filters) => {
return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
};
3 years ago
const normalizeDataURL = (urlString, {stripHash}) => {
const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
if (!match) {
throw new Error(`Invalid URL: ${urlString}`);
}
let {type, data, hash} = match.groups;
const mediaType = type.split(';');
hash = stripHash ? '' : hash;
let isBase64 = false;
if (mediaType[mediaType.length - 1] === 'base64') {
mediaType.pop();
isBase64 = true;
}
// Lowercase MIME type
const mimeType = (mediaType.shift() || '').toLowerCase();
const attributes = mediaType
.map(attribute => {
let [key, value = ''] = attribute.split('=').map(string => string.trim());
// Lowercase `charset`
if (key === 'charset') {
value = value.toLowerCase();
if (value === DATA_URL_DEFAULT_CHARSET) {
return '';
}
}
return `${key}${value ? `=${value}` : ''}`;
})
.filter(Boolean);
const normalizedMediaType = [
...attributes
];
if (isBase64) {
normalizedMediaType.push('base64');
}
if (normalizedMediaType.length !== 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
normalizedMediaType.unshift(mimeType);
}
return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
};
const normalizeUrl$1 = (urlString, options) => {
options = {
defaultProtocol: 'http:',
normalizeProtocol: true,
forceHttp: false,
forceHttps: false,
stripAuthentication: true,
stripHash: false,
stripTextFragment: true,
stripWWW: true,
removeQueryParameters: [/^utm_\w+/i],
removeTrailingSlash: true,
removeSingleSlash: true,
removeDirectoryIndex: false,
sortQueryParameters: true,
...options
};
urlString = urlString.trim();
// Data URL
if (/^data:/i.test(urlString)) {
return normalizeDataURL(urlString, options);
}
if (/^view-source:/i.test(urlString)) {
throw new Error('`view-source:` is not supported as it is a non-standard protocol');
}
const hasRelativeProtocol = urlString.startsWith('//');
const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
// Prepend protocol
if (!isRelativeUrl) {
urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
}
const urlObj = new URL(urlString);
if (options.forceHttp && options.forceHttps) {
throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
}
if (options.forceHttp && urlObj.protocol === 'https:') {
urlObj.protocol = 'http:';
}
if (options.forceHttps && urlObj.protocol === 'http:') {
urlObj.protocol = 'https:';
}
// Remove auth
if (options.stripAuthentication) {
urlObj.username = '';
urlObj.password = '';
}
// Remove hash
if (options.stripHash) {
urlObj.hash = '';
} else if (options.stripTextFragment) {
urlObj.hash = urlObj.hash.replace(/#?:~:text.*?$/i, '');
}
// Remove duplicate slashes if not preceded by a protocol
if (urlObj.pathname) {
urlObj.pathname = urlObj.pathname.replace(/(?<!\b(?:[a-z][a-z\d+\-.]{1,50}:))\/{2,}/g, '/');
}
// Decode URI octets
if (urlObj.pathname) {
try {
urlObj.pathname = decodeURI(urlObj.pathname);
} catch (_) {}
}
// Remove directory index
if (options.removeDirectoryIndex === true) {
options.removeDirectoryIndex = [/^index\.[a-z]+$/];
}
if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
let pathComponents = urlObj.pathname.split('/');
const lastComponent = pathComponents[pathComponents.length - 1];
if (testParameter(lastComponent, options.removeDirectoryIndex)) {
pathComponents = pathComponents.slice(0, pathComponents.length - 1);
urlObj.pathname = pathComponents.slice(1).join('/') + '/';
}
}
if (urlObj.hostname) {
// Remove trailing dot
urlObj.hostname = urlObj.hostname.replace(/\.$/, '');
// Remove `www.`
if (options.stripWWW && /^www\.(?!www\.)(?:[a-z\-\d]{1,63})\.(?:[a-z.\-\d]{2,63})$/.test(urlObj.hostname)) {
// Each label should be max 63 at length (min: 1).
// Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
// Each TLD should be up to 63 characters long (min: 2).
// It is technically possible to have a single character TLD, but none currently exist.
urlObj.hostname = urlObj.hostname.replace(/^www\./, '');
}
}
// Remove query unwanted parameters
if (Array.isArray(options.removeQueryParameters)) {
for (const key of [...urlObj.searchParams.keys()]) {
if (testParameter(key, options.removeQueryParameters)) {
urlObj.searchParams.delete(key);
}
}
}
if (options.removeQueryParameters === true) {
urlObj.search = '';
}
// Sort query parameters
if (options.sortQueryParameters) {
urlObj.searchParams.sort();
}
if (options.removeTrailingSlash) {
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
}
const oldUrlString = urlString;
// Take advantage of many of the Node `url` normalizations
urlString = urlObj.toString();
if (!options.removeSingleSlash && urlObj.pathname === '/' && !oldUrlString.endsWith('/') && urlObj.hash === '') {
urlString = urlString.replace(/\/$/, '');
}
// Remove ending `/` unless removeSingleSlash is false
if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '' && options.removeSingleSlash) {
urlString = urlString.replace(/\/$/, '');
}
// Restore relative protocol, if applicable
if (hasRelativeProtocol && !options.normalizeProtocol) {
urlString = urlString.replace(/^http:\/\//, '//');
}
// Remove http/https
if (options.stripProtocol) {
urlString = urlString.replace(/^(?:https?:)?\/\//, '');
}
return urlString;
};
var normalizeUrl_1 = normalizeUrl$1;
var getStream$2 = {exports: {}};
var once$3 = {exports: {}};
// Returns a wrapper function that returns a wrapped callback
// The wrapper function should do some stuff, and return a
// presumably different callback function.
// This makes sure that own properties are retained, so that
// decorations and such are not lost along the way.
var wrappy_1 = wrappy$1;
function wrappy$1 (fn, cb) {
if (fn && cb) return wrappy$1(fn)(cb)
if (typeof fn !== 'function')
throw new TypeError('need wrapper function')
Object.keys(fn).forEach(function (k) {
wrapper[k] = fn[k];
});
return wrapper
function wrapper() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
3 years ago
var ret = fn.apply(this, args);
var cb = args[args.length-1];
if (typeof ret === 'function' && ret !== cb) {
Object.keys(cb).forEach(function (k) {
ret[k] = cb[k];
});
}
return ret
}
}
var wrappy = wrappy_1;
once$3.exports = wrappy(once$2);
once$3.exports.strict = wrappy(onceStrict);
once$2.proto = once$2(function () {
Object.defineProperty(Function.prototype, 'once', {
value: function () {
return once$2(this)
},
configurable: true
});
Object.defineProperty(Function.prototype, 'onceStrict', {
value: function () {
return onceStrict(this)
},
configurable: true
});
});
function once$2 (fn) {
var f = function () {
if (f.called) return f.value
f.called = true;
return f.value = fn.apply(this, arguments)
};
f.called = false;
return f
}
function onceStrict (fn) {
var f = function () {
if (f.called)
throw new Error(f.onceError)
f.called = true;
return f.value = fn.apply(this, arguments)
};
var name = fn.name || 'Function wrapped with `once`';
f.onceError = name + " shouldn't be called more than once";
f.called = false;
return f
}
var once$1 = once$3.exports;
var noop$2 = function() {};
var isRequest$1 = function(stream) {
return stream.setHeader && typeof stream.abort === 'function';
};
var isChildProcess = function(stream) {
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
};
var eos$1 = function(stream, opts, callback) {
if (typeof opts === 'function') return eos$1(stream, null, opts);
if (!opts) opts = {};
callback = once$1(callback || noop$2);
var ws = stream._writableState;
var rs = stream._readableState;
var readable = opts.readable || (opts.readable !== false && stream.readable);
var writable = opts.writable || (opts.writable !== false && stream.writable);
var cancelled = false;
var onlegacyfinish = function() {
if (!stream.writable) onfinish();
};
var onfinish = function() {
writable = false;
if (!readable) callback.call(stream);
};
var onend = function() {
readable = false;
if (!writable) callback.call(stream);
};
var onexit = function(exitCode) {
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
};
var onerror = function(err) {
callback.call(stream, err);
};
var onclose = function() {
process.nextTick(onclosenexttick);
};
var onclosenexttick = function() {
if (cancelled) return;
if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
};
var onrequest = function() {
stream.req.on('finish', onfinish);
};
if (isRequest$1(stream)) {
stream.on('complete', onfinish);
stream.on('abort', onclose);
if (stream.req) onrequest();
else stream.on('request', onrequest);
} else if (writable && !ws) { // legacy streams
stream.on('end', onlegacyfinish);
stream.on('close', onlegacyfinish);
}
if (isChildProcess(stream)) stream.on('exit', onexit);
stream.on('end', onend);
stream.on('finish', onfinish);
if (opts.error !== false) stream.on('error', onerror);
stream.on('close', onclose);
return function() {
cancelled = true;
stream.removeListener('complete', onfinish);
stream.removeListener('abort', onclose);
stream.removeListener('request', onrequest);
if (stream.req) stream.req.removeListener('finish', onfinish);
stream.removeListener('end', onlegacyfinish);
stream.removeListener('close', onlegacyfinish);
stream.removeListener('finish', onfinish);
stream.removeListener('exit', onexit);
stream.removeListener('end', onend);
stream.removeListener('error', onerror);
stream.removeListener('close', onclose);
};
};
var endOfStream = eos$1;
var once = once$3.exports;
var eos = endOfStream;
var fs = require$$2__default$1["default"]; // we only need fs to get the ReadStream and WriteStream prototypes
var noop$1 = function () {};
var ancient = /^v?\.0/.test(process.version);
var isFn = function (fn) {
return typeof fn === 'function'
};
var isFS = function (stream) {
if (!ancient) return false // newer node version do not need to care about fs is a special way
if (!fs) return false // browser
return (stream instanceof (fs.ReadStream || noop$1) || stream instanceof (fs.WriteStream || noop$1)) && isFn(stream.close)
};
var isRequest = function (stream) {
return stream.setHeader && isFn(stream.abort)
};
var destroyer = function (stream, reading, writing, callback) {
callback = once(callback);
var closed = false;
stream.on('close', function () {
closed = true;
});
eos(stream, {readable: reading, writable: writing}, function (err) {
if (err) return callback(err)
closed = true;
callback();
});
var destroyed = false;
return function (err) {
if (closed) return
if (destroyed) return
destroyed = true;
if (isFS(stream)) return stream.close(noop$1) // use close for fs streams to avoid fd leaks
if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
if (isFn(stream.destroy)) return stream.destroy()
callback(err || new Error('stream was destroyed'));
}
};
var call = function (fn) {
fn();
};
var pipe = function (from, to) {
return from.pipe(to)
};
var pump$1 = function () {
var streams = Array.prototype.slice.call(arguments);
var callback = isFn(streams[streams.length - 1] || noop$1) && streams.pop() || noop$1;
if (Array.isArray(streams[0])) streams = streams[0];
if (streams.length < 2) throw new Error('pump requires two streams per minimum')
var error;
var destroys = streams.map(function (stream, i) {
var reading = i < streams.length - 1;
var writing = i > 0;
return destroyer(stream, reading, writing, function (err) {
if (!error) error = err;
if (err) destroys.forEach(call);
if (reading) return
destroys.forEach(call);
callback(error);
})
});
return streams.reduce(pipe)
};
var pump_1 = pump$1;
const {PassThrough: PassThroughStream} = require$$0__default$1["default"];
var bufferStream$1 = options => {
options = {...options};
const {array} = options;
let {encoding} = options;
const isBuffer = encoding === 'buffer';
let objectMode = false;
if (array) {
objectMode = !(encoding || isBuffer);
} else {
encoding = encoding || 'utf8';
}
if (isBuffer) {
encoding = null;
}
const stream = new PassThroughStream({objectMode});
if (encoding) {
stream.setEncoding(encoding);
}
let length = 0;
const chunks = [];
stream.on('data', chunk => {
chunks.push(chunk);
if (objectMode) {
length = chunks.length;
} else {
length += chunk.length;
}
});
stream.getBufferedValue = () => {
if (array) {
return chunks;
}
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
};
stream.getBufferedLength = () => length;
return stream;
};
const {constants: BufferConstants} = require$$0__default$2["default"];
const pump = pump_1;
const bufferStream = bufferStream$1;
class MaxBufferError extends Error {
constructor() {
super('maxBuffer exceeded');
this.name = 'MaxBufferError';
}
}
async function getStream$1(inputStream, options) {
if (!inputStream) {
return Promise.reject(new Error('Expected a stream'));
}
options = {
maxBuffer: Infinity,
...options
};
const {maxBuffer} = options;
let stream;
await new Promise((resolve, reject) => {
const rejectPromise = error => {
// Don't retrieve an oversized buffer.
if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
error.bufferedData = stream.getBufferedValue();
}
reject(error);
};
stream = pump(inputStream, bufferStream(options), error => {
if (error) {
rejectPromise(error);
return;
}
resolve();
});
stream.on('data', () => {
if (stream.getBufferedLength() > maxBuffer) {
rejectPromise(new MaxBufferError());
}
});
});
return stream.getBufferedValue();
}
getStream$2.exports = getStream$1;
// TODO: Remove this for the next major release
getStream$2.exports.default = getStream$1;
getStream$2.exports.buffer = (stream, options) => getStream$1(stream, {...options, encoding: 'buffer'});
getStream$2.exports.array = (stream, options) => getStream$1(stream, {...options, array: true});
getStream$2.exports.MaxBufferError = MaxBufferError;
// rfc7231 6.1
const statusCodeCacheableByDefault = new Set([
200,
203,
204,
206,
300,
301,
404,
405,
410,
414,
501,
]);
// This implementation does not understand partial responses (206)
const understoodStatuses = new Set([
200,
203,
204,
300,
301,
302,
303,
307,
308,
404,
405,
410,
414,
501,
]);
const errorStatusCodes = new Set([
500,
502,
503,
504,
]);
const hopByHopHeaders = {
date: true, // included, because we add Age update Date
connection: true,
'keep-alive': true,
'proxy-authenticate': true,
'proxy-authorization': true,
te: true,
trailer: true,
'transfer-encoding': true,
upgrade: true,
};
const excludedFromRevalidationUpdate = {
// Since the old body is reused, it doesn't make sense to change properties of the body
'content-length': true,
'content-encoding': true,
'transfer-encoding': true,
'content-range': true,
};
function toNumberOrZero(s) {
const n = parseInt(s, 10);
return isFinite(n) ? n : 0;
}
// RFC 5861
function isErrorResponse(response) {
// consider undefined response as faulty
if(!response) {
return true
}
return errorStatusCodes.has(response.status);
}
function parseCacheControl(header) {
const cc = {};
if (!header) return cc;
// TODO: When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives),
// the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
const parts = header.trim().split(/\s*,\s*/); // TODO: lame parsing
for (const part of parts) {
const [k, v] = part.split(/\s*=\s*/, 2);
cc[k] = v === undefined ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
}
return cc;
}
function formatCacheControl(cc) {
let parts = [];
for (const k in cc) {
const v = cc[k];
parts.push(v === true ? k : k + '=' + v);
}
if (!parts.length) {
return undefined;
}
return parts.join(', ');
}
var httpCacheSemantics = class CachePolicy {
constructor(
req,
res,
{
shared,
cacheHeuristic,
immutableMinTimeToLive,
ignoreCargoCult,
_fromObject,
} = {}
) {
if (_fromObject) {
this._fromObject(_fromObject);
return;
}
if (!res || !res.headers) {
throw Error('Response headers missing');
}
this._assertRequestHasHeaders(req);
this._responseTime = this.now();
this._isShared = shared !== false;
this._cacheHeuristic =
undefined !== cacheHeuristic ? cacheHeuristic : 0.1; // 10% matches IE
this._immutableMinTtl =
undefined !== immutableMinTimeToLive
? immutableMinTimeToLive
: 24 * 3600 * 1000;
this._status = 'status' in res ? res.status : 200;
this._resHeaders = res.headers;
this._rescc = parseCacheControl(res.headers['cache-control']);
this._method = 'method' in req ? req.method : 'GET';
this._url = req.url;
this._host = req.headers.host;
this._noAuthorization = !req.headers.authorization;
this._reqHeaders = res.headers.vary ? req.headers : null; // Don't keep all request headers if they won't be used
this._reqcc = parseCacheControl(req.headers['cache-control']);
// Assume that if someone uses legacy, non-standard uncecessary options they don't understand caching,
// so there's no point stricly adhering to the blindly copy&pasted directives.
if (
ignoreCargoCult &&
'pre-check' in this._rescc &&
'post-check' in this._rescc
) {
delete this._rescc['pre-check'];
delete this._rescc['post-check'];
delete this._rescc['no-cache'];
delete this._rescc['no-store'];
delete this._rescc['must-revalidate'];
this._resHeaders = Object.assign({}, this._resHeaders, {
'cache-control': formatCacheControl(this._rescc),
});
delete this._resHeaders.expires;
delete this._resHeaders.pragma;
}
// When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive
// as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1).
if (
res.headers['cache-control'] == null &&
/no-cache/.test(res.headers.pragma)
) {
this._rescc['no-cache'] = true;
}
}
now() {
return Date.now();
}
storable() {
// The "no-store" request directive indicates that a cache MUST NOT store any part of either this request or any response to it.
return !!(
!this._reqcc['no-store'] &&
// A cache MUST NOT store a response to any request, unless:
// The request method is understood by the cache and defined as being cacheable, and
('GET' === this._method ||
'HEAD' === this._method ||
('POST' === this._method && this._hasExplicitExpiration())) &&
// the response status code is understood by the cache, and
understoodStatuses.has(this._status) &&
// the "no-store" cache directive does not appear in request or response header fields, and
!this._rescc['no-store'] &&
// the "private" response directive does not appear in the response, if the cache is shared, and
(!this._isShared || !this._rescc.private) &&
// the Authorization header field does not appear in the request, if the cache is shared,
(!this._isShared ||
this._noAuthorization ||
this._allowsStoringAuthenticated()) &&
// the response either:
// contains an Expires header field, or
(this._resHeaders.expires ||
// contains a max-age response directive, or
// contains a s-maxage response directive and the cache is shared, or
// contains a public response directive.
this._rescc['max-age'] ||
(this._isShared && this._rescc['s-maxage']) ||
this._rescc.public ||
// has a status code that is defined as cacheable by default
statusCodeCacheableByDefault.has(this._status))
);
}
_hasExplicitExpiration() {
// 4.2.1 Calculating Freshness Lifetime
return (
(this._isShared && this._rescc['s-maxage']) ||
this._rescc['max-age'] ||
this._resHeaders.expires
);
}
_assertRequestHasHeaders(req) {
if (!req || !req.headers) {
throw Error('Request headers missing');
}
}
satisfiesWithoutRevalidation(req) {
this._assertRequestHasHeaders(req);
// When presented with a request, a cache MUST NOT reuse a stored response, unless:
// the presented request does not contain the no-cache pragma (Section 5.4), nor the no-cache cache directive,
// unless the stored response is successfully validated (Section 4.3), and
const requestCC = parseCacheControl(req.headers['cache-control']);
if (requestCC['no-cache'] || /no-cache/.test(req.headers.pragma)) {
return false;
}
if (requestCC['max-age'] && this.age() > requestCC['max-age']) {
return false;
}
if (
requestCC['min-fresh'] &&
this.timeToLive() < 1000 * requestCC['min-fresh']
) {
return false;
}
// the stored response is either:
// fresh, or allowed to be served stale
if (this.stale()) {
const allowsStale =
requestCC['max-stale'] &&
!this._rescc['must-revalidate'] &&
(true === requestCC['max-stale'] ||
requestCC['max-stale'] > this.age() - this.maxAge());
if (!allowsStale) {
return false;
}
}
return this._requestMatches(req, false);
}
_requestMatches(req, allowHeadMethod) {
// The presented effective request URI and that of the stored response match, and
return (
(!this._url || this._url === req.url) &&
this._host === req.headers.host &&
// the request method associated with the stored response allows it to be used for the presented request, and
(!req.method ||
this._method === req.method ||
(allowHeadMethod && 'HEAD' === req.method)) &&
// selecting header fields nominated by the stored response (if any) match those presented, and
this._varyMatches(req)
);
}
_allowsStoringAuthenticated() {
// following Cache-Control response directives (Section 5.2.2) have such an effect: must-revalidate, public, and s-maxage.
return (
this._rescc['must-revalidate'] ||
this._rescc.public ||
this._rescc['s-maxage']
);
}
_varyMatches(req) {
if (!this._resHeaders.vary) {
return true;
}
// A Vary header field-value of "*" always fails to match
if (this._resHeaders.vary === '*') {
return false;
}
const fields = this._resHeaders.vary
.trim()
.toLowerCase()
.split(/\s*,\s*/);
for (const name of fields) {
if (req.headers[name] !== this._reqHeaders[name]) return false;
}
return true;
}
_copyWithoutHopByHopHeaders(inHeaders) {
const headers = {};
for (const name in inHeaders) {
if (hopByHopHeaders[name]) continue;
headers[name] = inHeaders[name];
}
// 9.1. Connection
if (inHeaders.connection) {
const tokens = inHeaders.connection.trim().split(/\s*,\s*/);
for (const name of tokens) {
delete headers[name];
}
}
if (headers.warning) {
const warnings = headers.warning.split(/,/).filter(warning => {
return !/^\s*1[0-9][0-9]/.test(warning);
});
if (!warnings.length) {
delete headers.warning;
} else {
headers.warning = warnings.join(',').trim();
}
}
return headers;
}
responseHeaders() {
const headers = this._copyWithoutHopByHopHeaders(this._resHeaders);
const age = this.age();
// A cache SHOULD generate 113 warning if it heuristically chose a freshness
// lifetime greater than 24 hours and the response's age is greater than 24 hours.
if (
age > 3600 * 24 &&
!this._hasExplicitExpiration() &&
this.maxAge() > 3600 * 24
) {
headers.warning =
(headers.warning ? `${headers.warning}, ` : '') +
'113 - "rfc7234 5.5.4"';
}
headers.age = `${Math.round(age)}`;
headers.date = new Date(this.now()).toUTCString();
return headers;
}
/**
* Value of the Date response header or current time if Date was invalid
* @return timestamp
*/
date() {
const serverDate = Date.parse(this._resHeaders.date);
if (isFinite(serverDate)) {
return serverDate;
}
return this._responseTime;
}
/**
* Value of the Age header, in seconds, updated for the current time.
* May be fractional.
*
* @return Number
*/
age() {
let age = this._ageValue();
const residentTime = (this.now() - this._responseTime) / 1000;
return age + residentTime;
}
_ageValue() {
return toNumberOrZero(this._resHeaders.age);
}
/**
* Value of applicable max-age (or heuristic equivalent) in seconds. This counts since response's `Date`.
*
* For an up-to-date value, see `timeToLive()`.
*
* @return Number
*/
maxAge() {
if (!this.storable() || this._rescc['no-cache']) {
return 0;
}
// Shared responses with cookies are cacheable according to the RFC, but IMHO it'd be unwise to do so by default
// so this implementation requires explicit opt-in via public header
if (
this._isShared &&
(this._resHeaders['set-cookie'] &&
!this._rescc.public &&
!this._rescc.immutable)
) {
return 0;
}
if (this._resHeaders.vary === '*') {
return 0;
}
if (this._isShared) {
if (this._rescc['proxy-revalidate']) {
return 0;
}
// if a response includes the s-maxage directive, a shared cache recipient MUST ignore the Expires field.
if (this._rescc['s-maxage']) {
return toNumberOrZero(this._rescc['s-maxage']);
}
}
// If a response includes a Cache-Control field with the max-age directive, a recipient MUST ignore the Expires field.
if (this._rescc['max-age']) {
return toNumberOrZero(this._rescc['max-age']);
}
const defaultMinTtl = this._rescc.immutable ? this._immutableMinTtl : 0;
const serverDate = this.date();
if (this._resHeaders.expires) {
const expires = Date.parse(this._resHeaders.expires);
// A cache recipient MUST interpret invalid date formats, especially the value "0", as representing a time in the past (i.e., "already expired").
if (Number.isNaN(expires) || expires < serverDate) {
return 0;
}
return Math.max(defaultMinTtl, (expires - serverDate) / 1000);
}
if (this._resHeaders['last-modified']) {
const lastModified = Date.parse(this._resHeaders['last-modified']);
if (isFinite(lastModified) && serverDate > lastModified) {
return Math.max(
defaultMinTtl,
((serverDate - lastModified) / 1000) * this._cacheHeuristic
);
}
}
return defaultMinTtl;
}
timeToLive() {
const age = this.maxAge() - this.age();
const staleIfErrorAge = age + toNumberOrZero(this._rescc['stale-if-error']);
const staleWhileRevalidateAge = age + toNumberOrZero(this._rescc['stale-while-revalidate']);
return Math.max(0, age, staleIfErrorAge, staleWhileRevalidateAge) * 1000;
}
stale() {
return this.maxAge() <= this.age();
}
_useStaleIfError() {
return this.maxAge() + toNumberOrZero(this._rescc['stale-if-error']) > this.age();
}
useStaleWhileRevalidate() {
return this.maxAge() + toNumberOrZero(this._rescc['stale-while-revalidate']) > this.age();
}
static fromObject(obj) {
return new this(undefined, undefined, { _fromObject: obj });
}
_fromObject(obj) {
if (this._responseTime) throw Error('Reinitialized');
if (!obj || obj.v !== 1) throw Error('Invalid serialization');
this._responseTime = obj.t;
this._isShared = obj.sh;
this._cacheHeuristic = obj.ch;
this._immutableMinTtl =
obj.imm !== undefined ? obj.imm : 24 * 3600 * 1000;
this._status = obj.st;
this._resHeaders = obj.resh;
this._rescc = obj.rescc;
this._method = obj.m;
this._url = obj.u;
this._host = obj.h;
this._noAuthorization = obj.a;
this._reqHeaders = obj.reqh;
this._reqcc = obj.reqcc;
}
toObject() {
return {
v: 1,
t: this._responseTime,
sh: this._isShared,
ch: this._cacheHeuristic,
imm: this._immutableMinTtl,
st: this._status,
resh: this._resHeaders,
rescc: this._rescc,
m: this._method,
u: this._url,
h: this._host,
a: this._noAuthorization,
reqh: this._reqHeaders,
reqcc: this._reqcc,
};
}
/**
* Headers for sending to the origin server to revalidate stale response.
* Allows server to return 304 to allow reuse of the previous response.
*
* Hop by hop headers are always stripped.
* Revalidation headers may be added or removed, depending on request.
*/
revalidationHeaders(incomingReq) {
this._assertRequestHasHeaders(incomingReq);
const headers = this._copyWithoutHopByHopHeaders(incomingReq.headers);
// This implementation does not understand range requests
delete headers['if-range'];
if (!this._requestMatches(incomingReq, true) || !this.storable()) {
// revalidation allowed via HEAD
// not for the same resource, or wasn't allowed to be cached anyway
delete headers['if-none-match'];
delete headers['if-modified-since'];
return headers;
}
/* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
if (this._resHeaders.etag) {
headers['if-none-match'] = headers['if-none-match']
? `${headers['if-none-match']}, ${this._resHeaders.etag}`
: this._resHeaders.etag;
}
// Clients MAY issue simple (non-subrange) GET requests with either weak validators or strong validators. Clients MUST NOT use weak validators in other forms of request.
const forbidsWeakValidators =
headers['accept-ranges'] ||
headers['if-match'] ||
headers['if-unmodified-since'] ||
(this._method && this._method != 'GET');
/* SHOULD send the Last-Modified value in non-subrange cache validation requests (using If-Modified-Since) if only a Last-Modified value has been provided by the origin server.
Note: This implementation does not understand partial responses (206) */
if (forbidsWeakValidators) {
delete headers['if-modified-since'];
if (headers['if-none-match']) {
const etags = headers['if-none-match']
.split(/,/)
.filter(etag => {
return !/^\s*W\//.test(etag);
});
if (!etags.length) {
delete headers['if-none-match'];
} else {
headers['if-none-match'] = etags.join(',').trim();
}
}
} else if (
this._resHeaders['last-modified'] &&
!headers['if-modified-since']
) {
headers['if-modified-since'] = this._resHeaders['last-modified'];
}
return headers;
}
/**
* Creates new CachePolicy with information combined from the previews response,
* and the new revalidation response.
*
* Returns {policy, modified} where modified is a boolean indicating
* whether the response body has been modified, and old cached body can't be used.
*
* @return {Object} {policy: CachePolicy, modified: Boolean}
*/
revalidatedPolicy(request, response) {
this._assertRequestHasHeaders(request);
if(this._useStaleIfError() && isErrorResponse(response)) { // I consider the revalidation request unsuccessful
return {
modified: false,
matches: false,
policy: this,
};
}
if (!response || !response.headers) {
throw Error('Response headers missing');
}
// These aren't going to be supported exactly, since one CachePolicy object
// doesn't know about all the other cached objects.
let matches = false;
if (response.status !== undefined && response.status != 304) {
matches = false;
} else if (
response.headers.etag &&
!/^\s*W\//.test(response.headers.etag)
) {
// "All of the stored responses with the same strong validator are selected.
// If none of the stored responses contain the same strong validator,
// then the cache MUST NOT use the new response to update any stored responses."
matches =
this._resHeaders.etag &&
this._resHeaders.etag.replace(/^\s*W\//, '') ===
response.headers.etag;
} else if (this._resHeaders.etag && response.headers.etag) {
// "If the new response contains a weak validator and that validator corresponds
// to one of the cache's stored responses,
// then the most recent of those matching stored responses is selected for update."
matches =
this._resHeaders.etag.replace(/^\s*W\//, '') ===
response.headers.etag.replace(/^\s*W\//, '');
} else if (this._resHeaders['last-modified']) {
matches =
this._resHeaders['last-modified'] ===
response.headers['last-modified'];
} else {
// If the new response does not include any form of validator (such as in the case where
// a client generates an If-Modified-Since request from a source other than the Last-Modified
// response header field), and there is only one stored response, and that stored response also
// lacks a validator, then that stored response is selected for update.
if (
!this._resHeaders.etag &&
!this._resHeaders['last-modified'] &&
!response.headers.etag &&
!response.headers['last-modified']
) {
matches = true;
}
}
if (!matches) {
return {
policy: new this.constructor(request, response),
// Client receiving 304 without body, even if it's invalid/mismatched has no option
// but to reuse a cached body. We don't have a good way to tell clients to do
// error recovery in such case.
modified: response.status != 304,
matches: false,
};
}
// use other header fields provided in the 304 (Not Modified) response to replace all instances
// of the corresponding header fields in the stored response.
const headers = {};
for (const k in this._resHeaders) {
headers[k] =
k in response.headers && !excludedFromRevalidationUpdate[k]
? response.headers[k]
: this._resHeaders[k];
}
const newResponse = Object.assign({}, response, {
status: this._status,
method: this._method,
headers,
});
return {
policy: new this.constructor(request, newResponse, {
shared: this._isShared,
cacheHeuristic: this._cacheHeuristic,
immutableMinTimeToLive: this._immutableMinTtl,
}),
modified: false,
matches: true,
};
}
};
var lowercaseKeys$2 = object => {
const result = {};
for (const [key, value] of Object.entries(object)) {
result[key.toLowerCase()] = value;
}
return result;
};
const Readable$1 = require$$0__default$1["default"].Readable;
const lowercaseKeys$1 = lowercaseKeys$2;
class Response$1 extends Readable$1 {
constructor(statusCode, headers, body, url) {
if (typeof statusCode !== 'number') {
throw new TypeError('Argument `statusCode` should be a number');
}
if (typeof headers !== 'object') {
throw new TypeError('Argument `headers` should be an object');
}
if (!(body instanceof Buffer)) {
throw new TypeError('Argument `body` should be a buffer');
}
if (typeof url !== 'string') {
throw new TypeError('Argument `url` should be a string');
}
super();
this.statusCode = statusCode;
this.headers = lowercaseKeys$1(headers);
this.body = body;
this.url = url;
}
_read() {
this.push(this.body);
this.push(null);
}
}
var src$3 = Response$1;
// We define these manually to ensure they're always copied
// even if they would move up the prototype chain
// https://nodejs.org/api/http.html#http_class_http_incomingmessage
const knownProps = [
'destroy',
'setTimeout',
'socket',
'headers',
'trailers',
'rawHeaders',
'statusCode',
'httpVersion',
'httpVersionMinor',
'httpVersionMajor',
'rawTrailers',
'statusMessage'
];
var mimicResponse$3 = (fromStream, toStream) => {
const fromProps = new Set(Object.keys(fromStream).concat(knownProps));
for (const prop of fromProps) {
// Don't overwrite existing properties
if (prop in toStream) {
continue;
}
toStream[prop] = typeof fromStream[prop] === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop];
}
};
const PassThrough$1 = require$$0__default$1["default"].PassThrough;
const mimicResponse$2 = mimicResponse$3;
const cloneResponse$1 = response => {
if (!(response && response.pipe)) {
throw new TypeError('Parameter `response` must be a response stream.');
}
const clone = new PassThrough$1();
mimicResponse$2(response, clone);
return response.pipe(clone);
};
var src$2 = cloneResponse$1;
var jsonBuffer = {};
//TODO: handle reviver/dehydrate function like normal
//and handle indentation, like normal.
//if anyone needs this... please send pull request.
jsonBuffer.stringify = function stringify (o) {
if('undefined' == typeof o) return o
if(o && Buffer.isBuffer(o))
return JSON.stringify(':base64:' + o.toString('base64'))
if(o && o.toJSON)
o = o.toJSON();
if(o && 'object' === typeof o) {
var s = '';
var array = Array.isArray(o);
s = array ? '[' : '{';
var first = true;
for(var k in o) {
var ignore = 'function' == typeof o[k] || (!array && 'undefined' === typeof o[k]);
if(Object.hasOwnProperty.call(o, k) && !ignore) {
if(!first)
s += ',';
first = false;
if (array) {
if(o[k] == undefined)
s += 'null';
else
s += stringify(o[k]);
} else if (o[k] !== void(0)) {
s += stringify(k) + ':' + stringify(o[k]);
}
}
}
s += array ? ']' : '}';
return s
} else if ('string' === typeof o) {
return JSON.stringify(/^:/.test(o) ? ':' + o : o)
} else if ('undefined' === typeof o) {
return 'null';
} else
return JSON.stringify(o)
};
jsonBuffer.parse = function (s) {
return JSON.parse(s, function (key, value) {
if('string' === typeof value) {
if(/^:base64:/.test(value))
return Buffer.from(value.substring(8), 'base64')
else
return /^:/.test(value) ? value.substring(1) : value
}
return value
})
};
const EventEmitter$2 = require$$0__default$3["default"];
const JSONB = jsonBuffer;
// eslint-disable-next-line no-extend-native
BigInt.prototype.toJSON = function () {
return this.toString();
};
const loadStore = options => {
const adapters = {
redis: '@keyv/redis',
mongodb: '@keyv/mongo',
mongo: '@keyv/mongo',
sqlite: '@keyv/sqlite',
postgresql: '@keyv/postgres',
postgres: '@keyv/postgres',
mysql: '@keyv/mysql',
etcd: '@keyv/etcd',
};
if (options.adapter || options.uri) {
const adapter = options.adapter || /^[^:]*/.exec(options.uri)[0];
return new (commonjsRequire(adapters[adapter]))(options);
}
return new Map();
};
class Keyv$1 extends EventEmitter$2 {
constructor(uri, options) {
super();
this.opts = Object.assign(
{
namespace: 'keyv',
serialize: JSONB.stringify,
deserialize: JSONB.parse,
},
(typeof uri === 'string') ? { uri } : uri,
options,
);
if (!this.opts.store) {
const adapterOptions = Object.assign({}, this.opts);
this.opts.store = loadStore(adapterOptions);
}
if (typeof this.opts.store.on === 'function') {
this.opts.store.on('error', error => this.emit('error', error));
}
this.opts.store.namespace = this.opts.namespace;
}
_getKeyPrefix(key) {
return `${this.opts.namespace}:${key}`;
}
get(key, options) {
const keyPrefixed = this._getKeyPrefix(key);
const { store } = this.opts;
return Promise.resolve()
.then(() => store.get(keyPrefixed))
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
.then(data => {
if (data === undefined || data === null) {
return undefined;
}
if (typeof data.expires === 'number' && Date.now() > data.expires) {
this.delete(key);
return undefined;
}
return (options && options.raw) ? data : data.value;
});
}
set(key, value, ttl) {
const keyPrefixed = this._getKeyPrefix(key);
if (typeof ttl === 'undefined') {
ttl = this.opts.ttl;
}
if (ttl === 0) {
ttl = undefined;
}
const { store } = this.opts;
return Promise.resolve()
.then(() => {
const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
if (typeof value === 'symbol') {
this.emit('error', 'symbol cannot be serialized');
}
value = { value, expires };
return this.opts.serialize(value);
})
.then(value => store.set(keyPrefixed, value, ttl))
.then(() => true);
}
delete(key) {
const keyPrefixed = this._getKeyPrefix(key);
const { store } = this.opts;
return Promise.resolve()
.then(() => store.delete(keyPrefixed));
}
clear() {
const { store } = this.opts;
return Promise.resolve()
.then(() => store.clear());
}
}
var src$1 = Keyv$1;
const EventEmitter$1 = require$$0__default$3["default"];
const urlLib = require$$0__default$4["default"];
const normalizeUrl = normalizeUrl_1;
const getStream = getStream$2.exports;
const CachePolicy = httpCacheSemantics;
const Response = src$3;
const lowercaseKeys = lowercaseKeys$2;
const cloneResponse = src$2;
const Keyv = src$1;
class CacheableRequest {
constructor(request, cacheAdapter) {
if (typeof request !== 'function') {
throw new TypeError('Parameter `request` must be a function');
}
this.cache = new Keyv({
uri: typeof cacheAdapter === 'string' && cacheAdapter,
store: typeof cacheAdapter !== 'string' && cacheAdapter,
namespace: 'cacheable-request'
});
return this.createCacheableRequest(request);
}
createCacheableRequest(request) {
return (opts, cb) => {
let url;
if (typeof opts === 'string') {
url = normalizeUrlObject(urlLib.parse(opts));
opts = {};
} else if (opts instanceof urlLib.URL) {
url = normalizeUrlObject(urlLib.parse(opts.toString()));
opts = {};
} else {
const [pathname, ...searchParts] = (opts.path || '').split('?');
const search = searchParts.length > 0 ?
`?${searchParts.join('?')}` :
'';
url = normalizeUrlObject({ ...opts, pathname, search });
}
opts = {
headers: {},
method: 'GET',
cache: true,
strictTtl: false,
automaticFailover: false,
...opts,
...urlObjectToRequestOptions(url)
};
opts.headers = lowercaseKeys(opts.headers);
const ee = new EventEmitter$1();
const normalizedUrlString = normalizeUrl(
urlLib.format(url),
{
stripWWW: false,
removeTrailingSlash: false,
stripAuthentication: false
}
);
const key = `${opts.method}:${normalizedUrlString}`;
let revalidate = false;
let madeRequest = false;
const makeRequest = opts => {
madeRequest = true;
let requestErrored = false;
let requestErrorCallback;
const requestErrorPromise = new Promise(resolve => {
requestErrorCallback = () => {
if (!requestErrored) {
requestErrored = true;
resolve();
}
};
});
const handler = response => {
if (revalidate && !opts.forceRefresh) {
response.status = response.statusCode;
const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(opts, response);
if (!revalidatedPolicy.modified) {
const headers = revalidatedPolicy.policy.responseHeaders();
response = new Response(revalidate.statusCode, headers, revalidate.body, revalidate.url);
response.cachePolicy = revalidatedPolicy.policy;
response.fromCache = true;
}
}
if (!response.fromCache) {
response.cachePolicy = new CachePolicy(opts, response, opts);
response.fromCache = false;
}
let clonedResponse;
if (opts.cache && response.cachePolicy.storable()) {
clonedResponse = cloneResponse(response);
(async () => {
try {
const bodyPromise = getStream.buffer(response);
await Promise.race([
requestErrorPromise,
new Promise(resolve => response.once('end', resolve))
]);
if (requestErrored) {
return;
}
const body = await bodyPromise;
const value = {
cachePolicy: response.cachePolicy.toObject(),
url: response.url,
statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
body
};
let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
if (opts.maxTtl) {
ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
}
await this.cache.set(key, value, ttl);
} catch (error) {
ee.emit('error', new CacheableRequest.CacheError(error));
}
})();
} else if (opts.cache && revalidate) {
(async () => {
try {
await this.cache.delete(key);
} catch (error) {
ee.emit('error', new CacheableRequest.CacheError(error));
}
})();
}
ee.emit('response', clonedResponse || response);
if (typeof cb === 'function') {
cb(clonedResponse || response);
}
};
try {
const req = request(opts, handler);
req.once('error', requestErrorCallback);
req.once('abort', requestErrorCallback);
ee.emit('request', req);
} catch (error) {
ee.emit('error', new CacheableRequest.RequestError(error));
}
};
(async () => {
const get = async opts => {
await Promise.resolve();
const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
if (typeof cacheEntry === 'undefined') {
return makeRequest(opts);
}
const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
if (policy.satisfiesWithoutRevalidation(opts) && !opts.forceRefresh) {
const headers = policy.responseHeaders();
const response = new Response(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
response.cachePolicy = policy;
response.fromCache = true;
ee.emit('response', response);
if (typeof cb === 'function') {
cb(response);
}
} else {
revalidate = cacheEntry;
opts.headers = policy.revalidationHeaders(opts);
makeRequest(opts);
}
};
const errorHandler = error => ee.emit('error', new CacheableRequest.CacheError(error));
this.cache.once('error', errorHandler);
ee.on('response', () => this.cache.removeListener('error', errorHandler));
try {
await get(opts);
} catch (error) {
if (opts.automaticFailover && !madeRequest) {
makeRequest(opts);
}
ee.emit('error', new CacheableRequest.CacheError(error));
}
})();
return ee;
};
}
}
function urlObjectToRequestOptions(url) {
const options = { ...url };
options.path = `${url.pathname || '/'}${url.search || ''}`;
delete options.pathname;
delete options.search;
return options;
}
function normalizeUrlObject(url) {
// If url was parsed by url.parse or new URL:
// - hostname will be set
// - host will be hostname[:port]
// - port will be set if it was explicit in the parsed string
// Otherwise, url was from request options:
// - hostname or host may be set
// - host shall not have port encoded
return {
protocol: url.protocol,
auth: url.auth,
hostname: url.hostname || url.host || 'localhost',
port: url.port,
pathname: url.pathname,
search: url.search
};
}
CacheableRequest.RequestError = class extends Error {
constructor(error) {
super(error.message);
this.name = 'RequestError';
Object.assign(this, error);
}
};
CacheableRequest.CacheError = class extends Error {
constructor(error) {
super(error.message);
this.name = 'CacheError';
Object.assign(this, error);
}
};
var src = CacheableRequest;
// We define these manually to ensure they're always copied
// even if they would move up the prototype chain
// https://nodejs.org/api/http.html#http_class_http_incomingmessage
const knownProperties = [
'aborted',
'complete',
'headers',
'httpVersion',
'httpVersionMinor',
'httpVersionMajor',
'method',
'rawHeaders',
'rawTrailers',
'setTimeout',
'socket',
'statusCode',
'statusMessage',
'trailers',
'url'
];
var mimicResponse$1 = (fromStream, toStream) => {
if (toStream._readableState.autoDestroy) {
throw new Error('The second stream must have the `autoDestroy` option set to `false`');
}
const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties));
const properties = {};
for (const property of fromProperties) {
// Don't overwrite existing properties.
if (property in toStream) {
continue;
}
properties[property] = {
get() {
const value = fromStream[property];
const isFunction = typeof value === 'function';
return isFunction ? value.bind(fromStream) : value;
},
set(value) {
fromStream[property] = value;
},
enumerable: true,
configurable: false
};
}
Object.defineProperties(toStream, properties);
fromStream.once('aborted', () => {
toStream.destroy();
toStream.emit('aborted');
});
fromStream.once('close', () => {
if (fromStream.complete) {
if (toStream.readable) {
toStream.once('end', () => {
toStream.emit('close');
});
} else {
toStream.emit('close');
}
} else {
toStream.emit('close');
}
});
return toStream;
};
const {Transform, PassThrough} = require$$0__default$1["default"];
const zlib = require$$1__default$1["default"];
const mimicResponse = mimicResponse$1;
var decompressResponse = response => {
const contentEncoding = (response.headers['content-encoding'] || '').toLowerCase();
if (!['gzip', 'deflate', 'br'].includes(contentEncoding)) {
return response;
}
// TODO: Remove this when targeting Node.js 12.
const isBrotli = contentEncoding === 'br';
if (isBrotli && typeof zlib.createBrotliDecompress !== 'function') {
response.destroy(new Error('Brotli is not supported on Node.js < 12'));
return response;
}
let isEmpty = true;
const checker = new Transform({
transform(data, _encoding, callback) {
isEmpty = false;
callback(null, data);
},
flush(callback) {
callback();
}
});
const finalStream = new PassThrough({
autoDestroy: false,
destroy(error, callback) {
response.destroy();
callback(error);
}
});
const decompressStream = isBrotli ? zlib.createBrotliDecompress() : zlib.createUnzip();
decompressStream.once('error', error => {
if (isEmpty && !response.readable) {
finalStream.end();
return;
}
finalStream.destroy(error);
});
mimicResponse(response, finalStream);
response.pipe(checker).pipe(decompressStream).pipe(finalStream);
return finalStream;
};
class QuickLRU$2 {
constructor(options = {}) {
if (!(options.maxSize && options.maxSize > 0)) {
throw new TypeError('`maxSize` must be a number greater than 0');
}
this.maxSize = options.maxSize;
this.onEviction = options.onEviction;
this.cache = new Map();
this.oldCache = new Map();
this._size = 0;
}
_set(key, value) {
this.cache.set(key, value);
this._size++;
if (this._size >= this.maxSize) {
this._size = 0;
if (typeof this.onEviction === 'function') {
for (const [key, value] of this.oldCache.entries()) {
this.onEviction(key, value);
}
}
this.oldCache = this.cache;
this.cache = new Map();
}
}
get(key) {
if (this.cache.has(key)) {
return this.cache.get(key);
}
if (this.oldCache.has(key)) {
const value = this.oldCache.get(key);
this.oldCache.delete(key);
this._set(key, value);
return value;
}
}
set(key, value) {
if (this.cache.has(key)) {
this.cache.set(key, value);
} else {
this._set(key, value);
}
return this;
}
has(key) {
return this.cache.has(key) || this.oldCache.has(key);
}
peek(key) {
if (this.cache.has(key)) {
return this.cache.get(key);
}
if (this.oldCache.has(key)) {
return this.oldCache.get(key);
}
}
delete(key) {
const deleted = this.cache.delete(key);
if (deleted) {
this._size--;
}
return this.oldCache.delete(key) || deleted;
}
clear() {
this.cache.clear();
this.oldCache.clear();
this._size = 0;
}
* keys() {
for (const [key] of this) {
yield key;
}
}
* values() {
for (const [, value] of this) {
yield value;
}
}
* [Symbol.iterator]() {
for (const item of this.cache) {
yield item;
}
for (const item of this.oldCache) {
const [key] = item;
if (!this.cache.has(key)) {
yield item;
}
}
}
get size() {
let oldCacheSize = 0;
for (const key of this.oldCache.keys()) {
if (!this.cache.has(key)) {
oldCacheSize++;
}
}
return Math.min(this._size + oldCacheSize, this.maxSize);
}
}
var quickLru = QuickLRU$2;
const EventEmitter = require$$0__default$3["default"];
const tls$1 = require$$1__default$2["default"];
const http2$2 = require$$0__default$5["default"];
const QuickLRU$1 = quickLru;
const kCurrentStreamsCount = Symbol('currentStreamsCount');
const kRequest = Symbol('request');
const kOriginSet = Symbol('cachedOriginSet');
const kGracefullyClosing = Symbol('gracefullyClosing');
const nameKeys = [
// `http2.connect()` options
'maxDeflateDynamicTableSize',
'maxSessionMemory',
'maxHeaderListPairs',
'maxOutstandingPings',
'maxReservedRemoteStreams',
'maxSendHeaderBlockLength',
'paddingStrategy',
// `tls.connect()` options
'localAddress',
'path',
'rejectUnauthorized',
'minDHSize',
// `tls.createSecureContext()` options
'ca',
'cert',
'clientCertEngine',
'ciphers',
'key',
'pfx',
'servername',
'minVersion',
'maxVersion',
'secureProtocol',
'crl',
'honorCipherOrder',
'ecdhCurve',
'dhparam',
'secureOptions',
'sessionIdContext'
];
const getSortedIndex = (array, value, compare) => {
let low = 0;
let high = array.length;
while (low < high) {
const mid = (low + high) >>> 1;
/* istanbul ignore next */
if (compare(array[mid], value)) {
// This never gets called because we use descending sort. Better to have this anyway.
low = mid + 1;
} else {
high = mid;
}
}
return low;
};
const compareSessions = (a, b) => {
return a.remoteSettings.maxConcurrentStreams > b.remoteSettings.maxConcurrentStreams;
};
// See https://tools.ietf.org/html/rfc8336
const closeCoveredSessions = (where, session) => {
// Clients SHOULD NOT emit new requests on any connection whose Origin
// Set is a proper subset of another connection's Origin Set, and they
// SHOULD close it once all outstanding requests are satisfied.
for (const coveredSession of where) {
if (
// The set is a proper subset when its length is less than the other set.
coveredSession[kOriginSet].length < session[kOriginSet].length &&
// And the other set includes all elements of the subset.
coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin)) &&
// Makes sure that the session can handle all requests from the covered session.
coveredSession[kCurrentStreamsCount] + session[kCurrentStreamsCount] <= session.remoteSettings.maxConcurrentStreams
) {
// This allows pending requests to finish and prevents making new requests.
gracefullyClose(coveredSession);
}
}
};
// This is basically inverted `closeCoveredSessions(...)`.
const closeSessionIfCovered = (where, coveredSession) => {
for (const session of where) {
if (
coveredSession[kOriginSet].length < session[kOriginSet].length &&
coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin)) &&
coveredSession[kCurrentStreamsCount] + session[kCurrentStreamsCount] <= session.remoteSettings.maxConcurrentStreams
) {
gracefullyClose(coveredSession);
}
}
};
const getSessions = ({agent, isFree}) => {
const result = {};
// eslint-disable-next-line guard-for-in
for (const normalizedOptions in agent.sessions) {
const sessions = agent.sessions[normalizedOptions];
const filtered = sessions.filter(session => {
const result = session[Agent$1.kCurrentStreamsCount] < session.remoteSettings.maxConcurrentStreams;
return isFree ? result : !result;
});
if (filtered.length !== 0) {
result[normalizedOptions] = filtered;
}
}
return result;
};
const gracefullyClose = session => {
session[kGracefullyClosing] = true;
if (session[kCurrentStreamsCount] === 0) {
session.close();
}
};
class Agent$1 extends EventEmitter {
constructor({timeout = 60000, maxSessions = Infinity, maxFreeSessions = 10, maxCachedTlsSessions = 100} = {}) {
super();
// A session is considered busy when its current streams count
// is equal to or greater than the `maxConcurrentStreams` value.
// A session is considered free when its current streams count
// is less than the `maxConcurrentStreams` value.
// SESSIONS[NORMALIZED_OPTIONS] = [];
this.sessions = {};
// The queue for creating new sessions. It looks like this:
// QUEUE[NORMALIZED_OPTIONS][NORMALIZED_ORIGIN] = ENTRY_FUNCTION
//
// The entry function has `listeners`, `completed` and `destroyed` properties.
// `listeners` is an array of objects containing `resolve` and `reject` functions.
// `completed` is a boolean. It's set to true after ENTRY_FUNCTION is executed.
// `destroyed` is a boolean. If it's set to true, the session will be destroyed if hasn't connected yet.
this.queue = {};
// Each session will use this timeout value.
this.timeout = timeout;
// Max sessions in total
this.maxSessions = maxSessions;
// Max free sessions in total
// TODO: decreasing `maxFreeSessions` should close some sessions
this.maxFreeSessions = maxFreeSessions;
this._freeSessionsCount = 0;
this._sessionsCount = 0;
// We don't support push streams by default.
this.settings = {
enablePush: false
};
// Reusing TLS sessions increases performance.
this.tlsSessionCache = new QuickLRU$1({maxSize: maxCachedTlsSessions});
}
static normalizeOrigin(url, servername) {
if (typeof url === 'string') {
url = new URL(url);
}
if (servername && url.hostname !== servername) {
url.hostname = servername;
}
return url.origin;
}
normalizeOptions(options) {
let normalized = '';
if (options) {
for (const key of nameKeys) {
if (options[key]) {
normalized += `:${options[key]}`;
}
}
}
return normalized;
}
_tryToCreateNewSession(normalizedOptions, normalizedOrigin) {
if (!(normalizedOptions in this.queue) || !(normalizedOrigin in this.queue[normalizedOptions])) {
return;
}
const item = this.queue[normalizedOptions][normalizedOrigin];
// The entry function can be run only once.
// BUG: The session may be never created when:
// - the first condition is false AND
// - this function is never called with the same arguments in the future.
if (this._sessionsCount < this.maxSessions && !item.completed) {
item.completed = true;
item();
}
}
getSession(origin, options, listeners) {
return new Promise((resolve, reject) => {
if (Array.isArray(listeners)) {
listeners = [...listeners];
// Resolve the current promise ASAP, we're just moving the listeners.
// They will be executed at a different time.
resolve();
} else {
listeners = [{resolve, reject}];
}
const normalizedOptions = this.normalizeOptions(options);
const normalizedOrigin = Agent$1.normalizeOrigin(origin, options && options.servername);
if (normalizedOrigin === undefined) {
for (const {reject} of listeners) {
reject(new TypeError('The `origin` argument needs to be a string or an URL object'));
}
return;
}
if (normalizedOptions in this.sessions) {
const sessions = this.sessions[normalizedOptions];
let maxConcurrentStreams = -1;
let currentStreamsCount = -1;
let optimalSession;
// We could just do this.sessions[normalizedOptions].find(...) but that isn't optimal.
// Additionally, we are looking for session which has biggest current pending streams count.
for (const session of sessions) {
const sessionMaxConcurrentStreams = session.remoteSettings.maxConcurrentStreams;
if (sessionMaxConcurrentStreams < maxConcurrentStreams) {
break;
}
if (session[kOriginSet].includes(normalizedOrigin)) {
const sessionCurrentStreamsCount = session[kCurrentStreamsCount];
if (
sessionCurrentStreamsCount >= sessionMaxConcurrentStreams ||
session[kGracefullyClosing] ||
// Unfortunately the `close` event isn't called immediately,
// so `session.destroyed` is `true`, but `session.closed` is `false`.
session.destroyed
) {
continue;
}
// We only need set this once.
if (!optimalSession) {
maxConcurrentStreams = sessionMaxConcurrentStreams;
}
// We're looking for the session which has biggest current pending stream count,
// in order to minimalize the amount of active sessions.
if (sessionCurrentStreamsCount > currentStreamsCount) {
optimalSession = session;
currentStreamsCount = sessionCurrentStreamsCount;
}
}
}
if (optimalSession) {
/* istanbul ignore next: safety check */
if (listeners.length !== 1) {
for (const {reject} of listeners) {
const error = new Error(
`Expected the length of listeners to be 1, got ${listeners.length}.\n` +
'Please report this to https://github.com/szmarczak/http2-wrapper/'
);
reject(error);
}
return;
}
listeners[0].resolve(optimalSession);
return;
}
}
if (normalizedOptions in this.queue) {
if (normalizedOrigin in this.queue[normalizedOptions]) {
// There's already an item in the queue, just attach ourselves to it.
this.queue[normalizedOptions][normalizedOrigin].listeners.push(...listeners);
// This shouldn't be executed here.
// See the comment inside _tryToCreateNewSession.
this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
return;
}
} else {
this.queue[normalizedOptions] = {};
}
// The entry must be removed from the queue IMMEDIATELY when:
// 1. the session connects successfully,
// 2. an error occurs.
const removeFromQueue = () => {
// Our entry can be replaced. We cannot remove the new one.
if (normalizedOptions in this.queue && this.queue[normalizedOptions][normalizedOrigin] === entry) {
delete this.queue[normalizedOptions][normalizedOrigin];
if (Object.keys(this.queue[normalizedOptions]).length === 0) {
delete this.queue[normalizedOptions];
}
}
};
// The main logic is here
const entry = () => {
const name = `${normalizedOrigin}:${normalizedOptions}`;
let receivedSettings = false;
try {
const session = http2$2.connect(origin, {
createConnection: this.createConnection,
settings: this.settings,
session: this.tlsSessionCache.get(name),
...options
});
session[kCurrentStreamsCount] = 0;
session[kGracefullyClosing] = false;
const isFree = () => session[kCurrentStreamsCount] < session.remoteSettings.maxConcurrentStreams;
let wasFree = true;
session.socket.once('session', tlsSession => {
this.tlsSessionCache.set(name, tlsSession);
});
session.once('error', error => {
// Listeners are empty when the session successfully connected.
for (const {reject} of listeners) {
reject(error);
}
// The connection got broken, purge the cache.
this.tlsSessionCache.delete(name);
});
session.setTimeout(this.timeout, () => {
// Terminates all streams owned by this session.
// TODO: Maybe the streams should have a "Session timed out" error?
session.destroy();
});
session.once('close', () => {
if (receivedSettings) {
// 1. If it wasn't free then no need to decrease because
// it has been decreased already in session.request().
// 2. `stream.once('close')` won't increment the count
// because the session is already closed.
if (wasFree) {
this._freeSessionsCount--;
}
this._sessionsCount--;
// This cannot be moved to the stream logic,
// because there may be a session that hadn't made a single request.
const where = this.sessions[normalizedOptions];
where.splice(where.indexOf(session), 1);
if (where.length === 0) {
delete this.sessions[normalizedOptions];
}
} else {
// Broken connection
const error = new Error('Session closed without receiving a SETTINGS frame');
error.code = 'HTTP2WRAPPER_NOSETTINGS';
for (const {reject} of listeners) {
reject(error);
}
removeFromQueue();
}
// There may be another session awaiting.
this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
});
// Iterates over the queue and processes listeners.
const processListeners = () => {
if (!(normalizedOptions in this.queue) || !isFree()) {
return;
}
for (const origin of session[kOriginSet]) {
if (origin in this.queue[normalizedOptions]) {
const {listeners} = this.queue[normalizedOptions][origin];
// Prevents session overloading.
while (listeners.length !== 0 && isFree()) {
// We assume `resolve(...)` calls `request(...)` *directly*,
// otherwise the session will get overloaded.
listeners.shift().resolve(session);
}
const where = this.queue[normalizedOptions];
if (where[origin].listeners.length === 0) {
delete where[origin];
if (Object.keys(where).length === 0) {
delete this.queue[normalizedOptions];
break;
}
}
// We're no longer free, no point in continuing.
if (!isFree()) {
break;
}
}
}
};
// The Origin Set cannot shrink. No need to check if it suddenly became covered by another one.
session.on('origin', () => {
session[kOriginSet] = session.originSet;
if (!isFree()) {
// The session is full.
return;
}
processListeners();
// Close covered sessions (if possible).
closeCoveredSessions(this.sessions[normalizedOptions], session);
});
session.once('remoteSettings', () => {
// Fix Node.js bug preventing the process from exiting
session.ref();
session.unref();
this._sessionsCount++;
// The Agent could have been destroyed already.
if (entry.destroyed) {
const error = new Error('Agent has been destroyed');
for (const listener of listeners) {
listener.reject(error);
}
session.destroy();
return;
}
session[kOriginSet] = session.originSet;
{
const where = this.sessions;
if (normalizedOptions in where) {
const sessions = where[normalizedOptions];
sessions.splice(getSortedIndex(sessions, session, compareSessions), 0, session);
} else {
where[normalizedOptions] = [session];
}
}
this._freeSessionsCount += 1;
receivedSettings = true;
this.emit('session', session);
processListeners();
removeFromQueue();
// TODO: Close last recently used (or least used?) session
if (session[kCurrentStreamsCount] === 0 && this._freeSessionsCount > this.maxFreeSessions) {
session.close();
}
// Check if we haven't managed to execute all listeners.
if (listeners.length !== 0) {
// Request for a new session with predefined listeners.
this.getSession(normalizedOrigin, options, listeners);
listeners.length = 0;
}
// `session.remoteSettings.maxConcurrentStreams` might get increased
session.on('remoteSettings', () => {
processListeners();
// In case the Origin Set changes
closeCoveredSessions(this.sessions[normalizedOptions], session);
});
});
// Shim `session.request()` in order to catch all streams
session[kRequest] = session.request;
session.request = (headers, streamOptions) => {
if (session[kGracefullyClosing]) {
throw new Error('The session is gracefully closing. No new streams are allowed.');
}
const stream = session[kRequest](headers, streamOptions);
// The process won't exit until the session is closed or all requests are gone.
session.ref();
++session[kCurrentStreamsCount];
if (session[kCurrentStreamsCount] === session.remoteSettings.maxConcurrentStreams) {
this._freeSessionsCount--;
}
stream.once('close', () => {
wasFree = isFree();
--session[kCurrentStreamsCount];
if (!session.destroyed && !session.closed) {
closeSessionIfCovered(this.sessions[normalizedOptions], session);
if (isFree() && !session.closed) {
if (!wasFree) {
this._freeSessionsCount++;
wasFree = true;
}
const isEmpty = session[kCurrentStreamsCount] === 0;
if (isEmpty) {
session.unref();
}
if (
isEmpty &&
(
this._freeSessionsCount > this.maxFreeSessions ||
session[kGracefullyClosing]
)
) {
session.close();
} else {
closeCoveredSessions(this.sessions[normalizedOptions], session);
processListeners();
}
}
}
});
return stream;
};
} catch (error) {
for (const listener of listeners) {
listener.reject(error);
}
removeFromQueue();
}
};
entry.listeners = listeners;
entry.completed = false;
entry.destroyed = false;
this.queue[normalizedOptions][normalizedOrigin] = entry;
this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
});
}
request(origin, options, headers, streamOptions) {
return new Promise((resolve, reject) => {
this.getSession(origin, options, [{
reject,
resolve: session => {
try {
resolve(session.request(headers, streamOptions));
} catch (error) {
reject(error);
}
}
}]);
});
}
createConnection(origin, options) {
return Agent$1.connect(origin, options);
}
static connect(origin, options) {
options.ALPNProtocols = ['h2'];
const port = origin.port || 443;
const host = origin.hostname || origin.host;
if (typeof options.servername === 'undefined') {
options.servername = host;
}
return tls$1.connect(port, host, options);
}
closeFreeSessions() {
for (const sessions of Object.values(this.sessions)) {
for (const session of sessions) {
if (session[kCurrentStreamsCount] === 0) {
session.close();
}
}
}
}
destroy(reason) {
for (const sessions of Object.values(this.sessions)) {
for (const session of sessions) {
session.destroy(reason);
}
}
for (const entriesOfAuthority of Object.values(this.queue)) {
for (const entry of Object.values(entriesOfAuthority)) {
entry.destroyed = true;
}
}
// New requests should NOT attach to destroyed sessions
this.queue = {};
}
get freeSessions() {
return getSessions({agent: this, isFree: true});
}
get busySessions() {
return getSessions({agent: this, isFree: false});
}
}
Agent$1.kCurrentStreamsCount = kCurrentStreamsCount;
Agent$1.kGracefullyClosing = kGracefullyClosing;
var agent$1 = {
Agent: Agent$1,
globalAgent: new Agent$1()
};
const {Readable} = require$$0__default$1["default"];
class IncomingMessage$2 extends Readable {
constructor(socket, highWaterMark) {
super({
highWaterMark,
autoDestroy: false
});
this.statusCode = null;
this.statusMessage = '';
this.httpVersion = '2.0';
this.httpVersionMajor = 2;
this.httpVersionMinor = 0;
this.headers = {};
this.trailers = {};
this.req = null;
this.aborted = false;
this.complete = false;
this.upgrade = null;
this.rawHeaders = [];
this.rawTrailers = [];
this.socket = socket;
this.connection = socket;
this._dumped = false;
}
_destroy(error) {
this.req._request.destroy(error);
}
setTimeout(ms, callback) {
this.req.setTimeout(ms, callback);
return this;
}
_dump() {
if (!this._dumped) {
this._dumped = true;
this.removeAllListeners('data');
this.resume();
}
}
_read() {
if (this.req) {
this.req._request.resume();
}
}
}
var incomingMessage = IncomingMessage$2;
/* istanbul ignore file: https://github.com/nodejs/node/blob/a91293d4d9ab403046ab5eb022332e4e3d249bd3/lib/internal/url.js#L1257 */
var urlToOptions$3 = url => {
const options = {
protocol: url.protocol,
hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
host: url.host,
hash: url.hash,
search: url.search,
pathname: url.pathname,
href: url.href,
path: `${url.pathname || ''}${url.search || ''}`
};
if (typeof url.port === 'string' && url.port.length !== 0) {
options.port = Number(url.port);
}
if (url.username || url.password) {
options.auth = `${url.username || ''}:${url.password || ''}`;
}
return options;
};
var proxyEvents$2 = (from, to, events) => {
for (const event of events) {
from.on(event, (...args) => to.emit(event, ...args));
}
};
var isRequestPseudoHeader$1 = header => {
switch (header) {
case ':method':
case ':scheme':
case ':authority':
case ':path':
return true;
default:
return false;
}
};
var errors = {exports: {}};
(function (module) {
/* istanbul ignore file: https://github.com/nodejs/node/blob/master/lib/internal/errors.js */
const makeError = (Base, key, getMessage) => {
module.exports[key] = class NodeError extends Base {
constructor(...args) {
super(typeof getMessage === 'string' ? getMessage : getMessage(args));
this.name = `${super.name} [${key}]`;
this.code = key;
}
};
};
makeError(TypeError, 'ERR_INVALID_ARG_TYPE', args => {
const type = args[0].includes('.') ? 'property' : 'argument';
let valid = args[1];
const isManyTypes = Array.isArray(valid);
if (isManyTypes) {
valid = `${valid.slice(0, -1).join(', ')} or ${valid.slice(-1)}`;
}
return `The "${args[0]}" ${type} must be ${isManyTypes ? 'one of' : 'of'} type ${valid}. Received ${typeof args[2]}`;
});
makeError(TypeError, 'ERR_INVALID_PROTOCOL', args => {
return `Protocol "${args[0]}" not supported. Expected "${args[1]}"`;
});
makeError(Error, 'ERR_HTTP_HEADERS_SENT', args => {
return `Cannot ${args[0]} headers after they are sent to the client`;
});
makeError(TypeError, 'ERR_INVALID_HTTP_TOKEN', args => {
return `${args[0]} must be a valid HTTP token [${args[1]}]`;
});
makeError(TypeError, 'ERR_HTTP_INVALID_HEADER_VALUE', args => {
return `Invalid value "${args[0]} for header "${args[1]}"`;
});
makeError(TypeError, 'ERR_INVALID_CHAR', args => {
return `Invalid character in ${args[0]} [${args[1]}]`;
});
}(errors));
const http2$1 = require$$0__default$5["default"];
const {Writable} = require$$0__default$1["default"];
const {Agent, globalAgent} = agent$1;
const IncomingMessage$1 = incomingMessage;
const urlToOptions$2 = urlToOptions$3;
const proxyEvents$1 = proxyEvents$2;
const isRequestPseudoHeader = isRequestPseudoHeader$1;
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_PROTOCOL,
ERR_HTTP_HEADERS_SENT,
ERR_INVALID_HTTP_TOKEN,
ERR_HTTP_INVALID_HEADER_VALUE,
ERR_INVALID_CHAR
} = errors.exports;
const {
HTTP2_HEADER_STATUS,
HTTP2_HEADER_METHOD,
HTTP2_HEADER_PATH,
HTTP2_METHOD_CONNECT
} = http2$1.constants;
const kHeaders = Symbol('headers');
const kOrigin = Symbol('origin');
const kSession = Symbol('session');
const kOptions = Symbol('options');
const kFlushedHeaders = Symbol('flushedHeaders');
const kJobs = Symbol('jobs');
const isValidHttpToken = /^[\^`\-\w!#$%&*+.|~]+$/;
const isInvalidHeaderValue = /[^\t\u0020-\u007E\u0080-\u00FF]/;
class ClientRequest$1 extends Writable {
constructor(input, options, callback) {
super({
autoDestroy: false
});
const hasInput = typeof input === 'string' || input instanceof URL;
if (hasInput) {
input = urlToOptions$2(input instanceof URL ? input : new URL(input));
}
if (typeof options === 'function' || options === undefined) {
// (options, callback)
callback = options;
options = hasInput ? input : {...input};
} else {
// (input, options, callback)
options = {...input, ...options};
}
if (options.h2session) {
this[kSession] = options.h2session;
} else if (options.agent === false) {
this.agent = new Agent({maxFreeSessions: 0});
} else if (typeof options.agent === 'undefined' || options.agent === null) {
if (typeof options.createConnection === 'function') {
// This is a workaround - we don't have to create the session on our own.
this.agent = new Agent({maxFreeSessions: 0});
this.agent.createConnection = options.createConnection;
} else {
this.agent = globalAgent;
}
} else if (typeof options.agent.request === 'function') {
this.agent = options.agent;
} else {
throw new ERR_INVALID_ARG_TYPE('options.agent', ['Agent-like Object', 'undefined', 'false'], options.agent);
}
if (options.protocol && options.protocol !== 'https:') {
throw new ERR_INVALID_PROTOCOL(options.protocol, 'https:');
}
const port = options.port || options.defaultPort || (this.agent && this.agent.defaultPort) || 443;
const host = options.hostname || options.host || 'localhost';
// Don't enforce the origin via options. It may be changed in an Agent.
delete options.hostname;
delete options.host;
delete options.port;
const {timeout} = options;
options.timeout = undefined;
this[kHeaders] = Object.create(null);
this[kJobs] = [];
this.socket = null;
this.connection = null;
this.method = options.method || 'GET';
this.path = options.path;
this.res = null;
this.aborted = false;
this.reusedSocket = false;
if (options.headers) {
for (const [header, value] of Object.entries(options.headers)) {
this.setHeader(header, value);
}
}
if (options.auth && !('authorization' in this[kHeaders])) {
this[kHeaders].authorization = 'Basic ' + Buffer.from(options.auth).toString('base64');
}
options.session = options.tlsSession;
options.path = options.socketPath;
this[kOptions] = options;
// Clients that generate HTTP/2 requests directly SHOULD use the :authority pseudo-header field instead of the Host header field.
if (port === 443) {
this[kOrigin] = `https://${host}`;
if (!(':authority' in this[kHeaders])) {
this[kHeaders][':authority'] = host;
}
} else {
this[kOrigin] = `https://${host}:${port}`;
if (!(':authority' in this[kHeaders])) {
this[kHeaders][':authority'] = `${host}:${port}`;
}
}
if (timeout) {
this.setTimeout(timeout);
}
if (callback) {
this.once('response', callback);
}
this[kFlushedHeaders] = false;
}
get method() {
return this[kHeaders][HTTP2_HEADER_METHOD];
}
set method(value) {
if (value) {
this[kHeaders][HTTP2_HEADER_METHOD] = value.toUpperCase();
}
}
get path() {
return this[kHeaders][HTTP2_HEADER_PATH];
}
set path(value) {
if (value) {
this[kHeaders][HTTP2_HEADER_PATH] = value;
}
}
get _mustNotHaveABody() {
return this.method === 'GET' || this.method === 'HEAD' || this.method === 'DELETE';
}
_write(chunk, encoding, callback) {
// https://github.com/nodejs/node/blob/654df09ae0c5e17d1b52a900a545f0664d8c7627/lib/internal/http2/util.js#L148-L156
if (this._mustNotHaveABody) {
callback(new Error('The GET, HEAD and DELETE methods must NOT have a body'));
/* istanbul ignore next: Node.js 12 throws directly */
return;
}
this.flushHeaders();
const callWrite = () => this._request.write(chunk, encoding, callback);
if (this._request) {
callWrite();
} else {
this[kJobs].push(callWrite);
}
}
_final(callback) {
if (this.destroyed) {
return;
}
this.flushHeaders();
const callEnd = () => {
// For GET, HEAD and DELETE
if (this._mustNotHaveABody) {
callback();
return;
}
this._request.end(callback);
};
if (this._request) {
callEnd();
} else {
this[kJobs].push(callEnd);
}
}
abort() {
if (this.res && this.res.complete) {
return;
}
if (!this.aborted) {
process.nextTick(() => this.emit('abort'));
}
this.aborted = true;
this.destroy();
}
_destroy(error, callback) {
if (this.res) {
this.res._dump();
}
if (this._request) {
this._request.destroy();
}
callback(error);
}
async flushHeaders() {
if (this[kFlushedHeaders] || this.destroyed) {
return;
}
this[kFlushedHeaders] = true;
const isConnectMethod = this.method === HTTP2_METHOD_CONNECT;
// The real magic is here
const onStream = stream => {
this._request = stream;
if (this.destroyed) {
stream.destroy();
return;
}
// Forwards `timeout`, `continue`, `close` and `error` events to this instance.
if (!isConnectMethod) {
proxyEvents$1(stream, this, ['timeout', 'continue', 'close', 'error']);
}
// Wait for the `finish` event. We don't want to emit the `response` event
// before `request.end()` is called.
const waitForEnd = fn => {
return (...args) => {
if (!this.writable && !this.destroyed) {
fn(...args);
} else {
this.once('finish', () => {
fn(...args);
});
}
};
};
// This event tells we are ready to listen for the data.
stream.once('response', waitForEnd((headers, flags, rawHeaders) => {
// If we were to emit raw request stream, it would be as fast as the native approach.
// Note that wrapping the raw stream in a Proxy instance won't improve the performance (already tested it).
const response = new IncomingMessage$1(this.socket, stream.readableHighWaterMark);
this.res = response;
response.req = this;
response.statusCode = headers[HTTP2_HEADER_STATUS];
response.headers = headers;
response.rawHeaders = rawHeaders;
response.once('end', () => {
if (this.aborted) {
response.aborted = true;
response.emit('aborted');
} else {
response.complete = true;
// Has no effect, just be consistent with the Node.js behavior
response.socket = null;
response.connection = null;
}
});
if (isConnectMethod) {
response.upgrade = true;
// The HTTP1 API says the socket is detached here,
// but we can't do that so we pass the original HTTP2 request.
if (this.emit('connect', response, stream, Buffer.alloc(0))) {
this.emit('close');
} else {
// No listeners attached, destroy the original request.
stream.destroy();
}
} else {
// Forwards data
stream.on('data', chunk => {
if (!response._dumped && !response.push(chunk)) {
stream.pause();
}
});
stream.once('end', () => {
response.push(null);
});
if (!this.emit('response', response)) {
// No listeners attached, dump the response.
response._dump();
}
}
}));
// Emits `information` event
stream.once('headers', waitForEnd(
headers => this.emit('information', {statusCode: headers[HTTP2_HEADER_STATUS]})
));
stream.once('trailers', waitForEnd((trailers, flags, rawTrailers) => {
const {res} = this;
// Assigns trailers to the response object.
res.trailers = trailers;
res.rawTrailers = rawTrailers;
}));
const {socket} = stream.session;
this.socket = socket;
this.connection = socket;
for (const job of this[kJobs]) {
job();
}
this.emit('socket', this.socket);
};
// Makes a HTTP2 request
if (this[kSession]) {
try {
onStream(this[kSession].request(this[kHeaders]));
} catch (error) {
this.emit('error', error);
}
} else {
this.reusedSocket = true;
try {
onStream(await this.agent.request(this[kOrigin], this[kOptions], this[kHeaders]));
} catch (error) {
this.emit('error', error);
}
}
}
getHeader(name) {
if (typeof name !== 'string') {
throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
}
return this[kHeaders][name.toLowerCase()];
}
get headersSent() {
return this[kFlushedHeaders];
}
removeHeader(name) {
if (typeof name !== 'string') {
throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
}
if (this.headersSent) {
throw new ERR_HTTP_HEADERS_SENT('remove');
}
delete this[kHeaders][name.toLowerCase()];
}
setHeader(name, value) {
if (this.headersSent) {
throw new ERR_HTTP_HEADERS_SENT('set');
}
if (typeof name !== 'string' || (!isValidHttpToken.test(name) && !isRequestPseudoHeader(name))) {
throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
}
if (typeof value === 'undefined') {
throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
}
if (isInvalidHeaderValue.test(value)) {
throw new ERR_INVALID_CHAR('header content', name);
}
this[kHeaders][name.toLowerCase()] = value;
}
setNoDelay() {
// HTTP2 sockets cannot be malformed, do nothing.
}
setSocketKeepAlive() {
// HTTP2 sockets cannot be malformed, do nothing.
}
setTimeout(ms, callback) {
const applyTimeout = () => this._request.setTimeout(ms, callback);
if (this._request) {
applyTimeout();
} else {
this[kJobs].push(applyTimeout);
}
return this;
}
get maxHeadersCount() {
if (!this.destroyed && this._request) {
return this._request.session.localSettings.maxHeaderListSize;
}
return undefined;
}
set maxHeadersCount(_value) {
// Updating HTTP2 settings would affect all requests, do nothing.
}
}
var clientRequest = ClientRequest$1;
var auto$1 = {exports: {}};
const tls = require$$1__default$2["default"];
var resolveAlpn = (options = {}, connect = tls.connect) => new Promise((resolve, reject) => {
let timeout = false;
let socket;
const callback = async () => {
await socketPromise;
socket.off('timeout', onTimeout);
socket.off('error', reject);
if (options.resolveSocket) {
resolve({alpnProtocol: socket.alpnProtocol, socket, timeout});
if (timeout) {
await Promise.resolve();
socket.emit('timeout');
}
} else {
socket.destroy();
resolve({alpnProtocol: socket.alpnProtocol, timeout});
}
};
const onTimeout = async () => {
timeout = true;
callback();
};
const socketPromise = (async () => {
try {
socket = await connect(options, callback);
socket.on('error', reject);
socket.once('timeout', onTimeout);
} catch (error) {
reject(error);
}
})();
});
const net$1 = require$$0__default$6["default"];
/* istanbul ignore file: https://github.com/nodejs/node/blob/v13.0.1/lib/_http_agent.js */
var calculateServerName$1 = options => {
let servername = options.host;
const hostHeader = options.headers && options.headers.host;
if (hostHeader) {
if (hostHeader.startsWith('[')) {
const index = hostHeader.indexOf(']');
if (index === -1) {
servername = hostHeader;
} else {
servername = hostHeader.slice(1, -1);
}
} else {
servername = hostHeader.split(':', 1)[0];
}
}
if (net$1.isIP(servername)) {
return '';
}
return servername;
};
const http = require$$4__default["default"];
const https = require$$1__default$3["default"];
const resolveALPN = resolveAlpn;
const QuickLRU = quickLru;
const Http2ClientRequest = clientRequest;
const calculateServerName = calculateServerName$1;
const urlToOptions$1 = urlToOptions$3;
const cache = new QuickLRU({maxSize: 100});
const queue = new Map();
const installSocket = (agent, socket, options) => {
socket._httpMessage = {shouldKeepAlive: true};
const onFree = () => {
agent.emit('free', socket, options);
};
socket.on('free', onFree);
const onClose = () => {
agent.removeSocket(socket, options);
};
socket.on('close', onClose);
const onRemove = () => {
agent.removeSocket(socket, options);
socket.off('close', onClose);
socket.off('free', onFree);
socket.off('agentRemove', onRemove);
};
socket.on('agentRemove', onRemove);
agent.emit('free', socket, options);
};
const resolveProtocol = async options => {
const name = `${options.host}:${options.port}:${options.ALPNProtocols.sort()}`;
if (!cache.has(name)) {
if (queue.has(name)) {
const result = await queue.get(name);
return result.alpnProtocol;
}
const {path, agent} = options;
options.path = options.socketPath;
const resultPromise = resolveALPN(options);
queue.set(name, resultPromise);
try {
const {socket, alpnProtocol} = await resultPromise;
cache.set(name, alpnProtocol);
options.path = path;
if (alpnProtocol === 'h2') {
// https://github.com/nodejs/node/issues/33343
socket.destroy();
} else {
const {globalAgent} = https;
const defaultCreateConnection = https.Agent.prototype.createConnection;
if (agent) {
if (agent.createConnection === defaultCreateConnection) {
installSocket(agent, socket, options);
} else {
socket.destroy();
}
} else if (globalAgent.createConnection === defaultCreateConnection) {
installSocket(globalAgent, socket, options);
} else {
socket.destroy();
}
}
queue.delete(name);
return alpnProtocol;
} catch (error) {
queue.delete(name);
throw error;
}
}
return cache.get(name);
};
auto$1.exports = async (input, options, callback) => {
if (typeof input === 'string' || input instanceof URL) {
input = urlToOptions$1(new URL(input));
}
if (typeof options === 'function') {
callback = options;
options = undefined;
}
options = {
ALPNProtocols: ['h2', 'http/1.1'],
...input,
...options,
resolveSocket: true
};
if (!Array.isArray(options.ALPNProtocols) || options.ALPNProtocols.length === 0) {
throw new Error('The `ALPNProtocols` option must be an Array with at least one entry');
}
options.protocol = options.protocol || 'https:';
const isHttps = options.protocol === 'https:';
options.host = options.hostname || options.host || 'localhost';
options.session = options.tlsSession;
options.servername = options.servername || calculateServerName(options);
options.port = options.port || (isHttps ? 443 : 80);
options._defaultAgent = isHttps ? https.globalAgent : http.globalAgent;
const agents = options.agent;
if (agents) {
if (agents.addRequest) {
throw new Error('The `options.agent` object can contain only `http`, `https` or `http2` properties');
}
options.agent = agents[isHttps ? 'https' : 'http'];
}
if (isHttps) {
const protocol = await resolveProtocol(options);
if (protocol === 'h2') {
if (agents) {
options.agent = agents.http2;
}
return new Http2ClientRequest(options, callback);
}
}
return http.request(options, callback);
};
auto$1.exports.protocolCache = cache;
const http2 = require$$0__default$5["default"];
const agent = agent$1;
const ClientRequest = clientRequest;
const IncomingMessage = incomingMessage;
const auto = auto$1.exports;
const request = (url, options, callback) => {
return new ClientRequest(url, options, callback);
};
const get = (url, options, callback) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
const req = new ClientRequest(url, options, callback);
req.end();
return req;
};
var source = {
...http2,
ClientRequest,
IncomingMessage,
...agent,
request,
get,
auto
};
var getBodySize = {};
var isFormData = {};
Object.defineProperty(isFormData, "__esModule", { value: true });
const is_1$4 = dist$1.exports;
isFormData.default = (body) => is_1$4.default.nodeStream(body) && is_1$4.default.function_(body.getBoundary);
Object.defineProperty(getBodySize, "__esModule", { value: true });
const fs_1 = require$$2__default$1["default"];
const util_1 = require$$1__default["default"];
const is_1$3 = dist$1.exports;
const is_form_data_1 = isFormData;
const statAsync = util_1.promisify(fs_1.stat);
getBodySize.default = async (body, headers) => {
if (headers && 'content-length' in headers) {
return Number(headers['content-length']);
}
if (!body) {
return 0;
}
if (is_1$3.default.string(body)) {
return Buffer.byteLength(body);
}
if (is_1$3.default.buffer(body)) {
return body.length;
}
if (is_form_data_1.default(body)) {
return util_1.promisify(body.getLength.bind(body))();
}
if (body instanceof fs_1.ReadStream) {
const { size } = await statAsync(body.path);
if (size === 0) {
return undefined;
}
return size;
}
return undefined;
};
var proxyEvents = {};
Object.defineProperty(proxyEvents, "__esModule", { value: true });
function default_1$1(from, to, events) {
const fns = {};
for (const event of events) {
fns[event] = (...args) => {
to.emit(event, ...args);
};
from.on(event, fns[event]);
}
return () => {
for (const event of events) {
from.off(event, fns[event]);
}
};
}
proxyEvents.default = default_1$1;
var timedOut = {};
var unhandle = {};
Object.defineProperty(unhandle, "__esModule", { value: true });
// When attaching listeners, it's very easy to forget about them.
// Especially if you do error handling and set timeouts.
// So instead of checking if it's proper to throw an error on every timeout ever,
// use this simple tool which will remove all listeners you have attached.
unhandle.default = () => {
const handlers = [];
return {
once(origin, event, fn) {
origin.once(event, fn);
handlers.push({ origin, event, fn });
},
unhandleAll() {
for (const handler of handlers) {
const { origin, event, fn } = handler;
origin.removeListener(event, fn);
}
handlers.length = 0;
}
};
};
Object.defineProperty(timedOut, "__esModule", { value: true });
timedOut.TimeoutError = void 0;
const net = require$$0__default$6["default"];
const unhandle_1 = unhandle;
const reentry = Symbol('reentry');
const noop = () => { };
class TimeoutError extends Error {
constructor(threshold, event) {
super(`Timeout awaiting '${event}' for ${threshold}ms`);
this.event = event;
this.name = 'TimeoutError';
this.code = 'ETIMEDOUT';
}
}
timedOut.TimeoutError = TimeoutError;
timedOut.default = (request, delays, options) => {
if (reentry in request) {
return noop;
}
request[reentry] = true;
const cancelers = [];
const { once, unhandleAll } = unhandle_1.default();
const addTimeout = (delay, callback, event) => {
var _a;
const timeout = setTimeout(callback, delay, delay, event);
(_a = timeout.unref) === null || _a === void 0 ? void 0 : _a.call(timeout);
const cancel = () => {
clearTimeout(timeout);
};
cancelers.push(cancel);
return cancel;
};
const { host, hostname } = options;
const timeoutHandler = (delay, event) => {
request.destroy(new TimeoutError(delay, event));
};
const cancelTimeouts = () => {
for (const cancel of cancelers) {
cancel();
}
unhandleAll();
};
request.once('error', error => {
cancelTimeouts();
// Save original behavior
/* istanbul ignore next */
if (request.listenerCount('error') === 0) {
throw error;
}
});
request.once('close', cancelTimeouts);
once(request, 'response', (response) => {
once(response, 'end', cancelTimeouts);
});
if (typeof delays.request !== 'undefined') {
addTimeout(delays.request, timeoutHandler, 'request');
}
if (typeof delays.socket !== 'undefined') {
const socketTimeoutHandler = () => {
timeoutHandler(delays.socket, 'socket');
};
request.setTimeout(delays.socket, socketTimeoutHandler);
// `request.setTimeout(0)` causes a memory leak.
// We can just remove the listener and forget about the timer - it's unreffed.
// See https://github.com/sindresorhus/got/issues/690
cancelers.push(() => {
request.removeListener('timeout', socketTimeoutHandler);
});
}
once(request, 'socket', (socket) => {
var _a;
const { socketPath } = request;
/* istanbul ignore next: hard to test */
if (socket.connecting) {
const hasPath = Boolean(socketPath !== null && socketPath !== void 0 ? socketPath : net.isIP((_a = hostname !== null && hostname !== void 0 ? hostname : host) !== null && _a !== void 0 ? _a : '') !== 0);
if (typeof delays.lookup !== 'undefined' && !hasPath && typeof socket.address().address === 'undefined') {
const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
once(socket, 'lookup', cancelTimeout);
}
if (typeof delays.connect !== 'undefined') {
const timeConnect = () => addTimeout(delays.connect, timeoutHandler, 'connect');
if (hasPath) {
once(socket, 'connect', timeConnect());
}
else {
once(socket, 'lookup', (error) => {
if (error === null) {
once(socket, 'connect', timeConnect());
}
});
}
}
if (typeof delays.secureConnect !== 'undefined' && options.protocol === 'https:') {
once(socket, 'connect', () => {
const cancelTimeout = addTimeout(delays.secureConnect, timeoutHandler, 'secureConnect');
once(socket, 'secureConnect', cancelTimeout);
});
}
}
if (typeof delays.send !== 'undefined') {
const timeRequest = () => addTimeout(delays.send, timeoutHandler, 'send');
/* istanbul ignore next: hard to test */
if (socket.connecting) {
once(socket, 'connect', () => {
once(request, 'upload-complete', timeRequest());
});
}
else {
once(request, 'upload-complete', timeRequest());
}
}
});
if (typeof delays.response !== 'undefined') {
once(request, 'upload-complete', () => {
const cancelTimeout = addTimeout(delays.response, timeoutHandler, 'response');
once(request, 'response', cancelTimeout);
});
}
return cancelTimeouts;
};
var urlToOptions = {};
Object.defineProperty(urlToOptions, "__esModule", { value: true });
const is_1$2 = dist$1.exports;
urlToOptions.default = (url) => {
// Cast to URL
url = url;
const options = {
protocol: url.protocol,
hostname: is_1$2.default.string(url.hostname) && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
host: url.host,
hash: url.hash,
search: url.search,
pathname: url.pathname,
href: url.href,
path: `${url.pathname || ''}${url.search || ''}`
};
if (is_1$2.default.string(url.port) && url.port.length > 0) {
options.port = Number(url.port);
}
if (url.username || url.password) {
options.auth = `${url.username || ''}:${url.password || ''}`;
}
return options;
};
var optionsToUrl = {};
Object.defineProperty(optionsToUrl, "__esModule", { value: true });
/* istanbul ignore file: deprecated */
const url_1 = require$$0__default$4["default"];
const keys = [
'protocol',
'host',
'hostname',
'port',
'pathname',
'search'
];
optionsToUrl.default = (origin, options) => {
var _a, _b;
if (options.path) {
if (options.pathname) {
throw new TypeError('Parameters `path` and `pathname` are mutually exclusive.');
}
if (options.search) {
throw new TypeError('Parameters `path` and `search` are mutually exclusive.');
}
if (options.searchParams) {
throw new TypeError('Parameters `path` and `searchParams` are mutually exclusive.');
}
}
if (options.search && options.searchParams) {
throw new TypeError('Parameters `search` and `searchParams` are mutually exclusive.');
}
if (!origin) {
if (!options.protocol) {
throw new TypeError('No URL protocol specified');
}
origin = `${options.protocol}//${(_b = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host) !== null && _b !== void 0 ? _b : ''}`;
}
const url = new url_1.URL(origin);
if (options.path) {
const searchIndex = options.path.indexOf('?');
if (searchIndex === -1) {
options.pathname = options.path;
}
else {
options.pathname = options.path.slice(0, searchIndex);
options.search = options.path.slice(searchIndex + 1);
}
delete options.path;
}
for (const key of keys) {
if (options[key]) {
url[key] = options[key].toString();
}
}
return url;
};
var weakableMap = {};
Object.defineProperty(weakableMap, "__esModule", { value: true });
class WeakableMap {
constructor() {
this.weakMap = new WeakMap();
this.map = new Map();
}
set(key, value) {
if (typeof key === 'object') {
this.weakMap.set(key, value);
}
else {
this.map.set(key, value);
}
}
get(key) {
if (typeof key === 'object') {
return this.weakMap.get(key);
}
return this.map.get(key);
}
has(key) {
if (typeof key === 'object') {
return this.weakMap.has(key);
}
return this.map.has(key);
}
}
weakableMap.default = WeakableMap;
var getBuffer$1 = {};
Object.defineProperty(getBuffer$1, "__esModule", { value: true });
// TODO: Update https://github.com/sindresorhus/get-stream
const getBuffer = async (stream) => {
const chunks = [];
let length = 0;
for await (const chunk of stream) {
chunks.push(chunk);
length += Buffer.byteLength(chunk);
}
if (Buffer.isBuffer(chunks[0])) {
return Buffer.concat(chunks, length);
}
return Buffer.from(chunks.join(''));
};
getBuffer$1.default = getBuffer;
var dnsIpVersion = {};
(function (exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.dnsLookupIpVersionToFamily = exports.isDnsLookupIpVersion = void 0;
const conversionTable = {
auto: 0,
ipv4: 4,
ipv6: 6
};
exports.isDnsLookupIpVersion = (value) => {
return value in conversionTable;
};
exports.dnsLookupIpVersionToFamily = (dnsLookupIpVersion) => {
if (exports.isDnsLookupIpVersion(dnsLookupIpVersion)) {
return conversionTable[dnsLookupIpVersion];
}
throw new Error('Invalid DNS lookup IP version');
};
}(dnsIpVersion));
var isResponseOk = {};
Object.defineProperty(isResponseOk, "__esModule", { value: true });
isResponseOk.isResponseOk = void 0;
isResponseOk.isResponseOk = (response) => {
const { statusCode } = response;
const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
return (statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304;
};
var deprecationWarning = {};
Object.defineProperty(deprecationWarning, "__esModule", { value: true });
const alreadyWarned = new Set();
deprecationWarning.default = (message) => {
if (alreadyWarned.has(message)) {
return;
}
alreadyWarned.add(message);
// @ts-expect-error Missing types.
process.emitWarning(`Got: ${message}`, {
type: 'DeprecationWarning'
});
};
var normalizeArguments$1 = {};
Object.defineProperty(normalizeArguments$1, "__esModule", { value: true });
const is_1$1 = dist$1.exports;
const normalizeArguments = (options, defaults) => {
if (is_1$1.default.null_(options.encoding)) {
throw new TypeError('To get a Buffer, set `options.responseType` to `buffer` instead');
}
is_1$1.assert.any([is_1$1.default.string, is_1$1.default.undefined], options.encoding);
is_1$1.assert.any([is_1$1.default.boolean, is_1$1.default.undefined], options.resolveBodyOnly);
is_1$1.assert.any([is_1$1.default.boolean, is_1$1.default.undefined], options.methodRewriting);
is_1$1.assert.any([is_1$1.default.boolean, is_1$1.default.undefined], options.isStream);
is_1$1.assert.any([is_1$1.default.string, is_1$1.default.undefined], options.responseType);
// `options.responseType`
if (options.responseType === undefined) {
options.responseType = 'text';
}
// `options.retry`
const { retry } = options;
if (defaults) {
options.retry = { ...defaults.retry };
}
else {
options.retry = {
calculateDelay: retryObject => retryObject.computedValue,
limit: 0,
methods: [],
statusCodes: [],
errorCodes: [],
maxRetryAfter: undefined
};
}
if (is_1$1.default.object(retry)) {
options.retry = {
...options.retry,
...retry
};
options.retry.methods = [...new Set(options.retry.methods.map(method => method.toUpperCase()))];
options.retry.statusCodes = [...new Set(options.retry.statusCodes)];
options.retry.errorCodes = [...new Set(options.retry.errorCodes)];
}
else if (is_1$1.default.number(retry)) {
options.retry.limit = retry;
}
if (is_1$1.default.undefined(options.retry.maxRetryAfter)) {
options.retry.maxRetryAfter = Math.min(
// TypeScript is not smart enough to handle `.filter(x => is.number(x))`.
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
...[options.timeout.request, options.timeout.connect].filter(is_1$1.default.number));
}
// `options.pagination`
if (is_1$1.default.object(options.pagination)) {
if (defaults) {
options.pagination = {
...defaults.pagination,
...options.pagination
};
}
const { pagination } = options;
if (!is_1$1.default.function_(pagination.transform)) {
throw new Error('`options.pagination.transform` must be implemented');
}
if (!is_1$1.default.function_(pagination.shouldContinue)) {
throw new Error('`options.pagination.shouldContinue` must be implemented');
}
if (!is_1$1.default.function_(pagination.filter)) {
throw new TypeError('`options.pagination.filter` must be implemented');
}
if (!is_1$1.default.function_(pagination.paginate)) {
throw new Error('`options.pagination.paginate` must be implemented');
}
}
// JSON mode
if (options.responseType === 'json' && options.headers.accept === undefined) {
options.headers.accept = 'application/json';
}
return options;
};
normalizeArguments$1.default = normalizeArguments;
var calculateRetryDelay$1 = {};
Object.defineProperty(calculateRetryDelay$1, "__esModule", { value: true });
calculateRetryDelay$1.retryAfterStatusCodes = void 0;
calculateRetryDelay$1.retryAfterStatusCodes = new Set([413, 429, 503]);
const calculateRetryDelay = ({ attemptCount, retryOptions, error, retryAfter }) => {
if (attemptCount > retryOptions.limit) {
return 0;
}
const hasMethod = retryOptions.methods.includes(error.options.method);
const hasErrorCode = retryOptions.errorCodes.includes(error.code);
const hasStatusCode = error.response && retryOptions.statusCodes.includes(error.response.statusCode);
if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
return 0;
}
if (error.response) {
if (retryAfter) {
if (retryOptions.maxRetryAfter === undefined || retryAfter > retryOptions.maxRetryAfter) {
return 0;
}
return retryAfter;
}
if (error.response.statusCode === 413) {
return 0;
}
}
const noise = Math.random() * 100;
return ((2 ** (attemptCount - 1)) * 1000) + noise;
};
calculateRetryDelay$1.default = calculateRetryDelay;
(function (exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnsupportedProtocolError = exports.ReadError = exports.TimeoutError = exports.UploadError = exports.CacheError = exports.HTTPError = exports.MaxRedirectsError = exports.RequestError = exports.setNonEnumerableProperties = exports.knownHookEvents = exports.withoutBody = exports.kIsNormalizedAlready = void 0;
const util_1 = require$$1__default["default"];
const stream_1 = require$$0__default$1["default"];
const fs_1 = require$$2__default$1["default"];
const url_1 = require$$0__default$4["default"];
const http = require$$4__default["default"];
const http_1 = require$$4__default["default"];
const https = require$$1__default$3["default"];
const http_timer_1 = source$3.exports;
const cacheable_lookup_1 = source$1.exports;
const CacheableRequest = src;
const decompressResponse$1 = decompressResponse;
// @ts-expect-error Missing types
const http2wrapper = source;
const lowercaseKeys = lowercaseKeys$2;
const is_1 = dist$1.exports;
const get_body_size_1 = getBodySize;
const is_form_data_1 = isFormData;
const proxy_events_1 = proxyEvents;
const timed_out_1 = timedOut;
const url_to_options_1 = urlToOptions;
const options_to_url_1 = optionsToUrl;
const weakable_map_1 = weakableMap;
const get_buffer_1 = getBuffer$1;
const dns_ip_version_1 = dnsIpVersion;
const is_response_ok_1 = isResponseOk;
const deprecation_warning_1 = deprecationWarning;
const normalize_arguments_1 = normalizeArguments$1;
const calculate_retry_delay_1 = calculateRetryDelay$1;
let globalDnsCache;
const kRequest = Symbol('request');
const kResponse = Symbol('response');
const kResponseSize = Symbol('responseSize');
const kDownloadedSize = Symbol('downloadedSize');
const kBodySize = Symbol('bodySize');
const kUploadedSize = Symbol('uploadedSize');
const kServerResponsesPiped = Symbol('serverResponsesPiped');
const kUnproxyEvents = Symbol('unproxyEvents');
const kIsFromCache = Symbol('isFromCache');
const kCancelTimeouts = Symbol('cancelTimeouts');
const kStartedReading = Symbol('startedReading');
const kStopReading = Symbol('stopReading');
const kTriggerRead = Symbol('triggerRead');
const kBody = Symbol('body');
const kJobs = Symbol('jobs');
const kOriginalResponse = Symbol('originalResponse');
const kRetryTimeout = Symbol('retryTimeout');
exports.kIsNormalizedAlready = Symbol('isNormalizedAlready');
const supportsBrotli = is_1.default.string(process.versions.brotli);
exports.withoutBody = new Set(['GET', 'HEAD']);
exports.knownHookEvents = [
'init',
'beforeRequest',
'beforeRedirect',
'beforeError',
'beforeRetry',
// Promise-Only
'afterResponse'
];
function validateSearchParameters(searchParameters) {
// eslint-disable-next-line guard-for-in
for (const key in searchParameters) {
const value = searchParameters[key];
if (!is_1.default.string(value) && !is_1.default.number(value) && !is_1.default.boolean(value) && !is_1.default.null_(value) && !is_1.default.undefined(value)) {
throw new TypeError(`The \`searchParams\` value '${String(value)}' must be a string, number, boolean or null`);
}
}
}
function isClientRequest(clientRequest) {
return is_1.default.object(clientRequest) && !('statusCode' in clientRequest);
}
const cacheableStore = new weakable_map_1.default();
const waitForOpenFile = async (file) => new Promise((resolve, reject) => {
const onError = (error) => {
reject(error);
};
// Node.js 12 has incomplete types
if (!file.pending) {
resolve();
}
file.once('error', onError);
file.once('ready', () => {
file.off('error', onError);
resolve();
});
});
const redirectCodes = new Set([300, 301, 302, 303, 304, 307, 308]);
const nonEnumerableProperties = [
'context',
'body',
'json',
'form'
];
exports.setNonEnumerableProperties = (sources, to) => {
// Non enumerable properties shall not be merged
const properties = {};
for (const source of sources) {
if (!source) {
continue;
}
for (const name of nonEnumerableProperties) {
if (!(name in source)) {
continue;
}
properties[name] = {
writable: true,
configurable: true,
enumerable: false,
// @ts-expect-error TS doesn't see the check above
value: source[name]
};
}
}
Object.defineProperties(to, properties);
};
/**
An error to be thrown when a request fails.
Contains a `code` property with error class code, like `ECONNREFUSED`.
*/
class RequestError extends Error {
constructor(message, error, self) {
var _a, _b;
super(message);
Error.captureStackTrace(this, this.constructor);
this.name = 'RequestError';
this.code = (_a = error.code) !== null && _a !== void 0 ? _a : 'ERR_GOT_REQUEST_ERROR';
if (self instanceof Request) {
Object.defineProperty(this, 'request', {
enumerable: false,
value: self
});
Object.defineProperty(this, 'response', {
enumerable: false,
value: self[kResponse]
});
Object.defineProperty(this, 'options', {
// This fails because of TS 3.7.2 useDefineForClassFields
// Ref: https://github.com/microsoft/TypeScript/issues/34972
enumerable: false,
value: self.options
});
}
else {
Object.defineProperty(this, 'options', {
// This fails because of TS 3.7.2 useDefineForClassFields
// Ref: https://github.com/microsoft/TypeScript/issues/34972
enumerable: false,
value: self
});
}
this.timings = (_b = this.request) === null || _b === void 0 ? void 0 : _b.timings;
// Recover the original stacktrace
if (is_1.default.string(error.stack) && is_1.default.string(this.stack)) {
const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
// Remove duplicated traces
while (errorStackTrace.length !== 0 && errorStackTrace[0] === thisStackTrace[0]) {
thisStackTrace.shift();
}
this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.reverse().join('\n')}${errorStackTrace.reverse().join('\n')}`;
}
}
}
exports.RequestError = RequestError;
/**
An error to be thrown when the server redirects you more than ten times.
Includes a `response` property.
*/
class MaxRedirectsError extends RequestError {
constructor(request) {
super(`Redirected ${request.options.maxRedirects} times. Aborting.`, {}, request);
this.name = 'MaxRedirectsError';
this.code = 'ERR_TOO_MANY_REDIRECTS';
}
}
exports.MaxRedirectsError = MaxRedirectsError;
/**
An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
Includes a `response` property.
*/
class HTTPError extends RequestError {
constructor(response) {
super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, response.request);
this.name = 'HTTPError';
this.code = 'ERR_NON_2XX_3XX_RESPONSE';
}
}
exports.HTTPError = HTTPError;
/**
An error to be thrown when a cache method fails.
For example, if the database goes down or there's a filesystem error.
*/
class CacheError extends RequestError {
constructor(error, request) {
super(error.message, error, request);
this.name = 'CacheError';
this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_CACHE_ACCESS' : this.code;
}
}
exports.CacheError = CacheError;
/**
An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
*/
class UploadError extends RequestError {
constructor(error, request) {
super(error.message, error, request);
this.name = 'UploadError';
this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_UPLOAD' : this.code;
}
}
exports.UploadError = UploadError;
/**
An error to be thrown when the request is aborted due to a timeout.
Includes an `event` and `timings` property.
*/
class TimeoutError extends RequestError {
constructor(error, timings, request) {
super(error.message, error, request);
this.name = 'TimeoutError';
this.event = error.event;
this.timings = timings;
}
}
exports.TimeoutError = TimeoutError;
/**
An error to be thrown when reading from response stream fails.
*/
class ReadError extends RequestError {
constructor(error, request) {
super(error.message, error, request);
this.name = 'ReadError';
this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_READING_RESPONSE_STREAM' : this.code;
}
}
exports.ReadError = ReadError;
/**
An error to be thrown when given an unsupported protocol.
*/
class UnsupportedProtocolError extends RequestError {
constructor(options) {
super(`Unsupported protocol "${options.url.protocol}"`, {}, options);
this.name = 'UnsupportedProtocolError';
this.code = 'ERR_UNSUPPORTED_PROTOCOL';
}
}
exports.UnsupportedProtocolError = UnsupportedProtocolError;
const proxiedRequestEvents = [
'socket',
'connect',
'continue',
'information',
'upgrade',
'timeout'
];
class Request extends stream_1.Duplex {
constructor(url, options = {}, defaults) {
super({
// This must be false, to enable throwing after destroy
// It is used for retry logic in Promise API
autoDestroy: false,
// It needs to be zero because we're just proxying the data to another stream
highWaterMark: 0
});
this[kDownloadedSize] = 0;
this[kUploadedSize] = 0;
this.requestInitialized = false;
this[kServerResponsesPiped] = new Set();
this.redirects = [];
this[kStopReading] = false;
this[kTriggerRead] = false;
this[kJobs] = [];
this.retryCount = 0;
// TODO: Remove this when targeting Node.js >= 12
this._progressCallbacks = [];
const unlockWrite = () => this._unlockWrite();
const lockWrite = () => this._lockWrite();
this.on('pipe', (source) => {
source.prependListener('data', unlockWrite);
source.on('data', lockWrite);
source.prependListener('end', unlockWrite);
source.on('end', lockWrite);
});
this.on('unpipe', (source) => {
source.off('data', unlockWrite);
source.off('data', lockWrite);
source.off('end', unlockWrite);
source.off('end', lockWrite);
});
this.on('pipe', source => {
if (source instanceof http_1.IncomingMessage) {
this.options.headers = {
...source.headers,
...this.options.headers
};
}
});
const { json, body, form } = options;
if (json || body || form) {
this._lockWrite();
}
if (exports.kIsNormalizedAlready in options) {
this.options = options;
}
else {
try {
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
this.options = this.constructor.normalizeArguments(url, options, defaults);
}
catch (error) {
// TODO: Move this to `_destroy()`
if (is_1.default.nodeStream(options.body)) {
options.body.destroy();
}
this.destroy(error);
return;
}
}
(async () => {
var _a;
try {
if (this.options.body instanceof fs_1.ReadStream) {
await waitForOpenFile(this.options.body);
}
const { url: normalizedURL } = this.options;
if (!normalizedURL) {
throw new TypeError('Missing `url` property');
}
this.requestUrl = normalizedURL.toString();
decodeURI(this.requestUrl);
await this._finalizeBody();
await this._makeRequest();
if (this.destroyed) {
(_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroy();
return;
}
// Queued writes etc.
for (const job of this[kJobs]) {
job();
}
// Prevent memory leak
this[kJobs].length = 0;
this.requestInitialized = true;
}
catch (error) {
if (error instanceof RequestError) {
this._beforeError(error);
return;
}
// This is a workaround for https://github.com/nodejs/node/issues/33335
if (!this.destroyed) {
this.destroy(error);
}
}
})();
}
static normalizeArguments(url, options, defaults) {
var _a, _b, _c, _d, _e;
const rawOptions = options;
if (is_1.default.object(url) && !is_1.default.urlInstance(url)) {
options = { ...defaults, ...url, ...options };
}
else {
if (url && options && options.url !== undefined) {
throw new TypeError('The `url` option is mutually exclusive with the `input` argument');
}
options = { ...defaults, ...options };
if (url !== undefined) {
options.url = url;
}
if (is_1.default.urlInstance(options.url)) {
options.url = new url_1.URL(options.url.toString());
}
}
// TODO: Deprecate URL options in Got 12.
// Support extend-specific options
if (options.cache === false) {
options.cache = undefined;
}
if (options.dnsCache === false) {
options.dnsCache = undefined;
}
// Nice type assertions
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.method);
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.headers);
is_1.assert.any([is_1.default.string, is_1.default.urlInstance, is_1.default.undefined], options.prefixUrl);
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cookieJar);
is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.searchParams);
is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.cache);
is_1.assert.any([is_1.default.object, is_1.default.number, is_1.default.undefined], options.timeout);
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.context);
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.hooks);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.decompress);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.ignoreInvalidCookies);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.followRedirect);
is_1.assert.any([is_1.default.number, is_1.default.undefined], options.maxRedirects);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.throwHttpErrors);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.http2);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.allowGetBody);
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.localAddress);
is_1.assert.any([dns_ip_version_1.isDnsLookupIpVersion, is_1.default.undefined], options.dnsLookupIpVersion);
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.https);
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.rejectUnauthorized);
if (options.https) {
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.https.rejectUnauthorized);
is_1.assert.any([is_1.default.function_, is_1.default.undefined], options.https.checkServerIdentity);
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificateAuthority);
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.key);
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificate);
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.https.passphrase);
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.array, is_1.default.undefined], options.https.pfx);
}
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cacheOptions);
// `options.method`
if (is_1.default.string(options.method)) {
options.method = options.method.toUpperCase();
}
else {
options.method = 'GET';
}
// `options.headers`
if (options.headers === (defaults === null || defaults === void 0 ? void 0 : defaults.headers)) {
options.headers = { ...options.headers };
}
else {
options.headers = lowercaseKeys({ ...(defaults === null || defaults === void 0 ? void 0 : defaults.headers), ...options.headers });
}
// Disallow legacy `url.Url`
if ('slashes' in options) {
throw new TypeError('The legacy `url.Url` has been deprecated. Use `URL` instead.');
}
// `options.auth`
if ('auth' in options) {
throw new TypeError('Parameter `auth` is deprecated. Use `username` / `password` instead.');
}
// `options.searchParams`
if ('searchParams' in options) {
if (options.searchParams && options.searchParams !== (defaults === null || defaults === void 0 ? void 0 : defaults.searchParams)) {
let searchParameters;
if (is_1.default.string(options.searchParams) || (options.searchParams instanceof url_1.URLSearchParams)) {
searchParameters = new url_1.URLSearchParams(options.searchParams);
}
else {
validateSearchParameters(options.searchParams);
searchParameters = new url_1.URLSearchParams();
// eslint-disable-next-line guard-for-in
for (const key in options.searchParams) {
const value = options.searchParams[key];
if (value === null) {
searchParameters.append(key, '');
}
else if (value !== undefined) {
searchParameters.append(key, value);
}
}
}
// `normalizeArguments()` is also used to merge options
(_a = defaults === null || defaults === void 0 ? void 0 : defaults.searchParams) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
// Only use default if one isn't already defined
if (!searchParameters.has(key)) {
searchParameters.append(key, value);
}
});
options.searchParams = searchParameters;
}
}
// `options.username` & `options.password`
options.username = (_b = options.username) !== null && _b !== void 0 ? _b : '';
options.password = (_c = options.password) !== null && _c !== void 0 ? _c : '';
// `options.prefixUrl` & `options.url`
if (is_1.default.undefined(options.prefixUrl)) {
options.prefixUrl = (_d = defaults === null || defaults === void 0 ? void 0 : defaults.prefixUrl) !== null && _d !== void 0 ? _d : '';
}
else {
options.prefixUrl = options.prefixUrl.toString();
if (options.prefixUrl !== '' && !options.prefixUrl.endsWith('/')) {
options.prefixUrl += '/';
}
}
if (is_1.default.string(options.url)) {
if (options.url.startsWith('/')) {
throw new Error('`input` must not start with a slash when using `prefixUrl`');
}
options.url = options_to_url_1.default(options.prefixUrl + options.url, options);
}
else if ((is_1.default.undefined(options.url) && options.prefixUrl !== '') || options.protocol) {
options.url = options_to_url_1.default(options.prefixUrl, options);
}
if (options.url) {
if ('port' in options) {
delete options.port;
}
// Make it possible to change `options.prefixUrl`
let { prefixUrl } = options;
Object.defineProperty(options, 'prefixUrl', {
set: (value) => {
const url = options.url;
if (!url.href.startsWith(value)) {
throw new Error(`Cannot change \`prefixUrl\` from ${prefixUrl} to ${value}: ${url.href}`);
}
options.url = new url_1.URL(value + url.href.slice(prefixUrl.length));
prefixUrl = value;
},
get: () => prefixUrl
});
// Support UNIX sockets
let { protocol } = options.url;
if (protocol === 'unix:') {
protocol = 'http:';
options.url = new url_1.URL(`http://unix${options.url.pathname}${options.url.search}`);
}
// Set search params
if (options.searchParams) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
options.url.search = options.searchParams.toString();
}
// Protocol check
if (protocol !== 'http:' && protocol !== 'https:') {
throw new UnsupportedProtocolError(options);
}
// Update `username`
if (options.username === '') {
options.username = options.url.username;
}
else {
options.url.username = options.username;
}
// Update `password`
if (options.password === '') {
options.password = options.url.password;
}
else {
options.url.password = options.password;
}
}
// `options.cookieJar`
const { cookieJar } = options;
if (cookieJar) {
let { setCookie, getCookieString } = cookieJar;
is_1.assert.function_(setCookie);
is_1.assert.function_(getCookieString);
/* istanbul ignore next: Horrible `tough-cookie` v3 check */
if (setCookie.length === 4 && getCookieString.length === 0) {
setCookie = util_1.promisify(setCookie.bind(options.cookieJar));
getCookieString = util_1.promisify(getCookieString.bind(options.cookieJar));
options.cookieJar = {
setCookie,
getCookieString: getCookieString
};
}
}
// `options.cache`
const { cache } = options;
if (cache) {
if (!cacheableStore.has(cache)) {
cacheableStore.set(cache, new CacheableRequest(((requestOptions, handler) => {
const result = requestOptions[kRequest](requestOptions, handler);
// TODO: remove this when `cacheable-request` supports async request functions.
if (is_1.default.promise(result)) {
// @ts-expect-error
// We only need to implement the error handler in order to support HTTP2 caching.
// The result will be a promise anyway.
result.once = (event, handler) => {
if (event === 'error') {
result.catch(handler);
}
else if (event === 'abort') {
// The empty catch is needed here in case when
// it rejects before it's `await`ed in `_makeRequest`.
(async () => {
try {
const request = (await result);
request.once('abort', handler);
}
catch (_a) { }
})();
}
else {
/* istanbul ignore next: safety check */
throw new Error(`Unknown HTTP2 promise event: ${event}`);
}
return result;
};
}
return result;
}), cache));
}
}
// `options.cacheOptions`
options.cacheOptions = { ...options.cacheOptions };
// `options.dnsCache`
if (options.dnsCache === true) {
if (!globalDnsCache) {
globalDnsCache = new cacheable_lookup_1.default();
}
options.dnsCache = globalDnsCache;
}
else if (!is_1.default.undefined(options.dnsCache) && !options.dnsCache.lookup) {
throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is_1.default(options.dnsCache)}`);
}
// `options.timeout`
if (is_1.default.number(options.timeout)) {
options.timeout = { request: options.timeout };
}
else if (defaults && options.timeout !== defaults.timeout) {
options.timeout = {
...defaults.timeout,
...options.timeout
};
}
else {
options.timeout = { ...options.timeout };
}
// `options.context`
if (!options.context) {
options.context = {};
}
// `options.hooks`
const areHooksDefault = options.hooks === (defaults === null || defaults === void 0 ? void 0 : defaults.hooks);
options.hooks = { ...options.hooks };
for (const event of exports.knownHookEvents) {
if (event in options.hooks) {
if (is_1.default.array(options.hooks[event])) {
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
options.hooks[event] = [...options.hooks[event]];
}
else {
throw new TypeError(`Parameter \`${event}\` must be an Array, got ${is_1.default(options.hooks[event])}`);
}
}
else {
options.hooks[event] = [];
}
}
if (defaults && !areHooksDefault) {
for (const event of exports.knownHookEvents) {
const defaultHooks = defaults.hooks[event];
if (defaultHooks.length > 0) {
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
options.hooks[event] = [
...defaults.hooks[event],
...options.hooks[event]
];
}
}
}
// DNS options
if ('family' in options) {
deprecation_warning_1.default('"options.family" was never documented, please use "options.dnsLookupIpVersion"');
}
// HTTPS options
if (defaults === null || defaults === void 0 ? void 0 : defaults.https) {
options.https = { ...defaults.https, ...options.https };
}
if ('rejectUnauthorized' in options) {
deprecation_warning_1.default('"options.rejectUnauthorized" is now deprecated, please use "options.https.rejectUnauthorized"');
}
if ('checkServerIdentity' in options) {
deprecation_warning_1.default('"options.checkServerIdentity" was never documented, please use "options.https.checkServerIdentity"');
}
if ('ca' in options) {
deprecation_warning_1.default('"options.ca" was never documented, please use "options.https.certificateAuthority"');
}
if ('key' in options) {
deprecation_warning_1.default('"options.key" was never documented, please use "options.https.key"');
}
if ('cert' in options) {
deprecation_warning_1.default('"options.cert" was never documented, please use "options.https.certificate"');
}
if ('passphrase' in options) {
deprecation_warning_1.default('"options.passphrase" was never documented, please use "options.https.passphrase"');
}
if ('pfx' in options) {
deprecation_warning_1.default('"options.pfx" was never documented, please use "options.https.pfx"');
}
// Other options
if ('followRedirects' in options) {
throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
}
if (options.agent) {
for (const key in options.agent) {
if (key !== 'http' && key !== 'https' && key !== 'http2') {
throw new TypeError(`Expected the \`options.agent\` properties to be \`http\`, \`https\` or \`http2\`, got \`${key}\``);
}
}
}
options.maxRedirects = (_e = options.maxRedirects) !== null && _e !== void 0 ? _e : 0;
// Set non-enumerable properties
exports.setNonEnumerableProperties([defaults, rawOptions], options);
return normalize_arguments_1.default(options, defaults);
}
_lockWrite() {
const onLockedWrite = () => {
throw new TypeError('The payload has been already provided');
};
this.write = onLockedWrite;
this.end = onLockedWrite;
}
_unlockWrite() {
this.write = super.write;
this.end = super.end;
}
async _finalizeBody() {
const { options } = this;
const { headers } = options;
const isForm = !is_1.default.undefined(options.form);
const isJSON = !is_1.default.undefined(options.json);
const isBody = !is_1.default.undefined(options.body);
const hasPayload = isForm || isJSON || isBody;
const cannotHaveBody = exports.withoutBody.has(options.method) && !(options.method === 'GET' && options.allowGetBody);
this._cannotHaveBody = cannotHaveBody;
if (hasPayload) {
if (cannotHaveBody) {
throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
}
if ([isBody, isForm, isJSON].filter(isTrue => isTrue).length > 1) {
throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');
}
if (isBody &&
!(options.body instanceof stream_1.Readable) &&
!is_1.default.string(options.body) &&
!is_1.default.buffer(options.body) &&
!is_form_data_1.default(options.body)) {
throw new TypeError('The `body` option must be a stream.Readable, string or Buffer');
}
if (isForm && !is_1.default.object(options.form)) {
throw new TypeError('The `form` option must be an Object');
}
{
// Serialize body
const noContentType = !is_1.default.string(headers['content-type']);
if (isBody) {
// Special case for https://github.com/form-data/form-data
if (is_form_data_1.default(options.body) && noContentType) {
headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;
}
this[kBody] = options.body;
}
else if (isForm) {
if (noContentType) {
headers['content-type'] = 'application/x-www-form-urlencoded';
}
this[kBody] = (new url_1.URLSearchParams(options.form)).toString();
}
else {
if (noContentType) {
headers['content-type'] = 'application/json';
}
this[kBody] = options.stringifyJson(options.json);
}
const uploadBodySize = await get_body_size_1.default(this[kBody], options.headers);
// See https://tools.ietf.org/html/rfc7230#section-3.3.2
// A user agent SHOULD send a Content-Length in a request message when
// no Transfer-Encoding is sent and the request method defines a meaning
// for an enclosed payload body. For example, a Content-Length header
// field is normally sent in a POST request even when the value is 0
// (indicating an empty payload body). A user agent SHOULD NOT send a
// Content-Length header field when the request message does not contain
// a payload body and the method semantics do not anticipate such a
// body.
if (is_1.default.undefined(headers['content-length']) && is_1.default.undefined(headers['transfer-encoding'])) {
if (!cannotHaveBody && !is_1.default.undefined(uploadBodySize)) {
headers['content-length'] = String(uploadBodySize);
}
}
}
}
else if (cannotHaveBody) {
this._lockWrite();
}
else {
this._unlockWrite();
}
this[kBodySize] = Number(headers['content-length']) || undefined;
}
async _onResponseBase(response) {
const { options } = this;
const { url } = options;
this[kOriginalResponse] = response;
if (options.decompress) {
response = decompressResponse$1(response);
}
const statusCode = response.statusCode;
const typedResponse = response;
typedResponse.statusMessage = typedResponse.statusMessage ? typedResponse.statusMessage : http.STATUS_CODES[statusCode];
typedResponse.url = options.url.toString();
typedResponse.requestUrl = this.requestUrl;
typedResponse.redirectUrls = this.redirects;
typedResponse.request = this;
typedResponse.isFromCache = response.fromCache || false;
typedResponse.ip = this.ip;
typedResponse.retryCount = this.retryCount;
this[kIsFromCache] = typedResponse.isFromCache;
this[kResponseSize] = Number(response.headers['content-length']) || undefined;
this[kResponse] = response;
response.once('end', () => {
this[kResponseSize] = this[kDownloadedSize];
this.emit('downloadProgress', this.downloadProgress);
});
response.once('error', (error) => {
// Force clean-up, because some packages don't do this.
// TODO: Fix decompress-response
response.destroy();
this._beforeError(new ReadError(error, this));
});
response.once('aborted', () => {
this._beforeError(new ReadError({
name: 'Error',
message: 'The server aborted pending request',
code: 'ECONNRESET'
}, this));
});
this.emit('downloadProgress', this.downloadProgress);
const rawCookies = response.headers['set-cookie'];
if (is_1.default.object(options.cookieJar) && rawCookies) {
let promises = rawCookies.map(async (rawCookie) => options.cookieJar.setCookie(rawCookie, url.toString()));
if (options.ignoreInvalidCookies) {
promises = promises.map(async (p) => p.catch(() => { }));
}
try {
await Promise.all(promises);
}
catch (error) {
this._beforeError(error);
return;
}
}
if (options.followRedirect && response.headers.location && redirectCodes.has(statusCode)) {
// We're being redirected, we don't care about the response.
// It'd be best to abort the request, but we can't because
// we would have to sacrifice the TCP connection. We don't want that.
response.resume();
if (this[kRequest]) {
this[kCancelTimeouts]();
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this[kRequest];
this[kUnproxyEvents]();
}
const shouldBeGet = statusCode === 303 && options.method !== 'GET' && options.method !== 'HEAD';
if (shouldBeGet || !options.methodRewriting) {
// Server responded with "see other", indicating that the resource exists at another location,
// and the client should request it from that location via GET or HEAD.
options.method = 'GET';
if ('body' in options) {
delete options.body;
}
if ('json' in options) {
delete options.json;
}
if ('form' in options) {
delete options.form;
}
this[kBody] = undefined;
delete options.headers['content-length'];
}
if (this.redirects.length >= options.maxRedirects) {
this._beforeError(new MaxRedirectsError(this));
return;
}
try {
// Do not remove. See https://github.com/sindresorhus/got/pull/214
const redirectBuffer = Buffer.from(response.headers.location, 'binary').toString();
// Handles invalid URLs. See https://github.com/sindresorhus/got/issues/604
const redirectUrl = new url_1.URL(redirectBuffer, url);
const redirectString = redirectUrl.toString();
decodeURI(redirectString);
// Redirecting to a different site, clear sensitive data.
if (redirectUrl.hostname !== url.hostname || redirectUrl.port !== url.port) {
if ('host' in options.headers) {
delete options.headers.host;
}
if ('cookie' in options.headers) {
delete options.headers.cookie;
}
if ('authorization' in options.headers) {
delete options.headers.authorization;
}
if (options.username || options.password) {
options.username = '';
options.password = '';
}
}
else {
redirectUrl.username = options.username;
redirectUrl.password = options.password;
}
this.redirects.push(redirectString);
options.url = redirectUrl;
for (const hook of options.hooks.beforeRedirect) {
// eslint-disable-next-line no-await-in-loop
await hook(options, typedResponse);
}
this.emit('redirect', typedResponse, options);
await this._makeRequest();
}
catch (error) {
this._beforeError(error);
return;
}
return;
}
if (options.isStream && options.throwHttpErrors && !is_response_ok_1.isResponseOk(typedResponse)) {
this._beforeError(new HTTPError(typedResponse));
return;
}
response.on('readable', () => {
if (this[kTriggerRead]) {
this._read();
}
});
this.on('resume', () => {
response.resume();
});
this.on('pause', () => {
response.pause();
});
response.once('end', () => {
this.push(null);
});
this.emit('response', response);
for (const destination of this[kServerResponsesPiped]) {
if (destination.headersSent) {
continue;
}
// eslint-disable-next-line guard-for-in
for (const key in response.headers) {
const isAllowed = options.decompress ? key !== 'content-encoding' : true;
const value = response.headers[key];
if (isAllowed) {
destination.setHeader(key, value);
}
}
destination.statusCode = statusCode;
}
}
async _onResponse(response) {
try {
await this._onResponseBase(response);
}
catch (error) {
/* istanbul ignore next: better safe than sorry */
this._beforeError(error);
}
}
_onRequest(request) {
const { options } = this;
const { timeout, url } = options;
http_timer_1.default(request);
this[kCancelTimeouts] = timed_out_1.default(request, timeout, url);
const responseEventName = options.cache ? 'cacheableResponse' : 'response';
request.once(responseEventName, (response) => {
void this._onResponse(response);
});
request.once('error', (error) => {
var _a;
// Force clean-up, because some packages (e.g. nock) don't do this.
request.destroy();
// Node.js <= 12.18.2 mistakenly emits the response `end` first.
(_a = request.res) === null || _a === void 0 ? void 0 : _a.removeAllListeners('end');
error = error instanceof timed_out_1.TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
this._beforeError(error);
});
this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
this[kRequest] = request;
this.emit('uploadProgress', this.uploadProgress);
// Send body
const body = this[kBody];
const currentRequest = this.redirects.length === 0 ? this : request;
if (is_1.default.nodeStream(body)) {
body.pipe(currentRequest);
body.once('error', (error) => {
this._beforeError(new UploadError(error, this));
});
}
else {
this._unlockWrite();
if (!is_1.default.undefined(body)) {
this._writeRequest(body, undefined, () => { });
currentRequest.end();
this._lockWrite();
}
else if (this._cannotHaveBody || this._noPipe) {
currentRequest.end();
this._lockWrite();
}
}
this.emit('request', request);
}
async _createCacheableRequest(url, options) {
return new Promise((resolve, reject) => {
// TODO: Remove `utils/url-to-options.ts` when `cacheable-request` is fixed
Object.assign(options, url_to_options_1.default(url));
// `http-cache-semantics` checks this
// TODO: Fix this ignore.
// @ts-expect-error
delete options.url;
let request;
// This is ugly
const cacheRequest = cacheableStore.get(options.cache)(options, async (response) => {
// TODO: Fix `cacheable-response`
response._readableState.autoDestroy = false;
if (request) {
(await request).emit('cacheableResponse', response);
}
resolve(response);
});
// Restore options
options.url = url;
cacheRequest.once('error', reject);
cacheRequest.once('request', async (requestOrPromise) => {
request = requestOrPromise;
resolve(request);
});
});
}
async _makeRequest() {
var _a, _b, _c, _d, _e;
const { options } = this;
const { headers } = options;
for (const key in headers) {
if (is_1.default.undefined(headers[key])) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete headers[key];
}
else if (is_1.default.null_(headers[key])) {
throw new TypeError(`Use \`undefined\` instead of \`null\` to delete the \`${key}\` header`);
}
}
if (options.decompress && is_1.default.undefined(headers['accept-encoding'])) {
headers['accept-encoding'] = supportsBrotli ? 'gzip, deflate, br' : 'gzip, deflate';
}
// Set cookies
if (options.cookieJar) {
const cookieString = await options.cookieJar.getCookieString(options.url.toString());
if (is_1.default.nonEmptyString(cookieString)) {
options.headers.cookie = cookieString;
}
}
for (const hook of options.hooks.beforeRequest) {
// eslint-disable-next-line no-await-in-loop
const result = await hook(options);
if (!is_1.default.undefined(result)) {
// @ts-expect-error Skip the type mismatch to support abstract responses
options.request = () => result;
break;
}
}
if (options.body && this[kBody] !== options.body) {
this[kBody] = options.body;
}
const { agent, request, timeout, url } = options;
if (options.dnsCache && !('lookup' in options)) {
options.lookup = options.dnsCache.lookup;
}
// UNIX sockets
if (url.hostname === 'unix') {
const matches = /(?<socketPath>.+?):(?<path>.+)/.exec(`${url.pathname}${url.search}`);
if (matches === null || matches === void 0 ? void 0 : matches.groups) {
const { socketPath, path } = matches.groups;
Object.assign(options, {
socketPath,
path,
host: ''
});
}
}
const isHttps = url.protocol === 'https:';
// Fallback function
let fallbackFn;
if (options.http2) {
fallbackFn = http2wrapper.auto;
}
else {
fallbackFn = isHttps ? https.request : http.request;
}
const realFn = (_a = options.request) !== null && _a !== void 0 ? _a : fallbackFn;
// Cache support
const fn = options.cache ? this._createCacheableRequest : realFn;
// Pass an agent directly when HTTP2 is disabled
if (agent && !options.http2) {
options.agent = agent[isHttps ? 'https' : 'http'];
}
// Prepare plain HTTP request options
options[kRequest] = realFn;
delete options.request;
// TODO: Fix this ignore.
// @ts-expect-error
delete options.timeout;
const requestOptions = options;
requestOptions.shared = (_b = options.cacheOptions) === null || _b === void 0 ? void 0 : _b.shared;
requestOptions.cacheHeuristic = (_c = options.cacheOptions) === null || _c === void 0 ? void 0 : _c.cacheHeuristic;
requestOptions.immutableMinTimeToLive = (_d = options.cacheOptions) === null || _d === void 0 ? void 0 : _d.immutableMinTimeToLive;
requestOptions.ignoreCargoCult = (_e = options.cacheOptions) === null || _e === void 0 ? void 0 : _e.ignoreCargoCult;
// If `dnsLookupIpVersion` is not present do not override `family`
if (options.dnsLookupIpVersion !== undefined) {
try {
requestOptions.family = dns_ip_version_1.dnsLookupIpVersionToFamily(options.dnsLookupIpVersion);
}
catch (_f) {
throw new Error('Invalid `dnsLookupIpVersion` option value');
}
}
// HTTPS options remapping
if (options.https) {
if ('rejectUnauthorized' in options.https) {
requestOptions.rejectUnauthorized = options.https.rejectUnauthorized;
}
if (options.https.checkServerIdentity) {
requestOptions.checkServerIdentity = options.https.checkServerIdentity;
}
if (options.https.certificateAuthority) {
requestOptions.ca = options.https.certificateAuthority;
}
if (options.https.certificate) {
requestOptions.cert = options.https.certificate;
}
if (options.https.key) {
requestOptions.key = options.https.key;
}
if (options.https.passphrase) {
requestOptions.passphrase = options.https.passphrase;
}
if (options.https.pfx) {
requestOptions.pfx = options.https.pfx;
}
}
try {
let requestOrResponse = await fn(url, requestOptions);
if (is_1.default.undefined(requestOrResponse)) {
requestOrResponse = fallbackFn(url, requestOptions);
}
// Restore options
options.request = request;
options.timeout = timeout;
options.agent = agent;
// HTTPS options restore
if (options.https) {
if ('rejectUnauthorized' in options.https) {
delete requestOptions.rejectUnauthorized;
}
if (options.https.checkServerIdentity) {
// @ts-expect-error - This one will be removed when we remove the alias.
delete requestOptions.checkServerIdentity;
}
if (options.https.certificateAuthority) {
delete requestOptions.ca;
}
if (options.https.certificate) {
delete requestOptions.cert;
}
if (options.https.key) {
delete requestOptions.key;
}
if (options.https.passphrase) {
delete requestOptions.passphrase;
}
if (options.https.pfx) {
delete requestOptions.pfx;
}
}
if (isClientRequest(requestOrResponse)) {
this._onRequest(requestOrResponse);
// Emit the response after the stream has been ended
}
else if (this.writable) {
this.once('finish', () => {
void this._onResponse(requestOrResponse);
});
this._unlockWrite();
this.end();
this._lockWrite();
}
else {
void this._onResponse(requestOrResponse);
}
}
catch (error) {
if (error instanceof CacheableRequest.CacheError) {
throw new CacheError(error, this);
}
throw new RequestError(error.message, error, this);
}
}
async _error(error) {
try {
for (const hook of this.options.hooks.beforeError) {
// eslint-disable-next-line no-await-in-loop
error = await hook(error);
}
}
catch (error_) {
error = new RequestError(error_.message, error_, this);
}
this.destroy(error);
}
_beforeError(error) {
if (this[kStopReading]) {
return;
}
const { options } = this;
const retryCount = this.retryCount + 1;
this[kStopReading] = true;
if (!(error instanceof RequestError)) {
error = new RequestError(error.message, error, this);
}
const typedError = error;
const { response } = typedError;
void (async () => {
if (response && !response.body) {
response.setEncoding(this._readableState.encoding);
try {
response.rawBody = await get_buffer_1.default(response);
response.body = response.rawBody.toString();
}
catch (_a) { }
}
if (this.listenerCount('retry') !== 0) {
let backoff;
try {
let retryAfter;
if (response && 'retry-after' in response.headers) {
retryAfter = Number(response.headers['retry-after']);
if (Number.isNaN(retryAfter)) {
retryAfter = Date.parse(response.headers['retry-after']) - Date.now();
if (retryAfter <= 0) {
retryAfter = 1;
}
}
else {
retryAfter *= 1000;
}
}
backoff = await options.retry.calculateDelay({
attemptCount: retryCount,
retryOptions: options.retry,
error: typedError,
retryAfter,
computedValue: calculate_retry_delay_1.default({
attemptCount: retryCount,
retryOptions: options.retry,
error: typedError,
retryAfter,
computedValue: 0
})
});
}
catch (error_) {
void this._error(new RequestError(error_.message, error_, this));
return;
}
if (backoff) {
const retry = async () => {
try {
for (const hook of this.options.hooks.beforeRetry) {
// eslint-disable-next-line no-await-in-loop
await hook(this.options, typedError, retryCount);
}
}
catch (error_) {
void this._error(new RequestError(error_.message, error, this));
return;
}
// Something forced us to abort the retry
if (this.destroyed) {
return;
}
this.destroy();
this.emit('retry', retryCount, error);
};
this[kRetryTimeout] = setTimeout(retry, backoff);
return;
}
}
void this._error(typedError);
})();
}
_read() {
this[kTriggerRead] = true;
const response = this[kResponse];
if (response && !this[kStopReading]) {
// We cannot put this in the `if` above
// because `.read()` also triggers the `end` event
if (response.readableLength) {
this[kTriggerRead] = false;
}
let data;
while ((data = response.read()) !== null) {
this[kDownloadedSize] += data.length;
this[kStartedReading] = true;
const progress = this.downloadProgress;
if (progress.percent < 1) {
this.emit('downloadProgress', progress);
}
this.push(data);
}
}
}
// Node.js 12 has incorrect types, so the encoding must be a string
_write(chunk, encoding, callback) {
const write = () => {
this._writeRequest(chunk, encoding, callback);
};
if (this.requestInitialized) {
write();
}
else {
this[kJobs].push(write);
}
}
_writeRequest(chunk, encoding, callback) {
if (this[kRequest].destroyed) {
// Probably the `ClientRequest` instance will throw
return;
}
this._progressCallbacks.push(() => {
this[kUploadedSize] += Buffer.byteLength(chunk, encoding);
const progress = this.uploadProgress;
if (progress.percent < 1) {
this.emit('uploadProgress', progress);
}
});
// TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
this[kRequest].write(chunk, encoding, (error) => {
if (!error && this._progressCallbacks.length > 0) {
this._progressCallbacks.shift()();
}
callback(error);
});
}
_final(callback) {
const endRequest = () => {
// FIX: Node.js 10 calls the write callback AFTER the end callback!
while (this._progressCallbacks.length !== 0) {
this._progressCallbacks.shift()();
}
// We need to check if `this[kRequest]` is present,
// because it isn't when we use cache.
if (!(kRequest in this)) {
callback();
return;
}
if (this[kRequest].destroyed) {
callback();
return;
}
this[kRequest].end((error) => {
if (!error) {
this[kBodySize] = this[kUploadedSize];
this.emit('uploadProgress', this.uploadProgress);
this[kRequest].emit('upload-complete');
}
callback(error);
});
};
if (this.requestInitialized) {
endRequest();
}
else {
this[kJobs].push(endRequest);
}
}
_destroy(error, callback) {
var _a;
this[kStopReading] = true;
// Prevent further retries
clearTimeout(this[kRetryTimeout]);
if (kRequest in this) {
this[kCancelTimeouts]();
// TODO: Remove the next `if` when these get fixed:
// - https://github.com/nodejs/node/issues/32851
if (!((_a = this[kResponse]) === null || _a === void 0 ? void 0 : _a.complete)) {
this[kRequest].destroy();
}
}
if (error !== null && !is_1.default.undefined(error) && !(error instanceof RequestError)) {
error = new RequestError(error.message, error, this);
}
callback(error);
}
get _isAboutToError() {
return this[kStopReading];
}
/**
The remote IP address.
*/
get ip() {
var _a;
return (_a = this.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress;
}
/**
Indicates whether the request has been aborted or not.
*/
get aborted() {
var _a, _b, _c;
return ((_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroyed) !== null && _b !== void 0 ? _b : this.destroyed) && !((_c = this[kOriginalResponse]) === null || _c === void 0 ? void 0 : _c.complete);
}
get socket() {
var _a, _b;
return (_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket) !== null && _b !== void 0 ? _b : undefined;
}
/**
Progress event for downloading (receiving a response).
*/
get downloadProgress() {
let percent;
if (this[kResponseSize]) {
percent = this[kDownloadedSize] / this[kResponseSize];
}
else if (this[kResponseSize] === this[kDownloadedSize]) {
percent = 1;
}
else {
percent = 0;
}
return {
percent,
transferred: this[kDownloadedSize],
total: this[kResponseSize]
};
}
/**
Progress event for uploading (sending a request).
*/
get uploadProgress() {
let percent;
if (this[kBodySize]) {
percent = this[kUploadedSize] / this[kBodySize];
}
else if (this[kBodySize] === this[kUploadedSize]) {
percent = 1;
}
else {
percent = 0;
}
return {
percent,
transferred: this[kUploadedSize],
total: this[kBodySize]
};
}
/**
The object contains the following properties:
- `start` - Time when the request started.
- `socket` - Time when a socket was assigned to the request.
- `lookup` - Time when the DNS lookup finished.
- `connect` - Time when the socket successfully connected.
- `secureConnect` - Time when the socket securely connected.
- `upload` - Time when the request finished uploading.
- `response` - Time when the request fired `response` event.
- `end` - Time when the response fired `end` event.
- `error` - Time when the request fired `error` event.
- `abort` - Time when the request fired `abort` event.
- `phases`
- `wait` - `timings.socket - timings.start`
- `dns` - `timings.lookup - timings.socket`
- `tcp` - `timings.connect - timings.lookup`
- `tls` - `timings.secureConnect - timings.connect`
- `request` - `timings.upload - (timings.secureConnect || timings.connect)`
- `firstByte` - `timings.response - timings.upload`
- `download` - `timings.end - timings.response`
- `total` - `(timings.end || timings.error || timings.abort) - timings.start`
If something has not been measured yet, it will be `undefined`.
__Note__: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
*/
get timings() {
var _a;
return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.timings;
}
/**
Whether the response was retrieved from the cache.
*/
get isFromCache() {
return this[kIsFromCache];
}
pipe(destination, options) {
if (this[kStartedReading]) {
throw new Error('Failed to pipe. The response has been emitted already.');
}
if (destination instanceof http_1.ServerResponse) {
this[kServerResponsesPiped].add(destination);
}
return super.pipe(destination, options);
}
unpipe(destination) {
if (destination instanceof http_1.ServerResponse) {
this[kServerResponsesPiped].delete(destination);
}
super.unpipe(destination);
return this;
}
}
exports.default = Request;
}(core));
(function (exports) {
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CancelError = exports.ParseError = void 0;
const core_1 = core;
/**
An error to be thrown when server response code is 2xx, and parsing body fails.
Includes a `response` property.
*/
class ParseError extends core_1.RequestError {
constructor(error, response) {
const { options } = response.request;
super(`${error.message} in "${options.url.toString()}"`, error, response.request);
this.name = 'ParseError';
this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_BODY_PARSE_FAILURE' : this.code;
}
}
exports.ParseError = ParseError;
/**
An error to be thrown when the request is aborted with `.cancel()`.
*/
class CancelError extends core_1.RequestError {
constructor(request) {
super('Promise was canceled', {}, request);
this.name = 'CancelError';
this.code = 'ERR_CANCELED';
}
get isCanceled() {
return true;
}
}
exports.CancelError = CancelError;
__exportStar(core, exports);
}(types$1));
var parseBody$1 = {};
Object.defineProperty(parseBody$1, "__esModule", { value: true });
const types_1$1 = types$1;
const parseBody = (response, responseType, parseJson, encoding) => {
const { rawBody } = response;
try {
if (responseType === 'text') {
return rawBody.toString(encoding);
}
if (responseType === 'json') {
return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
}
if (responseType === 'buffer') {
return rawBody;
}
throw new types_1$1.ParseError({
message: `Unknown body type '${responseType}'`,
name: 'Error'
}, response);
}
catch (error) {
throw new types_1$1.ParseError(error, response);
}
};
parseBody$1.default = parseBody;
(function (exports) {
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require$$0__default$3["default"];
const is_1 = dist$1.exports;
const PCancelable = pCancelable.exports;
const types_1 = types$1;
const parse_body_1 = parseBody$1;
const core_1 = core;
const proxy_events_1 = proxyEvents;
const get_buffer_1 = getBuffer$1;
const is_response_ok_1 = isResponseOk;
const proxiedRequestEvents = [
'request',
'response',
'redirect',
'uploadProgress',
'downloadProgress'
];
function asPromise(normalizedOptions) {
let globalRequest;
let globalResponse;
const emitter = new events_1.EventEmitter();
const promise = new PCancelable((resolve, reject, onCancel) => {
const makeRequest = (retryCount) => {
const request = new core_1.default(undefined, normalizedOptions);
request.retryCount = retryCount;
request._noPipe = true;
onCancel(() => request.destroy());
onCancel.shouldReject = false;
onCancel(() => reject(new types_1.CancelError(request)));
globalRequest = request;
request.once('response', async (response) => {
var _a;
response.retryCount = retryCount;
if (response.request.aborted) {
// Canceled while downloading - will throw a `CancelError` or `TimeoutError` error
return;
}
// Download body
let rawBody;
try {
rawBody = await get_buffer_1.default(request);
response.rawBody = rawBody;
}
catch (_b) {
// The same error is caught below.
// See request.once('error')
return;
}
if (request._isAboutToError) {
return;
}
// Parse body
const contentEncoding = ((_a = response.headers['content-encoding']) !== null && _a !== void 0 ? _a : '').toLowerCase();
const isCompressed = ['gzip', 'deflate', 'br'].includes(contentEncoding);
const { options } = request;
if (isCompressed && !options.decompress) {
response.body = rawBody;
}
else {
try {
response.body = parse_body_1.default(response, options.responseType, options.parseJson, options.encoding);
}
catch (error) {
// Fallback to `utf8`
response.body = rawBody.toString();
if (is_response_ok_1.isResponseOk(response)) {
request._beforeError(error);
return;
}
}
}
try {
for (const [index, hook] of options.hooks.afterResponse.entries()) {
// @ts-expect-error TS doesn't notice that CancelableRequest is a Promise
// eslint-disable-next-line no-await-in-loop
response = await hook(response, async (updatedOptions) => {
const typedOptions = core_1.default.normalizeArguments(undefined, {
...updatedOptions,
retry: {
calculateDelay: () => 0
},
throwHttpErrors: false,
resolveBodyOnly: false
}, options);
// Remove any further hooks for that request, because we'll call them anyway.
// The loop continues. We don't want duplicates (asPromise recursion).
typedOptions.hooks.afterResponse = typedOptions.hooks.afterResponse.slice(0, index);
for (const hook of typedOptions.hooks.beforeRetry) {
// eslint-disable-next-line no-await-in-loop
await hook(typedOptions);
}
const promise = asPromise(typedOptions);
onCancel(() => {
promise.catch(() => { });
promise.cancel();
});
return promise;
});
}
}
catch (error) {
request._beforeError(new types_1.RequestError(error.message, error, request));
return;
}
if (!is_response_ok_1.isResponseOk(response)) {
request._beforeError(new types_1.HTTPError(response));
return;
}
globalResponse = response;
resolve(request.options.resolveBodyOnly ? response.body : response);
});
const onError = (error) => {
if (promise.isCanceled) {
return;
}
const { options } = request;
if (error instanceof types_1.HTTPError && !options.throwHttpErrors) {
const { response } = error;
resolve(request.options.resolveBodyOnly ? response.body : response);
return;
}
reject(error);
};
request.once('error', onError);
const previousBody = request.options.body;
request.once('retry', (newRetryCount, error) => {
var _a, _b;
if (previousBody === ((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body) && is_1.default.nodeStream((_b = error.request) === null || _b === void 0 ? void 0 : _b.options.body)) {
onError(error);
return;
}
makeRequest(newRetryCount);
});
proxy_events_1.default(request, emitter, proxiedRequestEvents);
};
makeRequest(0);
});
promise.on = (event, fn) => {
emitter.on(event, fn);
return promise;
};
const shortcut = (responseType) => {
const newPromise = (async () => {
// Wait until downloading has ended
await promise;
const { options } = globalResponse.request;
return parse_body_1.default(globalResponse, responseType, options.parseJson, options.encoding);
})();
Object.defineProperties(newPromise, Object.getOwnPropertyDescriptors(promise));
return newPromise;
};
promise.json = () => {
const { headers } = globalRequest.options;
if (!globalRequest.writableFinished && headers.accept === undefined) {
headers.accept = 'application/json';
}
return shortcut('json');
};
promise.buffer = () => shortcut('buffer');
promise.text = () => shortcut('text');
return promise;
}
exports.default = asPromise;
__exportStar(types$1, exports);
}(asPromise));
var createRejection$1 = {};
Object.defineProperty(createRejection$1, "__esModule", { value: true });
const types_1 = types$1;
function createRejection(error, ...beforeErrorGroups) {
const promise = (async () => {
if (error instanceof types_1.RequestError) {
try {
for (const hooks of beforeErrorGroups) {
if (hooks) {
for (const hook of hooks) {
// eslint-disable-next-line no-await-in-loop
error = await hook(error);
}
}
}
}
catch (error_) {
error = error_;
}
}
throw error;
})();
const returnPromise = () => promise;
promise.json = returnPromise;
promise.text = returnPromise;
promise.buffer = returnPromise;
promise.on = returnPromise;
return promise;
}
createRejection$1.default = createRejection;
var deepFreeze$1 = {};
Object.defineProperty(deepFreeze$1, "__esModule", { value: true });
const is_1 = dist$1.exports;
function deepFreeze(object) {
for (const value of Object.values(object)) {
if (is_1.default.plainObject(value) || is_1.default.array(value)) {
deepFreeze(value);
}
}
return Object.freeze(object);
}
deepFreeze$1.default = deepFreeze;
var types = {};
Object.defineProperty(types, "__esModule", { value: true });
(function (exports) {
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultHandler = void 0;
const is_1 = dist$1.exports;
const as_promise_1 = asPromise;
const create_rejection_1 = createRejection$1;
const core_1 = core;
const deep_freeze_1 = deepFreeze$1;
const errors = {
RequestError: as_promise_1.RequestError,
CacheError: as_promise_1.CacheError,
ReadError: as_promise_1.ReadError,
HTTPError: as_promise_1.HTTPError,
MaxRedirectsError: as_promise_1.MaxRedirectsError,
TimeoutError: as_promise_1.TimeoutError,
ParseError: as_promise_1.ParseError,
CancelError: as_promise_1.CancelError,
UnsupportedProtocolError: as_promise_1.UnsupportedProtocolError,
UploadError: as_promise_1.UploadError
};
// The `delay` package weighs 10KB (!)
const delay = async (ms) => new Promise(resolve => {
setTimeout(resolve, ms);
});
const { normalizeArguments } = core_1.default;
const mergeOptions = (...sources) => {
let mergedOptions;
for (const source of sources) {
mergedOptions = normalizeArguments(undefined, source, mergedOptions);
}
return mergedOptions;
};
const getPromiseOrStream = (options) => options.isStream ? new core_1.default(undefined, options) : as_promise_1.default(options);
const isGotInstance = (value) => ('defaults' in value && 'options' in value.defaults);
const aliases = [
'get',
'post',
'put',
'patch',
'head',
'delete'
];
exports.defaultHandler = (options, next) => next(options);
const callInitHooks = (hooks, options) => {
if (hooks) {
for (const hook of hooks) {
hook(options);
}
}
};
const create = (defaults) => {
// Proxy properties from next handlers
defaults._rawHandlers = defaults.handlers;
defaults.handlers = defaults.handlers.map(fn => ((options, next) => {
// This will be assigned by assigning result
let root;
const result = fn(options, newOptions => {
root = next(newOptions);
return root;
});
if (result !== root && !options.isStream && root) {
const typedResult = result;
const { then: promiseThen, catch: promiseCatch, finally: promiseFianlly } = typedResult;
Object.setPrototypeOf(typedResult, Object.getPrototypeOf(root));
Object.defineProperties(typedResult, Object.getOwnPropertyDescriptors(root));
// These should point to the new promise
// eslint-disable-next-line promise/prefer-await-to-then
typedResult.then = promiseThen;
typedResult.catch = promiseCatch;
typedResult.finally = promiseFianlly;
}
return result;
}));
// Got interface
const got = ((url, options = {}, _defaults) => {
var _a, _b;
let iteration = 0;
const iterateHandlers = (newOptions) => {
return defaults.handlers[iteration++](newOptions, iteration === defaults.handlers.length ? getPromiseOrStream : iterateHandlers);
};
// TODO: Remove this in Got 12.
if (is_1.default.plainObject(url)) {
const mergedOptions = {
...url,
...options
};
core_1.setNonEnumerableProperties([url, options], mergedOptions);
options = mergedOptions;
url = undefined;
}
try {
// Call `init` hooks
let initHookError;
try {
callInitHooks(defaults.options.hooks.init, options);
callInitHooks((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
}
catch (error) {
initHookError = error;
}
// Normalize options & call handlers
const normalizedOptions = normalizeArguments(url, options, _defaults !== null && _defaults !== void 0 ? _defaults : defaults.options);
normalizedOptions[core_1.kIsNormalizedAlready] = true;
if (initHookError) {
throw new as_promise_1.RequestError(initHookError.message, initHookError, normalizedOptions);
}
return iterateHandlers(normalizedOptions);
}
catch (error) {
if (options.isStream) {
throw error;
}
else {
return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
}
}
});
got.extend = (...instancesOrOptions) => {
const optionsArray = [defaults.options];
let handlers = [...defaults._rawHandlers];
let isMutableDefaults;
for (const value of instancesOrOptions) {
if (isGotInstance(value)) {
optionsArray.push(value.defaults.options);
handlers.push(...value.defaults._rawHandlers);
isMutableDefaults = value.defaults.mutableDefaults;
}
else {
optionsArray.push(value);
if ('handlers' in value) {
handlers.push(...value.handlers);
}
isMutableDefaults = value.mutableDefaults;
}
}
handlers = handlers.filter(handler => handler !== exports.defaultHandler);
if (handlers.length === 0) {
handlers.push(exports.defaultHandler);
}
return create({
options: mergeOptions(...optionsArray),
handlers,
mutableDefaults: Boolean(isMutableDefaults)
});
};
// Pagination
const paginateEach = (async function* (url, options) {
// TODO: Remove this `@ts-expect-error` when upgrading to TypeScript 4.
// Error: Argument of type 'Merge<Options, PaginationOptions<T, R>> | undefined' is not assignable to parameter of type 'Options | undefined'.
// @ts-expect-error
let normalizedOptions = normalizeArguments(url, options, defaults.options);
normalizedOptions.resolveBodyOnly = false;
const pagination = normalizedOptions.pagination;
if (!is_1.default.object(pagination)) {
throw new TypeError('`options.pagination` must be implemented');
}
const all = [];
let { countLimit } = pagination;
let numberOfRequests = 0;
while (numberOfRequests < pagination.requestLimit) {
if (numberOfRequests !== 0) {
// eslint-disable-next-line no-await-in-loop
await delay(pagination.backoff);
}
// @ts-expect-error FIXME!
// TODO: Throw when result is not an instance of Response
// eslint-disable-next-line no-await-in-loop
const result = (await got(undefined, undefined, normalizedOptions));
// eslint-disable-next-line no-await-in-loop
const parsed = await pagination.transform(result);
const current = [];
for (const item of parsed) {
if (pagination.filter(item, all, current)) {
if (!pagination.shouldContinue(item, all, current)) {
return;
}
yield item;
if (pagination.stackAllItems) {
all.push(item);
}
current.push(item);
if (--countLimit <= 0) {
return;
}
}
}
const optionsToMerge = pagination.paginate(result, all, current);
if (optionsToMerge === false) {
return;
}
if (optionsToMerge === result.request.options) {
normalizedOptions = result.request.options;
}
else if (optionsToMerge !== undefined) {
normalizedOptions = normalizeArguments(undefined, optionsToMerge, normalizedOptions);
}
numberOfRequests++;
}
});
got.paginate = paginateEach;
got.paginate.all = (async (url, options) => {
const results = [];
for await (const item of paginateEach(url, options)) {
results.push(item);
}
return results;
});
// For those who like very descriptive names
got.paginate.each = paginateEach;
// Stream API
got.stream = ((url, options) => got(url, { ...options, isStream: true }));
// Shortcuts
for (const method of aliases) {
got[method] = ((url, options) => got(url, { ...options, method }));
got.stream[method] = ((url, options) => {
return got(url, { ...options, method, isStream: true });
});
}
Object.assign(got, errors);
Object.defineProperty(got, 'defaults', {
value: defaults.mutableDefaults ? defaults : deep_freeze_1.default(defaults),
writable: defaults.mutableDefaults,
configurable: defaults.mutableDefaults,
enumerable: true
});
got.mergeOptions = mergeOptions;
return got;
};
exports.default = create;
__exportStar(types, exports);
}(create));
(function (module, exports) {
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
const url_1 = require$$0__default$4["default"];
const create_1 = create;
const defaults = {
options: {
method: 'GET',
retry: {
limit: 2,
methods: [
'GET',
'PUT',
'HEAD',
'DELETE',
'OPTIONS',
'TRACE'
],
statusCodes: [
408,
413,
429,
500,
502,
503,
504,
521,
522,
524
],
errorCodes: [
'ETIMEDOUT',
'ECONNRESET',
'EADDRINUSE',
'ECONNREFUSED',
'EPIPE',
'ENOTFOUND',
'ENETUNREACH',
'EAI_AGAIN'
],
maxRetryAfter: undefined,
calculateDelay: ({ computedValue }) => computedValue
},
timeout: {},
headers: {
'user-agent': 'got (https://github.com/sindresorhus/got)'
},
hooks: {
init: [],
beforeRequest: [],
beforeRedirect: [],
beforeRetry: [],
beforeError: [],
afterResponse: []
},
cache: undefined,
dnsCache: undefined,
decompress: true,
throwHttpErrors: true,
followRedirect: true,
isStream: false,
responseType: 'text',
resolveBodyOnly: false,
maxRedirects: 10,
prefixUrl: '',
methodRewriting: true,
ignoreInvalidCookies: false,
context: {},
// TODO: Set this to `true` when Got 12 gets released
http2: false,
allowGetBody: false,
https: undefined,
pagination: {
transform: (response) => {
if (response.request.options.responseType === 'json') {
return response.body;
}
return JSON.parse(response.body);
},
paginate: response => {
if (!Reflect.has(response.headers, 'link')) {
return false;
}
const items = response.headers.link.split(',');
let next;
for (const item of items) {
const parsed = item.split(';');
if (parsed[1].includes('next')) {
next = parsed[0].trimStart().trim();
next = next.slice(1, -1);
break;
}
}
if (next) {
const options = {
url: new url_1.URL(next)
};
return options;
}
return false;
},
filter: () => true,
shouldContinue: () => true,
countLimit: Infinity,
backoff: 0,
requestLimit: 10000,
stackAllItems: true
},
parseJson: (text) => JSON.parse(text),
stringifyJson: (object) => JSON.stringify(object),
cacheOptions: {}
},
handlers: [create_1.defaultHandler],
mutableDefaults: false
};
const got = create_1.default(defaults);
exports.default = got;
// For CommonJS default export support
module.exports = got;
module.exports.default = got;
module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267
__exportStar(create, exports);
__exportStar(asPromise, exports);
}(source$4, source$4.exports));
var got = /*@__PURE__*/getDefaultExportFromCjs(source$4.exports);
var mimeTypes = {};
var require$$0 = {
"application/1d-interleaved-parityfec": {
source: "iana"
},
"application/3gpdash-qoe-report+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/3gpp-ims+xml": {
source: "iana",
compressible: true
},
"application/3gpphal+json": {
source: "iana",
compressible: true
},
"application/3gpphalforms+json": {
source: "iana",
compressible: true
},
"application/a2l": {
source: "iana"
},
"application/ace+cbor": {
source: "iana"
},
"application/activemessage": {
source: "iana"
},
"application/activity+json": {
source: "iana",
compressible: true
},
"application/alto-costmap+json": {
source: "iana",
compressible: true
},
"application/alto-costmapfilter+json": {
source: "iana",
compressible: true
},
"application/alto-directory+json": {
source: "iana",
compressible: true
},
"application/alto-endpointcost+json": {
source: "iana",
compressible: true
},
"application/alto-endpointcostparams+json": {
source: "iana",
compressible: true
},
"application/alto-endpointprop+json": {
source: "iana",
compressible: true
},
"application/alto-endpointpropparams+json": {
source: "iana",
compressible: true
},
"application/alto-error+json": {
source: "iana",
compressible: true
},
"application/alto-networkmap+json": {
source: "iana",
compressible: true
},
"application/alto-networkmapfilter+json": {
source: "iana",
compressible: true
},
"application/alto-updatestreamcontrol+json": {
source: "iana",
compressible: true
},
"application/alto-updatestreamparams+json": {
source: "iana",
compressible: true
},
"application/aml": {
source: "iana"
},
"application/andrew-inset": {
source: "iana",
extensions: [
"ez"
]
},
"application/applefile": {
source: "iana"
},
"application/applixware": {
source: "apache",
extensions: [
"aw"
]
},
"application/at+jwt": {
source: "iana"
},
"application/atf": {
source: "iana"
},
"application/atfx": {
source: "iana"
},
"application/atom+xml": {
source: "iana",
compressible: true,
extensions: [
"atom"
]
},
"application/atomcat+xml": {
source: "iana",
compressible: true,
extensions: [
"atomcat"
]
},
"application/atomdeleted+xml": {
source: "iana",
compressible: true,
extensions: [
"atomdeleted"
]
},
"application/atomicmail": {
source: "iana"
},
"application/atomsvc+xml": {
source: "iana",
compressible: true,
extensions: [
"atomsvc"
]
},
"application/atsc-dwd+xml": {
source: "iana",
compressible: true,
extensions: [
"dwd"
]
},
"application/atsc-dynamic-event-message": {
source: "iana"
},
"application/atsc-held+xml": {
source: "iana",
compressible: true,
extensions: [
"held"
]
},
"application/atsc-rdt+json": {
source: "iana",
compressible: true
},
"application/atsc-rsat+xml": {
source: "iana",
compressible: true,
extensions: [
"rsat"
]
},
"application/atxml": {
source: "iana"
},
"application/auth-policy+xml": {
source: "iana",
compressible: true
},
"application/bacnet-xdd+zip": {
source: "iana",
compressible: false
},
"application/batch-smtp": {
source: "iana"
},
"application/bdoc": {
compressible: false,
extensions: [
"bdoc"
]
},
"application/beep+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/calendar+json": {
source: "iana",
compressible: true
},
"application/calendar+xml": {
source: "iana",
compressible: true,
extensions: [
"xcs"
]
},
"application/call-completion": {
source: "iana"
},
"application/cals-1840": {
source: "iana"
},
"application/captive+json": {
source: "iana",
compressible: true
},
"application/cbor": {
source: "iana"
},
"application/cbor-seq": {
source: "iana"
},
"application/cccex": {
source: "iana"
},
"application/ccmp+xml": {
source: "iana",
compressible: true
},
"application/ccxml+xml": {
source: "iana",
compressible: true,
extensions: [
"ccxml"
]
},
"application/cdfx+xml": {
source: "iana",
compressible: true,
extensions: [
"cdfx"
]
},
"application/cdmi-capability": {
source: "iana",
extensions: [
"cdmia"
]
},
"application/cdmi-container": {
source: "iana",
extensions: [
"cdmic"
]
},
"application/cdmi-domain": {
source: "iana",
extensions: [
"cdmid"
]
},
"application/cdmi-object": {
source: "iana",
extensions: [
"cdmio"
]
},
"application/cdmi-queue": {
source: "iana",
extensions: [
"cdmiq"
]
},
"application/cdni": {
source: "iana"
},
"application/cea": {
source: "iana"
},
"application/cea-2018+xml": {
source: "iana",
compressible: true
},
"application/cellml+xml": {
source: "iana",
compressible: true
},
"application/cfw": {
source: "iana"
},
"application/clr": {
source: "iana"
},
"application/clue+xml": {
source: "iana",
compressible: true
},
"application/clue_info+xml": {
source: "iana",
compressible: true
},
"application/cms": {
source: "iana"
},
"application/cnrp+xml": {
source: "iana",
compressible: true
},
"application/coap-group+json": {
source: "iana",
compressible: true
},
"application/coap-payload": {
source: "iana"
},
"application/commonground": {
source: "iana"
},
"application/conference-info+xml": {
source: "iana",
compressible: true
},
"application/cose": {
source: "iana"
},
"application/cose-key": {
source: "iana"
},
"application/cose-key-set": {
source: "iana"
},
"application/cpl+xml": {
source: "iana",
compressible: true
},
"application/csrattrs": {
source: "iana"
},
"application/csta+xml": {
source: "iana",
compressible: true
},
"application/cstadata+xml": {
source: "iana",
compressible: true
},
"application/csvm+json": {
source: "iana",
compressible: true
},
"application/cu-seeme": {
source: "apache",
extensions: [
"cu"
]
},
"application/cwt": {
source: "iana"
},
"application/cybercash": {
source: "iana"
},
"application/dart": {
compressible: true
},
"application/dash+xml": {
source: "iana",
compressible: true,
extensions: [
"mpd"
]
},
"application/dashdelta": {
source: "iana"
},
"application/davmount+xml": {
source: "iana",
compressible: true,
extensions: [
"davmount"
]
},
"application/dca-rft": {
source: "iana"
},
"application/dcd": {
source: "iana"
},
"application/dec-dx": {
source: "iana"
},
"application/dialog-info+xml": {
source: "iana",
compressible: true
},
"application/dicom": {
source: "iana"
},
"application/dicom+json": {
source: "iana",
compressible: true
},
"application/dicom+xml": {
source: "iana",
compressible: true
},
"application/dii": {
source: "iana"
},
"application/dit": {
source: "iana"
},
"application/dns": {
source: "iana"
},
"application/dns+json": {
source: "iana",
compressible: true
},
"application/dns-message": {
source: "iana"
},
"application/docbook+xml": {
source: "apache",
compressible: true,
extensions: [
"dbk"
]
},
"application/dots+cbor": {
source: "iana"
},
"application/dskpp+xml": {
source: "iana",
compressible: true
},
"application/dssc+der": {
source: "iana",
extensions: [
"dssc"
]
},
"application/dssc+xml": {
source: "iana",
compressible: true,
extensions: [
"xdssc"
]
},
"application/dvcs": {
source: "iana"
},
"application/ecmascript": {
source: "iana",
compressible: true,
extensions: [
"es",
"ecma"
]
},
"application/edi-consent": {
source: "iana"
},
"application/edi-x12": {
source: "iana",
compressible: false
},
"application/edifact": {
source: "iana",
compressible: false
},
"application/efi": {
source: "iana"
},
"application/elm+json": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/elm+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.cap+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/emergencycalldata.comment+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.control+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.deviceinfo+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.ecall.msd": {
source: "iana"
},
"application/emergencycalldata.providerinfo+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.serviceinfo+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.subscriberinfo+xml": {
source: "iana",
compressible: true
},
"application/emergencycalldata.veds+xml": {
source: "iana",
compressible: true
},
"application/emma+xml": {
source: "iana",
compressible: true,
extensions: [
"emma"
]
},
"application/emotionml+xml": {
source: "iana",
compressible: true,
extensions: [
"emotionml"
]
},
"application/encaprtp": {
source: "iana"
},
"application/epp+xml": {
source: "iana",
compressible: true
},
"application/epub+zip": {
source: "iana",
compressible: false,
extensions: [
"epub"
]
},
"application/eshop": {
source: "iana"
},
"application/exi": {
source: "iana",
extensions: [
"exi"
]
},
"application/expect-ct-report+json": {
source: "iana",
compressible: true
},
"application/express": {
source: "iana",
extensions: [
"exp"
]
},
"application/fastinfoset": {
source: "iana"
},
"application/fastsoap": {
source: "iana"
},
"application/fdt+xml": {
source: "iana",
compressible: true,
extensions: [
"fdt"
]
},
"application/fhir+json": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/fhir+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/fido.trusted-apps+json": {
compressible: true
},
"application/fits": {
source: "iana"
},
"application/flexfec": {
source: "iana"
},
"application/font-sfnt": {
source: "iana"
},
"application/font-tdpfr": {
source: "iana",
extensions: [
"pfr"
]
},
"application/font-woff": {
source: "iana",
compressible: false
},
"application/framework-attributes+xml": {
source: "iana",
compressible: true
},
"application/geo+json": {
source: "iana",
compressible: true,
extensions: [
"geojson"
]
},
"application/geo+json-seq": {
source: "iana"
},
"application/geopackage+sqlite3": {
source: "iana"
},
"application/geoxacml+xml": {
source: "iana",
compressible: true
},
"application/gltf-buffer": {
source: "iana"
},
"application/gml+xml": {
source: "iana",
compressible: true,
extensions: [
"gml"
]
},
"application/gpx+xml": {
source: "apache",
compressible: true,
extensions: [
"gpx"
]
},
"application/gxf": {
source: "apache",
extensions: [
"gxf"
]
},
"application/gzip": {
source: "iana",
compressible: false,
extensions: [
"gz"
]
},
"application/h224": {
source: "iana"
},
"application/held+xml": {
source: "iana",
compressible: true
},
"application/hjson": {
extensions: [
"hjson"
]
},
"application/http": {
source: "iana"
},
"application/hyperstudio": {
source: "iana",
extensions: [
"stk"
]
},
"application/ibe-key-request+xml": {
source: "iana",
compressible: true
},
"application/ibe-pkg-reply+xml": {
source: "iana",
compressible: true
},
"application/ibe-pp-data": {
source: "iana"
},
"application/iges": {
source: "iana"
},
"application/im-iscomposing+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/index": {
source: "iana"
},
"application/index.cmd": {
source: "iana"
},
"application/index.obj": {
source: "iana"
},
"application/index.response": {
source: "iana"
},
"application/index.vnd": {
source: "iana"
},
"application/inkml+xml": {
source: "iana",
compressible: true,
extensions: [
"ink",
"inkml"
]
},
"application/iotp": {
source: "iana"
},
"application/ipfix": {
source: "iana",
extensions: [
"ipfix"
]
},
"application/ipp": {
source: "iana"
},
"application/isup": {
source: "iana"
},
"application/its+xml": {
source: "iana",
compressible: true,
extensions: [
"its"
]
},
"application/java-archive": {
source: "apache",
compressible: false,
extensions: [
"jar",
"war",
"ear"
]
},
"application/java-serialized-object": {
source: "apache",
compressible: false,
extensions: [
"ser"
]
},
"application/java-vm": {
source: "apache",
compressible: false,
extensions: [
"class"
]
},
"application/javascript": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"js",
"mjs"
]
},
"application/jf2feed+json": {
source: "iana",
compressible: true
},
"application/jose": {
source: "iana"
},
"application/jose+json": {
source: "iana",
compressible: true
},
"application/jrd+json": {
source: "iana",
compressible: true
},
"application/jscalendar+json": {
source: "iana",
compressible: true
},
"application/json": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"json",
"map"
]
},
"application/json-patch+json": {
source: "iana",
compressible: true
},
"application/json-seq": {
source: "iana"
},
"application/json5": {
extensions: [
"json5"
]
},
"application/jsonml+json": {
source: "apache",
compressible: true,
extensions: [
"jsonml"
]
},
"application/jwk+json": {
source: "iana",
compressible: true
},
"application/jwk-set+json": {
source: "iana",
compressible: true
},
"application/jwt": {
source: "iana"
},
"application/kpml-request+xml": {
source: "iana",
compressible: true
},
"application/kpml-response+xml": {
source: "iana",
compressible: true
},
"application/ld+json": {
source: "iana",
compressible: true,
extensions: [
"jsonld"
]
},
"application/lgr+xml": {
source: "iana",
compressible: true,
extensions: [
"lgr"
]
},
"application/link-format": {
source: "iana"
},
"application/load-control+xml": {
source: "iana",
compressible: true
},
"application/lost+xml": {
source: "iana",
compressible: true,
extensions: [
"lostxml"
]
},
"application/lostsync+xml": {
source: "iana",
compressible: true
},
"application/lpf+zip": {
source: "iana",
compressible: false
},
"application/lxf": {
source: "iana"
},
"application/mac-binhex40": {
source: "iana",
extensions: [
"hqx"
]
},
"application/mac-compactpro": {
source: "apache",
extensions: [
"cpt"
]
},
"application/macwriteii": {
source: "iana"
},
"application/mads+xml": {
source: "iana",
compressible: true,
extensions: [
"mads"
]
},
"application/manifest+json": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"webmanifest"
]
},
"application/marc": {
source: "iana",
extensions: [
"mrc"
]
},
"application/marcxml+xml": {
source: "iana",
compressible: true,
extensions: [
"mrcx"
]
},
"application/mathematica": {
source: "iana",
extensions: [
"ma",
"nb",
"mb"
]
},
"application/mathml+xml": {
source: "iana",
compressible: true,
extensions: [
"mathml"
]
},
"application/mathml-content+xml": {
source: "iana",
compressible: true
},
"application/mathml-presentation+xml": {
source: "iana",
compressible: true
},
"application/mbms-associated-procedure-description+xml": {
source: "iana",
compressible: true
},
"application/mbms-deregister+xml": {
source: "iana",
compressible: true
},
"application/mbms-envelope+xml": {
source: "iana",
compressible: true
},
"application/mbms-msk+xml": {
source: "iana",
compressible: true
},
"application/mbms-msk-response+xml": {
source: "iana",
compressible: true
},
"application/mbms-protection-description+xml": {
source: "iana",
compressible: true
},
"application/mbms-reception-report+xml": {
source: "iana",
compressible: true
},
"application/mbms-register+xml": {
source: "iana",
compressible: true
},
"application/mbms-register-response+xml": {
source: "iana",
compressible: true
},
"application/mbms-schedule+xml": {
source: "iana",
compressible: true
},
"application/mbms-user-service-description+xml": {
source: "iana",
compressible: true
},
"application/mbox": {
source: "iana",
extensions: [
"mbox"
]
},
"application/media-policy-dataset+xml": {
source: "iana",
compressible: true
},
"application/media_control+xml": {
source: "iana",
compressible: true
},
"application/mediaservercontrol+xml": {
source: "iana",
compressible: true,
extensions: [
"mscml"
]
},
"application/merge-patch+json": {
source: "iana",
compressible: true
},
"application/metalink+xml": {
source: "apache",
compressible: true,
extensions: [
"metalink"
]
},
"application/metalink4+xml": {
source: "iana",
compressible: true,
extensions: [
"meta4"
]
},
"application/mets+xml": {
source: "iana",
compressible: true,
extensions: [
"mets"
]
},
"application/mf4": {
source: "iana"
},
"application/mikey": {
source: "iana"
},
"application/mipc": {
source: "iana"
},
"application/missing-blocks+cbor-seq": {
source: "iana"
},
"application/mmt-aei+xml": {
source: "iana",
compressible: true,
extensions: [
"maei"
]
},
"application/mmt-usd+xml": {
source: "iana",
compressible: true,
extensions: [
"musd"
]
},
"application/mods+xml": {
source: "iana",
compressible: true,
extensions: [
"mods"
]
},
"application/moss-keys": {
source: "iana"
},
"application/moss-signature": {
source: "iana"
},
"application/mosskey-data": {
source: "iana"
},
"application/mosskey-request": {
source: "iana"
},
"application/mp21": {
source: "iana",
extensions: [
"m21",
"mp21"
]
},
"application/mp4": {
source: "iana",
extensions: [
"mp4s",
"m4p"
]
},
"application/mpeg4-generic": {
source: "iana"
},
"application/mpeg4-iod": {
source: "iana"
},
"application/mpeg4-iod-xmt": {
source: "iana"
},
"application/mrb-consumer+xml": {
source: "iana",
compressible: true
},
"application/mrb-publish+xml": {
source: "iana",
compressible: true
},
"application/msc-ivr+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/msc-mixer+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/msword": {
source: "iana",
compressible: false,
extensions: [
"doc",
"dot"
]
},
"application/mud+json": {
source: "iana",
compressible: true
},
"application/multipart-core": {
source: "iana"
},
"application/mxf": {
source: "iana",
extensions: [
"mxf"
]
},
"application/n-quads": {
source: "iana",
extensions: [
"nq"
]
},
"application/n-triples": {
source: "iana",
extensions: [
"nt"
]
},
"application/nasdata": {
source: "iana"
},
"application/news-checkgroups": {
source: "iana",
charset: "US-ASCII"
},
"application/news-groupinfo": {
source: "iana",
charset: "US-ASCII"
},
"application/news-transmission": {
source: "iana"
},
"application/nlsml+xml": {
source: "iana",
compressible: true
},
"application/node": {
source: "iana",
extensions: [
"cjs"
]
},
"application/nss": {
source: "iana"
},
"application/oauth-authz-req+jwt": {
source: "iana"
},
"application/ocsp-request": {
source: "iana"
},
"application/ocsp-response": {
source: "iana"
},
"application/octet-stream": {
source: "iana",
compressible: false,
extensions: [
"bin",
"dms",
"lrf",
"mar",
"so",
"dist",
"distz",
"pkg",
"bpk",
"dump",
"elc",
"deploy",
"exe",
"dll",
"deb",
"dmg",
"iso",
"img",
"msi",
"msp",
"msm",
"buffer"
]
},
"application/oda": {
source: "iana",
extensions: [
"oda"
]
},
"application/odm+xml": {
source: "iana",
compressible: true
},
"application/odx": {
source: "iana"
},
"application/oebps-package+xml": {
source: "iana",
compressible: true,
extensions: [
"opf"
]
},
"application/ogg": {
source: "iana",
compressible: false,
extensions: [
"ogx"
]
},
"application/omdoc+xml": {
source: "apache",
compressible: true,
extensions: [
"omdoc"
]
},
"application/onenote": {
source: "apache",
extensions: [
"onetoc",
"onetoc2",
"onetmp",
"onepkg"
]
},
"application/opc-nodeset+xml": {
source: "iana",
compressible: true
},
"application/oscore": {
source: "iana"
},
"application/oxps": {
source: "iana",
extensions: [
"oxps"
]
},
"application/p21": {
source: "iana"
},
"application/p21+zip": {
source: "iana",
compressible: false
},
"application/p2p-overlay+xml": {
source: "iana",
compressible: true,
extensions: [
"relo"
]
},
"application/parityfec": {
source: "iana"
},
"application/passport": {
source: "iana"
},
"application/patch-ops-error+xml": {
source: "iana",
compressible: true,
extensions: [
"xer"
]
},
"application/pdf": {
source: "iana",
compressible: false,
extensions: [
"pdf"
]
},
"application/pdx": {
source: "iana"
},
"application/pem-certificate-chain": {
source: "iana"
},
"application/pgp-encrypted": {
source: "iana",
compressible: false,
extensions: [
"pgp"
]
},
"application/pgp-keys": {
source: "iana"
},
"application/pgp-signature": {
source: "iana",
extensions: [
"asc",
"sig"
]
},
"application/pics-rules": {
source: "apache",
extensions: [
"prf"
]
},
"application/pidf+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/pidf-diff+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/pkcs10": {
source: "iana",
extensions: [
"p10"
]
},
"application/pkcs12": {
source: "iana"
},
"application/pkcs7-mime": {
source: "iana",
extensions: [
"p7m",
"p7c"
]
},
"application/pkcs7-signature": {
source: "iana",
extensions: [
"p7s"
]
},
"application/pkcs8": {
source: "iana",
extensions: [
"p8"
]
},
"application/pkcs8-encrypted": {
source: "iana"
},
"application/pkix-attr-cert": {
source: "iana",
extensions: [
"ac"
]
},
"application/pkix-cert": {
source: "iana",
extensions: [
"cer"
]
},
"application/pkix-crl": {
source: "iana",
extensions: [
"crl"
]
},
"application/pkix-pkipath": {
source: "iana",
extensions: [
"pkipath"
]
},
"application/pkixcmp": {
source: "iana",
extensions: [
"pki"
]
},
"application/pls+xml": {
source: "iana",
compressible: true,
extensions: [
"pls"
]
},
"application/poc-settings+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/postscript": {
source: "iana",
compressible: true,
extensions: [
"ai",
"eps",
"ps"
]
},
"application/ppsp-tracker+json": {
source: "iana",
compressible: true
},
"application/problem+json": {
source: "iana",
compressible: true
},
"application/problem+xml": {
source: "iana",
compressible: true
},
"application/provenance+xml": {
source: "iana",
compressible: true,
extensions: [
"provx"
]
},
"application/prs.alvestrand.titrax-sheet": {
source: "iana"
},
"application/prs.cww": {
source: "iana",
extensions: [
"cww"
]
},
"application/prs.cyn": {
source: "iana",
charset: "7-BIT"
},
"application/prs.hpub+zip": {
source: "iana",
compressible: false
},
"application/prs.nprend": {
source: "iana"
},
"application/prs.plucker": {
source: "iana"
},
"application/prs.rdf-xml-crypt": {
source: "iana"
},
"application/prs.xsf+xml": {
source: "iana",
compressible: true
},
"application/pskc+xml": {
source: "iana",
compressible: true,
extensions: [
"pskcxml"
]
},
"application/pvd+json": {
source: "iana",
compressible: true
},
"application/qsig": {
source: "iana"
},
"application/raml+yaml": {
compressible: true,
extensions: [
"raml"
]
},
"application/raptorfec": {
source: "iana"
},
"application/rdap+json": {
source: "iana",
compressible: true
},
"application/rdf+xml": {
source: "iana",
compressible: true,
extensions: [
"rdf",
"owl"
]
},
"application/reginfo+xml": {
source: "iana",
compressible: true,
extensions: [
"rif"
]
},
"application/relax-ng-compact-syntax": {
source: "iana",
extensions: [
"rnc"
]
},
"application/remote-printing": {
source: "iana"
},
"application/reputon+json": {
source: "iana",
compressible: true
},
"application/resource-lists+xml": {
source: "iana",
compressible: true,
extensions: [
"rl"
]
},
"application/resource-lists-diff+xml": {
source: "iana",
compressible: true,
extensions: [
"rld"
]
},
"application/rfc+xml": {
source: "iana",
compressible: true
},
"application/riscos": {
source: "iana"
},
"application/rlmi+xml": {
source: "iana",
compressible: true
},
"application/rls-services+xml": {
source: "iana",
compressible: true,
extensions: [
"rs"
]
},
"application/route-apd+xml": {
source: "iana",
compressible: true,
extensions: [
"rapd"
]
},
"application/route-s-tsid+xml": {
source: "iana",
compressible: true,
extensions: [
"sls"
]
},
"application/route-usd+xml": {
source: "iana",
compressible: true,
extensions: [
"rusd"
]
},
"application/rpki-ghostbusters": {
source: "iana",
extensions: [
"gbr"
]
},
"application/rpki-manifest": {
source: "iana",
extensions: [
"mft"
]
},
"application/rpki-publication": {
source: "iana"
},
"application/rpki-roa": {
source: "iana",
extensions: [
"roa"
]
},
"application/rpki-updown": {
source: "iana"
},
"application/rsd+xml": {
source: "apache",
compressible: true,
extensions: [
"rsd"
]
},
"application/rss+xml": {
source: "apache",
compressible: true,
extensions: [
"rss"
]
},
"application/rtf": {
source: "iana",
compressible: true,
extensions: [
"rtf"
]
},
"application/rtploopback": {
source: "iana"
},
"application/rtx": {
source: "iana"
},
"application/samlassertion+xml": {
source: "iana",
compressible: true
},
"application/samlmetadata+xml": {
source: "iana",
compressible: true
},
"application/sarif+json": {
source: "iana",
compressible: true
},
"application/sarif-external-properties+json": {
source: "iana",
compressible: true
},
"application/sbe": {
source: "iana"
},
"application/sbml+xml": {
source: "iana",
compressible: true,
extensions: [
"sbml"
]
},
"application/scaip+xml": {
source: "iana",
compressible: true
},
"application/scim+json": {
source: "iana",
compressible: true
},
"application/scvp-cv-request": {
source: "iana",
extensions: [
"scq"
]
},
"application/scvp-cv-response": {
source: "iana",
extensions: [
"scs"
]
},
"application/scvp-vp-request": {
source: "iana",
extensions: [
"spq"
]
},
"application/scvp-vp-response": {
source: "iana",
extensions: [
"spp"
]
},
"application/sdp": {
source: "iana",
extensions: [
"sdp"
]
},
"application/secevent+jwt": {
source: "iana"
},
"application/senml+cbor": {
source: "iana"
},
"application/senml+json": {
source: "iana",
compressible: true
},
"application/senml+xml": {
source: "iana",
compressible: true,
extensions: [
"senmlx"
]
},
"application/senml-etch+cbor": {
source: "iana"
},
"application/senml-etch+json": {
source: "iana",
compressible: true
},
"application/senml-exi": {
source: "iana"
},
"application/sensml+cbor": {
source: "iana"
},
"application/sensml+json": {
source: "iana",
compressible: true
},
"application/sensml+xml": {
source: "iana",
compressible: true,
extensions: [
"sensmlx"
]
},
"application/sensml-exi": {
source: "iana"
},
"application/sep+xml": {
source: "iana",
compressible: true
},
"application/sep-exi": {
source: "iana"
},
"application/session-info": {
source: "iana"
},
"application/set-payment": {
source: "iana"
},
"application/set-payment-initiation": {
source: "iana",
extensions: [
"setpay"
]
},
"application/set-registration": {
source: "iana"
},
"application/set-registration-initiation": {
source: "iana",
extensions: [
"setreg"
]
},
"application/sgml": {
source: "iana"
},
"application/sgml-open-catalog": {
source: "iana"
},
"application/shf+xml": {
source: "iana",
compressible: true,
extensions: [
"shf"
]
},
"application/sieve": {
source: "iana",
extensions: [
"siv",
"sieve"
]
},
"application/simple-filter+xml": {
source: "iana",
compressible: true
},
"application/simple-message-summary": {
source: "iana"
},
"application/simplesymbolcontainer": {
source: "iana"
},
"application/sipc": {
source: "iana"
},
"application/slate": {
source: "iana"
},
"application/smil": {
source: "iana"
},
"application/smil+xml": {
source: "iana",
compressible: true,
extensions: [
"smi",
"smil"
]
},
"application/smpte336m": {
source: "iana"
},
"application/soap+fastinfoset": {
source: "iana"
},
"application/soap+xml": {
source: "iana",
compressible: true
},
"application/sparql-query": {
source: "iana",
extensions: [
"rq"
]
},
"application/sparql-results+xml": {
source: "iana",
compressible: true,
extensions: [
"srx"
]
},
"application/spdx+json": {
source: "iana",
compressible: true
},
"application/spirits-event+xml": {
source: "iana",
compressible: true
},
"application/sql": {
source: "iana"
},
"application/srgs": {
source: "iana",
extensions: [
"gram"
]
},
"application/srgs+xml": {
source: "iana",
compressible: true,
extensions: [
"grxml"
]
},
"application/sru+xml": {
source: "iana",
compressible: true,
extensions: [
"sru"
]
},
"application/ssdl+xml": {
source: "apache",
compressible: true,
extensions: [
"ssdl"
]
},
"application/ssml+xml": {
source: "iana",
compressible: true,
extensions: [
"ssml"
]
},
"application/stix+json": {
source: "iana",
compressible: true
},
"application/swid+xml": {
source: "iana",
compressible: true,
extensions: [
"swidtag"
]
},
"application/tamp-apex-update": {
source: "iana"
},
"application/tamp-apex-update-confirm": {
source: "iana"
},
"application/tamp-community-update": {
source: "iana"
},
"application/tamp-community-update-confirm": {
source: "iana"
},
"application/tamp-error": {
source: "iana"
},
"application/tamp-sequence-adjust": {
source: "iana"
},
"application/tamp-sequence-adjust-confirm": {
source: "iana"
},
"application/tamp-status-query": {
source: "iana"
},
"application/tamp-status-response": {
source: "iana"
},
"application/tamp-update": {
source: "iana"
},
"application/tamp-update-confirm": {
source: "iana"
},
"application/tar": {
compressible: true
},
"application/taxii+json": {
source: "iana",
compressible: true
},
"application/td+json": {
source: "iana",
compressible: true
},
"application/tei+xml": {
source: "iana",
compressible: true,
extensions: [
"tei",
"teicorpus"
]
},
"application/tetra_isi": {
source: "iana"
},
"application/thraud+xml": {
source: "iana",
compressible: true,
extensions: [
"tfi"
]
},
"application/timestamp-query": {
source: "iana"
},
"application/timestamp-reply": {
source: "iana"
},
"application/timestamped-data": {
source: "iana",
extensions: [
"tsd"
]
},
"application/tlsrpt+gzip": {
source: "iana"
},
"application/tlsrpt+json": {
source: "iana",
compressible: true
},
"application/tnauthlist": {
source: "iana"
},
"application/token-introspection+jwt": {
source: "iana"
},
"application/toml": {
compressible: true,
extensions: [
"toml"
]
},
"application/trickle-ice-sdpfrag": {
source: "iana"
},
"application/trig": {
source: "iana",
extensions: [
"trig"
]
},
"application/ttml+xml": {
source: "iana",
compressible: true,
extensions: [
"ttml"
]
},
"application/tve-trigger": {
source: "iana"
},
"application/tzif": {
source: "iana"
},
"application/tzif-leap": {
source: "iana"
},
"application/ubjson": {
compressible: false,
extensions: [
"ubj"
]
},
"application/ulpfec": {
source: "iana"
},
"application/urc-grpsheet+xml": {
source: "iana",
compressible: true
},
"application/urc-ressheet+xml": {
source: "iana",
compressible: true,
extensions: [
"rsheet"
]
},
"application/urc-targetdesc+xml": {
source: "iana",
compressible: true,
extensions: [
"td"
]
},
"application/urc-uisocketdesc+xml": {
source: "iana",
compressible: true
},
"application/vcard+json": {
source: "iana",
compressible: true
},
"application/vcard+xml": {
source: "iana",
compressible: true
},
"application/vemmi": {
source: "iana"
},
"application/vividence.scriptfile": {
source: "apache"
},
"application/vnd.1000minds.decision-model+xml": {
source: "iana",
compressible: true,
extensions: [
"1km"
]
},
"application/vnd.3gpp-prose+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp-prose-pc3ch+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp-v2x-local-service-information": {
source: "iana"
},
"application/vnd.3gpp.5gnas": {
source: "iana"
},
"application/vnd.3gpp.access-transfer-events+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.bsf+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.gmop+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.gtpc": {
source: "iana"
},
"application/vnd.3gpp.interworking-data": {
source: "iana"
},
"application/vnd.3gpp.lpp": {
source: "iana"
},
"application/vnd.3gpp.mc-signalling-ear": {
source: "iana"
},
"application/vnd.3gpp.mcdata-affiliation-command+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcdata-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcdata-payload": {
source: "iana"
},
"application/vnd.3gpp.mcdata-service-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcdata-signalling": {
source: "iana"
},
"application/vnd.3gpp.mcdata-ue-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcdata-user-profile+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-affiliation-command+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-floor-request+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-location-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-mbms-usage-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-service-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-signed+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-ue-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-ue-init-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcptt-user-profile+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-affiliation-command+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-affiliation-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-location-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-mbms-usage-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-service-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-transmission-request+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-ue-config+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mcvideo-user-profile+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.mid-call+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.ngap": {
source: "iana"
},
"application/vnd.3gpp.pfcp": {
source: "iana"
},
"application/vnd.3gpp.pic-bw-large": {
source: "iana",
extensions: [
"plb"
]
},
"application/vnd.3gpp.pic-bw-small": {
source: "iana",
extensions: [
"psb"
]
},
"application/vnd.3gpp.pic-bw-var": {
source: "iana",
extensions: [
"pvb"
]
},
"application/vnd.3gpp.s1ap": {
source: "iana"
},
"application/vnd.3gpp.sms": {
source: "iana"
},
"application/vnd.3gpp.sms+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.srvcc-ext+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.srvcc-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.state-and-event-info+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp.ussd+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp2.bcmcsinfo+xml": {
source: "iana",
compressible: true
},
"application/vnd.3gpp2.sms": {
source: "iana"
},
"application/vnd.3gpp2.tcap": {
source: "iana",
extensions: [
"tcap"
]
},
"application/vnd.3lightssoftware.imagescal": {
source: "iana"
},
"application/vnd.3m.post-it-notes": {
source: "iana",
extensions: [
"pwn"
]
},
"application/vnd.accpac.simply.aso": {
source: "iana",
extensions: [
"aso"
]
},
"application/vnd.accpac.simply.imp": {
source: "iana",
extensions: [
"imp"
]
},
"application/vnd.acucobol": {
source: "iana",
extensions: [
"acu"
]
},
"application/vnd.acucorp": {
source: "iana",
extensions: [
"atc",
"acutc"
]
},
"application/vnd.adobe.air-application-installer-package+zip": {
source: "apache",
compressible: false,
extensions: [
"air"
]
},
"application/vnd.adobe.flash.movie": {
source: "iana"
},
"application/vnd.adobe.formscentral.fcdt": {
source: "iana",
extensions: [
"fcdt"
]
},
"application/vnd.adobe.fxp": {
source: "iana",
extensions: [
"fxp",
"fxpl"
]
},
"application/vnd.adobe.partial-upload": {
source: "iana"
},
"application/vnd.adobe.xdp+xml": {
source: "iana",
compressible: true,
extensions: [
"xdp"
]
},
"application/vnd.adobe.xfdf": {
source: "iana",
extensions: [
"xfdf"
]
},
"application/vnd.aether.imp": {
source: "iana"
},
"application/vnd.afpc.afplinedata": {
source: "iana"
},
"application/vnd.afpc.afplinedata-pagedef": {
source: "iana"
},
"application/vnd.afpc.cmoca-cmresource": {
source: "iana"
},
"application/vnd.afpc.foca-charset": {
source: "iana"
},
"application/vnd.afpc.foca-codedfont": {
source: "iana"
},
"application/vnd.afpc.foca-codepage": {
source: "iana"
},
"application/vnd.afpc.modca": {
source: "iana"
},
"application/vnd.afpc.modca-cmtable": {
source: "iana"
},
"application/vnd.afpc.modca-formdef": {
source: "iana"
},
"application/vnd.afpc.modca-mediummap": {
source: "iana"
},
"application/vnd.afpc.modca-objectcontainer": {
source: "iana"
},
"application/vnd.afpc.modca-overlay": {
source: "iana"
},
"application/vnd.afpc.modca-pagesegment": {
source: "iana"
},
"application/vnd.age": {
source: "iana",
extensions: [
"age"
]
},
"application/vnd.ah-barcode": {
source: "iana"
},
"application/vnd.ahead.space": {
source: "iana",
extensions: [
"ahead"
]
},
"application/vnd.airzip.filesecure.azf": {
source: "iana",
extensions: [
"azf"
]
},
"application/vnd.airzip.filesecure.azs": {
source: "iana",
extensions: [
"azs"
]
},
"application/vnd.amadeus+json": {
source: "iana",
compressible: true
},
"application/vnd.amazon.ebook": {
source: "apache",
extensions: [
"azw"
]
},
"application/vnd.amazon.mobi8-ebook": {
source: "iana"
},
"application/vnd.americandynamics.acc": {
source: "iana",
extensions: [
"acc"
]
},
"application/vnd.amiga.ami": {
source: "iana",
extensions: [
"ami"
]
},
"application/vnd.amundsen.maze+xml": {
source: "iana",
compressible: true
},
"application/vnd.android.ota": {
source: "iana"
},
"application/vnd.android.package-archive": {
source: "apache",
compressible: false,
extensions: [
"apk"
]
},
"application/vnd.anki": {
source: "iana"
},
"application/vnd.anser-web-certificate-issue-initiation": {
source: "iana",
extensions: [
"cii"
]
},
"application/vnd.anser-web-funds-transfer-initiation": {
source: "apache",
extensions: [
"fti"
]
},
"application/vnd.antix.game-component": {
source: "iana",
extensions: [
"atx"
]
},
"application/vnd.apache.arrow.file": {
source: "iana"
},
"application/vnd.apache.arrow.stream": {
source: "iana"
},
"application/vnd.apache.thrift.binary": {
source: "iana"
},
"application/vnd.apache.thrift.compact": {
source: "iana"
},
"application/vnd.apache.thrift.json": {
source: "iana"
},
"application/vnd.api+json": {
source: "iana",
compressible: true
},
"application/vnd.aplextor.warrp+json": {
source: "iana",
compressible: true
},
"application/vnd.apothekende.reservation+json": {
source: "iana",
compressible: true
},
"application/vnd.apple.installer+xml": {
source: "iana",
compressible: true,
extensions: [
"mpkg"
]
},
"application/vnd.apple.keynote": {
source: "iana",
extensions: [
"key"
]
},
"application/vnd.apple.mpegurl": {
source: "iana",
extensions: [
"m3u8"
]
},
"application/vnd.apple.numbers": {
source: "iana",
extensions: [
"numbers"
]
},
"application/vnd.apple.pages": {
source: "iana",
extensions: [
"pages"
]
},
"application/vnd.apple.pkpass": {
compressible: false,
extensions: [
"pkpass"
]
},
"application/vnd.arastra.swi": {
source: "iana"
},
"application/vnd.aristanetworks.swi": {
source: "iana",
extensions: [
"swi"
]
},
"application/vnd.artisan+json": {
source: "iana",
compressible: true
},
"application/vnd.artsquare": {
source: "iana"
},
"application/vnd.astraea-software.iota": {
source: "iana",
extensions: [
"iota"
]
},
"application/vnd.audiograph": {
source: "iana",
extensions: [
"aep"
]
},
"application/vnd.autopackage": {
source: "iana"
},
"application/vnd.avalon+json": {
source: "iana",
compressible: true
},
"application/vnd.avistar+xml": {
source: "iana",
compressible: true
},
"application/vnd.balsamiq.bmml+xml": {
source: "iana",
compressible: true,
extensions: [
"bmml"
]
},
"application/vnd.balsamiq.bmpr": {
source: "iana"
},
"application/vnd.banana-accounting": {
source: "iana"
},
"application/vnd.bbf.usp.error": {
source: "iana"
},
"application/vnd.bbf.usp.msg": {
source: "iana"
},
"application/vnd.bbf.usp.msg+json": {
source: "iana",
compressible: true
},
"application/vnd.bekitzur-stech+json": {
source: "iana",
compressible: true
},
"application/vnd.bint.med-content": {
source: "iana"
},
"application/vnd.biopax.rdf+xml": {
source: "iana",
compressible: true
},
"application/vnd.blink-idb-value-wrapper": {
source: "iana"
},
"application/vnd.blueice.multipass": {
source: "iana",
extensions: [
"mpm"
]
},
"application/vnd.bluetooth.ep.oob": {
source: "iana"
},
"application/vnd.bluetooth.le.oob": {
source: "iana"
},
"application/vnd.bmi": {
source: "iana",
extensions: [
"bmi"
]
},
"application/vnd.bpf": {
source: "iana"
},
"application/vnd.bpf3": {
source: "iana"
},
"application/vnd.businessobjects": {
source: "iana",
extensions: [
"rep"
]
},
"application/vnd.byu.uapi+json": {
source: "iana",
compressible: true
},
"application/vnd.cab-jscript": {
source: "iana"
},
"application/vnd.canon-cpdl": {
source: "iana"
},
"application/vnd.canon-lips": {
source: "iana"
},
"application/vnd.capasystems-pg+json": {
source: "iana",
compressible: true
},
"application/vnd.cendio.thinlinc.clientconf": {
source: "iana"
},
"application/vnd.century-systems.tcp_stream": {
source: "iana"
},
"application/vnd.chemdraw+xml": {
source: "iana",
compressible: true,
extensions: [
"cdxml"
]
},
"application/vnd.chess-pgn": {
source: "iana"
},
"application/vnd.chipnuts.karaoke-mmd": {
source: "iana",
extensions: [
"mmd"
]
},
"application/vnd.ciedi": {
source: "iana"
},
"application/vnd.cinderella": {
source: "iana",
extensions: [
"cdy"
]
},
"application/vnd.cirpack.isdn-ext": {
source: "iana"
},
"application/vnd.citationstyles.style+xml": {
source: "iana",
compressible: true,
extensions: [
"csl"
]
},
"application/vnd.claymore": {
source: "iana",
extensions: [
"cla"
]
},
"application/vnd.cloanto.rp9": {
source: "iana",
extensions: [
"rp9"
]
},
"application/vnd.clonk.c4group": {
source: "iana",
extensions: [
"c4g",
"c4d",
"c4f",
"c4p",
"c4u"
]
},
"application/vnd.cluetrust.cartomobile-config": {
source: "iana",
extensions: [
"c11amc"
]
},
"application/vnd.cluetrust.cartomobile-config-pkg": {
source: "iana",
extensions: [
"c11amz"
]
},
"application/vnd.coffeescript": {
source: "iana"
},
"application/vnd.collabio.xodocuments.document": {
source: "iana"
},
"application/vnd.collabio.xodocuments.document-template": {
source: "iana"
},
"application/vnd.collabio.xodocuments.presentation": {
source: "iana"
},
"application/vnd.collabio.xodocuments.presentation-template": {
source: "iana"
},
"application/vnd.collabio.xodocuments.spreadsheet": {
source: "iana"
},
"application/vnd.collabio.xodocuments.spreadsheet-template": {
source: "iana"
},
"application/vnd.collection+json": {
source: "iana",
compressible: true
},
"application/vnd.collection.doc+json": {
source: "iana",
compressible: true
},
"application/vnd.collection.next+json": {
source: "iana",
compressible: true
},
"application/vnd.comicbook+zip": {
source: "iana",
compressible: false
},
"application/vnd.comicbook-rar": {
source: "iana"
},
"application/vnd.commerce-battelle": {
source: "iana"
},
"application/vnd.commonspace": {
source: "iana",
extensions: [
"csp"
]
},
"application/vnd.contact.cmsg": {
source: "iana",
extensions: [
"cdbcmsg"
]
},
"application/vnd.coreos.ignition+json": {
source: "iana",
compressible: true
},
"application/vnd.cosmocaller": {
source: "iana",
extensions: [
"cmc"
]
},
"application/vnd.crick.clicker": {
source: "iana",
extensions: [
"clkx"
]
},
"application/vnd.crick.clicker.keyboard": {
source: "iana",
extensions: [
"clkk"
]
},
"application/vnd.crick.clicker.palette": {
source: "iana",
extensions: [
"clkp"
]
},
"application/vnd.crick.clicker.template": {
source: "iana",
extensions: [
"clkt"
]
},
"application/vnd.crick.clicker.wordbank": {
source: "iana",
extensions: [
"clkw"
]
},
"application/vnd.criticaltools.wbs+xml": {
source: "iana",
compressible: true,
extensions: [
"wbs"
]
},
"application/vnd.cryptii.pipe+json": {
source: "iana",
compressible: true
},
"application/vnd.crypto-shade-file": {
source: "iana"
},
"application/vnd.cryptomator.encrypted": {
source: "iana"
},
"application/vnd.cryptomator.vault": {
source: "iana"
},
"application/vnd.ctc-posml": {
source: "iana",
extensions: [
"pml"
]
},
"application/vnd.ctct.ws+xml": {
source: "iana",
compressible: true
},
"application/vnd.cups-pdf": {
source: "iana"
},
"application/vnd.cups-postscript": {
source: "iana"
},
"application/vnd.cups-ppd": {
source: "iana",
extensions: [
"ppd"
]
},
"application/vnd.cups-raster": {
source: "iana"
},
"application/vnd.cups-raw": {
source: "iana"
},
"application/vnd.curl": {
source: "iana"
},
"application/vnd.curl.car": {
source: "apache",
extensions: [
"car"
]
},
"application/vnd.curl.pcurl": {
source: "apache",
extensions: [
"pcurl"
]
},
"application/vnd.cyan.dean.root+xml": {
source: "iana",
compressible: true
},
"application/vnd.cybank": {
source: "iana"
},
"application/vnd.cyclonedx+json": {
source: "iana",
compressible: true
},
"application/vnd.cyclonedx+xml": {
source: "iana",
compressible: true
},
"application/vnd.d2l.coursepackage1p0+zip": {
source: "iana",
compressible: false
},
"application/vnd.d3m-dataset": {
source: "iana"
},
"application/vnd.d3m-problem": {
source: "iana"
},
"application/vnd.dart": {
source: "iana",
compressible: true,
extensions: [
"dart"
]
},
"application/vnd.data-vision.rdz": {
source: "iana",
extensions: [
"rdz"
]
},
"application/vnd.datapackage+json": {
source: "iana",
compressible: true
},
"application/vnd.dataresource+json": {
source: "iana",
compressible: true
},
"application/vnd.dbf": {
source: "iana",
extensions: [
"dbf"
]
},
"application/vnd.debian.binary-package": {
source: "iana"
},
"application/vnd.dece.data": {
source: "iana",
extensions: [
"uvf",
"uvvf",
"uvd",
"uvvd"
]
},
"application/vnd.dece.ttml+xml": {
source: "iana",
compressible: true,
extensions: [
"uvt",
"uvvt"
]
},
"application/vnd.dece.unspecified": {
source: "iana",
extensions: [
"uvx",
"uvvx"
]
},
"application/vnd.dece.zip": {
source: "iana",
extensions: [
"uvz",
"uvvz"
]
},
"application/vnd.denovo.fcselayout-link": {
source: "iana",
extensions: [
"fe_launch"
]
},
"application/vnd.desmume.movie": {
source: "iana"
},
"application/vnd.dir-bi.plate-dl-nosuffix": {
source: "iana"
},
"application/vnd.dm.delegation+xml": {
source: "iana",
compressible: true
},
"application/vnd.dna": {
source: "iana",
extensions: [
"dna"
]
},
"application/vnd.document+json": {
source: "iana",
compressible: true
},
"application/vnd.dolby.mlp": {
source: "apache",
extensions: [
"mlp"
]
},
"application/vnd.dolby.mobile.1": {
source: "iana"
},
"application/vnd.dolby.mobile.2": {
source: "iana"
},
"application/vnd.doremir.scorecloud-binary-document": {
source: "iana"
},
"application/vnd.dpgraph": {
source: "iana",
extensions: [
"dpg"
]
},
"application/vnd.dreamfactory": {
source: "iana",
extensions: [
"dfac"
]
},
"application/vnd.drive+json": {
source: "iana",
compressible: true
},
"application/vnd.ds-keypoint": {
source: "apache",
extensions: [
"kpxx"
]
},
"application/vnd.dtg.local": {
source: "iana"
},
"application/vnd.dtg.local.flash": {
source: "iana"
},
"application/vnd.dtg.local.html": {
source: "iana"
},
"application/vnd.dvb.ait": {
source: "iana",
extensions: [
"ait"
]
},
"application/vnd.dvb.dvbisl+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.dvbj": {
source: "iana"
},
"application/vnd.dvb.esgcontainer": {
source: "iana"
},
"application/vnd.dvb.ipdcdftnotifaccess": {
source: "iana"
},
"application/vnd.dvb.ipdcesgaccess": {
source: "iana"
},
"application/vnd.dvb.ipdcesgaccess2": {
source: "iana"
},
"application/vnd.dvb.ipdcesgpdd": {
source: "iana"
},
"application/vnd.dvb.ipdcroaming": {
source: "iana"
},
"application/vnd.dvb.iptv.alfec-base": {
source: "iana"
},
"application/vnd.dvb.iptv.alfec-enhancement": {
source: "iana"
},
"application/vnd.dvb.notif-aggregate-root+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-container+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-generic+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-ia-msglist+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-ia-registration-request+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-ia-registration-response+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.notif-init+xml": {
source: "iana",
compressible: true
},
"application/vnd.dvb.pfr": {
source: "iana"
},
"application/vnd.dvb.service": {
source: "iana",
extensions: [
"svc"
]
},
"application/vnd.dxr": {
source: "iana"
},
"application/vnd.dynageo": {
source: "iana",
extensions: [
"geo"
]
},
"application/vnd.dzr": {
source: "iana"
},
"application/vnd.easykaraoke.cdgdownload": {
source: "iana"
},
"application/vnd.ecdis-update": {
source: "iana"
},
"application/vnd.ecip.rlp": {
source: "iana"
},
"application/vnd.ecowin.chart": {
source: "iana",
extensions: [
"mag"
]
},
"application/vnd.ecowin.filerequest": {
source: "iana"
},
"application/vnd.ecowin.fileupdate": {
source: "iana"
},
"application/vnd.ecowin.series": {
source: "iana"
},
"application/vnd.ecowin.seriesrequest": {
source: "iana"
},
"application/vnd.ecowin.seriesupdate": {
source: "iana"
},
"application/vnd.efi.img": {
source: "iana"
},
"application/vnd.efi.iso": {
source: "iana"
},
"application/vnd.emclient.accessrequest+xml": {
source: "iana",
compressible: true
},
"application/vnd.enliven": {
source: "iana",
extensions: [
"nml"
]
},
"application/vnd.enphase.envoy": {
source: "iana"
},
"application/vnd.eprints.data+xml": {
source: "iana",
compressible: true
},
"application/vnd.epson.esf": {
source: "iana",
extensions: [
"esf"
]
},
"application/vnd.epson.msf": {
source: "iana",
extensions: [
"msf"
]
},
"application/vnd.epson.quickanime": {
source: "iana",
extensions: [
"qam"
]
},
"application/vnd.epson.salt": {
source: "iana",
extensions: [
"slt"
]
},
"application/vnd.epson.ssf": {
source: "iana",
extensions: [
"ssf"
]
},
"application/vnd.ericsson.quickcall": {
source: "iana"
},
"application/vnd.espass-espass+zip": {
source: "iana",
compressible: false
},
"application/vnd.eszigno3+xml": {
source: "iana",
compressible: true,
extensions: [
"es3",
"et3"
]
},
"application/vnd.etsi.aoc+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.asic-e+zip": {
source: "iana",
compressible: false
},
"application/vnd.etsi.asic-s+zip": {
source: "iana",
compressible: false
},
"application/vnd.etsi.cug+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvcommand+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvdiscovery+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvprofile+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvsad-bc+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvsad-cod+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvsad-npvr+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvservice+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvsync+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.iptvueprofile+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.mcid+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.mheg5": {
source: "iana"
},
"application/vnd.etsi.overload-control-policy-dataset+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.pstn+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.sci+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.simservs+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.timestamp-token": {
source: "iana"
},
"application/vnd.etsi.tsl+xml": {
source: "iana",
compressible: true
},
"application/vnd.etsi.tsl.der": {
source: "iana"
},
"application/vnd.eudora.data": {
source: "iana"
},
"application/vnd.evolv.ecig.profile": {
source: "iana"
},
"application/vnd.evolv.ecig.settings": {
source: "iana"
},
"application/vnd.evolv.ecig.theme": {
source: "iana"
},
"application/vnd.exstream-empower+zip": {
source: "iana",
compressible: false
},
"application/vnd.exstream-package": {
source: "iana"
},
"application/vnd.ezpix-album": {
source: "iana",
extensions: [
"ez2"
]
},
"application/vnd.ezpix-package": {
source: "iana",
extensions: [
"ez3"
]
},
"application/vnd.f-secure.mobile": {
source: "iana"
},
"application/vnd.fastcopy-disk-image": {
source: "iana"
},
"application/vnd.fdf": {
source: "iana",
extensions: [
"fdf"
]
},
"application/vnd.fdsn.mseed": {
source: "iana",
extensions: [
"mseed"
]
},
"application/vnd.fdsn.seed": {
source: "iana",
extensions: [
"seed",
"dataless"
]
},
"application/vnd.ffsns": {
source: "iana"
},
"application/vnd.ficlab.flb+zip": {
source: "iana",
compressible: false
},
"application/vnd.filmit.zfc": {
source: "iana"
},
"application/vnd.fints": {
source: "iana"
},
"application/vnd.firemonkeys.cloudcell": {
source: "iana"
},
"application/vnd.flographit": {
source: "iana",
extensions: [
"gph"
]
},
"application/vnd.fluxtime.clip": {
source: "iana",
extensions: [
"ftc"
]
},
"application/vnd.font-fontforge-sfd": {
source: "iana"
},
"application/vnd.framemaker": {
source: "iana",
extensions: [
"fm",
"frame",
"maker",
"book"
]
},
"application/vnd.frogans.fnc": {
source: "iana",
extensions: [
"fnc"
]
},
"application/vnd.frogans.ltf": {
source: "iana",
extensions: [
"ltf"
]
},
"application/vnd.fsc.weblaunch": {
source: "iana",
extensions: [
"fsc"
]
},
"application/vnd.fujifilm.fb.docuworks": {
source: "iana"
},
"application/vnd.fujifilm.fb.docuworks.binder": {
source: "iana"
},
"application/vnd.fujifilm.fb.docuworks.container": {
source: "iana"
},
"application/vnd.fujifilm.fb.jfi+xml": {
source: "iana",
compressible: true
},
"application/vnd.fujitsu.oasys": {
source: "iana",
extensions: [
"oas"
]
},
"application/vnd.fujitsu.oasys2": {
source: "iana",
extensions: [
"oa2"
]
},
"application/vnd.fujitsu.oasys3": {
source: "iana",
extensions: [
"oa3"
]
},
"application/vnd.fujitsu.oasysgp": {
source: "iana",
extensions: [
"fg5"
]
},
"application/vnd.fujitsu.oasysprs": {
source: "iana",
extensions: [
"bh2"
]
},
"application/vnd.fujixerox.art-ex": {
source: "iana"
},
"application/vnd.fujixerox.art4": {
source: "iana"
},
"application/vnd.fujixerox.ddd": {
source: "iana",
extensions: [
"ddd"
]
},
"application/vnd.fujixerox.docuworks": {
source: "iana",
extensions: [
"xdw"
]
},
"application/vnd.fujixerox.docuworks.binder": {
source: "iana",
extensions: [
"xbd"
]
},
"application/vnd.fujixerox.docuworks.container": {
source: "iana"
},
"application/vnd.fujixerox.hbpl": {
source: "iana"
},
"application/vnd.fut-misnet": {
source: "iana"
},
"application/vnd.futoin+cbor": {
source: "iana"
},
"application/vnd.futoin+json": {
source: "iana",
compressible: true
},
"application/vnd.fuzzysheet": {
source: "iana",
extensions: [
"fzs"
]
},
"application/vnd.genomatix.tuxedo": {
source: "iana",
extensions: [
"txd"
]
},
"application/vnd.gentics.grd+json": {
source: "iana",
compressible: true
},
"application/vnd.geo+json": {
source: "iana",
compressible: true
},
"application/vnd.geocube+xml": {
source: "iana",
compressible: true
},
"application/vnd.geogebra.file": {
source: "iana",
extensions: [
"ggb"
]
},
"application/vnd.geogebra.slides": {
source: "iana"
},
"application/vnd.geogebra.tool": {
source: "iana",
extensions: [
"ggt"
]
},
"application/vnd.geometry-explorer": {
source: "iana",
extensions: [
"gex",
"gre"
]
},
"application/vnd.geonext": {
source: "iana",
extensions: [
"gxt"
]
},
"application/vnd.geoplan": {
source: "iana",
extensions: [
"g2w"
]
},
"application/vnd.geospace": {
source: "iana",
extensions: [
"g3w"
]
},
"application/vnd.gerber": {
source: "iana"
},
"application/vnd.globalplatform.card-content-mgt": {
source: "iana"
},
"application/vnd.globalplatform.card-content-mgt-response": {
source: "iana"
},
"application/vnd.gmx": {
source: "iana",
extensions: [
"gmx"
]
},
"application/vnd.google-apps.document": {
compressible: false,
extensions: [
"gdoc"
]
},
"application/vnd.google-apps.presentation": {
compressible: false,
extensions: [
"gslides"
]
},
"application/vnd.google-apps.spreadsheet": {
compressible: false,
extensions: [
"gsheet"
]
},
"application/vnd.google-earth.kml+xml": {
source: "iana",
compressible: true,
extensions: [
"kml"
]
},
"application/vnd.google-earth.kmz": {
source: "iana",
compressible: false,
extensions: [
"kmz"
]
},
"application/vnd.gov.sk.e-form+xml": {
source: "iana",
compressible: true
},
"application/vnd.gov.sk.e-form+zip": {
source: "iana",
compressible: false
},
"application/vnd.gov.sk.xmldatacontainer+xml": {
source: "iana",
compressible: true
},
"application/vnd.grafeq": {
source: "iana",
extensions: [
"gqf",
"gqs"
]
},
"application/vnd.gridmp": {
source: "iana"
},
"application/vnd.groove-account": {
source: "iana",
extensions: [
"gac"
]
},
"application/vnd.groove-help": {
source: "iana",
extensions: [
"ghf"
]
},
"application/vnd.groove-identity-message": {
source: "iana",
extensions: [
"gim"
]
},
"application/vnd.groove-injector": {
source: "iana",
extensions: [
"grv"
]
},
"application/vnd.groove-tool-message": {
source: "iana",
extensions: [
"gtm"
]
},
"application/vnd.groove-tool-template": {
source: "iana",
extensions: [
"tpl"
]
},
"application/vnd.groove-vcard": {
source: "iana",
extensions: [
"vcg"
]
},
"application/vnd.hal+json": {
source: "iana",
compressible: true
},
"application/vnd.hal+xml": {
source: "iana",
compressible: true,
extensions: [
"hal"
]
},
"application/vnd.handheld-entertainment+xml": {
source: "iana",
compressible: true,
extensions: [
"zmm"
]
},
"application/vnd.hbci": {
source: "iana",
extensions: [
"hbci"
]
},
"application/vnd.hc+json": {
source: "iana",
compressible: true
},
"application/vnd.hcl-bireports": {
source: "iana"
},
"application/vnd.hdt": {
source: "iana"
},
"application/vnd.heroku+json": {
source: "iana",
compressible: true
},
"application/vnd.hhe.lesson-player": {
source: "iana",
extensions: [
"les"
]
},
"application/vnd.hp-hpgl": {
source: "iana",
extensions: [
"hpgl"
]
},
"application/vnd.hp-hpid": {
source: "iana",
extensions: [
"hpid"
]
},
"application/vnd.hp-hps": {
source: "iana",
extensions: [
"hps"
]
},
"application/vnd.hp-jlyt": {
source: "iana",
extensions: [
"jlt"
]
},
"application/vnd.hp-pcl": {
source: "iana",
extensions: [
"pcl"
]
},
"application/vnd.hp-pclxl": {
source: "iana",
extensions: [
"pclxl"
]
},
"application/vnd.httphone": {
source: "iana"
},
"application/vnd.hydrostatix.sof-data": {
source: "iana",
extensions: [
"sfd-hdstx"
]
},
"application/vnd.hyper+json": {
source: "iana",
compressible: true
},
"application/vnd.hyper-item+json": {
source: "iana",
compressible: true
},
"application/vnd.hyperdrive+json": {
source: "iana",
compressible: true
},
"application/vnd.hzn-3d-crossword": {
source: "iana"
},
"application/vnd.ibm.afplinedata": {
source: "iana"
},
"application/vnd.ibm.electronic-media": {
source: "iana"
},
"application/vnd.ibm.minipay": {
source: "iana",
extensions: [
"mpy"
]
},
"application/vnd.ibm.modcap": {
source: "iana",
extensions: [
"afp",
"listafp",
"list3820"
]
},
"application/vnd.ibm.rights-management": {
source: "iana",
extensions: [
"irm"
]
},
"application/vnd.ibm.secure-container": {
source: "iana",
extensions: [
"sc"
]
},
"application/vnd.iccprofile": {
source: "iana",
extensions: [
"icc",
"icm"
]
},
"application/vnd.ieee.1905": {
source: "iana"
},
"application/vnd.igloader": {
source: "iana",
extensions: [
"igl"
]
},
"application/vnd.imagemeter.folder+zip": {
source: "iana",
compressible: false
},
"application/vnd.imagemeter.image+zip": {
source: "iana",
compressible: false
},
"application/vnd.immervision-ivp": {
source: "iana",
extensions: [
"ivp"
]
},
"application/vnd.immervision-ivu": {
source: "iana",
extensions: [
"ivu"
]
},
"application/vnd.ims.imsccv1p1": {
source: "iana"
},
"application/vnd.ims.imsccv1p2": {
source: "iana"
},
"application/vnd.ims.imsccv1p3": {
source: "iana"
},
"application/vnd.ims.lis.v2.result+json": {
source: "iana",
compressible: true
},
"application/vnd.ims.lti.v2.toolconsumerprofile+json": {
source: "iana",
compressible: true
},
"application/vnd.ims.lti.v2.toolproxy+json": {
source: "iana",
compressible: true
},
"application/vnd.ims.lti.v2.toolproxy.id+json": {
source: "iana",
compressible: true
},
"application/vnd.ims.lti.v2.toolsettings+json": {
source: "iana",
compressible: true
},
"application/vnd.ims.lti.v2.toolsettings.simple+json": {
source: "iana",
compressible: true
},
"application/vnd.informedcontrol.rms+xml": {
source: "iana",
compressible: true
},
"application/vnd.informix-visionary": {
source: "iana"
},
"application/vnd.infotech.project": {
source: "iana"
},
"application/vnd.infotech.project+xml": {
source: "iana",
compressible: true
},
"application/vnd.innopath.wamp.notification": {
source: "iana"
},
"application/vnd.insors.igm": {
source: "iana",
extensions: [
"igm"
]
},
"application/vnd.intercon.formnet": {
source: "iana",
extensions: [
"xpw",
"xpx"
]
},
"application/vnd.intergeo": {
source: "iana",
extensions: [
"i2g"
]
},
"application/vnd.intertrust.digibox": {
source: "iana"
},
"application/vnd.intertrust.nncp": {
source: "iana"
},
"application/vnd.intu.qbo": {
source: "iana",
extensions: [
"qbo"
]
},
"application/vnd.intu.qfx": {
source: "iana",
extensions: [
"qfx"
]
},
"application/vnd.iptc.g2.catalogitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.conceptitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.knowledgeitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.newsitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.newsmessage+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.packageitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.iptc.g2.planningitem+xml": {
source: "iana",
compressible: true
},
"application/vnd.ipunplugged.rcprofile": {
source: "iana",
extensions: [
"rcprofile"
]
},
"application/vnd.irepository.package+xml": {
source: "iana",
compressible: true,
extensions: [
"irp"
]
},
"application/vnd.is-xpr": {
source: "iana",
extensions: [
"xpr"
]
},
"application/vnd.isac.fcs": {
source: "iana",
extensions: [
"fcs"
]
},
"application/vnd.iso11783-10+zip": {
source: "iana",
compressible: false
},
"application/vnd.jam": {
source: "iana",
extensions: [
"jam"
]
},
"application/vnd.japannet-directory-service": {
source: "iana"
},
"application/vnd.japannet-jpnstore-wakeup": {
source: "iana"
},
"application/vnd.japannet-payment-wakeup": {
source: "iana"
},
"application/vnd.japannet-registration": {
source: "iana"
},
"application/vnd.japannet-registration-wakeup": {
source: "iana"
},
"application/vnd.japannet-setstore-wakeup": {
source: "iana"
},
"application/vnd.japannet-verification": {
source: "iana"
},
"application/vnd.japannet-verification-wakeup": {
source: "iana"
},
"application/vnd.jcp.javame.midlet-rms": {
source: "iana",
extensions: [
"rms"
]
},
"application/vnd.jisp": {
source: "iana",
extensions: [
"jisp"
]
},
"application/vnd.joost.joda-archive": {
source: "iana",
extensions: [
"joda"
]
},
"application/vnd.jsk.isdn-ngn": {
source: "iana"
},
"application/vnd.kahootz": {
source: "iana",
extensions: [
"ktz",
"ktr"
]
},
"application/vnd.kde.karbon": {
source: "iana",
extensions: [
"karbon"
]
},
"application/vnd.kde.kchart": {
source: "iana",
extensions: [
"chrt"
]
},
"application/vnd.kde.kformula": {
source: "iana",
extensions: [
"kfo"
]
},
"application/vnd.kde.kivio": {
source: "iana",
extensions: [
"flw"
]
},
"application/vnd.kde.kontour": {
source: "iana",
extensions: [
"kon"
]
},
"application/vnd.kde.kpresenter": {
source: "iana",
extensions: [
"kpr",
"kpt"
]
},
"application/vnd.kde.kspread": {
source: "iana",
extensions: [
"ksp"
]
},
"application/vnd.kde.kword": {
source: "iana",
extensions: [
"kwd",
"kwt"
]
},
"application/vnd.kenameaapp": {
source: "iana",
extensions: [
"htke"
]
},
"application/vnd.kidspiration": {
source: "iana",
extensions: [
"kia"
]
},
"application/vnd.kinar": {
source: "iana",
extensions: [
"kne",
"knp"
]
},
"application/vnd.koan": {
source: "iana",
extensions: [
"skp",
"skd",
"skt",
"skm"
]
},
"application/vnd.kodak-descriptor": {
source: "iana",
extensions: [
"sse"
]
},
"application/vnd.las": {
source: "iana"
},
"application/vnd.las.las+json": {
source: "iana",
compressible: true
},
"application/vnd.las.las+xml": {
source: "iana",
compressible: true,
extensions: [
"lasxml"
]
},
"application/vnd.laszip": {
source: "iana"
},
"application/vnd.leap+json": {
source: "iana",
compressible: true
},
"application/vnd.liberty-request+xml": {
source: "iana",
compressible: true
},
"application/vnd.llamagraphics.life-balance.desktop": {
source: "iana",
extensions: [
"lbd"
]
},
"application/vnd.llamagraphics.life-balance.exchange+xml": {
source: "iana",
compressible: true,
extensions: [
"lbe"
]
},
"application/vnd.logipipe.circuit+zip": {
source: "iana",
compressible: false
},
"application/vnd.loom": {
source: "iana"
},
"application/vnd.lotus-1-2-3": {
source: "iana",
extensions: [
"123"
]
},
"application/vnd.lotus-approach": {
source: "iana",
extensions: [
"apr"
]
},
"application/vnd.lotus-freelance": {
source: "iana",
extensions: [
"pre"
]
},
"application/vnd.lotus-notes": {
source: "iana",
extensions: [
"nsf"
]
},
"application/vnd.lotus-organizer": {
source: "iana",
extensions: [
"org"
]
},
"application/vnd.lotus-screencam": {
source: "iana",
extensions: [
"scm"
]
},
"application/vnd.lotus-wordpro": {
source: "iana",
extensions: [
"lwp"
]
},
"application/vnd.macports.portpkg": {
source: "iana",
extensions: [
"portpkg"
]
},
"application/vnd.mapbox-vector-tile": {
source: "iana",
extensions: [
"mvt"
]
},
"application/vnd.marlin.drm.actiontoken+xml": {
source: "iana",
compressible: true
},
"application/vnd.marlin.drm.conftoken+xml": {
source: "iana",
compressible: true
},
"application/vnd.marlin.drm.license+xml": {
source: "iana",
compressible: true
},
"application/vnd.marlin.drm.mdcf": {
source: "iana"
},
"application/vnd.mason+json": {
source: "iana",
compressible: true
},
"application/vnd.maxmind.maxmind-db": {
source: "iana"
},
"application/vnd.mcd": {
source: "iana",
extensions: [
"mcd"
]
},
"application/vnd.medcalcdata": {
source: "iana",
extensions: [
"mc1"
]
},
"application/vnd.mediastation.cdkey": {
source: "iana",
extensions: [
"cdkey"
]
},
"application/vnd.meridian-slingshot": {
source: "iana"
},
"application/vnd.mfer": {
source: "iana",
extensions: [
"mwf"
]
},
"application/vnd.mfmp": {
source: "iana",
extensions: [
"mfm"
]
},
"application/vnd.micro+json": {
source: "iana",
compressible: true
},
"application/vnd.micrografx.flo": {
source: "iana",
extensions: [
"flo"
]
},
"application/vnd.micrografx.igx": {
source: "iana",
extensions: [
"igx"
]
},
"application/vnd.microsoft.portable-executable": {
source: "iana"
},
"application/vnd.microsoft.windows.thumbnail-cache": {
source: "iana"
},
"application/vnd.miele+json": {
source: "iana",
compressible: true
},
"application/vnd.mif": {
source: "iana",
extensions: [
"mif"
]
},
"application/vnd.minisoft-hp3000-save": {
source: "iana"
},
"application/vnd.mitsubishi.misty-guard.trustweb": {
source: "iana"
},
"application/vnd.mobius.daf": {
source: "iana",
extensions: [
"daf"
]
},
"application/vnd.mobius.dis": {
source: "iana",
extensions: [
"dis"
]
},
"application/vnd.mobius.mbk": {
source: "iana",
extensions: [
"mbk"
]
},
"application/vnd.mobius.mqy": {
source: "iana",
extensions: [
"mqy"
]
},
"application/vnd.mobius.msl": {
source: "iana",
extensions: [
"msl"
]
},
"application/vnd.mobius.plc": {
source: "iana",
extensions: [
"plc"
]
},
"application/vnd.mobius.txf": {
source: "iana",
extensions: [
"txf"
]
},
"application/vnd.mophun.application": {
source: "iana",
extensions: [
"mpn"
]
},
"application/vnd.mophun.certificate": {
source: "iana",
extensions: [
"mpc"
]
},
"application/vnd.motorola.flexsuite": {
source: "iana"
},
"application/vnd.motorola.flexsuite.adsi": {
source: "iana"
},
"application/vnd.motorola.flexsuite.fis": {
source: "iana"
},
"application/vnd.motorola.flexsuite.gotap": {
source: "iana"
},
"application/vnd.motorola.flexsuite.kmr": {
source: "iana"
},
"application/vnd.motorola.flexsuite.ttc": {
source: "iana"
},
"application/vnd.motorola.flexsuite.wem": {
source: "iana"
},
"application/vnd.motorola.iprm": {
source: "iana"
},
"application/vnd.mozilla.xul+xml": {
source: "iana",
compressible: true,
extensions: [
"xul"
]
},
"application/vnd.ms-3mfdocument": {
source: "iana"
},
"application/vnd.ms-artgalry": {
source: "iana",
extensions: [
"cil"
]
},
"application/vnd.ms-asf": {
source: "iana"
},
"application/vnd.ms-cab-compressed": {
source: "iana",
extensions: [
"cab"
]
},
"application/vnd.ms-color.iccprofile": {
source: "apache"
},
"application/vnd.ms-excel": {
source: "iana",
compressible: false,
extensions: [
"xls",
"xlm",
"xla",
"xlc",
"xlt",
"xlw"
]
},
"application/vnd.ms-excel.addin.macroenabled.12": {
source: "iana",
extensions: [
"xlam"
]
},
"application/vnd.ms-excel.sheet.binary.macroenabled.12": {
source: "iana",
extensions: [
"xlsb"
]
},
"application/vnd.ms-excel.sheet.macroenabled.12": {
source: "iana",
extensions: [
"xlsm"
]
},
"application/vnd.ms-excel.template.macroenabled.12": {
source: "iana",
extensions: [
"xltm"
]
},
"application/vnd.ms-fontobject": {
source: "iana",
compressible: true,
extensions: [
"eot"
]
},
"application/vnd.ms-htmlhelp": {
source: "iana",
extensions: [
"chm"
]
},
"application/vnd.ms-ims": {
source: "iana",
extensions: [
"ims"
]
},
"application/vnd.ms-lrm": {
source: "iana",
extensions: [
"lrm"
]
},
"application/vnd.ms-office.activex+xml": {
source: "iana",
compressible: true
},
"application/vnd.ms-officetheme": {
source: "iana",
extensions: [
"thmx"
]
},
"application/vnd.ms-opentype": {
source: "apache",
compressible: true
},
"application/vnd.ms-outlook": {
compressible: false,
extensions: [
"msg"
]
},
"application/vnd.ms-package.obfuscated-opentype": {
source: "apache"
},
"application/vnd.ms-pki.seccat": {
source: "apache",
extensions: [
"cat"
]
},
"application/vnd.ms-pki.stl": {
source: "apache",
extensions: [
"stl"
]
},
"application/vnd.ms-playready.initiator+xml": {
source: "iana",
compressible: true
},
"application/vnd.ms-powerpoint": {
source: "iana",
compressible: false,
extensions: [
"ppt",
"pps",
"pot"
]
},
"application/vnd.ms-powerpoint.addin.macroenabled.12": {
source: "iana",
extensions: [
"ppam"
]
},
"application/vnd.ms-powerpoint.presentation.macroenabled.12": {
source: "iana",
extensions: [
"pptm"
]
},
"application/vnd.ms-powerpoint.slide.macroenabled.12": {
source: "iana",
extensions: [
"sldm"
]
},
"application/vnd.ms-powerpoint.slideshow.macroenabled.12": {
source: "iana",
extensions: [
"ppsm"
]
},
"application/vnd.ms-powerpoint.template.macroenabled.12": {
source: "iana",
extensions: [
"potm"
]
},
"application/vnd.ms-printdevicecapabilities+xml": {
source: "iana",
compressible: true
},
"application/vnd.ms-printing.printticket+xml": {
source: "apache",
compressible: true
},
"application/vnd.ms-printschematicket+xml": {
source: "iana",
compressible: true
},
"application/vnd.ms-project": {
source: "iana",
extensions: [
"mpp",
"mpt"
]
},
"application/vnd.ms-tnef": {
source: "iana"
},
"application/vnd.ms-windows.devicepairing": {
source: "iana"
},
"application/vnd.ms-windows.nwprinting.oob": {
source: "iana"
},
"application/vnd.ms-windows.printerpairing": {
source: "iana"
},
"application/vnd.ms-windows.wsd.oob": {
source: "iana"
},
"application/vnd.ms-wmdrm.lic-chlg-req": {
source: "iana"
},
"application/vnd.ms-wmdrm.lic-resp": {
source: "iana"
},
"application/vnd.ms-wmdrm.meter-chlg-req": {
source: "iana"
},
"application/vnd.ms-wmdrm.meter-resp": {
source: "iana"
},
"application/vnd.ms-word.document.macroenabled.12": {
source: "iana",
extensions: [
"docm"
]
},
"application/vnd.ms-word.template.macroenabled.12": {
source: "iana",
extensions: [
"dotm"
]
},
"application/vnd.ms-works": {
source: "iana",
extensions: [
"wps",
"wks",
"wcm",
"wdb"
]
},
"application/vnd.ms-wpl": {
source: "iana",
extensions: [
"wpl"
]
},
"application/vnd.ms-xpsdocument": {
source: "iana",
compressible: false,
extensions: [
"xps"
]
},
"application/vnd.msa-disk-image": {
source: "iana"
},
"application/vnd.mseq": {
source: "iana",
extensions: [
"mseq"
]
},
"application/vnd.msign": {
source: "iana"
},
"application/vnd.multiad.creator": {
source: "iana"
},
"application/vnd.multiad.creator.cif": {
source: "iana"
},
"application/vnd.music-niff": {
source: "iana"
},
"application/vnd.musician": {
source: "iana",
extensions: [
"mus"
]
},
"application/vnd.muvee.style": {
source: "iana",
extensions: [
"msty"
]
},
"application/vnd.mynfc": {
source: "iana",
extensions: [
"taglet"
]
},
"application/vnd.nacamar.ybrid+json": {
source: "iana",
compressible: true
},
"application/vnd.ncd.control": {
source: "iana"
},
"application/vnd.ncd.reference": {
source: "iana"
},
"application/vnd.nearst.inv+json": {
source: "iana",
compressible: true
},
"application/vnd.nebumind.line": {
source: "iana"
},
"application/vnd.nervana": {
source: "iana"
},
"application/vnd.netfpx": {
source: "iana"
},
"application/vnd.neurolanguage.nlu": {
source: "iana",
extensions: [
"nlu"
]
},
"application/vnd.nimn": {
source: "iana"
},
"application/vnd.nintendo.nitro.rom": {
source: "iana"
},
"application/vnd.nintendo.snes.rom": {
source: "iana"
},
"application/vnd.nitf": {
source: "iana",
extensions: [
"ntf",
"nitf"
]
},
"application/vnd.noblenet-directory": {
source: "iana",
extensions: [
"nnd"
]
},
"application/vnd.noblenet-sealer": {
source: "iana",
extensions: [
"nns"
]
},
"application/vnd.noblenet-web": {
source: "iana",
extensions: [
"nnw"
]
},
"application/vnd.nokia.catalogs": {
source: "iana"
},
"application/vnd.nokia.conml+wbxml": {
source: "iana"
},
"application/vnd.nokia.conml+xml": {
source: "iana",
compressible: true
},
"application/vnd.nokia.iptv.config+xml": {
source: "iana",
compressible: true
},
"application/vnd.nokia.isds-radio-presets": {
source: "iana"
},
"application/vnd.nokia.landmark+wbxml": {
source: "iana"
},
"application/vnd.nokia.landmark+xml": {
source: "iana",
compressible: true
},
"application/vnd.nokia.landmarkcollection+xml": {
source: "iana",
compressible: true
},
"application/vnd.nokia.n-gage.ac+xml": {
source: "iana",
compressible: true,
extensions: [
"ac"
]
},
"application/vnd.nokia.n-gage.data": {
source: "iana",
extensions: [
"ngdat"
]
},
"application/vnd.nokia.n-gage.symbian.install": {
source: "iana",
extensions: [
"n-gage"
]
},
"application/vnd.nokia.ncd": {
source: "iana"
},
"application/vnd.nokia.pcd+wbxml": {
source: "iana"
},
"application/vnd.nokia.pcd+xml": {
source: "iana",
compressible: true
},
"application/vnd.nokia.radio-preset": {
source: "iana",
extensions: [
"rpst"
]
},
"application/vnd.nokia.radio-presets": {
source: "iana",
extensions: [
"rpss"
]
},
"application/vnd.novadigm.edm": {
source: "iana",
extensions: [
"edm"
]
},
"application/vnd.novadigm.edx": {
source: "iana",
extensions: [
"edx"
]
},
"application/vnd.novadigm.ext": {
source: "iana",
extensions: [
"ext"
]
},
"application/vnd.ntt-local.content-share": {
source: "iana"
},
"application/vnd.ntt-local.file-transfer": {
source: "iana"
},
"application/vnd.ntt-local.ogw_remote-access": {
source: "iana"
},
"application/vnd.ntt-local.sip-ta_remote": {
source: "iana"
},
"application/vnd.ntt-local.sip-ta_tcp_stream": {
source: "iana"
},
"application/vnd.oasis.opendocument.chart": {
source: "iana",
extensions: [
"odc"
]
},
"application/vnd.oasis.opendocument.chart-template": {
source: "iana",
extensions: [
"otc"
]
},
"application/vnd.oasis.opendocument.database": {
source: "iana",
extensions: [
"odb"
]
},
"application/vnd.oasis.opendocument.formula": {
source: "iana",
extensions: [
"odf"
]
},
"application/vnd.oasis.opendocument.formula-template": {
source: "iana",
extensions: [
"odft"
]
},
"application/vnd.oasis.opendocument.graphics": {
source: "iana",
compressible: false,
extensions: [
"odg"
]
},
"application/vnd.oasis.opendocument.graphics-template": {
source: "iana",
extensions: [
"otg"
]
},
"application/vnd.oasis.opendocument.image": {
source: "iana",
extensions: [
"odi"
]
},
"application/vnd.oasis.opendocument.image-template": {
source: "iana",
extensions: [
"oti"
]
},
"application/vnd.oasis.opendocument.presentation": {
source: "iana",
compressible: false,
extensions: [
"odp"
]
},
"application/vnd.oasis.opendocument.presentation-template": {
source: "iana",
extensions: [
"otp"
]
},
"application/vnd.oasis.opendocument.spreadsheet": {
source: "iana",
compressible: false,
extensions: [
"ods"
]
},
"application/vnd.oasis.opendocument.spreadsheet-template": {
source: "iana",
extensions: [
"ots"
]
},
"application/vnd.oasis.opendocument.text": {
source: "iana",
compressible: false,
extensions: [
"odt"
]
},
"application/vnd.oasis.opendocument.text-master": {
source: "iana",
extensions: [
"odm"
]
},
"application/vnd.oasis.opendocument.text-template": {
source: "iana",
extensions: [
"ott"
]
},
"application/vnd.oasis.opendocument.text-web": {
source: "iana",
extensions: [
"oth"
]
},
"application/vnd.obn": {
source: "iana"
},
"application/vnd.ocf+cbor": {
source: "iana"
},
"application/vnd.oci.image.manifest.v1+json": {
source: "iana",
compressible: true
},
"application/vnd.oftn.l10n+json": {
source: "iana",
compressible: true
},
"application/vnd.oipf.contentaccessdownload+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.contentaccessstreaming+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.cspg-hexbinary": {
source: "iana"
},
"application/vnd.oipf.dae.svg+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.dae.xhtml+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.mippvcontrolmessage+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.pae.gem": {
source: "iana"
},
"application/vnd.oipf.spdiscovery+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.spdlist+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.ueprofile+xml": {
source: "iana",
compressible: true
},
"application/vnd.oipf.userprofile+xml": {
source: "iana",
compressible: true
},
"application/vnd.olpc-sugar": {
source: "iana",
extensions: [
"xo"
]
},
"application/vnd.oma-scws-config": {
source: "iana"
},
"application/vnd.oma-scws-http-request": {
source: "iana"
},
"application/vnd.oma-scws-http-response": {
source: "iana"
},
"application/vnd.oma.bcast.associated-procedure-parameter+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.drm-trigger+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.imd+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.ltkm": {
source: "iana"
},
"application/vnd.oma.bcast.notification+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.provisioningtrigger": {
source: "iana"
},
"application/vnd.oma.bcast.sgboot": {
source: "iana"
},
"application/vnd.oma.bcast.sgdd+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.sgdu": {
source: "iana"
},
"application/vnd.oma.bcast.simple-symbol-container": {
source: "iana"
},
"application/vnd.oma.bcast.smartcard-trigger+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.sprov+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.bcast.stkm": {
source: "iana"
},
"application/vnd.oma.cab-address-book+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.cab-feature-handler+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.cab-pcc+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.cab-subs-invite+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.cab-user-prefs+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.dcd": {
source: "iana"
},
"application/vnd.oma.dcdc": {
source: "iana"
},
"application/vnd.oma.dd2+xml": {
source: "iana",
compressible: true,
extensions: [
"dd2"
]
},
"application/vnd.oma.drm.risd+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.group-usage-list+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.lwm2m+cbor": {
source: "iana"
},
"application/vnd.oma.lwm2m+json": {
source: "iana",
compressible: true
},
"application/vnd.oma.lwm2m+tlv": {
source: "iana"
},
"application/vnd.oma.pal+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.poc.detailed-progress-report+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.poc.final-report+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.poc.groups+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.poc.invocation-descriptor+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.poc.optimized-progress-report+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.push": {
source: "iana"
},
"application/vnd.oma.scidm.messages+xml": {
source: "iana",
compressible: true
},
"application/vnd.oma.xcap-directory+xml": {
source: "iana",
compressible: true
},
"application/vnd.omads-email+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/vnd.omads-file+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/vnd.omads-folder+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/vnd.omaloc-supl-init": {
source: "iana"
},
"application/vnd.onepager": {
source: "iana"
},
"application/vnd.onepagertamp": {
source: "iana"
},
"application/vnd.onepagertamx": {
source: "iana"
},
"application/vnd.onepagertat": {
source: "iana"
},
"application/vnd.onepagertatp": {
source: "iana"
},
"application/vnd.onepagertatx": {
source: "iana"
},
"application/vnd.openblox.game+xml": {
source: "iana",
compressible: true,
extensions: [
"obgx"
]
},
"application/vnd.openblox.game-binary": {
source: "iana"
},
"application/vnd.openeye.oeb": {
source: "iana"
},
"application/vnd.openofficeorg.extension": {
source: "apache",
extensions: [
"oxt"
]
},
"application/vnd.openstreetmap.data+xml": {
source: "iana",
compressible: true,
extensions: [
"osm"
]
},
"application/vnd.opentimestamps.ots": {
source: "iana"
},
"application/vnd.openxmlformats-officedocument.custom-properties+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.customxmlproperties+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawing+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramcolors+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramdata+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramlayout+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramstyle+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.extended-properties+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.commentauthors+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.comments+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.handoutmaster+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.notesmaster+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.notesslide+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
source: "iana",
compressible: false,
extensions: [
"pptx"
]
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.presprops+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.slide": {
source: "iana",
extensions: [
"sldx"
]
},
"application/vnd.openxmlformats-officedocument.presentationml.slide+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.slidelayout+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.slidemaster+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.slideshow": {
source: "iana",
extensions: [
"ppsx"
]
},
"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.slideupdateinfo+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.tablestyles+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.tags+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.template": {
source: "iana",
extensions: [
"potx"
]
},
"application/vnd.openxmlformats-officedocument.presentationml.template.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.presentationml.viewprops+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.calcchain+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.externallink+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcachedefinition+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcacherecords+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivottable+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.querytable+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionheaders+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionlog+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedstrings+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
source: "iana",
compressible: false,
extensions: [
"xlsx"
]
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetmetadata+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.tablesinglecells+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.template": {
source: "iana",
extensions: [
"xltx"
]
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.usernames+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.volatiledependencies+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.theme+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.themeoverride+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.vmldrawing": {
source: "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
source: "iana",
compressible: false,
extensions: [
"docx"
]
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.fonttable+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.template": {
source: "iana",
extensions: [
"dotx"
]
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.websettings+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-package.core-properties+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml": {
source: "iana",
compressible: true
},
"application/vnd.openxmlformats-package.relationships+xml": {
source: "iana",
compressible: true
},
"application/vnd.oracle.resource+json": {
source: "iana",
compressible: true
},
"application/vnd.orange.indata": {
source: "iana"
},
"application/vnd.osa.netdeploy": {
source: "iana"
},
"application/vnd.osgeo.mapguide.package": {
source: "iana",
extensions: [
"mgp"
]
},
"application/vnd.osgi.bundle": {
source: "iana"
},
"application/vnd.osgi.dp": {
source: "iana",
extensions: [
"dp"
]
},
"application/vnd.osgi.subsystem": {
source: "iana",
extensions: [
"esa"
]
},
"application/vnd.otps.ct-kip+xml": {
source: "iana",
compressible: true
},
"application/vnd.oxli.countgraph": {
source: "iana"
},
"application/vnd.pagerduty+json": {
source: "iana",
compressible: true
},
"application/vnd.palm": {
source: "iana",
extensions: [
"pdb",
"pqa",
"oprc"
]
},
"application/vnd.panoply": {
source: "iana"
},
"application/vnd.paos.xml": {
source: "iana"
},
"application/vnd.patentdive": {
source: "iana"
},
"application/vnd.patientecommsdoc": {
source: "iana"
},
"application/vnd.pawaafile": {
source: "iana",
extensions: [
"paw"
]
},
"application/vnd.pcos": {
source: "iana"
},
"application/vnd.pg.format": {
source: "iana",
extensions: [
"str"
]
},
"application/vnd.pg.osasli": {
source: "iana",
extensions: [
"ei6"
]
},
"application/vnd.piaccess.application-licence": {
source: "iana"
},
"application/vnd.picsel": {
source: "iana",
extensions: [
"efif"
]
},
"application/vnd.pmi.widget": {
source: "iana",
extensions: [
"wg"
]
},
"application/vnd.poc.group-advertisement+xml": {
source: "iana",
compressible: true
},
"application/vnd.pocketlearn": {
source: "iana",
extensions: [
"plf"
]
},
"application/vnd.powerbuilder6": {
source: "iana",
extensions: [
"pbd"
]
},
"application/vnd.powerbuilder6-s": {
source: "iana"
},
"application/vnd.powerbuilder7": {
source: "iana"
},
"application/vnd.powerbuilder7-s": {
source: "iana"
},
"application/vnd.powerbuilder75": {
source: "iana"
},
"application/vnd.powerbuilder75-s": {
source: "iana"
},
"application/vnd.preminet": {
source: "iana"
},
"application/vnd.previewsystems.box": {
source: "iana",
extensions: [
"box"
]
},
"application/vnd.proteus.magazine": {
source: "iana",
extensions: [
"mgz"
]
},
"application/vnd.psfs": {
source: "iana"
},
"application/vnd.publishare-delta-tree": {
source: "iana",
extensions: [
"qps"
]
},
"application/vnd.pvi.ptid1": {
source: "iana",
extensions: [
"ptid"
]
},
"application/vnd.pwg-multiplexed": {
source: "iana"
},
"application/vnd.pwg-xhtml-print+xml": {
source: "iana",
compressible: true
},
"application/vnd.qualcomm.brew-app-res": {
source: "iana"
},
"application/vnd.quarantainenet": {
source: "iana"
},
"application/vnd.quark.quarkxpress": {
source: "iana",
extensions: [
"qxd",
"qxt",
"qwd",
"qwt",
"qxl",
"qxb"
]
},
"application/vnd.quobject-quoxdocument": {
source: "iana"
},
"application/vnd.radisys.moml+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-audit+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-audit-conf+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-audit-conn+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-audit-dialog+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-audit-stream+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-conf+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-base+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-fax-detect+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-fax-sendrecv+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-group+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-speech+xml": {
source: "iana",
compressible: true
},
"application/vnd.radisys.msml-dialog-transform+xml": {
source: "iana",
compressible: true
},
"application/vnd.rainstor.data": {
source: "iana"
},
"application/vnd.rapid": {
source: "iana"
},
"application/vnd.rar": {
source: "iana",
extensions: [
"rar"
]
},
"application/vnd.realvnc.bed": {
source: "iana",
extensions: [
"bed"
]
},
"application/vnd.recordare.musicxml": {
source: "iana",
extensions: [
"mxl"
]
},
"application/vnd.recordare.musicxml+xml": {
source: "iana",
compressible: true,
extensions: [
"musicxml"
]
},
"application/vnd.renlearn.rlprint": {
source: "iana"
},
"application/vnd.resilient.logic": {
source: "iana"
},
"application/vnd.restful+json": {
source: "iana",
compressible: true
},
"application/vnd.rig.cryptonote": {
source: "iana",
extensions: [
"cryptonote"
]
},
"application/vnd.rim.cod": {
source: "apache",
extensions: [
"cod"
]
},
"application/vnd.rn-realmedia": {
source: "apache",
extensions: [
"rm"
]
},
"application/vnd.rn-realmedia-vbr": {
source: "apache",
extensions: [
"rmvb"
]
},
"application/vnd.route66.link66+xml": {
source: "iana",
compressible: true,
extensions: [
"link66"
]
},
"application/vnd.rs-274x": {
source: "iana"
},
"application/vnd.ruckus.download": {
source: "iana"
},
"application/vnd.s3sms": {
source: "iana"
},
"application/vnd.sailingtracker.track": {
source: "iana",
extensions: [
"st"
]
},
"application/vnd.sar": {
source: "iana"
},
"application/vnd.sbm.cid": {
source: "iana"
},
"application/vnd.sbm.mid2": {
source: "iana"
},
"application/vnd.scribus": {
source: "iana"
},
"application/vnd.sealed.3df": {
source: "iana"
},
"application/vnd.sealed.csf": {
source: "iana"
},
"application/vnd.sealed.doc": {
source: "iana"
},
"application/vnd.sealed.eml": {
source: "iana"
},
"application/vnd.sealed.mht": {
source: "iana"
},
"application/vnd.sealed.net": {
source: "iana"
},
"application/vnd.sealed.ppt": {
source: "iana"
},
"application/vnd.sealed.tiff": {
source: "iana"
},
"application/vnd.sealed.xls": {
source: "iana"
},
"application/vnd.sealedmedia.softseal.html": {
source: "iana"
},
"application/vnd.sealedmedia.softseal.pdf": {
source: "iana"
},
"application/vnd.seemail": {
source: "iana",
extensions: [
"see"
]
},
"application/vnd.seis+json": {
source: "iana",
compressible: true
},
"application/vnd.sema": {
source: "iana",
extensions: [
"sema"
]
},
"application/vnd.semd": {
source: "iana",
extensions: [
"semd"
]
},
"application/vnd.semf": {
source: "iana",
extensions: [
"semf"
]
},
"application/vnd.shade-save-file": {
source: "iana"
},
"application/vnd.shana.informed.formdata": {
source: "iana",
extensions: [
"ifm"
]
},
"application/vnd.shana.informed.formtemplate": {
source: "iana",
extensions: [
"itp"
]
},
"application/vnd.shana.informed.interchange": {
source: "iana",
extensions: [
"iif"
]
},
"application/vnd.shana.informed.package": {
source: "iana",
extensions: [
"ipk"
]
},
"application/vnd.shootproof+json": {
source: "iana",
compressible: true
},
"application/vnd.shopkick+json": {
source: "iana",
compressible: true
},
"application/vnd.shp": {
source: "iana"
},
"application/vnd.shx": {
source: "iana"
},
"application/vnd.sigrok.session": {
source: "iana"
},
"application/vnd.simtech-mindmapper": {
source: "iana",
extensions: [
"twd",
"twds"
]
},
"application/vnd.siren+json": {
source: "iana",
compressible: true
},
"application/vnd.smaf": {
source: "iana",
extensions: [
"mmf"
]
},
"application/vnd.smart.notebook": {
source: "iana"
},
"application/vnd.smart.teacher": {
source: "iana",
extensions: [
"teacher"
]
},
"application/vnd.snesdev-page-table": {
source: "iana"
},
"application/vnd.software602.filler.form+xml": {
source: "iana",
compressible: true,
extensions: [
"fo"
]
},
"application/vnd.software602.filler.form-xml-zip": {
source: "iana"
},
"application/vnd.solent.sdkm+xml": {
source: "iana",
compressible: true,
extensions: [
"sdkm",
"sdkd"
]
},
"application/vnd.spotfire.dxp": {
source: "iana",
extensions: [
"dxp"
]
},
"application/vnd.spotfire.sfs": {
source: "iana",
extensions: [
"sfs"
]
},
"application/vnd.sqlite3": {
source: "iana"
},
"application/vnd.sss-cod": {
source: "iana"
},
"application/vnd.sss-dtf": {
source: "iana"
},
"application/vnd.sss-ntf": {
source: "iana"
},
"application/vnd.stardivision.calc": {
source: "apache",
extensions: [
"sdc"
]
},
"application/vnd.stardivision.draw": {
source: "apache",
extensions: [
"sda"
]
},
"application/vnd.stardivision.impress": {
source: "apache",
extensions: [
"sdd"
]
},
"application/vnd.stardivision.math": {
source: "apache",
extensions: [
"smf"
]
},
"application/vnd.stardivision.writer": {
source: "apache",
extensions: [
"sdw",
"vor"
]
},
"application/vnd.stardivision.writer-global": {
source: "apache",
extensions: [
"sgl"
]
},
"application/vnd.stepmania.package": {
source: "iana",
extensions: [
"smzip"
]
},
"application/vnd.stepmania.stepchart": {
source: "iana",
extensions: [
"sm"
]
},
"application/vnd.street-stream": {
source: "iana"
},
"application/vnd.sun.wadl+xml": {
source: "iana",
compressible: true,
extensions: [
"wadl"
]
},
"application/vnd.sun.xml.calc": {
source: "apache",
extensions: [
"sxc"
]
},
"application/vnd.sun.xml.calc.template": {
source: "apache",
extensions: [
"stc"
]
},
"application/vnd.sun.xml.draw": {
source: "apache",
extensions: [
"sxd"
]
},
"application/vnd.sun.xml.draw.template": {
source: "apache",
extensions: [
"std"
]
},
"application/vnd.sun.xml.impress": {
source: "apache",
extensions: [
"sxi"
]
},
"application/vnd.sun.xml.impress.template": {
source: "apache",
extensions: [
"sti"
]
},
"application/vnd.sun.xml.math": {
source: "apache",
extensions: [
"sxm"
]
},
"application/vnd.sun.xml.writer": {
source: "apache",
extensions: [
"sxw"
]
},
"application/vnd.sun.xml.writer.global": {
source: "apache",
extensions: [
"sxg"
]
},
"application/vnd.sun.xml.writer.template": {
source: "apache",
extensions: [
"stw"
]
},
"application/vnd.sus-calendar": {
source: "iana",
extensions: [
"sus",
"susp"
]
},
"application/vnd.svd": {
source: "iana",
extensions: [
"svd"
]
},
"application/vnd.swiftview-ics": {
source: "iana"
},
"application/vnd.sycle+xml": {
source: "iana",
compressible: true
},
"application/vnd.symbian.install": {
source: "apache",
extensions: [
"sis",
"sisx"
]
},
"application/vnd.syncml+xml": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"xsm"
]
},
"application/vnd.syncml.dm+wbxml": {
source: "iana",
charset: "UTF-8",
extensions: [
"bdm"
]
},
"application/vnd.syncml.dm+xml": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"xdm"
]
},
"application/vnd.syncml.dm.notification": {
source: "iana"
},
"application/vnd.syncml.dmddf+wbxml": {
source: "iana"
},
"application/vnd.syncml.dmddf+xml": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"ddf"
]
},
"application/vnd.syncml.dmtnds+wbxml": {
source: "iana"
},
"application/vnd.syncml.dmtnds+xml": {
source: "iana",
charset: "UTF-8",
compressible: true
},
"application/vnd.syncml.ds.notification": {
source: "iana"
},
"application/vnd.tableschema+json": {
source: "iana",
compressible: true
},
"application/vnd.tao.intent-module-archive": {
source: "iana",
extensions: [
"tao"
]
},
"application/vnd.tcpdump.pcap": {
source: "iana",
extensions: [
"pcap",
"cap",
"dmp"
]
},
"application/vnd.think-cell.ppttc+json": {
source: "iana",
compressible: true
},
"application/vnd.tmd.mediaflex.api+xml": {
source: "iana",
compressible: true
},
"application/vnd.tml": {
source: "iana"
},
"application/vnd.tmobile-livetv": {
source: "iana",
extensions: [
"tmo"
]
},
"application/vnd.tri.onesource": {
source: "iana"
},
"application/vnd.trid.tpt": {
source: "iana",
extensions: [
"tpt"
]
},
"application/vnd.triscape.mxs": {
source: "iana",
extensions: [
"mxs"
]
},
"application/vnd.trueapp": {
source: "iana",
extensions: [
"tra"
]
},
"application/vnd.truedoc": {
source: "iana"
},
"application/vnd.ubisoft.webplayer": {
source: "iana"
},
"application/vnd.ufdl": {
source: "iana",
extensions: [
"ufd",
"ufdl"
]
},
"application/vnd.uiq.theme": {
source: "iana",
extensions: [
"utz"
]
},
"application/vnd.umajin": {
source: "iana",
extensions: [
"umj"
]
},
"application/vnd.unity": {
source: "iana",
extensions: [
"unityweb"
]
},
"application/vnd.uoml+xml": {
source: "iana",
compressible: true,
extensions: [
"uoml"
]
},
"application/vnd.uplanet.alert": {
source: "iana"
},
"application/vnd.uplanet.alert-wbxml": {
source: "iana"
},
"application/vnd.uplanet.bearer-choice": {
source: "iana"
},
"application/vnd.uplanet.bearer-choice-wbxml": {
source: "iana"
},
"application/vnd.uplanet.cacheop": {
source: "iana"
},
"application/vnd.uplanet.cacheop-wbxml": {
source: "iana"
},
"application/vnd.uplanet.channel": {
source: "iana"
},
"application/vnd.uplanet.channel-wbxml": {
source: "iana"
},
"application/vnd.uplanet.list": {
source: "iana"
},
"application/vnd.uplanet.list-wbxml": {
source: "iana"
},
"application/vnd.uplanet.listcmd": {
source: "iana"
},
"application/vnd.uplanet.listcmd-wbxml": {
source: "iana"
},
"application/vnd.uplanet.signal": {
source: "iana"
},
"application/vnd.uri-map": {
source: "iana"
},
"application/vnd.valve.source.material": {
source: "iana"
},
"application/vnd.vcx": {
source: "iana",
extensions: [
"vcx"
]
},
"application/vnd.vd-study": {
source: "iana"
},
"application/vnd.vectorworks": {
source: "iana"
},
"application/vnd.vel+json": {
source: "iana",
compressible: true
},
"application/vnd.verimatrix.vcas": {
source: "iana"
},
"application/vnd.veritone.aion+json": {
source: "iana",
compressible: true
},
"application/vnd.veryant.thin": {
source: "iana"
},
"application/vnd.ves.encrypted": {
source: "iana"
},
"application/vnd.vidsoft.vidconference": {
source: "iana"
},
"application/vnd.visio": {
source: "iana",
extensions: [
"vsd",
"vst",
"vss",
"vsw"
]
},
"application/vnd.visionary": {
source: "iana",
extensions: [
"vis"
]
},
"application/vnd.vividence.scriptfile": {
source: "iana"
},
"application/vnd.vsf": {
source: "iana",
extensions: [
"vsf"
]
},
"application/vnd.wap.sic": {
source: "iana"
},
"application/vnd.wap.slc": {
source: "iana"
},
"application/vnd.wap.wbxml": {
source: "iana",
charset: "UTF-8",
extensions: [
"wbxml"
]
},
"application/vnd.wap.wmlc": {
source: "iana",
extensions: [
"wmlc"
]
},
"application/vnd.wap.wmlscriptc": {
source: "iana",
extensions: [
"wmlsc"
]
},
"application/vnd.webturbo": {
source: "iana",
extensions: [
"wtb"
]
},
"application/vnd.wfa.dpp": {
source: "iana"
},
"application/vnd.wfa.p2p": {
source: "iana"
},
"application/vnd.wfa.wsc": {
source: "iana"
},
"application/vnd.windows.devicepairing": {
source: "iana"
},
"application/vnd.wmc": {
source: "iana"
},
"application/vnd.wmf.bootstrap": {
source: "iana"
},
"application/vnd.wolfram.mathematica": {
source: "iana"
},
"application/vnd.wolfram.mathematica.package": {
source: "iana"
},
"application/vnd.wolfram.player": {
source: "iana",
extensions: [
"nbp"
]
},
"application/vnd.wordperfect": {
source: "iana",
extensions: [
"wpd"
]
},
"application/vnd.wqd": {
source: "iana",
extensions: [
"wqd"
]
},
"application/vnd.wrq-hp3000-labelled": {
source: "iana"
},
"application/vnd.wt.stf": {
source: "iana",
extensions: [
"stf"
]
},
"application/vnd.wv.csp+wbxml": {
source: "iana"
},
"application/vnd.wv.csp+xml": {
source: "iana",
compressible: true
},
"application/vnd.wv.ssp+xml": {
source: "iana",
compressible: true
},
"application/vnd.xacml+json": {
source: "iana",
compressible: true
},
"application/vnd.xara": {
source: "iana",
extensions: [
"xar"
]
},
"application/vnd.xfdl": {
source: "iana",
extensions: [
"xfdl"
]
},
"application/vnd.xfdl.webform": {
source: "iana"
},
"application/vnd.xmi+xml": {
source: "iana",
compressible: true
},
"application/vnd.xmpie.cpkg": {
source: "iana"
},
"application/vnd.xmpie.dpkg": {
source: "iana"
},
"application/vnd.xmpie.plan": {
source: "iana"
},
"application/vnd.xmpie.ppkg": {
source: "iana"
},
"application/vnd.xmpie.xlim": {
source: "iana"
},
"application/vnd.yamaha.hv-dic": {
source: "iana",
extensions: [
"hvd"
]
},
"application/vnd.yamaha.hv-script": {
source: "iana",
extensions: [
"hvs"
]
},
"application/vnd.yamaha.hv-voice": {
source: "iana",
extensions: [
"hvp"
]
},
"application/vnd.yamaha.openscoreformat": {
source: "iana",
extensions: [
"osf"
]
},
"application/vnd.yamaha.openscoreformat.osfpvg+xml": {
source: "iana",
compressible: true,
extensions: [
"osfpvg"
]
},
"application/vnd.yamaha.remote-setup": {
source: "iana"
},
"application/vnd.yamaha.smaf-audio": {
source: "iana",
extensions: [
"saf"
]
},
"application/vnd.yamaha.smaf-phrase": {
source: "iana",
extensions: [
"spf"
]
},
"application/vnd.yamaha.through-ngn": {
source: "iana"
},
"application/vnd.yamaha.tunnel-udpencap": {
source: "iana"
},
"application/vnd.yaoweme": {
source: "iana"
},
"application/vnd.yellowriver-custom-menu": {
source: "iana",
extensions: [
"cmp"
]
},
"application/vnd.youtube.yt": {
source: "iana"
},
"application/vnd.zul": {
source: "iana",
extensions: [
"zir",
"zirz"
]
},
"application/vnd.zzazz.deck+xml": {
source: "iana",
compressible: true,
extensions: [
"zaz"
]
},
"application/voicexml+xml": {
source: "iana",
compressible: true,
extensions: [
"vxml"
]
},
"application/voucher-cms+json": {
source: "iana",
compressible: true
},
"application/vq-rtcpxr": {
source: "iana"
},
"application/wasm": {
source: "iana",
compressible: true,
extensions: [
"wasm"
]
},
"application/watcherinfo+xml": {
source: "iana",
compressible: true
},
"application/webpush-options+json": {
source: "iana",
compressible: true
},
"application/whoispp-query": {
source: "iana"
},
"application/whoispp-response": {
source: "iana"
},
"application/widget": {
source: "iana",
extensions: [
"wgt"
]
},
"application/winhlp": {
source: "apache",
extensions: [
"hlp"
]
},
"application/wita": {
source: "iana"
},
"application/wordperfect5.1": {
source: "iana"
},
"application/wsdl+xml": {
source: "iana",
compressible: true,
extensions: [
"wsdl"
]
},
"application/wspolicy+xml": {
source: "iana",
compressible: true,
extensions: [
"wspolicy"
]
},
"application/x-7z-compressed": {
source: "apache",
compressible: false,
extensions: [
"7z"
]
},
"application/x-abiword": {
source: "apache",
extensions: [
"abw"
]
},
"application/x-ace-compressed": {
source: "apache",
extensions: [
"ace"
]
},
"application/x-amf": {
source: "apache"
},
"application/x-apple-diskimage": {
source: "apache",
extensions: [
"dmg"
]
},
"application/x-arj": {
compressible: false,
extensions: [
"arj"
]
},
"application/x-authorware-bin": {
source: "apache",
extensions: [
"aab",
"x32",
"u32",
"vox"
]
},
"application/x-authorware-map": {
source: "apache",
extensions: [
"aam"
]
},
"application/x-authorware-seg": {
source: "apache",
extensions: [
"aas"
]
},
"application/x-bcpio": {
source: "apache",
extensions: [
"bcpio"
]
},
"application/x-bdoc": {
compressible: false,
extensions: [
"bdoc"
]
},
"application/x-bittorrent": {
source: "apache",
extensions: [
"torrent"
]
},
"application/x-blorb": {
source: "apache",
extensions: [
"blb",
"blorb"
]
},
"application/x-bzip": {
source: "apache",
compressible: false,
extensions: [
"bz"
]
},
"application/x-bzip2": {
source: "apache",
compressible: false,
extensions: [
"bz2",
"boz"
]
},
"application/x-cbr": {
source: "apache",
extensions: [
"cbr",
"cba",
"cbt",
"cbz",
"cb7"
]
},
"application/x-cdlink": {
source: "apache",
extensions: [
"vcd"
]
},
"application/x-cfs-compressed": {
source: "apache",
extensions: [
"cfs"
]
},
"application/x-chat": {
source: "apache",
extensions: [
"chat"
]
},
"application/x-chess-pgn": {
source: "apache",
extensions: [
"pgn"
]
},
"application/x-chrome-extension": {
extensions: [
"crx"
]
},
"application/x-cocoa": {
source: "nginx",
extensions: [
"cco"
]
},
"application/x-compress": {
source: "apache"
},
"application/x-conference": {
source: "apache",
extensions: [
"nsc"
]
},
"application/x-cpio": {
source: "apache",
extensions: [
"cpio"
]
},
"application/x-csh": {
source: "apache",
extensions: [
"csh"
]
},
"application/x-deb": {
compressible: false
},
"application/x-debian-package": {
source: "apache",
extensions: [
"deb",
"udeb"
]
},
"application/x-dgc-compressed": {
source: "apache",
extensions: [
"dgc"
]
},
"application/x-director": {
source: "apache",
extensions: [
"dir",
"dcr",
"dxr",
"cst",
"cct",
"cxt",
"w3d",
"fgd",
"swa"
]
},
"application/x-doom": {
source: "apache",
extensions: [
"wad"
]
},
"application/x-dtbncx+xml": {
source: "apache",
compressible: true,
extensions: [
"ncx"
]
},
"application/x-dtbook+xml": {
source: "apache",
compressible: true,
extensions: [
"dtb"
]
},
"application/x-dtbresource+xml": {
source: "apache",
compressible: true,
extensions: [
"res"
]
},
"application/x-dvi": {
source: "apache",
compressible: false,
extensions: [
"dvi"
]
},
"application/x-envoy": {
source: "apache",
extensions: [
"evy"
]
},
"application/x-eva": {
source: "apache",
extensions: [
"eva"
]
},
"application/x-font-bdf": {
source: "apache",
extensions: [
"bdf"
]
},
"application/x-font-dos": {
source: "apache"
},
"application/x-font-framemaker": {
source: "apache"
},
"application/x-font-ghostscript": {
source: "apache",
extensions: [
"gsf"
]
},
"application/x-font-libgrx": {
source: "apache"
},
"application/x-font-linux-psf": {
source: "apache",
extensions: [
"psf"
]
},
"application/x-font-pcf": {
source: "apache",
extensions: [
"pcf"
]
},
"application/x-font-snf": {
source: "apache",
extensions: [
"snf"
]
},
"application/x-font-speedo": {
source: "apache"
},
"application/x-font-sunos-news": {
source: "apache"
},
"application/x-font-type1": {
source: "apache",
extensions: [
"pfa",
"pfb",
"pfm",
"afm"
]
},
"application/x-font-vfont": {
source: "apache"
},
"application/x-freearc": {
source: "apache",
extensions: [
"arc"
]
},
"application/x-futuresplash": {
source: "apache",
extensions: [
"spl"
]
},
"application/x-gca-compressed": {
source: "apache",
extensions: [
"gca"
]
},
"application/x-glulx": {
source: "apache",
extensions: [
"ulx"
]
},
"application/x-gnumeric": {
source: "apache",
extensions: [
"gnumeric"
]
},
"application/x-gramps-xml": {
source: "apache",
extensions: [
"gramps"
]
},
"application/x-gtar": {
source: "apache",
extensions: [
"gtar"
]
},
"application/x-gzip": {
source: "apache"
},
"application/x-hdf": {
source: "apache",
extensions: [
"hdf"
]
},
"application/x-httpd-php": {
compressible: true,
extensions: [
"php"
]
},
"application/x-install-instructions": {
source: "apache",
extensions: [
"install"
]
},
"application/x-iso9660-image": {
source: "apache",
extensions: [
"iso"
]
},
"application/x-iwork-keynote-sffkey": {
extensions: [
"key"
]
},
"application/x-iwork-numbers-sffnumbers": {
extensions: [
"numbers"
]
},
"application/x-iwork-pages-sffpages": {
extensions: [
"pages"
]
},
"application/x-java-archive-diff": {
source: "nginx",
extensions: [
"jardiff"
]
},
"application/x-java-jnlp-file": {
source: "apache",
compressible: false,
extensions: [
"jnlp"
]
},
"application/x-javascript": {
compressible: true
},
"application/x-keepass2": {
extensions: [
"kdbx"
]
},
"application/x-latex": {
source: "apache",
compressible: false,
extensions: [
"latex"
]
},
"application/x-lua-bytecode": {
extensions: [
"luac"
]
},
"application/x-lzh-compressed": {
source: "apache",
extensions: [
"lzh",
"lha"
]
},
"application/x-makeself": {
source: "nginx",
extensions: [
"run"
]
},
"application/x-mie": {
source: "apache",
extensions: [
"mie"
]
},
"application/x-mobipocket-ebook": {
source: "apache",
extensions: [
"prc",
"mobi"
]
},
"application/x-mpegurl": {
compressible: false
},
"application/x-ms-application": {
source: "apache",
extensions: [
"application"
]
},
"application/x-ms-shortcut": {
source: "apache",
extensions: [
"lnk"
]
},
"application/x-ms-wmd": {
source: "apache",
extensions: [
"wmd"
]
},
"application/x-ms-wmz": {
source: "apache",
extensions: [
"wmz"
]
},
"application/x-ms-xbap": {
source: "apache",
extensions: [
"xbap"
]
},
"application/x-msaccess": {
source: "apache",
extensions: [
"mdb"
]
},
"application/x-msbinder": {
source: "apache",
extensions: [
"obd"
]
},
"application/x-mscardfile": {
source: "apache",
extensions: [
"crd"
]
},
"application/x-msclip": {
source: "apache",
extensions: [
"clp"
]
},
"application/x-msdos-program": {
extensions: [
"exe"
]
},
"application/x-msdownload": {
source: "apache",
extensions: [
"exe",
"dll",
"com",
"bat",
"msi"
]
},
"application/x-msmediaview": {
source: "apache",
extensions: [
"mvb",
"m13",
"m14"
]
},
"application/x-msmetafile": {
source: "apache",
extensions: [
"wmf",
"wmz",
"emf",
"emz"
]
},
"application/x-msmoney": {
source: "apache",
extensions: [
"mny"
]
},
"application/x-mspublisher": {
source: "apache",
extensions: [
"pub"
]
},
"application/x-msschedule": {
source: "apache",
extensions: [
"scd"
]
},
"application/x-msterminal": {
source: "apache",
extensions: [
"trm"
]
},
"application/x-mswrite": {
source: "apache",
extensions: [
"wri"
]
},
"application/x-netcdf": {
source: "apache",
extensions: [
"nc",
"cdf"
]
},
"application/x-ns-proxy-autoconfig": {
compressible: true,
extensions: [
"pac"
]
},
"application/x-nzb": {
source: "apache",
extensions: [
"nzb"
]
},
"application/x-perl": {
source: "nginx",
extensions: [
"pl",
"pm"
]
},
"application/x-pilot": {
source: "nginx",
extensions: [
"prc",
"pdb"
]
},
"application/x-pkcs12": {
source: "apache",
compressible: false,
extensions: [
"p12",
"pfx"
]
},
"application/x-pkcs7-certificates": {
source: "apache",
extensions: [
"p7b",
"spc"
]
},
"application/x-pkcs7-certreqresp": {
source: "apache",
extensions: [
"p7r"
]
},
"application/x-pki-message": {
source: "iana"
},
"application/x-rar-compressed": {
source: "apache",
compressible: false,
extensions: [
"rar"
]
},
"application/x-redhat-package-manager": {
source: "nginx",
extensions: [
"rpm"
]
},
"application/x-research-info-systems": {
source: "apache",
extensions: [
"ris"
]
},
"application/x-sea": {
source: "nginx",
extensions: [
"sea"
]
},
"application/x-sh": {
source: "apache",
compressible: true,
extensions: [
"sh"
]
},
"application/x-shar": {
source: "apache",
extensions: [
"shar"
]
},
"application/x-shockwave-flash": {
source: "apache",
compressible: false,
extensions: [
"swf"
]
},
"application/x-silverlight-app": {
source: "apache",
extensions: [
"xap"
]
},
"application/x-sql": {
source: "apache",
extensions: [
"sql"
]
},
"application/x-stuffit": {
source: "apache",
compressible: false,
extensions: [
"sit"
]
},
"application/x-stuffitx": {
source: "apache",
extensions: [
"sitx"
]
},
"application/x-subrip": {
source: "apache",
extensions: [
"srt"
]
},
"application/x-sv4cpio": {
source: "apache",
extensions: [
"sv4cpio"
]
},
"application/x-sv4crc": {
source: "apache",
extensions: [
"sv4crc"
]
},
"application/x-t3vm-image": {
source: "apache",
extensions: [
"t3"
]
},
"application/x-tads": {
source: "apache",
extensions: [
"gam"
]
},
"application/x-tar": {
source: "apache",
compressible: true,
extensions: [
"tar"
]
},
"application/x-tcl": {
source: "apache",
extensions: [
"tcl",
"tk"
]
},
"application/x-tex": {
source: "apache",
extensions: [
"tex"
]
},
"application/x-tex-tfm": {
source: "apache",
extensions: [
"tfm"
]
},
"application/x-texinfo": {
source: "apache",
extensions: [
"texinfo",
"texi"
]
},
"application/x-tgif": {
source: "apache",
extensions: [
"obj"
]
},
"application/x-ustar": {
source: "apache",
extensions: [
"ustar"
]
},
"application/x-virtualbox-hdd": {
compressible: true,
extensions: [
"hdd"
]
},
"application/x-virtualbox-ova": {
compressible: true,
extensions: [
"ova"
]
},
"application/x-virtualbox-ovf": {
compressible: true,
extensions: [
"ovf"
]
},
"application/x-virtualbox-vbox": {
compressible: true,
extensions: [
"vbox"
]
},
"application/x-virtualbox-vbox-extpack": {
compressible: false,
extensions: [
"vbox-extpack"
]
},
"application/x-virtualbox-vdi": {
compressible: true,
extensions: [
"vdi"
]
},
"application/x-virtualbox-vhd": {
compressible: true,
extensions: [
"vhd"
]
},
"application/x-virtualbox-vmdk": {
compressible: true,
extensions: [
"vmdk"
]
},
"application/x-wais-source": {
source: "apache",
extensions: [
"src"
]
},
"application/x-web-app-manifest+json": {
compressible: true,
extensions: [
"webapp"
]
},
"application/x-www-form-urlencoded": {
source: "iana",
compressible: true
},
"application/x-x509-ca-cert": {
source: "iana",
extensions: [
"der",
"crt",
"pem"
]
},
"application/x-x509-ca-ra-cert": {
source: "iana"
},
"application/x-x509-next-ca-cert": {
source: "iana"
},
"application/x-xfig": {
source: "apache",
extensions: [
"fig"
]
},
"application/x-xliff+xml": {
source: "apache",
compressible: true,
extensions: [
"xlf"
]
},
"application/x-xpinstall": {
source: "apache",
compressible: false,
extensions: [
"xpi"
]
},
"application/x-xz": {
source: "apache",
extensions: [
"xz"
]
},
"application/x-zmachine": {
source: "apache",
extensions: [
"z1",
"z2",
"z3",
"z4",
"z5",
"z6",
"z7",
"z8"
]
},
"application/x400-bp": {
source: "iana"
},
"application/xacml+xml": {
source: "iana",
compressible: true
},
"application/xaml+xml": {
source: "apache",
compressible: true,
extensions: [
"xaml"
]
},
"application/xcap-att+xml": {
source: "iana",
compressible: true,
extensions: [
"xav"
]
},
"application/xcap-caps+xml": {
source: "iana",
compressible: true,
extensions: [
"xca"
]
},
"application/xcap-diff+xml": {
source: "iana",
compressible: true,
extensions: [
"xdf"
]
},
"application/xcap-el+xml": {
source: "iana",
compressible: true,
extensions: [
"xel"
]
},
"application/xcap-error+xml": {
source: "iana",
compressible: true
},
"application/xcap-ns+xml": {
source: "iana",
compressible: true,
extensions: [
"xns"
]
},
"application/xcon-conference-info+xml": {
source: "iana",
compressible: true
},
"application/xcon-conference-info-diff+xml": {
source: "iana",
compressible: true
},
"application/xenc+xml": {
source: "iana",
compressible: true,
extensions: [
"xenc"
]
},
"application/xhtml+xml": {
source: "iana",
compressible: true,
extensions: [
"xhtml",
"xht"
]
},
"application/xhtml-voice+xml": {
source: "apache",
compressible: true
},
"application/xliff+xml": {
source: "iana",
compressible: true,
extensions: [
"xlf"
]
},
"application/xml": {
source: "iana",
compressible: true,
extensions: [
"xml",
"xsl",
"xsd",
"rng"
]
},
"application/xml-dtd": {
source: "iana",
compressible: true,
extensions: [
"dtd"
]
},
"application/xml-external-parsed-entity": {
source: "iana"
},
"application/xml-patch+xml": {
source: "iana",
compressible: true
},
"application/xmpp+xml": {
source: "iana",
compressible: true
},
"application/xop+xml": {
source: "iana",
compressible: true,
extensions: [
"xop"
]
},
"application/xproc+xml": {
source: "apache",
compressible: true,
extensions: [
"xpl"
]
},
"application/xslt+xml": {
source: "iana",
compressible: true,
extensions: [
"xsl",
"xslt"
]
},
"application/xspf+xml": {
source: "apache",
compressible: true,
extensions: [
"xspf"
]
},
"application/xv+xml": {
source: "iana",
compressible: true,
extensions: [
"mxml",
"xhvml",
"xvml",
"xvm"
]
},
"application/yang": {
source: "iana",
extensions: [
"yang"
]
},
"application/yang-data+json": {
source: "iana",
compressible: true
},
"application/yang-data+xml": {
source: "iana",
compressible: true
},
"application/yang-patch+json": {
source: "iana",
compressible: true
},
"application/yang-patch+xml": {
source: "iana",
compressible: true
},
"application/yin+xml": {
source: "iana",
compressible: true,
extensions: [
"yin"
]
},
"application/zip": {
source: "iana",
compressible: false,
extensions: [
"zip"
]
},
"application/zlib": {
source: "iana"
},
"application/zstd": {
source: "iana"
},
"audio/1d-interleaved-parityfec": {
source: "iana"
},
"audio/32kadpcm": {
source: "iana"
},
"audio/3gpp": {
source: "iana",
compressible: false,
extensions: [
"3gpp"
]
},
"audio/3gpp2": {
source: "iana"
},
"audio/aac": {
source: "iana"
},
"audio/ac3": {
source: "iana"
},
"audio/adpcm": {
source: "apache",
extensions: [
"adp"
]
},
"audio/amr": {
source: "iana",
extensions: [
"amr"
]
},
"audio/amr-wb": {
source: "iana"
},
"audio/amr-wb+": {
source: "iana"
},
"audio/aptx": {
source: "iana"
},
"audio/asc": {
source: "iana"
},
"audio/atrac-advanced-lossless": {
source: "iana"
},
"audio/atrac-x": {
source: "iana"
},
"audio/atrac3": {
source: "iana"
},
"audio/basic": {
source: "iana",
compressible: false,
extensions: [
"au",
"snd"
]
},
"audio/bv16": {
source: "iana"
},
"audio/bv32": {
source: "iana"
},
"audio/clearmode": {
source: "iana"
},
"audio/cn": {
source: "iana"
},
"audio/dat12": {
source: "iana"
},
"audio/dls": {
source: "iana"
},
"audio/dsr-es201108": {
source: "iana"
},
"audio/dsr-es202050": {
source: "iana"
},
"audio/dsr-es202211": {
source: "iana"
},
"audio/dsr-es202212": {
source: "iana"
},
"audio/dv": {
source: "iana"
},
"audio/dvi4": {
source: "iana"
},
"audio/eac3": {
source: "iana"
},
"audio/encaprtp": {
source: "iana"
},
"audio/evrc": {
source: "iana"
},
"audio/evrc-qcp": {
source: "iana"
},
"audio/evrc0": {
source: "iana"
},
"audio/evrc1": {
source: "iana"
},
"audio/evrcb": {
source: "iana"
},
"audio/evrcb0": {
source: "iana"
},
"audio/evrcb1": {
source: "iana"
},
"audio/evrcnw": {
source: "iana"
},
"audio/evrcnw0": {
source: "iana"
},
"audio/evrcnw1": {
source: "iana"
},
"audio/evrcwb": {
source: "iana"
},
"audio/evrcwb0": {
source: "iana"
},
"audio/evrcwb1": {
source: "iana"
},
"audio/evs": {
source: "iana"
},
"audio/flexfec": {
source: "iana"
},
"audio/fwdred": {
source: "iana"
},
"audio/g711-0": {
source: "iana"
},
"audio/g719": {
source: "iana"
},
"audio/g722": {
source: "iana"
},
"audio/g7221": {
source: "iana"
},
"audio/g723": {
source: "iana"
},
"audio/g726-16": {
source: "iana"
},
"audio/g726-24": {
source: "iana"
},
"audio/g726-32": {
source: "iana"
},
"audio/g726-40": {
source: "iana"
},
"audio/g728": {
source: "iana"
},
"audio/g729": {
source: "iana"
},
"audio/g7291": {
source: "iana"
},
"audio/g729d": {
source: "iana"
},
"audio/g729e": {
source: "iana"
},
"audio/gsm": {
source: "iana"
},
"audio/gsm-efr": {
source: "iana"
},
"audio/gsm-hr-08": {
source: "iana"
},
"audio/ilbc": {
source: "iana"
},
"audio/ip-mr_v2.5": {
source: "iana"
},
"audio/isac": {
source: "apache"
},
"audio/l16": {
source: "iana"
},
"audio/l20": {
source: "iana"
},
"audio/l24": {
source: "iana",
compressible: false
},
"audio/l8": {
source: "iana"
},
"audio/lpc": {
source: "iana"
},
"audio/melp": {
source: "iana"
},
"audio/melp1200": {
source: "iana"
},
"audio/melp2400": {
source: "iana"
},
"audio/melp600": {
source: "iana"
},
"audio/mhas": {
source: "iana"
},
"audio/midi": {
source: "apache",
extensions: [
"mid",
"midi",
"kar",
"rmi"
]
},
"audio/mobile-xmf": {
source: "iana",
extensions: [
"mxmf"
]
},
"audio/mp3": {
compressible: false,
extensions: [
"mp3"
]
},
"audio/mp4": {
source: "iana",
compressible: false,
extensions: [
"m4a",
"mp4a"
]
},
"audio/mp4a-latm": {
source: "iana"
},
"audio/mpa": {
source: "iana"
},
"audio/mpa-robust": {
source: "iana"
},
"audio/mpeg": {
source: "iana",
compressible: false,
extensions: [
"mpga",
"mp2",
"mp2a",
"mp3",
"m2a",
"m3a"
]
},
"audio/mpeg4-generic": {
source: "iana"
},
"audio/musepack": {
source: "apache"
},
"audio/ogg": {
source: "iana",
compressible: false,
extensions: [
"oga",
"ogg",
"spx",
"opus"
]
},
"audio/opus": {
source: "iana"
},
"audio/parityfec": {
source: "iana"
},
"audio/pcma": {
source: "iana"
},
"audio/pcma-wb": {
source: "iana"
},
"audio/pcmu": {
source: "iana"
},
"audio/pcmu-wb": {
source: "iana"
},
"audio/prs.sid": {
source: "iana"
},
"audio/qcelp": {
source: "iana"
},
"audio/raptorfec": {
source: "iana"
},
"audio/red": {
source: "iana"
},
"audio/rtp-enc-aescm128": {
source: "iana"
},
"audio/rtp-midi": {
source: "iana"
},
"audio/rtploopback": {
source: "iana"
},
"audio/rtx": {
source: "iana"
},
"audio/s3m": {
source: "apache",
extensions: [
"s3m"
]
},
"audio/scip": {
source: "iana"
},
"audio/silk": {
source: "apache",
extensions: [
"sil"
]
},
"audio/smv": {
source: "iana"
},
"audio/smv-qcp": {
source: "iana"
},
"audio/smv0": {
source: "iana"
},
"audio/sofa": {
source: "iana"
},
"audio/sp-midi": {
source: "iana"
},
"audio/speex": {
source: "iana"
},
"audio/t140c": {
source: "iana"
},
"audio/t38": {
source: "iana"
},
"audio/telephone-event": {
source: "iana"
},
"audio/tetra_acelp": {
source: "iana"
},
"audio/tetra_acelp_bb": {
source: "iana"
},
"audio/tone": {
source: "iana"
},
"audio/tsvcis": {
source: "iana"
},
"audio/uemclip": {
source: "iana"
},
"audio/ulpfec": {
source: "iana"
},
"audio/usac": {
source: "iana"
},
"audio/vdvi": {
source: "iana"
},
"audio/vmr-wb": {
source: "iana"
},
"audio/vnd.3gpp.iufp": {
source: "iana"
},
"audio/vnd.4sb": {
source: "iana"
},
"audio/vnd.audiokoz": {
source: "iana"
},
"audio/vnd.celp": {
source: "iana"
},
"audio/vnd.cisco.nse": {
source: "iana"
},
"audio/vnd.cmles.radio-events": {
source: "iana"
},
"audio/vnd.cns.anp1": {
source: "iana"
},
"audio/vnd.cns.inf1": {
source: "iana"
},
"audio/vnd.dece.audio": {
source: "iana",
extensions: [
"uva",
"uvva"
]
},
"audio/vnd.digital-winds": {
source: "iana",
extensions: [
"eol"
]
},
"audio/vnd.dlna.adts": {
source: "iana"
},
"audio/vnd.dolby.heaac.1": {
source: "iana"
},
"audio/vnd.dolby.heaac.2": {
source: "iana"
},
"audio/vnd.dolby.mlp": {
source: "iana"
},
"audio/vnd.dolby.mps": {
source: "iana"
},
"audio/vnd.dolby.pl2": {
source: "iana"
},
"audio/vnd.dolby.pl2x": {
source: "iana"
},
"audio/vnd.dolby.pl2z": {
source: "iana"
},
"audio/vnd.dolby.pulse.1": {
source: "iana"
},
"audio/vnd.dra": {
source: "iana",
extensions: [
"dra"
]
},
"audio/vnd.dts": {
source: "iana",
extensions: [
"dts"
]
},
"audio/vnd.dts.hd": {
source: "iana",
extensions: [
"dtshd"
]
},
"audio/vnd.dts.uhd": {
source: "iana"
},
"audio/vnd.dvb.file": {
source: "iana"
},
"audio/vnd.everad.plj": {
source: "iana"
},
"audio/vnd.hns.audio": {
source: "iana"
},
"audio/vnd.lucent.voice": {
source: "iana",
extensions: [
"lvp"
]
},
"audio/vnd.ms-playready.media.pya": {
source: "iana",
extensions: [
"pya"
]
},
"audio/vnd.nokia.mobile-xmf": {
source: "iana"
},
"audio/vnd.nortel.vbk": {
source: "iana"
},
"audio/vnd.nuera.ecelp4800": {
source: "iana",
extensions: [
"ecelp4800"
]
},
"audio/vnd.nuera.ecelp7470": {
source: "iana",
extensions: [
"ecelp7470"
]
},
"audio/vnd.nuera.ecelp9600": {
source: "iana",
extensions: [
"ecelp9600"
]
},
"audio/vnd.octel.sbc": {
source: "iana"
},
"audio/vnd.presonus.multitrack": {
source: "iana"
},
"audio/vnd.qcelp": {
source: "iana"
},
"audio/vnd.rhetorex.32kadpcm": {
source: "iana"
},
"audio/vnd.rip": {
source: "iana",
extensions: [
"rip"
]
},
"audio/vnd.rn-realaudio": {
compressible: false
},
"audio/vnd.sealedmedia.softseal.mpeg": {
source: "iana"
},
"audio/vnd.vmx.cvsd": {
source: "iana"
},
"audio/vnd.wave": {
compressible: false
},
"audio/vorbis": {
source: "iana",
compressible: false
},
"audio/vorbis-config": {
source: "iana"
},
"audio/wav": {
compressible: false,
extensions: [
"wav"
]
},
"audio/wave": {
compressible: false,
extensions: [
"wav"
]
},
"audio/webm": {
source: "apache",
compressible: false,
extensions: [
"weba"
]
},
"audio/x-aac": {
source: "apache",
compressible: false,
extensions: [
"aac"
]
},
"audio/x-aiff": {
source: "apache",
extensions: [
"aif",
"aiff",
"aifc"
]
},
"audio/x-caf": {
source: "apache",
compressible: false,
extensions: [
"caf"
]
},
"audio/x-flac": {
source: "apache",
extensions: [
"flac"
]
},
"audio/x-m4a": {
source: "nginx",
extensions: [
"m4a"
]
},
"audio/x-matroska": {
source: "apache",
extensions: [
"mka"
]
},
"audio/x-mpegurl": {
source: "apache",
extensions: [
"m3u"
]
},
"audio/x-ms-wax": {
source: "apache",
extensions: [
"wax"
]
},
"audio/x-ms-wma": {
source: "apache",
extensions: [
"wma"
]
},
"audio/x-pn-realaudio": {
source: "apache",
extensions: [
"ram",
"ra"
]
},
"audio/x-pn-realaudio-plugin": {
source: "apache",
extensions: [
"rmp"
]
},
"audio/x-realaudio": {
source: "nginx",
extensions: [
"ra"
]
},
"audio/x-tta": {
source: "apache"
},
"audio/x-wav": {
source: "apache",
extensions: [
"wav"
]
},
"audio/xm": {
source: "apache",
extensions: [
"xm"
]
},
"chemical/x-cdx": {
source: "apache",
extensions: [
"cdx"
]
},
"chemical/x-cif": {
source: "apache",
extensions: [
"cif"
]
},
"chemical/x-cmdf": {
source: "apache",
extensions: [
"cmdf"
]
},
"chemical/x-cml": {
source: "apache",
extensions: [
"cml"
]
},
"chemical/x-csml": {
source: "apache",
extensions: [
"csml"
]
},
"chemical/x-pdb": {
source: "apache"
},
"chemical/x-xyz": {
source: "apache",
extensions: [
"xyz"
]
},
"font/collection": {
source: "iana",
extensions: [
"ttc"
]
},
"font/otf": {
source: "iana",
compressible: true,
extensions: [
"otf"
]
},
"font/sfnt": {
source: "iana"
},
"font/ttf": {
source: "iana",
compressible: true,
extensions: [
"ttf"
]
},
"font/woff": {
source: "iana",
extensions: [
"woff"
]
},
"font/woff2": {
source: "iana",
extensions: [
"woff2"
]
},
"image/aces": {
source: "iana",
extensions: [
"exr"
]
},
"image/apng": {
compressible: false,
extensions: [
"apng"
]
},
"image/avci": {
source: "iana"
},
"image/avcs": {
source: "iana"
},
"image/avif": {
source: "iana",
compressible: false,
extensions: [
"avif"
]
},
"image/bmp": {
source: "iana",
compressible: true,
extensions: [
"bmp"
]
},
"image/cgm": {
source: "iana",
extensions: [
"cgm"
]
},
"image/dicom-rle": {
source: "iana",
extensions: [
"drle"
]
},
"image/emf": {
source: "iana",
extensions: [
"emf"
]
},
"image/fits": {
source: "iana",
extensions: [
"fits"
]
},
"image/g3fax": {
source: "iana",
extensions: [
"g3"
]
},
"image/gif": {
source: "iana",
compressible: false,
extensions: [
"gif"
]
},
"image/heic": {
source: "iana",
extensions: [
"heic"
]
},
"image/heic-sequence": {
source: "iana",
extensions: [
"heics"
]
},
"image/heif": {
source: "iana",
extensions: [
"heif"
]
},
"image/heif-sequence": {
source: "iana",
extensions: [
"heifs"
]
},
"image/hej2k": {
source: "iana",
extensions: [
"hej2"
]
},
"image/hsj2": {
source: "iana",
extensions: [
"hsj2"
]
},
"image/ief": {
source: "iana",
extensions: [
"ief"
]
},
"image/jls": {
source: "iana",
extensions: [
"jls"
]
},
"image/jp2": {
source: "iana",
compressible: false,
extensions: [
"jp2",
"jpg2"
]
},
"image/jpeg": {
source: "iana",
compressible: false,
extensions: [
"jpeg",
"jpg",
"jpe"
]
},
"image/jph": {
source: "iana",
extensions: [
"jph"
]
},
"image/jphc": {
source: "iana",
extensions: [
"jhc"
]
},
"image/jpm": {
source: "iana",
compressible: false,
extensions: [
"jpm"
]
},
"image/jpx": {
source: "iana",
compressible: false,
extensions: [
"jpx",
"jpf"
]
},
"image/jxr": {
source: "iana",
extensions: [
"jxr"
]
},
"image/jxra": {
source: "iana",
extensions: [
"jxra"
]
},
"image/jxrs": {
source: "iana",
extensions: [
"jxrs"
]
},
"image/jxs": {
source: "iana",
extensions: [
"jxs"
]
},
"image/jxsc": {
source: "iana",
extensions: [
"jxsc"
]
},
"image/jxsi": {
source: "iana",
extensions: [
"jxsi"
]
},
"image/jxss": {
source: "iana",
extensions: [
"jxss"
]
},
"image/ktx": {
source: "iana",
extensions: [
"ktx"
]
},
"image/ktx2": {
source: "iana",
extensions: [
"ktx2"
]
},
"image/naplps": {
source: "iana"
},
"image/pjpeg": {
compressible: false
},
"image/png": {
source: "iana",
compressible: false,
extensions: [
"png"
]
},
"image/prs.btif": {
source: "iana",
extensions: [
"btif"
]
},
"image/prs.pti": {
source: "iana",
extensions: [
"pti"
]
},
"image/pwg-raster": {
source: "iana"
},
"image/sgi": {
source: "apache",
extensions: [
"sgi"
]
},
"image/svg+xml": {
source: "iana",
compressible: true,
extensions: [
"svg",
"svgz"
]
},
"image/t38": {
source: "iana",
extensions: [
"t38"
]
},
"image/tiff": {
source: "iana",
compressible: false,
extensions: [
"tif",
"tiff"
]
},
"image/tiff-fx": {
source: "iana",
extensions: [
"tfx"
]
},
"image/vnd.adobe.photoshop": {
source: "iana",
compressible: true,
extensions: [
"psd"
]
},
"image/vnd.airzip.accelerator.azv": {
source: "iana",
extensions: [
"azv"
]
},
"image/vnd.cns.inf2": {
source: "iana"
},
"image/vnd.dece.graphic": {
source: "iana",
extensions: [
"uvi",
"uvvi",
"uvg",
"uvvg"
]
},
"image/vnd.djvu": {
source: "iana",
extensions: [
"djvu",
"djv"
]
},
"image/vnd.dvb.subtitle": {
source: "iana",
extensions: [
"sub"
]
},
"image/vnd.dwg": {
source: "iana",
extensions: [
"dwg"
]
},
"image/vnd.dxf": {
source: "iana",
extensions: [
"dxf"
]
},
"image/vnd.fastbidsheet": {
source: "iana",
extensions: [
"fbs"
]
},
"image/vnd.fpx": {
source: "iana",
extensions: [
"fpx"
]
},
"image/vnd.fst": {
source: "iana",
extensions: [
"fst"
]
},
"image/vnd.fujixerox.edmics-mmr": {
source: "iana",
extensions: [
"mmr"
]
},
"image/vnd.fujixerox.edmics-rlc": {
source: "iana",
extensions: [
"rlc"
]
},
"image/vnd.globalgraphics.pgb": {
source: "iana"
},
"image/vnd.microsoft.icon": {
source: "iana",
compressible: true,
extensions: [
"ico"
]
},
"image/vnd.mix": {
source: "iana"
},
"image/vnd.mozilla.apng": {
source: "iana"
},
"image/vnd.ms-dds": {
compressible: true,
extensions: [
"dds"
]
},
"image/vnd.ms-modi": {
source: "iana",
extensions: [
"mdi"
]
},
"image/vnd.ms-photo": {
source: "apache",
extensions: [
"wdp"
]
},
"image/vnd.net-fpx": {
source: "iana",
extensions: [
"npx"
]
},
"image/vnd.pco.b16": {
source: "iana",
extensions: [
"b16"
]
},
"image/vnd.radiance": {
source: "iana"
},
"image/vnd.sealed.png": {
source: "iana"
},
"image/vnd.sealedmedia.softseal.gif": {
source: "iana"
},
"image/vnd.sealedmedia.softseal.jpg": {
source: "iana"
},
"image/vnd.svf": {
source: "iana"
},
"image/vnd.tencent.tap": {
source: "iana",
extensions: [
"tap"
]
},
"image/vnd.valve.source.texture": {
source: "iana",
extensions: [
"vtf"
]
},
"image/vnd.wap.wbmp": {
source: "iana",
extensions: [
"wbmp"
]
},
"image/vnd.xiff": {
source: "iana",
extensions: [
"xif"
]
},
"image/vnd.zbrush.pcx": {
source: "iana",
extensions: [
"pcx"
]
},
"image/webp": {
source: "apache",
extensions: [
"webp"
]
},
"image/wmf": {
source: "iana",
extensions: [
"wmf"
]
},
"image/x-3ds": {
source: "apache",
extensions: [
"3ds"
]
},
"image/x-cmu-raster": {
source: "apache",
extensions: [
"ras"
]
},
"image/x-cmx": {
source: "apache",
extensions: [
"cmx"
]
},
"image/x-freehand": {
source: "apache",
extensions: [
"fh",
"fhc",
"fh4",
"fh5",
"fh7"
]
},
"image/x-icon": {
source: "apache",
compressible: true,
extensions: [
"ico"
]
},
"image/x-jng": {
source: "nginx",
extensions: [
"jng"
]
},
"image/x-mrsid-image": {
source: "apache",
extensions: [
"sid"
]
},
"image/x-ms-bmp": {
source: "nginx",
compressible: true,
extensions: [
"bmp"
]
},
"image/x-pcx": {
source: "apache",
extensions: [
"pcx"
]
},
"image/x-pict": {
source: "apache",
extensions: [
"pic",
"pct"
]
},
"image/x-portable-anymap": {
source: "apache",
extensions: [
"pnm"
]
},
"image/x-portable-bitmap": {
source: "apache",
extensions: [
"pbm"
]
},
"image/x-portable-graymap": {
source: "apache",
extensions: [
"pgm"
]
},
"image/x-portable-pixmap": {
source: "apache",
extensions: [
"ppm"
]
},
"image/x-rgb": {
source: "apache",
extensions: [
"rgb"
]
},
"image/x-tga": {
source: "apache",
extensions: [
"tga"
]
},
"image/x-xbitmap": {
source: "apache",
extensions: [
"xbm"
]
},
"image/x-xcf": {
compressible: false
},
"image/x-xpixmap": {
source: "apache",
extensions: [
"xpm"
]
},
"image/x-xwindowdump": {
source: "apache",
extensions: [
"xwd"
]
},
"message/cpim": {
source: "iana"
},
"message/delivery-status": {
source: "iana"
},
"message/disposition-notification": {
source: "iana",
extensions: [
"disposition-notification"
]
},
"message/external-body": {
source: "iana"
},
"message/feedback-report": {
source: "iana"
},
"message/global": {
source: "iana",
extensions: [
"u8msg"
]
},
"message/global-delivery-status": {
source: "iana",
extensions: [
"u8dsn"
]
},
"message/global-disposition-notification": {
source: "iana",
extensions: [
"u8mdn"
]
},
"message/global-headers": {
source: "iana",
extensions: [
"u8hdr"
]
},
"message/http": {
source: "iana",
compressible: false
},
"message/imdn+xml": {
source: "iana",
compressible: true
},
"message/news": {
source: "iana"
},
"message/partial": {
source: "iana",
compressible: false
},
"message/rfc822": {
source: "iana",
compressible: true,
extensions: [
"eml",
"mime"
]
},
"message/s-http": {
source: "iana"
},
"message/sip": {
source: "iana"
},
"message/sipfrag": {
source: "iana"
},
"message/tracking-status": {
source: "iana"
},
"message/vnd.si.simp": {
source: "iana"
},
"message/vnd.wfa.wsc": {
source: "iana",
extensions: [
"wsc"
]
},
"model/3mf": {
source: "iana",
extensions: [
"3mf"
]
},
"model/e57": {
source: "iana"
},
"model/gltf+json": {
source: "iana",
compressible: true,
extensions: [
"gltf"
]
},
"model/gltf-binary": {
source: "iana",
compressible: true,
extensions: [
"glb"
]
},
"model/iges": {
source: "iana",
compressible: false,
extensions: [
"igs",
"iges"
]
},
"model/mesh": {
source: "iana",
compressible: false,
extensions: [
"msh",
"mesh",
"silo"
]
},
"model/mtl": {
source: "iana",
extensions: [
"mtl"
]
},
"model/obj": {
source: "iana",
extensions: [
"obj"
]
},
"model/step": {
source: "iana"
},
"model/step+xml": {
source: "iana",
compressible: true,
extensions: [
"stpx"
]
},
"model/step+zip": {
source: "iana",
compressible: false,
extensions: [
"stpz"
]
},
"model/step-xml+zip": {
source: "iana",
compressible: false,
extensions: [
"stpxz"
]
},
"model/stl": {
source: "iana",
extensions: [
"stl"
]
},
"model/vnd.collada+xml": {
source: "iana",
compressible: true,
extensions: [
"dae"
]
},
"model/vnd.dwf": {
source: "iana",
extensions: [
"dwf"
]
},
"model/vnd.flatland.3dml": {
source: "iana"
},
"model/vnd.gdl": {
source: "iana",
extensions: [
"gdl"
]
},
"model/vnd.gs-gdl": {
source: "apache"
},
"model/vnd.gs.gdl": {
source: "iana"
},
"model/vnd.gtw": {
source: "iana",
extensions: [
"gtw"
]
},
"model/vnd.moml+xml": {
source: "iana",
compressible: true
},
"model/vnd.mts": {
source: "iana",
extensions: [
"mts"
]
},
"model/vnd.opengex": {
source: "iana",
extensions: [
"ogex"
]
},
"model/vnd.parasolid.transmit.binary": {
source: "iana",
extensions: [
"x_b"
]
},
"model/vnd.parasolid.transmit.text": {
source: "iana",
extensions: [
"x_t"
]
},
"model/vnd.pytha.pyox": {
source: "iana"
},
"model/vnd.rosette.annotated-data-model": {
source: "iana"
},
"model/vnd.sap.vds": {
source: "iana",
extensions: [
"vds"
]
},
"model/vnd.usdz+zip": {
source: "iana",
compressible: false,
extensions: [
"usdz"
]
},
"model/vnd.valve.source.compiled-map": {
source: "iana",
extensions: [
"bsp"
]
},
"model/vnd.vtu": {
source: "iana",
extensions: [
"vtu"
]
},
"model/vrml": {
source: "iana",
compressible: false,
extensions: [
"wrl",
"vrml"
]
},
"model/x3d+binary": {
source: "apache",
compressible: false,
extensions: [
"x3db",
"x3dbz"
]
},
"model/x3d+fastinfoset": {
source: "iana",
extensions: [
"x3db"
]
},
"model/x3d+vrml": {
source: "apache",
compressible: false,
extensions: [
"x3dv",
"x3dvz"
]
},
"model/x3d+xml": {
source: "iana",
compressible: true,
extensions: [
"x3d",
"x3dz"
]
},
"model/x3d-vrml": {
source: "iana",
extensions: [
"x3dv"
]
},
"multipart/alternative": {
source: "iana",
compressible: false
},
"multipart/appledouble": {
source: "iana"
},
"multipart/byteranges": {
source: "iana"
},
"multipart/digest": {
source: "iana"
},
"multipart/encrypted": {
source: "iana",
compressible: false
},
"multipart/form-data": {
source: "iana",
compressible: false
},
"multipart/header-set": {
source: "iana"
},
"multipart/mixed": {
source: "iana"
},
"multipart/multilingual": {
source: "iana"
},
"multipart/parallel": {
source: "iana"
},
"multipart/related": {
source: "iana",
compressible: false
},
"multipart/report": {
source: "iana"
},
"multipart/signed": {
source: "iana",
compressible: false
},
"multipart/vnd.bint.med-plus": {
source: "iana"
},
"multipart/voice-message": {
source: "iana"
},
"multipart/x-mixed-replace": {
source: "iana"
},
"text/1d-interleaved-parityfec": {
source: "iana"
},
"text/cache-manifest": {
source: "iana",
compressible: true,
extensions: [
"appcache",
"manifest"
]
},
"text/calendar": {
source: "iana",
extensions: [
"ics",
"ifb"
]
},
"text/calender": {
compressible: true
},
"text/cmd": {
compressible: true
},
"text/coffeescript": {
extensions: [
"coffee",
"litcoffee"
]
},
"text/cql": {
source: "iana"
},
"text/cql-expression": {
source: "iana"
},
"text/cql-identifier": {
source: "iana"
},
"text/css": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"css"
]
},
"text/csv": {
source: "iana",
compressible: true,
extensions: [
"csv"
]
},
"text/csv-schema": {
source: "iana"
},
"text/directory": {
source: "iana"
},
"text/dns": {
source: "iana"
},
"text/ecmascript": {
source: "iana"
},
"text/encaprtp": {
source: "iana"
},
"text/enriched": {
source: "iana"
},
"text/fhirpath": {
source: "iana"
},
"text/flexfec": {
source: "iana"
},
"text/fwdred": {
source: "iana"
},
"text/gff3": {
source: "iana"
},
"text/grammar-ref-list": {
source: "iana"
},
"text/html": {
source: "iana",
compressible: true,
extensions: [
"html",
"htm",
"shtml"
]
},
"text/jade": {
extensions: [
"jade"
]
},
"text/javascript": {
source: "iana",
compressible: true
},
"text/jcr-cnd": {
source: "iana"
},
"text/jsx": {
compressible: true,
extensions: [
"jsx"
]
},
"text/less": {
compressible: true,
extensions: [
"less"
]
},
"text/markdown": {
source: "iana",
compressible: true,
extensions: [
"markdown",
"md"
]
},
"text/mathml": {
source: "nginx",
extensions: [
"mml"
]
},
"text/mdx": {
compressible: true,
extensions: [
"mdx"
]
},
"text/mizar": {
source: "iana"
},
"text/n3": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"n3"
]
},
"text/parameters": {
source: "iana",
charset: "UTF-8"
},
"text/parityfec": {
source: "iana"
},
"text/plain": {
source: "iana",
compressible: true,
extensions: [
"txt",
"text",
"conf",
"def",
"list",
"log",
"in",
"ini"
]
},
"text/provenance-notation": {
source: "iana",
charset: "UTF-8"
},
"text/prs.fallenstein.rst": {
source: "iana"
},
"text/prs.lines.tag": {
source: "iana",
extensions: [
"dsc"
]
},
"text/prs.prop.logic": {
source: "iana"
},
"text/raptorfec": {
source: "iana"
},
"text/red": {
source: "iana"
},
"text/rfc822-headers": {
source: "iana"
},
"text/richtext": {
source: "iana",
compressible: true,
extensions: [
"rtx"
]
},
"text/rtf": {
source: "iana",
compressible: true,
extensions: [
"rtf"
]
},
"text/rtp-enc-aescm128": {
source: "iana"
},
"text/rtploopback": {
source: "iana"
},
"text/rtx": {
source: "iana"
},
"text/sgml": {
source: "iana",
extensions: [
"sgml",
"sgm"
]
},
"text/shaclc": {
source: "iana"
},
"text/shex": {
source: "iana",
extensions: [
"shex"
]
},
"text/slim": {
extensions: [
"slim",
"slm"
]
},
"text/spdx": {
source: "iana",
extensions: [
"spdx"
]
},
"text/strings": {
source: "iana"
},
"text/stylus": {
extensions: [
"stylus",
"styl"
]
},
"text/t140": {
source: "iana"
},
"text/tab-separated-values": {
source: "iana",
compressible: true,
extensions: [
"tsv"
]
},
"text/troff": {
source: "iana",
extensions: [
"t",
"tr",
"roff",
"man",
"me",
"ms"
]
},
"text/turtle": {
source: "iana",
charset: "UTF-8",
extensions: [
"ttl"
]
},
"text/ulpfec": {
source: "iana"
},
"text/uri-list": {
source: "iana",
compressible: true,
extensions: [
"uri",
"uris",
"urls"
]
},
"text/vcard": {
source: "iana",
compressible: true,
extensions: [
"vcard"
]
},
"text/vnd.a": {
source: "iana"
},
"text/vnd.abc": {
source: "iana"
},
"text/vnd.ascii-art": {
source: "iana"
},
"text/vnd.curl": {
source: "iana",
extensions: [
"curl"
]
},
"text/vnd.curl.dcurl": {
source: "apache",
extensions: [
"dcurl"
]
},
"text/vnd.curl.mcurl": {
source: "apache",
extensions: [
"mcurl"
]
},
"text/vnd.curl.scurl": {
source: "apache",
extensions: [
"scurl"
]
},
"text/vnd.debian.copyright": {
source: "iana",
charset: "UTF-8"
},
"text/vnd.dmclientscript": {
source: "iana"
},
"text/vnd.dvb.subtitle": {
source: "iana",
extensions: [
"sub"
]
},
"text/vnd.esmertec.theme-descriptor": {
source: "iana",
charset: "UTF-8"
},
"text/vnd.familysearch.gedcom": {
source: "iana",
extensions: [
"ged"
]
},
"text/vnd.ficlab.flt": {
source: "iana"
},
"text/vnd.fly": {
source: "iana",
extensions: [
"fly"
]
},
"text/vnd.fmi.flexstor": {
source: "iana",
extensions: [
"flx"
]
},
"text/vnd.gml": {
source: "iana"
},
"text/vnd.graphviz": {
source: "iana",
extensions: [
"gv"
]
},
"text/vnd.hans": {
source: "iana"
},
"text/vnd.hgl": {
source: "iana"
},
"text/vnd.in3d.3dml": {
source: "iana",
extensions: [
"3dml"
]
},
"text/vnd.in3d.spot": {
source: "iana",
extensions: [
"spot"
]
},
"text/vnd.iptc.newsml": {
source: "iana"
},
"text/vnd.iptc.nitf": {
source: "iana"
},
"text/vnd.latex-z": {
source: "iana"
},
"text/vnd.motorola.reflex": {
source: "iana"
},
"text/vnd.ms-mediapackage": {
source: "iana"
},
"text/vnd.net2phone.commcenter.command": {
source: "iana"
},
"text/vnd.radisys.msml-basic-layout": {
source: "iana"
},
"text/vnd.senx.warpscript": {
source: "iana"
},
"text/vnd.si.uricatalogue": {
source: "iana"
},
"text/vnd.sosi": {
source: "iana"
},
"text/vnd.sun.j2me.app-descriptor": {
source: "iana",
charset: "UTF-8",
extensions: [
"jad"
]
},
"text/vnd.trolltech.linguist": {
source: "iana",
charset: "UTF-8"
},
"text/vnd.wap.si": {
source: "iana"
},
"text/vnd.wap.sl": {
source: "iana"
},
"text/vnd.wap.wml": {
source: "iana",
extensions: [
"wml"
]
},
"text/vnd.wap.wmlscript": {
source: "iana",
extensions: [
"wmls"
]
},
"text/vtt": {
source: "iana",
charset: "UTF-8",
compressible: true,
extensions: [
"vtt"
]
},
"text/x-asm": {
source: "apache",
extensions: [
"s",
"asm"
]
},
"text/x-c": {
source: "apache",
extensions: [
"c",
"cc",
"cxx",
"cpp",
"h",
"hh",
"dic"
]
},
"text/x-component": {
source: "nginx",
extensions: [
"htc"
]
},
"text/x-fortran": {
source: "apache",
extensions: [
"f",
"for",
"f77",
"f90"
]
},
"text/x-gwt-rpc": {
compressible: true
},
"text/x-handlebars-template": {
extensions: [
"hbs"
]
},
"text/x-java-source": {
source: "apache",
extensions: [
"java"
]
},
"text/x-jquery-tmpl": {
compressible: true
},
"text/x-lua": {
extensions: [
"lua"
]
},
"text/x-markdown": {
compressible: true,
extensions: [
"mkd"
]
},
"text/x-nfo": {
source: "apache",
extensions: [
"nfo"
]
},
"text/x-opml": {
source: "apache",
extensions: [
"opml"
]
},
"text/x-org": {
compressible: true,
extensions: [
"org"
]
},
"text/x-pascal": {
source: "apache",
extensions: [
"p",
"pas"
]
},
"text/x-processing": {
compressible: true,
extensions: [
"pde"
]
},
"text/x-sass": {
extensions: [
"sass"
]
},
"text/x-scss": {
extensions: [
"scss"
]
},
"text/x-setext": {
source: "apache",
extensions: [
"etx"
]
},
"text/x-sfv": {
source: "apache",
extensions: [
"sfv"
]
},
"text/x-suse-ymp": {
compressible: true,
extensions: [
"ymp"
]
},
"text/x-uuencode": {
source: "apache",
extensions: [
"uu"
]
},
"text/x-vcalendar": {
source: "apache",
extensions: [
"vcs"
]
},
"text/x-vcard": {
source: "apache",
extensions: [
"vcf"
]
},
"text/xml": {
source: "iana",
compressible: true,
extensions: [
"xml"
]
},
"text/xml-external-parsed-entity": {
source: "iana"
},
"text/yaml": {
compressible: true,
extensions: [
"yaml",
"yml"
]
},
"video/1d-interleaved-parityfec": {
source: "iana"
},
"video/3gpp": {
source: "iana",
extensions: [
"3gp",
"3gpp"
]
},
"video/3gpp-tt": {
source: "iana"
},
"video/3gpp2": {
source: "iana",
extensions: [
"3g2"
]
},
"video/av1": {
source: "iana"
},
"video/bmpeg": {
source: "iana"
},
"video/bt656": {
source: "iana"
},
"video/celb": {
source: "iana"
},
"video/dv": {
source: "iana"
},
"video/encaprtp": {
source: "iana"
},
"video/ffv1": {
source: "iana"
},
"video/flexfec": {
source: "iana"
},
"video/h261": {
source: "iana",
extensions: [
"h261"
]
},
"video/h263": {
source: "iana",
extensions: [
"h263"
]
},
"video/h263-1998": {
source: "iana"
},
"video/h263-2000": {
source: "iana"
},
"video/h264": {
source: "iana",
extensions: [
"h264"
]
},
"video/h264-rcdo": {
source: "iana"
},
"video/h264-svc": {
source: "iana"
},
"video/h265": {
source: "iana"
},
"video/iso.segment": {
source: "iana",
extensions: [
"m4s"
]
},
"video/jpeg": {
source: "iana",
extensions: [
"jpgv"
]
},
"video/jpeg2000": {
source: "iana"
},
"video/jpm": {
source: "apache",
extensions: [
"jpm",
"jpgm"
]
},
"video/jxsv": {
source: "iana"
},
"video/mj2": {
source: "iana",
extensions: [
"mj2",
"mjp2"
]
},
"video/mp1s": {
source: "iana"
},
"video/mp2p": {
source: "iana"
},
"video/mp2t": {
source: "iana",
extensions: [
"ts"
]
},
"video/mp4": {
source: "iana",
compressible: false,
extensions: [
"mp4",
"mp4v",
"mpg4"
]
},
"video/mp4v-es": {
source: "iana"
},
"video/mpeg": {
source: "iana",
compressible: false,
extensions: [
"mpeg",
"mpg",
"mpe",
"m1v",
"m2v"
]
},
"video/mpeg4-generic": {
source: "iana"
},
"video/mpv": {
source: "iana"
},
"video/nv": {
source: "iana"
},
"video/ogg": {
source: "iana",
compressible: false,
extensions: [
"ogv"
]
},
"video/parityfec": {
source: "iana"
},
"video/pointer": {
source: "iana"
},
"video/quicktime": {
source: "iana",
compressible: false,
extensions: [
"qt",
"mov"
]
},
"video/raptorfec": {
source: "iana"
},
"video/raw": {
source: "iana"
},
"video/rtp-enc-aescm128": {
source: "iana"
},
"video/rtploopback": {
source: "iana"
},
"video/rtx": {
source: "iana"
},
"video/scip": {
source: "iana"
},
"video/smpte291": {
source: "iana"
},
"video/smpte292m": {
source: "iana"
},
"video/ulpfec": {
source: "iana"
},
"video/vc1": {
source: "iana"
},
"video/vc2": {
source: "iana"
},
"video/vnd.cctv": {
source: "iana"
},
"video/vnd.dece.hd": {
source: "iana",
extensions: [
"uvh",
"uvvh"
]
},
"video/vnd.dece.mobile": {
source: "iana",
extensions: [
"uvm",
"uvvm"
]
},
"video/vnd.dece.mp4": {
source: "iana"
},
"video/vnd.dece.pd": {
source: "iana",
extensions: [
"uvp",
"uvvp"
]
},
"video/vnd.dece.sd": {
source: "iana",
extensions: [
"uvs",
"uvvs"
]
},
"video/vnd.dece.video": {
source: "iana",
extensions: [
"uvv",
"uvvv"
]
},
"video/vnd.directv.mpeg": {
source: "iana"
},
"video/vnd.directv.mpeg-tts": {
source: "iana"
},
"video/vnd.dlna.mpeg-tts": {
source: "iana"
},
"video/vnd.dvb.file": {
source: "iana",
extensions: [
"dvb"
]
},
"video/vnd.fvt": {
source: "iana",
extensions: [
"fvt"
]
},
"video/vnd.hns.video": {
source: "iana"
},
"video/vnd.iptvforum.1dparityfec-1010": {
source: "iana"
},
"video/vnd.iptvforum.1dparityfec-2005": {
source: "iana"
},
"video/vnd.iptvforum.2dparityfec-1010": {
source: "iana"
},
"video/vnd.iptvforum.2dparityfec-2005": {
source: "iana"
},
"video/vnd.iptvforum.ttsavc": {
source: "iana"
},
"video/vnd.iptvforum.ttsmpeg2": {
source: "iana"
},
"video/vnd.motorola.video": {
source: "iana"
},
"video/vnd.motorola.videop": {
source: "iana"
},
"video/vnd.mpegurl": {
source: "iana",
extensions: [
"mxu",
"m4u"
]
},
"video/vnd.ms-playready.media.pyv": {
source: "iana",
extensions: [
"pyv"
]
},
"video/vnd.nokia.interleaved-multimedia": {
source: "iana"
},
"video/vnd.nokia.mp4vr": {
source: "iana"
},
"video/vnd.nokia.videovoip": {
source: "iana"
},
"video/vnd.objectvideo": {
source: "iana"
},
"video/vnd.radgamettools.bink": {
source: "iana"
},
"video/vnd.radgamettools.smacker": {
source: "iana"
},
"video/vnd.sealed.mpeg1": {
source: "iana"
},
"video/vnd.sealed.mpeg4": {
source: "iana"
},
"video/vnd.sealed.swf": {
source: "iana"
},
"video/vnd.sealedmedia.softseal.mov": {
source: "iana"
},
"video/vnd.uvvu.mp4": {
source: "iana",
extensions: [
"uvu",
"uvvu"
]
},
"video/vnd.vivo": {
source: "iana",
extensions: [
"viv"
]
},
"video/vnd.youtube.yt": {
source: "iana"
},
"video/vp8": {
source: "iana"
},
"video/vp9": {
source: "iana"
},
"video/webm": {
source: "apache",
compressible: false,
extensions: [
"webm"
]
},
"video/x-f4v": {
source: "apache",
extensions: [
"f4v"
]
},
"video/x-fli": {
source: "apache",
extensions: [
"fli"
]
},
"video/x-flv": {
source: "apache",
compressible: false,
extensions: [
"flv"
]
},
"video/x-m4v": {
source: "apache",
extensions: [
"m4v"
]
},
"video/x-matroska": {
source: "apache",
compressible: false,
extensions: [
"mkv",
"mk3d",
"mks"
]
},
"video/x-mng": {
source: "apache",
extensions: [
"mng"
]
},
"video/x-ms-asf": {
source: "apache",
extensions: [
"asf",
"asx"
]
},
"video/x-ms-vob": {
source: "apache",
extensions: [
"vob"
]
},
"video/x-ms-wm": {
source: "apache",
extensions: [
"wm"
]
},
"video/x-ms-wmv": {
source: "apache",
compressible: false,
extensions: [
"wmv"
]
},
"video/x-ms-wmx": {
source: "apache",
extensions: [
"wmx"
]
},
"video/x-ms-wvx": {
source: "apache",
extensions: [
"wvx"
]
},
"video/x-msvideo": {
source: "apache",
extensions: [
"avi"
]
},
"video/x-sgi-movie": {
source: "apache",
extensions: [
"movie"
]
},
"video/x-smv": {
source: "apache",
extensions: [
"smv"
]
},
"x-conference/x-cooltalk": {
source: "apache",
extensions: [
"ice"
]
},
"x-shader/x-fragment": {
compressible: true
},
"x-shader/x-vertex": {
compressible: true
}
};
/*!
* mime-db
* Copyright(c) 2014 Jonathan Ong
* MIT Licensed
*/
/**
* Module exports.
*/
var mimeDb = require$$0;
/*!
* mime-types
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
(function (exports) {
/**
* Module dependencies.
* @private
*/
var db = mimeDb;
var extname = require$$1__default$4["default"].extname;
/**
* Module variables.
* @private
*/
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
var TEXT_TYPE_REGEXP = /^text\//i;
/**
* Module exports.
* @public
*/
exports.charset = charset;
exports.charsets = { lookup: charset };
exports.contentType = contentType;
exports.extension = extension;
exports.extensions = Object.create(null);
exports.lookup = lookup;
exports.types = Object.create(null);
// Populate the extensions/types maps
populateMaps(exports.extensions, exports.types);
/**
* Get the default charset for a MIME type.
*
* @param {string} type
* @return {boolean|string}
*/
function charset (type) {
if (!type || typeof type !== 'string') {
return false
}
// TODO: use media-typer
var match = EXTRACT_TYPE_REGEXP.exec(type);
var mime = match && db[match[1].toLowerCase()];
if (mime && mime.charset) {
return mime.charset
}
// default text/* to utf-8
if (match && TEXT_TYPE_REGEXP.test(match[1])) {
return 'UTF-8'
}
return false
}
/**
* Create a full Content-Type header given a MIME type or extension.
*
* @param {string} str
* @return {boolean|string}
*/
function contentType (str) {
// TODO: should this even be in this module?
if (!str || typeof str !== 'string') {
return false
}
var mime = str.indexOf('/') === -1
? exports.lookup(str)
: str;
if (!mime) {
return false
}
// TODO: use content-type or other module
if (mime.indexOf('charset') === -1) {
var charset = exports.charset(mime);
if (charset) mime += '; charset=' + charset.toLowerCase();
}
return mime
}
/**
* Get the default extension for a MIME type.
*
* @param {string} type
* @return {boolean|string}
*/
function extension (type) {
if (!type || typeof type !== 'string') {
return false
}
// TODO: use media-typer
var match = EXTRACT_TYPE_REGEXP.exec(type);
// get extensions
var exts = match && exports.extensions[match[1].toLowerCase()];
if (!exts || !exts.length) {
return false
}
return exts[0]
}
/**
* Lookup the MIME type for a file path/extension.
*
* @param {string} path
* @return {boolean|string}
*/
function lookup (path) {
if (!path || typeof path !== 'string') {
return false
}
// get the extension ("ext" or ".ext" or full path)
var extension = extname('x.' + path)
.toLowerCase()
.substr(1);
if (!extension) {
return false
}
return exports.types[extension] || false
}
/**
* Populate the extensions and types maps.
* @private
*/
function populateMaps (extensions, types) {
// source preference (least -> most)
var preference = ['nginx', 'apache', undefined, 'iana'];
Object.keys(db).forEach(function forEachMimeType (type) {
var mime = db[type];
var exts = mime.extensions;
if (!exts || !exts.length) {
return
}
// mime -> extensions
extensions[type] = exts;
// extension -> mime
for (var i = 0; i < exts.length; i++) {
var extension = exts[i];
if (types[extension]) {
var from = preference.indexOf(db[types[extension]].source);
var to = preference.indexOf(mime.source);
if (types[extension] !== 'application/octet-stream' &&
(from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
// skip the remapping
continue
}
}
// set the extension -> mime
types[extension] = type;
}
});
}
}(mimeTypes));
function downloadImage(url) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield got(url, { responseType: 'buffer' });
return {
fileContent: res.body,
fileExtension: mimeTypes.extension(res.headers['content-type'])
};
});
}
/**
* Open or create a folderpath if it does not exist
* @param vault
* @param folderpath
*/
function checkAndCreateFolder(vault, folderpath) {
return __awaiter(this, void 0, void 0, function* () {
folderpath = obsidian.normalizePath(folderpath);
const folder = vault.getAbstractFileByPath(folderpath);
if (folder && folder instanceof obsidian.TFolder) {
return;
}
yield vault.createFolder(folderpath);
});
}
function isValidUrl(url) {
try {
new URL(url);
}
catch (e) {
return false;
}
return true;
}
function getBaseUrl(url, prefix) {
const dir = '/';
const urlAsArray = url.split(dir);
const doubleSlashIndex = url.indexOf('://');
if (doubleSlashIndex !== -1 && doubleSlashIndex === url.indexOf(dir) - 1) {
urlAsArray.length = 3;
let url = urlAsArray.join(dir);
if (prefix !== undefined)
url = url.replace(/http:\/\/|https:\/\//, prefix);
return url;
}
else {
const pointIndex = url.indexOf('.');
if (pointIndex !== -1 && pointIndex !== 0) {
return (prefix !== undefined ? prefix : 'https://') + urlAsArray[0];
}
}
}
function normalizeFilename(fileName) {
const illegalSymbols = [':', '#', '/', '\\', '|', '?', '*', '<', '>', '"'];
if (illegalSymbols.some((el) => fileName.contains(el))) {
illegalSymbols.forEach((ilSymbol) => {
fileName = fileName.replace(ilSymbol, '');
});
return fileName;
}
else {
return fileName;
}
}
function pathJoin(dir, subpath) {
const result = require$$1__default$4["default"].join(dir, subpath);
// it seems that obsidian do not understand paths with backslashes in Windows, so turn them into forward slashes
return obsidian.normalizePath(result.replace(/\\/g, '/'));
}
var dist = {};
var xxhash64 = {};
var cuint = {};
var uint32 = {exports: {}};
/**
C-like unsigned 32 bits integers in Javascript
Copyright (C) 2013, Pierre Curto
MIT license
*/
(function (module) {
(function (root) {
// Local cache for typical radices
({
36: UINT32( Math.pow(36, 5) )
, 16: UINT32( Math.pow(16, 7) )
, 10: UINT32( Math.pow(10, 9) )
, 2: UINT32( Math.pow(2, 30) )
});
({
36: UINT32(36)
, 16: UINT32(16)
, 10: UINT32(10)
, 2: UINT32(2)
});
/**
* Represents an unsigned 32 bits integer
* @constructor
* @param {Number|String|Number} low bits | integer as a string | integer as a number
* @param {Number|Number|Undefined} high bits | radix (optional, default=10)
* @return
*/
function UINT32 (l, h) {
if ( !(this instanceof UINT32) )
return new UINT32(l, h)
this._low = 0;
this._high = 0;
this.remainder = null;
if (typeof h == 'undefined')
return fromNumber.call(this, l)
if (typeof l == 'string')
return fromString.call(this, l, h)
fromBits.call(this, l, h);
}
/**
* Set the current _UINT32_ object with its low and high bits
* @method fromBits
* @param {Number} low bits
* @param {Number} high bits
* @return ThisExpression
*/
function fromBits (l, h) {
this._low = l | 0;
this._high = h | 0;
return this
}
UINT32.prototype.fromBits = fromBits;
/**
* Set the current _UINT32_ object from a number
* @method fromNumber
* @param {Number} number
* @return ThisExpression
*/
function fromNumber (value) {
this._low = value & 0xFFFF;
this._high = value >>> 16;
return this
}
UINT32.prototype.fromNumber = fromNumber;
/**
* Set the current _UINT32_ object from a string
* @method fromString
* @param {String} integer as a string
* @param {Number} radix (optional, default=10)
* @return ThisExpression
*/
function fromString (s, radix) {
var value = parseInt(s, radix || 10);
this._low = value & 0xFFFF;
this._high = value >>> 16;
return this
}
UINT32.prototype.fromString = fromString;
/**
* Convert this _UINT32_ to a number
* @method toNumber
* @return {Number} the converted UINT32
*/
UINT32.prototype.toNumber = function () {
return (this._high * 65536) + this._low
};
/**
* Convert this _UINT32_ to a string
* @method toString
* @param {Number} radix (optional, default=10)
* @return {String} the converted UINT32
*/
UINT32.prototype.toString = function (radix) {
return this.toNumber().toString(radix || 10)
};
/**
* Add two _UINT32_. The current _UINT32_ stores the result
* @method add
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.add = function (other) {
var a00 = this._low + other._low;
var a16 = a00 >>> 16;
a16 += this._high + other._high;
this._low = a00 & 0xFFFF;
this._high = a16 & 0xFFFF;
return this
};
/**
* Subtract two _UINT32_. The current _UINT32_ stores the result
* @method subtract
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.subtract = function (other) {
//TODO inline
return this.add( other.clone().negate() )
};
/**
* Multiply two _UINT32_. The current _UINT32_ stores the result
* @method multiply
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.multiply = function (other) {
/*
a = a00 + a16
b = b00 + b16
a*b = (a00 + a16)(b00 + b16)
= a00b00 + a00b16 + a16b00 + a16b16
a16b16 overflows the 32bits
*/
var a16 = this._high;
var a00 = this._low;
var b16 = other._high;
var b00 = other._low;
/* Removed to increase speed under normal circumstances (i.e. not multiplying by 0 or 1)
// this == 0 or other == 1: nothing to do
if ((a00 == 0 && a16 == 0) || (b00 == 1 && b16 == 0)) return this
// other == 0 or this == 1: this = other
if ((b00 == 0 && b16 == 0) || (a00 == 1 && a16 == 0)) {
this._low = other._low
this._high = other._high
return this
}
*/
var c16, c00;
c00 = a00 * b00;
c16 = c00 >>> 16;
c16 += a16 * b00;
c16 &= 0xFFFF; // Not required but improves performance
c16 += a00 * b16;
this._low = c00 & 0xFFFF;
this._high = c16 & 0xFFFF;
return this
};
/**
* Divide two _UINT32_. The current _UINT32_ stores the result.
* The remainder is made available as the _remainder_ property on
* the _UINT32_ object. It can be null, meaning there are no remainder.
* @method div
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.div = function (other) {
if ( (other._low == 0) && (other._high == 0) ) throw Error('division by zero')
// other == 1
if (other._high == 0 && other._low == 1) {
this.remainder = new UINT32(0);
return this
}
// other > this: 0
if ( other.gt(this) ) {
this.remainder = this.clone();
this._low = 0;
this._high = 0;
return this
}
// other == this: 1
if ( this.eq(other) ) {
this.remainder = new UINT32(0);
this._low = 1;
this._high = 0;
return this
}
// Shift the divisor left until it is higher than the dividend
var _other = other.clone();
var i = -1;
while ( !this.lt(_other) ) {
// High bit can overflow the default 16bits
// Its ok since we right shift after this loop
// The overflown bit must be kept though
_other.shiftLeft(1, true);
i++;
}
// Set the remainder
this.remainder = this.clone();
// Initialize the current result to 0
this._low = 0;
this._high = 0;
for (; i >= 0; i--) {
_other.shiftRight(1);
// If shifted divisor is smaller than the dividend
// then subtract it from the dividend
if ( !this.remainder.lt(_other) ) {
this.remainder.subtract(_other);
// Update the current result
if (i >= 16) {
this._high |= 1 << (i - 16);
} else {
this._low |= 1 << i;
}
}
}
return this
};
/**
* Negate the current _UINT32_
* @method negate
* @return ThisExpression
*/
UINT32.prototype.negate = function () {
var v = ( ~this._low & 0xFFFF ) + 1;
this._low = v & 0xFFFF;
this._high = (~this._high + (v >>> 16)) & 0xFFFF;
return this
};
/**
* Equals
* @method eq
* @param {Object} other UINT32
* @return {Boolean}
*/
UINT32.prototype.equals = UINT32.prototype.eq = function (other) {
return (this._low == other._low) && (this._high == other._high)
};
/**
* Greater than (strict)
* @method gt
* @param {Object} other UINT32
* @return {Boolean}
*/
UINT32.prototype.greaterThan = UINT32.prototype.gt = function (other) {
if (this._high > other._high) return true
if (this._high < other._high) return false
return this._low > other._low
};
/**
* Less than (strict)
* @method lt
* @param {Object} other UINT32
* @return {Boolean}
*/
UINT32.prototype.lessThan = UINT32.prototype.lt = function (other) {
if (this._high < other._high) return true
if (this._high > other._high) return false
return this._low < other._low
};
/**
* Bitwise OR
* @method or
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.or = function (other) {
this._low |= other._low;
this._high |= other._high;
return this
};
/**
* Bitwise AND
* @method and
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.and = function (other) {
this._low &= other._low;
this._high &= other._high;
return this
};
/**
* Bitwise NOT
* @method not
* @return ThisExpression
*/
UINT32.prototype.not = function() {
this._low = ~this._low & 0xFFFF;
this._high = ~this._high & 0xFFFF;
return this
};
/**
* Bitwise XOR
* @method xor
* @param {Object} other UINT32
* @return ThisExpression
*/
UINT32.prototype.xor = function (other) {
this._low ^= other._low;
this._high ^= other._high;
return this
};
/**
* Bitwise shift right
* @method shiftRight
* @param {Number} number of bits to shift
* @return ThisExpression
*/
UINT32.prototype.shiftRight = UINT32.prototype.shiftr = function (n) {
if (n > 16) {
this._low = this._high >> (n - 16);
this._high = 0;
} else if (n == 16) {
this._low = this._high;
this._high = 0;
} else {
this._low = (this._low >> n) | ( (this._high << (16-n)) & 0xFFFF );
this._high >>= n;
}
return this
};
/**
* Bitwise shift left
* @method shiftLeft
* @param {Number} number of bits to shift
* @param {Boolean} allow overflow
* @return ThisExpression
*/
UINT32.prototype.shiftLeft = UINT32.prototype.shiftl = function (n, allowOverflow) {
if (n > 16) {
this._high = this._low << (n - 16);
this._low = 0;
if (!allowOverflow) {
this._high &= 0xFFFF;
}
} else if (n == 16) {
this._high = this._low;
this._low = 0;
} else {
this._high = (this._high << n) | (this._low >> (16-n));
this._low = (this._low << n) & 0xFFFF;
if (!allowOverflow) {
// Overflow only allowed on the high bits...
this._high &= 0xFFFF;
}
}
return this
};
/**
* Bitwise rotate left
* @method rotl
* @param {Number} number of bits to rotate
* @return ThisExpression
*/
UINT32.prototype.rotateLeft = UINT32.prototype.rotl = function (n) {
var v = (this._high << 16) | this._low;
v = (v << n) | (v >>> (32 - n));
this._low = v & 0xFFFF;
this._high = v >>> 16;
return this
};
/**
* Bitwise rotate right
* @method rotr
* @param {Number} number of bits to rotate
* @return ThisExpression
*/
UINT32.prototype.rotateRight = UINT32.prototype.rotr = function (n) {
var v = (this._high << 16) | this._low;
v = (v >>> n) | (v << (32 - n));
this._low = v & 0xFFFF;
this._high = v >>> 16;
return this
};
/**
* Clone the current _UINT32_
* @method clone
* @return {Object} cloned UINT32
*/
UINT32.prototype.clone = function () {
return new UINT32(this._low, this._high)
};
if (module.exports) {
// Node.js
module.exports = UINT32;
} else {
// Browser
root['UINT32'] = UINT32;
}
})(commonjsGlobal);
}(uint32));
var uint64 = {exports: {}};
/**
C-like unsigned 64 bits integers in Javascript
Copyright (C) 2013, Pierre Curto
MIT license
*/
(function (module) {
(function (root) {
// Local cache for typical radices
var radixPowerCache = {
16: UINT64( Math.pow(16, 5) )
, 10: UINT64( Math.pow(10, 5) )
, 2: UINT64( Math.pow(2, 5) )
};
var radixCache = {
16: UINT64(16)
, 10: UINT64(10)
, 2: UINT64(2)
};
/**
* Represents an unsigned 64 bits integer
* @constructor
* @param {Number} first low bits (8)
* @param {Number} second low bits (8)
* @param {Number} first high bits (8)
* @param {Number} second high bits (8)
* or
* @param {Number} low bits (32)
* @param {Number} high bits (32)
* or
* @param {String|Number} integer as a string | integer as a number
* @param {Number|Undefined} radix (optional, default=10)
* @return
*/
function UINT64 (a00, a16, a32, a48) {
if ( !(this instanceof UINT64) )
return new UINT64(a00, a16, a32, a48)
this.remainder = null;
if (typeof a00 == 'string')
return fromString.call(this, a00, a16)
if (typeof a16 == 'undefined')
return fromNumber.call(this, a00)
fromBits.apply(this, arguments);
}
/**
* Set the current _UINT64_ object with its low and high bits
* @method fromBits
* @param {Number} first low bits (8)
* @param {Number} second low bits (8)
* @param {Number} first high bits (8)
* @param {Number} second high bits (8)
* or
* @param {Number} low bits (32)
* @param {Number} high bits (32)
* @return ThisExpression
*/
function fromBits (a00, a16, a32, a48) {
if (typeof a32 == 'undefined') {
this._a00 = a00 & 0xFFFF;
this._a16 = a00 >>> 16;
this._a32 = a16 & 0xFFFF;
this._a48 = a16 >>> 16;
return this
}
this._a00 = a00 | 0;
this._a16 = a16 | 0;
this._a32 = a32 | 0;
this._a48 = a48 | 0;
return this
}
UINT64.prototype.fromBits = fromBits;
/**
* Set the current _UINT64_ object from a number
* @method fromNumber
* @param {Number} number
* @return ThisExpression
*/
function fromNumber (value) {
this._a00 = value & 0xFFFF;
this._a16 = value >>> 16;
this._a32 = 0;
this._a48 = 0;
return this
}
UINT64.prototype.fromNumber = fromNumber;
/**
* Set the current _UINT64_ object from a string
* @method fromString
* @param {String} integer as a string
* @param {Number} radix (optional, default=10)
* @return ThisExpression
*/
function fromString (s, radix) {
radix = radix || 10;
this._a00 = 0;
this._a16 = 0;
this._a32 = 0;
this._a48 = 0;
/*
In Javascript, bitwise operators only operate on the first 32 bits
of a number, even though parseInt() encodes numbers with a 53 bits
mantissa.
Therefore UINT64(<Number>) can only work on 32 bits.
The radix maximum value is 36 (as per ECMA specs) (26 letters + 10 digits)
maximum input value is m = 32bits as 1 = 2^32 - 1
So the maximum substring length n is:
36^(n+1) - 1 = 2^32 - 1
36^(n+1) = 2^32
(n+1)ln(36) = 32ln(2)
n = 32ln(2)/ln(36) - 1
n = 5.189644915687692
n = 5
*/
var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 5) );
for (var i = 0, len = s.length; i < len; i += 5) {
var size = Math.min(5, len - i);
var value = parseInt( s.slice(i, i + size), radix );
this.multiply(
size < 5
? new UINT64( Math.pow(radix, size) )
: radixUint
)
.add( new UINT64(value) );
}
return this
}
UINT64.prototype.fromString = fromString;
/**
* Convert this _UINT64_ to a number (last 32 bits are dropped)
* @method toNumber
* @return {Number} the converted UINT64
*/
UINT64.prototype.toNumber = function () {
return (this._a16 * 65536) + this._a00
};
/**
* Convert this _UINT64_ to a string
* @method toString
* @param {Number} radix (optional, default=10)
* @return {String} the converted UINT64
*/
UINT64.prototype.toString = function (radix) {
radix = radix || 10;
var radixUint = radixCache[radix] || new UINT64(radix);
if ( !this.gt(radixUint) ) return this.toNumber().toString(radix)
var self = this.clone();
var res = new Array(64);
for (var i = 63; i >= 0; i--) {
self.div(radixUint);
res[i] = self.remainder.toNumber().toString(radix);
if ( !self.gt(radixUint) ) break
}
res[i-1] = self.toNumber().toString(radix);
return res.join('')
};
/**
* Add two _UINT64_. The current _UINT64_ stores the result
* @method add
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.add = function (other) {
var a00 = this._a00 + other._a00;
var a16 = a00 >>> 16;
a16 += this._a16 + other._a16;
var a32 = a16 >>> 16;
a32 += this._a32 + other._a32;
var a48 = a32 >>> 16;
a48 += this._a48 + other._a48;
this._a00 = a00 & 0xFFFF;
this._a16 = a16 & 0xFFFF;
this._a32 = a32 & 0xFFFF;
this._a48 = a48 & 0xFFFF;
return this
};
/**
* Subtract two _UINT64_. The current _UINT64_ stores the result
* @method subtract
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.subtract = function (other) {
return this.add( other.clone().negate() )
};
/**
* Multiply two _UINT64_. The current _UINT64_ stores the result
* @method multiply
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.multiply = function (other) {
/*
a = a00 + a16 + a32 + a48
b = b00 + b16 + b32 + b48
a*b = (a00 + a16 + a32 + a48)(b00 + b16 + b32 + b48)
= a00b00 + a00b16 + a00b32 + a00b48
+ a16b00 + a16b16 + a16b32 + a16b48
+ a32b00 + a32b16 + a32b32 + a32b48
+ a48b00 + a48b16 + a48b32 + a48b48
a16b48, a32b32, a48b16, a48b32 and a48b48 overflow the 64 bits
so it comes down to:
a*b = a00b00 + a00b16 + a00b32 + a00b48
+ a16b00 + a16b16 + a16b32
+ a32b00 + a32b16
+ a48b00
= a00b00
+ a00b16 + a16b00
+ a00b32 + a16b16 + a32b00
+ a00b48 + a16b32 + a32b16 + a48b00
*/
var a00 = this._a00;
var a16 = this._a16;
var a32 = this._a32;
var a48 = this._a48;
var b00 = other._a00;
var b16 = other._a16;
var b32 = other._a32;
var b48 = other._a48;
var c00 = a00 * b00;
var c16 = c00 >>> 16;
c16 += a00 * b16;
var c32 = c16 >>> 16;
c16 &= 0xFFFF;
c16 += a16 * b00;
c32 += c16 >>> 16;
c32 += a00 * b32;
var c48 = c32 >>> 16;
c32 &= 0xFFFF;
c32 += a16 * b16;
c48 += c32 >>> 16;
c32 &= 0xFFFF;
c32 += a32 * b00;
c48 += c32 >>> 16;
c48 += a00 * b48;
c48 &= 0xFFFF;
c48 += a16 * b32;
c48 &= 0xFFFF;
c48 += a32 * b16;
c48 &= 0xFFFF;
c48 += a48 * b00;
this._a00 = c00 & 0xFFFF;
this._a16 = c16 & 0xFFFF;
this._a32 = c32 & 0xFFFF;
this._a48 = c48 & 0xFFFF;
return this
};
/**
* Divide two _UINT64_. The current _UINT64_ stores the result.
* The remainder is made available as the _remainder_ property on
* the _UINT64_ object. It can be null, meaning there are no remainder.
* @method div
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.div = function (other) {
if ( (other._a16 == 0) && (other._a32 == 0) && (other._a48 == 0) ) {
if (other._a00 == 0) throw Error('division by zero')
// other == 1: this
if (other._a00 == 1) {
this.remainder = new UINT64(0);
return this
}
}
// other > this: 0
if ( other.gt(this) ) {
this.remainder = this.clone();
this._a00 = 0;
this._a16 = 0;
this._a32 = 0;
this._a48 = 0;
return this
}
// other == this: 1
if ( this.eq(other) ) {
this.remainder = new UINT64(0);
this._a00 = 1;
this._a16 = 0;
this._a32 = 0;
this._a48 = 0;
return this
}
// Shift the divisor left until it is higher than the dividend
var _other = other.clone();
var i = -1;
while ( !this.lt(_other) ) {
// High bit can overflow the default 16bits
// Its ok since we right shift after this loop
// The overflown bit must be kept though
_other.shiftLeft(1, true);
i++;
}
// Set the remainder
this.remainder = this.clone();
// Initialize the current result to 0
this._a00 = 0;
this._a16 = 0;
this._a32 = 0;
this._a48 = 0;
for (; i >= 0; i--) {
_other.shiftRight(1);
// If shifted divisor is smaller than the dividend
// then subtract it from the dividend
if ( !this.remainder.lt(_other) ) {
this.remainder.subtract(_other);
// Update the current result
if (i >= 48) {
this._a48 |= 1 << (i - 48);
} else if (i >= 32) {
this._a32 |= 1 << (i - 32);
} else if (i >= 16) {
this._a16 |= 1 << (i - 16);
} else {
this._a00 |= 1 << i;
}
}
}
return this
};
/**
* Negate the current _UINT64_
* @method negate
* @return ThisExpression
*/
UINT64.prototype.negate = function () {
var v = ( ~this._a00 & 0xFFFF ) + 1;
this._a00 = v & 0xFFFF;
v = (~this._a16 & 0xFFFF) + (v >>> 16);
this._a16 = v & 0xFFFF;
v = (~this._a32 & 0xFFFF) + (v >>> 16);
this._a32 = v & 0xFFFF;
this._a48 = (~this._a48 + (v >>> 16)) & 0xFFFF;
return this
};
/**
* @method eq
* @param {Object} other UINT64
* @return {Boolean}
*/
UINT64.prototype.equals = UINT64.prototype.eq = function (other) {
return (this._a48 == other._a48) && (this._a00 == other._a00)
&& (this._a32 == other._a32) && (this._a16 == other._a16)
};
/**
* Greater than (strict)
* @method gt
* @param {Object} other UINT64
* @return {Boolean}
*/
UINT64.prototype.greaterThan = UINT64.prototype.gt = function (other) {
if (this._a48 > other._a48) return true
if (this._a48 < other._a48) return false
if (this._a32 > other._a32) return true
if (this._a32 < other._a32) return false
if (this._a16 > other._a16) return true
if (this._a16 < other._a16) return false
return this._a00 > other._a00
};
/**
* Less than (strict)
* @method lt
* @param {Object} other UINT64
* @return {Boolean}
*/
UINT64.prototype.lessThan = UINT64.prototype.lt = function (other) {
if (this._a48 < other._a48) return true
if (this._a48 > other._a48) return false
if (this._a32 < other._a32) return true
if (this._a32 > other._a32) return false
if (this._a16 < other._a16) return true
if (this._a16 > other._a16) return false
return this._a00 < other._a00
};
/**
* Bitwise OR
* @method or
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.or = function (other) {
this._a00 |= other._a00;
this._a16 |= other._a16;
this._a32 |= other._a32;
this._a48 |= other._a48;
return this
};
/**
* Bitwise AND
* @method and
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.and = function (other) {
this._a00 &= other._a00;
this._a16 &= other._a16;
this._a32 &= other._a32;
this._a48 &= other._a48;
return this
};
/**
* Bitwise XOR
* @method xor
* @param {Object} other UINT64
* @return ThisExpression
*/
UINT64.prototype.xor = function (other) {
this._a00 ^= other._a00;
this._a16 ^= other._a16;
this._a32 ^= other._a32;
this._a48 ^= other._a48;
return this
};
/**
* Bitwise NOT
* @method not
* @return ThisExpression
*/
UINT64.prototype.not = function() {
this._a00 = ~this._a00 & 0xFFFF;
this._a16 = ~this._a16 & 0xFFFF;
this._a32 = ~this._a32 & 0xFFFF;
this._a48 = ~this._a48 & 0xFFFF;
return this
};
/**
* Bitwise shift right
* @method shiftRight
* @param {Number} number of bits to shift
* @return ThisExpression
*/
UINT64.prototype.shiftRight = UINT64.prototype.shiftr = function (n) {
n %= 64;
if (n >= 48) {
this._a00 = this._a48 >> (n - 48);
this._a16 = 0;
this._a32 = 0;
this._a48 = 0;
} else if (n >= 32) {
n -= 32;
this._a00 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF;
this._a16 = (this._a48 >> n) & 0xFFFF;
this._a32 = 0;
this._a48 = 0;
} else if (n >= 16) {
n -= 16;
this._a00 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF;
this._a16 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF;
this._a32 = (this._a48 >> n) & 0xFFFF;
this._a48 = 0;
} else {
this._a00 = ( (this._a00 >> n) | (this._a16 << (16-n)) ) & 0xFFFF;
this._a16 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF;
this._a32 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF;
this._a48 = (this._a48 >> n) & 0xFFFF;
}
return this
};
/**
* Bitwise shift left
* @method shiftLeft
* @param {Number} number of bits to shift
* @param {Boolean} allow overflow
* @return ThisExpression
*/
UINT64.prototype.shiftLeft = UINT64.prototype.shiftl = function (n, allowOverflow) {
n %= 64;
if (n >= 48) {
this._a48 = this._a00 << (n - 48);
this._a32 = 0;
this._a16 = 0;
this._a00 = 0;
} else if (n >= 32) {
n -= 32;
this._a48 = (this._a16 << n) | (this._a00 >> (16-n));
this._a32 = (this._a00 << n) & 0xFFFF;
this._a16 = 0;
this._a00 = 0;
} else if (n >= 16) {
n -= 16;
this._a48 = (this._a32 << n) | (this._a16 >> (16-n));
this._a32 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF;
this._a16 = (this._a00 << n) & 0xFFFF;
this._a00 = 0;
} else {
this._a48 = (this._a48 << n) | (this._a32 >> (16-n));
this._a32 = ( (this._a32 << n) | (this._a16 >> (16-n)) ) & 0xFFFF;
this._a16 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF;
this._a00 = (this._a00 << n) & 0xFFFF;
}
if (!allowOverflow) {
this._a48 &= 0xFFFF;
}
return this
};
/**
* Bitwise rotate left
* @method rotl
* @param {Number} number of bits to rotate
* @return ThisExpression
*/
UINT64.prototype.rotateLeft = UINT64.prototype.rotl = function (n) {
n %= 64;
if (n == 0) return this
if (n >= 32) {
// A.B.C.D
// B.C.D.A rotl(16)
// C.D.A.B rotl(32)
var v = this._a00;
this._a00 = this._a32;
this._a32 = v;
v = this._a48;
this._a48 = this._a16;
this._a16 = v;
if (n == 32) return this
n -= 32;
}
var high = (this._a48 << 16) | this._a32;
var low = (this._a16 << 16) | this._a00;
var _high = (high << n) | (low >>> (32 - n));
var _low = (low << n) | (high >>> (32 - n));
this._a00 = _low & 0xFFFF;
this._a16 = _low >>> 16;
this._a32 = _high & 0xFFFF;
this._a48 = _high >>> 16;
return this
};
/**
* Bitwise rotate right
* @method rotr
* @param {Number} number of bits to rotate
* @return ThisExpression
*/
UINT64.prototype.rotateRight = UINT64.prototype.rotr = function (n) {
n %= 64;
if (n == 0) return this
if (n >= 32) {
// A.B.C.D
// D.A.B.C rotr(16)
// C.D.A.B rotr(32)
var v = this._a00;
this._a00 = this._a32;
this._a32 = v;
v = this._a48;
this._a48 = this._a16;
this._a16 = v;
if (n == 32) return this
n -= 32;
}
var high = (this._a48 << 16) | this._a32;
var low = (this._a16 << 16) | this._a00;
var _high = (high >>> n) | (low << (32 - n));
var _low = (low >>> n) | (high << (32 - n));
this._a00 = _low & 0xFFFF;
this._a16 = _low >>> 16;
this._a32 = _high & 0xFFFF;
this._a48 = _high >>> 16;
return this
};
/**
* Clone the current _UINT64_
* @method clone
* @return {Object} cloned UINT64
*/
UINT64.prototype.clone = function () {
return new UINT64(this._a00, this._a16, this._a32, this._a48)
};
if (module.exports) {
// Node.js
module.exports = UINT64;
} else {
// Browser
root['UINT64'] = UINT64;
}
})(commonjsGlobal);
}(uint64));
cuint.UINT32 = uint32.exports;
cuint.UINT64 = uint64.exports;
var xxhash = {};
var toBuffer = {};
var toUtf8Array = {};
Object.defineProperty(toUtf8Array, "__esModule", { value: true });
/**
* Convert string to proper UTF-8 array
*/
function toUTF8Array(str) {
const len = str.length;
const utf8 = [];
for (let i = 0; i < len; i++) {
let c = str.charCodeAt(i);
if (c < 0x80) {
utf8.push(c);
}
else if (c < 0x800) {
utf8.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
}
else if (c < 0xd800 || c >= 0xe000) {
utf8.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
}
else {
// surrogate pair
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 0x3f), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
}
}
return new Uint8Array(utf8);
}
toUtf8Array.default = toUTF8Array;
Object.defineProperty(toBuffer, "__esModule", { value: true });
const to_utf8_array_1 = toUtf8Array;
function default_1(input) {
if (input instanceof ArrayBuffer) {
return new Uint8Array(input);
}
else if (typeof input === "string") {
return to_utf8_array_1.default(input);
}
return input;
}
toBuffer.default = default_1;
Object.defineProperty(xxhash, "__esModule", { value: true });
const cuint_1$2 = cuint;
const to_buffer_1 = toBuffer;
function isClonable(obj) {
return obj.hasOwnProperty("clone");
}
class XXHash extends cuint_1$2.UINT64 {
/**
* @param seed unsigned 32-bit integer
*/
constructor(uintConstructor) {
super(NaN);
this.uintConstructor = uintConstructor;
}
get vn() {
return [this.v1, this.v2, this.v3, this.v4];
}
getIncrement() {
return this.size / 4;
}
reseed(seed) {
this.seed = isClonable(seed)
? seed.clone()
: this.uintConstructor(seed);
this.v1 = this.seed
.clone()
.add(this.primes.P1)
.add(this.primes.P2);
this.v2 = this.seed.clone().add(this.primes.P2);
this.v3 = this.seed.clone();
this.v4 = this.seed.clone().subtract(this.primes.P1);
this.totalLen = 0;
this.memsize = 0;
this.memory = undefined;
}
/**
* Finalize the hash computation. The hash instance is ready for reuse for the given seed
*/
digest() {
const m = this.memory;
if (m === undefined)
throw new ReferenceError("Hash Memory not set, .update() has to be called before digest()");
const { P5 } = this.primes;
const h = this.totalLen >= this.size
? this.v1
.rotl(1)
.add(this.v2.clone().rotl(7))
.add(this.v3.clone().rotl(12))
.add(this.v4.clone().rotl(18))
: this.seed.clone().add(P5);
const hash = this.digestCore(m, h);
// Reset the state
this.reseed(this.seed);
return hash;
}
/**
* Add data to be computed for the hash
*/
update(v) {
const input = to_buffer_1.default(v);
const len = input.length;
if (len === 0)
return this;
this.totalLen += len;
const memory = this.memsize === 0
? input instanceof Buffer
? new Buffer(this.size)
: new Uint8Array(this.size)
: this.memory;
if (this.memsize + len < this.size) {
// fill in tmp buffer
// XXH64_memcpy(memory + this.memsize, input, len)
if (input instanceof Buffer) {
input.copy(memory, this.memsize, 0, len);
}
else {
memory.set(input.subarray(0, len), this.memsize);
}
this.memsize += len;
this.memory = memory;
return this;
}
let p = 0;
const bEnd = p + len;
const inc = this.getIncrement();
if (this.memsize > 0) {
// some data left from previous update
// XXH64_memcpy(memory + this.memsize, input, 16-this.memsize);
if (input instanceof Buffer) {
input.copy(memory, this.memsize, 0, this.size - this.memsize);
}
else {
memory.set(input.subarray(0, this.size - this.memsize), this.memsize);
}
let i = 0;
for (const v of this.vn) {
this.shiftUpdate(v, memory, i);
i += inc;
}
p += this.size - this.memsize;
this.memsize = 0;
}
if (p <= bEnd - this.size) {
const limit = bEnd - this.size;
do {
for (const v of this.vn) {
this.shiftUpdate(v, input, p);
p += inc;
}
} while (p <= limit);
}
if (p < bEnd) {
// XXH64_memcpy(memory, p, bEnd-p);
if (input instanceof Buffer) {
input.copy(memory, this.memsize, p, bEnd);
}
else {
memory.set(input.subarray(p, bEnd), this.memsize);
}
this.memsize = bEnd - p;
}
this.memory = memory;
return this;
}
}
xxhash.default = XXHash;
Object.defineProperty(xxhash64, "__esModule", { value: true });
const cuint_1$1 = cuint;
const xxhash_1$1 = xxhash;
class XXHash64 extends xxhash_1$1.default {
constructor(seed) {
super(cuint_1$1.UINT64);
this.size = 32;
this.primes = {
P1: this.uintConstructor("11400714785074694791"),
P2: this.uintConstructor("14029467366897019727"),
P3: this.uintConstructor("1609587929392839161"),
P4: this.uintConstructor("9650029242287828579"),
P5: this.uintConstructor("2870177450012600261")
};
this.reseed(seed);
}
static hash(seed, input) {
const instance = new this(seed);
if (input === undefined)
return instance;
return instance.update(input).digest();
}
shiftDigest(h, v) {
h.xor(v
.multiply(this.primes.P2)
.rotl(31)
.multiply(this.primes.P1));
h.multiply(this.primes.P1).add(this.primes.P4);
}
shiftUpdate(v, m, p) {
v.add(this.uintConstructor((m[p + 1] << 8) | m[p], (m[p + 3] << 8) | m[p + 2], (m[p + 5] << 8) | m[p + 4], (m[p + 7] << 8) | m[p + 6]).multiply(this.primes.P2))
.rotl(31)
.multiply(this.primes.P1);
}
digestCore(m, h) {
const { P1, P2, P3, P4, P5 } = this.primes;
if (this.totalLen >= this.size) {
for (const v of this.vn) {
this.shiftDigest(h, v);
}
}
const u = this.uintConstructor(NaN);
h.add(u.fromNumber(this.totalLen));
let i = 0;
const inc = this.getIncrement();
while (i <= this.memsize - inc) {
u.fromBits((m[i + 1] << 8) | m[i], (m[i + 3] << 8) | m[i + 2], (m[i + 5] << 8) | m[i + 4], (m[i + 7] << 8) | m[i + 6]);
u.multiply(P2)
.rotl(31)
.multiply(P1);
h.xor(u)
.rotl(27)
.multiply(P1)
.add(P4);
i += inc;
}
if (i + 4 <= this.memsize) {
u.fromBits((m[i + 1] << 8) | m[i], (m[i + 3] << 8) | m[i + 2], 0, 0);
h.xor(u.multiply(P1))
.rotl(23)
.multiply(P2)
.add(P3);
i += 4;
}
while (i < this.memsize) {
u.fromBits(m[i++], 0, 0, 0);
h.xor(u.multiply(P5))
.rotl(11)
.multiply(P1);
}
h.xor(h.clone().shiftRight(33)).multiply(P2);
h.xor(h.clone().shiftRight(29)).multiply(P3);
h.xor(h.clone().shiftRight(32));
return h;
}
}
xxhash64.default = XXHash64;
var xxhash32 = {};
Object.defineProperty(xxhash32, "__esModule", { value: true });
const cuint_1 = cuint;
const xxhash_1 = xxhash;
class XXHash32$1 extends xxhash_1.default {
constructor(seed) {
super(cuint_1.UINT32);
this.size = 16;
this.primes = {
P1: this.uintConstructor("2654435761"),
P2: this.uintConstructor("2246822519"),
P3: this.uintConstructor("3266489917"),
P4: this.uintConstructor("668265263"),
P5: this.uintConstructor("374761393")
};
this.reseed(seed);
}
static hash(seed, input) {
const instance = new this(seed);
if (input === undefined)
return instance;
return instance.update(input).digest();
}
/**
* Merged this sequence of method calls as it speeds up
the calculations by a factor of 2
*/
updateUint(uint, low, high) {
const { P1, P2 } = this.primes;
let b00 = P2._low;
let b16 = P2._high;
let c00 = low * b00;
let c16 = c00 >>> 16;
c16 += high * b00;
c16 &= 0xffff; // Not required but improves performance
c16 += low * b16;
let a00 = uint._low + (c00 & 0xffff);
let a16 = a00 >>> 16;
a16 += uint._high + (c16 & 0xffff);
let v = (a16 << 16) | (a00 & 0xffff);
v = (v << 13) | (v >>> 19);
a00 = v & 0xffff;
a16 = v >>> 16;
b00 = P1._low;
b16 = P1._high;
c00 = a00 * b00;
c16 = c00 >>> 16;
c16 += a16 * b00;
c16 &= 0xffff; // Not required but improves performance
c16 += a00 * b16;
uint._low = c00 & 0xffff;
uint._high = c16 & 0xffff;
}
shiftUpdate(v, m, p) {
this.updateUint(v, (m[p + 1] << 8) | m[p], (m[p + 3] << 8) | m[p + 2]);
}
digestCore(m, h) {
const { P1, P2, P3, P4, P5 } = this.primes;
const u = this.uintConstructor(NaN);
h.add(u.fromNumber(this.totalLen));
let i = 0;
const inc = this.getIncrement();
while (i <= this.memsize - inc) {
u.fromBits((m[i + 1] << 8) | m[i], (m[i + 3] << 8) | m[i + 2]);
h.add(u.multiply(P3))
.rotl(17)
.multiply(P4);
i += inc;
}
while (i < this.memsize) {
u.fromBits(m[i++], 0);
h.add(u.multiply(P5))
.rotl(11)
.multiply(P1);
}
h.xor(h.clone().shiftRight(15)).multiply(P2);
h.xor(h.clone().shiftRight(13)).multiply(P3);
h.xor(h.clone().shiftRight(16));
return h;
}
}
xxhash32.default = XXHash32$1;
Object.defineProperty(dist, "__esModule", { value: true });
const xxhash64_1 = xxhash64;
dist.XXHash64 = xxhash64_1.default;
const xxhash32_1 = xxhash32;
var XXHash32 = dist.XXHash32 = xxhash32_1.default;
class LinkHashes {
constructor() {
this.linksInfo = {};
}
ensureHashGenerated(link, data) {
if (!this.linksInfo[link]) {
this.linksInfo[link] = XXHash32.hash(0, data).toNumber();
}
}
isSame(link, data) {
const fileHash = XXHash32.hash(0, data).toNumber();
return this.linksInfo[link] == fileHash;
}
}
const linkHashes = new LinkHashes();
const EXTERNAL_MEDIA_LINK_PATTERN = /\!\[(?<anchor>.*?)\]\((?<link>.+?)\)/g;
function replaceImages(app, content, assetsDir) {
return __awaiter(this, void 0, void 0, function* () {
return yield replaceAsync(content, EXTERNAL_MEDIA_LINK_PATTERN, imageTagProcessor(app, assetsDir));
});
}
function replaceAsync(string, searchValue, replacer) {
try {
if (typeof replacer === 'function') {
// 1. Run fake pass of `replace`, collect values from `replacer` calls
// 2. Resolve them with `Promise.all`
// 3. Run `replace` with resolved values
var values = [];
String.prototype.replace.call(string, searchValue, function () {
values.push(replacer.apply(undefined, arguments));
return '';
});
return Promise.all(values).then(function (resolvedValues) {
return String.prototype.replace.call(string, searchValue, function () {
return resolvedValues.shift();
});
});
}
else {
return Promise.resolve(String.prototype.replace.call(string, searchValue, replacer));
}
}
catch (error) {
return Promise.reject(error);
}
}
const FILENAME_ATTEMPTS = 5;
function imageTagProcessor(app, mediaDir) {
return function processImageTag(match, anchor, link) {
return __awaiter(this, void 0, void 0, function* () {
if (!isValidUrl(link)) {
return match;
}
yield checkAndCreateFolder(app.vault, mediaDir);
try {
const { fileContent, fileExtension } = yield downloadImage(link);
let attempt = 0;
while (attempt < FILENAME_ATTEMPTS) {
try {
const { fileName, needWrite } = yield chooseFileName(app.vault.adapter, mediaDir, anchor, link, fileContent, fileExtension);
if (needWrite && fileName) {
yield app.vault.createBinary(fileName, fileContent);
}
if (fileName) {
const maskedFilename = fileName.replace(/\s/g, '%20');
return `![${anchor}](${maskedFilename})`;
}
else {
return match;
}
}
catch (error) {
if (error.message === 'File already exists.') {
attempt++;
}
else {
throw error;
}
}
}
return match;
}
catch (error) {
console.warn('Image processing failed: ', error);
return match;
}
});
};
}
const FILENAME_TEMPLATE = 'media';
const MAX_FILENAME_INDEX = 1000;
function chooseFileName(adapter, dir, baseName, link, contentData, fileExtension) {
return __awaiter(this, void 0, void 0, function* () {
if (!fileExtension) {
return { fileName: '', needWrite: false };
}
// if there is no anchor try get file name from url
if (!baseName) {
const parsedUrl = new URL(link);
baseName = require$$1$4.basename(parsedUrl.pathname);
}
// if there is no part for file name from url use name template
if (!baseName) {
baseName = FILENAME_TEMPLATE;
}
// if filename already ends with correct extension, remove it to work with base name
if (baseName.endsWith(`.${fileExtension}`)) {
baseName = baseName.slice(0, -1 * (fileExtension.length + 1));
}
baseName = normalizeFilename(baseName);
let fileName = '';
let needWrite = true;
let index = 0;
while (!fileName && index < MAX_FILENAME_INDEX) {
const suggestedName = index
? pathJoin(dir, `${baseName}-${index}.${fileExtension}`)
: pathJoin(dir, `${baseName}.${fileExtension}`);
if (yield adapter.exists(suggestedName, false)) {
linkHashes.ensureHashGenerated(link, contentData);
const fileData = yield adapter.readBinary(suggestedName);
if (linkHashes.isSame(link, fileData)) {
fileName = suggestedName;
needWrite = false;
}
}
else {
fileName = suggestedName;
}
index++;
}
if (!fileName) {
throw new Error('Failed to generate file name for media file.');
}
linkHashes.ensureHashGenerated(link, contentData);
return { fileName, needWrite };
});
}
const DEFAULT_SETTINGS = {
inboxDir: 'ReadItLater Inbox',
assetsDir: 'ReadItLater Inbox/assets',
openNewNote: false,
youtubeNoteTitle: 'Youtube - %title%',
youtubeNote: `[[ReadItLater]] [[Youtube]]\n\n# [%videoTitle%](%videoURL%)\n\n%videoPlayer%`,
twitterNoteTitle: 'Tweet from %tweetAuthorName% (%date%)',
twitterNote: `[[ReadItLater]] [[Tweet]]\n\n# [%tweetAuthorName%](%tweetURL%)\n\n%tweetContent%`,
parseableArticleNoteTitle: '%title%',
parsableArticleNote: `[[ReadItLater]] [[Article]]\n\n# [%articleTitle%](%articleURL%)\n\n%articleContent%`,
notParseableArticleNoteTitle: 'Article %date%',
notParsableArticleNote: `[[ReadItLater]] [[Article]]\n\n[%articleURL%](%articleURL%)`,
textSnippetNoteTitle: 'Notice %date%',
textSnippetNote: `[[ReadItLater]] [[Textsnippet]]\n\n%content%`,
downloadImages: true,
};
class Note {
constructor(fileName, content) {
this.fileName = fileName;
this.content = content;
}
}
class Parser {
constructor(app, settings) {
this.app = app;
this.settings = settings;
}
isValidUrl(url) {
try {
new URL(url);
}
catch (e) {
return false;
}
return true;
}
getFormattedDateForFilename() {
const date = new Date();
return obsidian.moment(date).format('YYYY-MM-DD HH-mm-ss');
}
}
class YoutubeParser extends Parser {
constructor(app, settings) {
super(app, settings);
this.PATTERN = /(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/;
}
test(url) {
return this.isValidUrl(url) && this.PATTERN.test(url);
}
prepareNote(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield obsidian.request({ method: 'GET', url });
const videoTitle = new DOMParser().parseFromString(response, 'text/html').title;
const videoId = this.PATTERN.exec(url)[4];
const videoPlayer = `<iframe width="560" height="315" src="https://www.youtube.com/embed/${videoId}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
const content = this.settings.youtubeNote
.replace(/%videoTitle%/g, videoTitle)
.replace(/%videoURL%/g, url)
.replace(/%videoId%/g, videoId)
.replace(/%videoPlayer%/g, videoPlayer);
const fileNameTemplate = this.settings.youtubeNoteTitle.replace(/%title%/g, videoTitle);
const fileName = `${fileNameTemplate}.md`;
return new Note(fileName, content);
});
}
}
function extend (destination) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (source.hasOwnProperty(key)) destination[key] = source[key];
}
}
return destination
}
function repeat (character, count) {
return Array(count + 1).join(character)
}
function trimLeadingNewlines (string) {
return string.replace(/^\n*/, '')
}
function trimTrailingNewlines (string) {
// avoid match-at-end regexp bottleneck, see #370
var indexEnd = string.length;
while (indexEnd > 0 && string[indexEnd - 1] === '\n') indexEnd--;
return string.substring(0, indexEnd)
}
var blockElements = [
'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
'FOOTER', 'FORM', 'FRAMESET', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HEADER',
'HGROUP', 'HR', 'HTML', 'ISINDEX', 'LI', 'MAIN', 'MENU', 'NAV', 'NOFRAMES',
'NOSCRIPT', 'OL', 'OUTPUT', 'P', 'PRE', 'SECTION', 'TABLE', 'TBODY', 'TD',
'TFOOT', 'TH', 'THEAD', 'TR', 'UL'
];
function isBlock (node) {
return is(node, blockElements)
}
var voidElements = [
'AREA', 'BASE', 'BR', 'COL', 'COMMAND', 'EMBED', 'HR', 'IMG', 'INPUT',
'KEYGEN', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR'
];
function isVoid (node) {
return is(node, voidElements)
}
function hasVoid (node) {
return has(node, voidElements)
}
var meaningfulWhenBlankElements = [
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT',
'AUDIO', 'VIDEO'
];
function isMeaningfulWhenBlank (node) {
return is(node, meaningfulWhenBlankElements)
}
function hasMeaningfulWhenBlank (node) {
return has(node, meaningfulWhenBlankElements)
}
function is (node, tagNames) {
return tagNames.indexOf(node.nodeName) >= 0
}
function has (node, tagNames) {
return (
node.getElementsByTagName &&
tagNames.some(function (tagName) {
return node.getElementsByTagName(tagName).length
})
)
}
var rules$1 = {};
rules$1.paragraph = {
filter: 'p',
replacement: function (content) {
return '\n\n' + content + '\n\n'
}
};
rules$1.lineBreak = {
filter: 'br',
replacement: function (content, node, options) {
return options.br + '\n'
}
};
rules$1.heading = {
filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
replacement: function (content, node, options) {
var hLevel = Number(node.nodeName.charAt(1));
if (options.headingStyle === 'setext' && hLevel < 3) {
var underline = repeat((hLevel === 1 ? '=' : '-'), content.length);
return (
'\n\n' + content + '\n' + underline + '\n\n'
)
} else {
return '\n\n' + repeat('#', hLevel) + ' ' + content + '\n\n'
}
}
};
rules$1.blockquote = {
filter: 'blockquote',
replacement: function (content) {
content = content.replace(/^\n+|\n+$/g, '');
content = content.replace(/^/gm, '> ');
return '\n\n' + content + '\n\n'
}
};
rules$1.list = {
filter: ['ul', 'ol'],
replacement: function (content, node) {
var parent = node.parentNode;
if (parent.nodeName === 'LI' && parent.lastElementChild === node) {
return '\n' + content
} else {
return '\n\n' + content + '\n\n'
}
}
};
rules$1.listItem = {
filter: 'li',
replacement: function (content, node, options) {
content = content
.replace(/^\n+/, '') // remove leading newlines
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
.replace(/\n/gm, '\n '); // indent
var prefix = options.bulletListMarker + ' ';
var parent = node.parentNode;
if (parent.nodeName === 'OL') {
var start = parent.getAttribute('start');
var index = Array.prototype.indexOf.call(parent.children, node);
prefix = (start ? Number(start) + index : index + 1) + '. ';
}
return (
prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
)
}
};
rules$1.indentedCodeBlock = {
filter: function (node, options) {
return (
options.codeBlockStyle === 'indented' &&
node.nodeName === 'PRE' &&
node.firstChild &&
node.firstChild.nodeName === 'CODE'
)
},
replacement: function (content, node, options) {
return (
'\n\n ' +
node.firstChild.textContent.replace(/\n/g, '\n ') +
'\n\n'
)
}
};
rules$1.fencedCodeBlock = {
filter: function (node, options) {
return (
options.codeBlockStyle === 'fenced' &&
node.nodeName === 'PRE' &&
node.firstChild &&
node.firstChild.nodeName === 'CODE'
)
},
replacement: function (content, node, options) {
var className = node.firstChild.getAttribute('class') || '';
var language = (className.match(/language-(\S+)/) || [null, ''])[1];
var code = node.firstChild.textContent;
var fenceChar = options.fence.charAt(0);
var fenceSize = 3;
var fenceInCodeRegex = new RegExp('^' + fenceChar + '{3,}', 'gm');
var match;
while ((match = fenceInCodeRegex.exec(code))) {
if (match[0].length >= fenceSize) {
fenceSize = match[0].length + 1;
}
}
var fence = repeat(fenceChar, fenceSize);
return (
'\n\n' + fence + language + '\n' +
code.replace(/\n$/, '') +
'\n' + fence + '\n\n'
)
}
};
rules$1.horizontalRule = {
filter: 'hr',
replacement: function (content, node, options) {
return '\n\n' + options.hr + '\n\n'
}
};
rules$1.inlineLink = {
filter: function (node, options) {
return (
options.linkStyle === 'inlined' &&
node.nodeName === 'A' &&
node.getAttribute('href')
)
},
replacement: function (content, node) {
var href = node.getAttribute('href');
var title = cleanAttribute(node.getAttribute('title'));
if (title) title = ' "' + title + '"';
return '[' + content + '](' + href + title + ')'
}
};
rules$1.referenceLink = {
filter: function (node, options) {
return (
options.linkStyle === 'referenced' &&
node.nodeName === 'A' &&
node.getAttribute('href')
)
},
replacement: function (content, node, options) {
var href = node.getAttribute('href');
var title = cleanAttribute(node.getAttribute('title'));
if (title) title = ' "' + title + '"';
var replacement;
var reference;
switch (options.linkReferenceStyle) {
case 'collapsed':
replacement = '[' + content + '][]';
reference = '[' + content + ']: ' + href + title;
break
case 'shortcut':
replacement = '[' + content + ']';
reference = '[' + content + ']: ' + href + title;
break
default:
var id = this.references.length + 1;
replacement = '[' + content + '][' + id + ']';
reference = '[' + id + ']: ' + href + title;
}
this.references.push(reference);
return replacement
},
references: [],
append: function (options) {
var references = '';
if (this.references.length) {
references = '\n\n' + this.references.join('\n') + '\n\n';
this.references = []; // Reset references
}
return references
}
};
rules$1.emphasis = {
filter: ['em', 'i'],
replacement: function (content, node, options) {
if (!content.trim()) return ''
return options.emDelimiter + content + options.emDelimiter
}
};
rules$1.strong = {
filter: ['strong', 'b'],
replacement: function (content, node, options) {
if (!content.trim()) return ''
return options.strongDelimiter + content + options.strongDelimiter
}
};
rules$1.code = {
filter: function (node) {
var hasSiblings = node.previousSibling || node.nextSibling;
var isCodeBlock = node.parentNode.nodeName === 'PRE' && !hasSiblings;
return node.nodeName === 'CODE' && !isCodeBlock
},
replacement: function (content) {
if (!content) return ''
content = content.replace(/\r?\n|\r/g, ' ');
var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? ' ' : '';
var delimiter = '`';
var matches = content.match(/`+/gm) || [];
while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + '`';
return delimiter + extraSpace + content + extraSpace + delimiter
}
};
rules$1.image = {
filter: 'img',
replacement: function (content, node) {
var alt = cleanAttribute(node.getAttribute('alt'));
var src = node.getAttribute('src') || '';
var title = cleanAttribute(node.getAttribute('title'));
var titlePart = title ? ' "' + title + '"' : '';
return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : ''
}
};
function cleanAttribute (attribute) {
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : ''
}
/**
* Manages a collection of rules used to convert HTML to Markdown
*/
function Rules (options) {
this.options = options;
this._keep = [];
this._remove = [];
this.blankRule = {
replacement: options.blankReplacement
};
this.keepReplacement = options.keepReplacement;
this.defaultRule = {
replacement: options.defaultReplacement
};
this.array = [];
for (var key in options.rules) this.array.push(options.rules[key]);
}
Rules.prototype = {
add: function (key, rule) {
this.array.unshift(rule);
},
keep: function (filter) {
this._keep.unshift({
filter: filter,
replacement: this.keepReplacement
});
},
remove: function (filter) {
this._remove.unshift({
filter: filter,
replacement: function () {
return ''
}
});
},
forNode: function (node) {
if (node.isBlank) return this.blankRule
var rule;
if ((rule = findRule(this.array, node, this.options))) return rule
if ((rule = findRule(this._keep, node, this.options))) return rule
if ((rule = findRule(this._remove, node, this.options))) return rule
return this.defaultRule
},
forEach: function (fn) {
for (var i = 0; i < this.array.length; i++) fn(this.array[i], i);
}
};
function findRule (rules, node, options) {
for (var i = 0; i < rules.length; i++) {
var rule = rules[i];
if (filterValue(rule, node, options)) return rule
}
return void 0
}
function filterValue (rule, node, options) {
var filter = rule.filter;
if (typeof filter === 'string') {
if (filter === node.nodeName.toLowerCase()) return true
} else if (Array.isArray(filter)) {
if (filter.indexOf(node.nodeName.toLowerCase()) > -1) return true
} else if (typeof filter === 'function') {
if (filter.call(rule, node, options)) return true
} else {
throw new TypeError('`filter` needs to be a string, array, or function')
}
}
/**
* The collapseWhitespace function is adapted from collapse-whitespace
* by Luc Thevenard.
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Luc Thevenard <lucthevenard@gmail.com>
*
* 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.
*/
/**
* collapseWhitespace(options) removes extraneous whitespace from an the given element.
*
* @param {Object} options
*/
function collapseWhitespace (options) {
var element = options.element;
var isBlock = options.isBlock;
var isVoid = options.isVoid;
var isPre = options.isPre || function (node) {
return node.nodeName === 'PRE'
};
if (!element.firstChild || isPre(element)) return
var prevText = null;
var keepLeadingWs = false;
var prev = null;
var node = next(prev, element, isPre);
while (node !== element) {
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE
var text = node.data.replace(/[ \r\n\t]+/g, ' ');
if ((!prevText || / $/.test(prevText.data)) &&
!keepLeadingWs && text[0] === ' ') {
text = text.substr(1);
}
// `text` might be empty at this point.
if (!text) {
node = remove(node);
continue
}
node.data = text;
prevText = node;
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE
if (isBlock(node) || node.nodeName === 'BR') {
if (prevText) {
prevText.data = prevText.data.replace(/ $/, '');
}
prevText = null;
keepLeadingWs = false;
} else if (isVoid(node) || isPre(node)) {
// Avoid trimming space around non-block, non-BR void elements and inline PRE.
prevText = null;
keepLeadingWs = true;
} else if (prevText) {
// Drop protection if set previously.
keepLeadingWs = false;
}
} else {
node = remove(node);
continue
}
var nextNode = next(prev, node, isPre);
prev = node;
node = nextNode;
}
if (prevText) {
prevText.data = prevText.data.replace(/ $/, '');
if (!prevText.data) {
remove(prevText);
}
}
}
/**
* remove(node) removes the given node from the DOM and returns the
* next node in the sequence.
*
* @param {Node} node
* @return {Node} node
*/
function remove (node) {
var next = node.nextSibling || node.parentNode;
node.parentNode.removeChild(node);
return next
}
/**
* next(prev, current, isPre) returns the next node in the sequence, given the
* current and previous nodes.
*
* @param {Node} prev
* @param {Node} current
* @param {Function} isPre
* @return {Node}
*/
function next (prev, current, isPre) {
if ((prev && prev.parentNode === current) || isPre(current)) {
return current.nextSibling || current.parentNode
}
return current.firstChild || current.nextSibling || current.parentNode
}
/*
* Set up window for Node.js
*/
var root = (typeof window !== 'undefined' ? window : {});
/*
* Parsing HTML strings
*/
function canParseHTMLNatively () {
var Parser = root.DOMParser;
var canParse = false;
// Adapted from https://gist.github.com/1129031
// Firefox/Opera/IE throw errors on unsupported types
try {
// WebKit returns null on unsupported types
if (new Parser().parseFromString('', 'text/html')) {
canParse = true;
}
} catch (e) {}
return canParse
}
function createHTMLParser () {
var Parser = function () {};
{
if (shouldUseActiveX()) {
Parser.prototype.parseFromString = function (string) {
var doc = new window.ActiveXObject('htmlfile');
doc.designMode = 'on'; // disable on-page scripts
doc.open();
doc.write(string);
doc.close();
return doc
};
} else {
Parser.prototype.parseFromString = function (string) {
var doc = document.implementation.createHTMLDocument('');
doc.open();
doc.write(string);
doc.close();
return doc
};
}
}
return Parser
}
function shouldUseActiveX () {
var useActiveX = false;
try {
document.implementation.createHTMLDocument('').open();
} catch (e) {
if (window.ActiveXObject) useActiveX = true;
}
return useActiveX
}
var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser();
function RootNode (input, options) {
var root;
if (typeof input === 'string') {
var doc = htmlParser().parseFromString(
// DOM parsers arrange elements in the <head> and <body>.
// Wrapping in a custom element ensures elements are reliably arranged in
// a single element.
'<x-turndown id="turndown-root">' + input + '</x-turndown>',
'text/html'
);
root = doc.getElementById('turndown-root');
} else {
root = input.cloneNode(true);
}
collapseWhitespace({
element: root,
isBlock: isBlock,
isVoid: isVoid,
isPre: options.preformattedCode ? isPreOrCode : null
});
return root
}
var _htmlParser;
function htmlParser () {
_htmlParser = _htmlParser || new HTMLParser();
return _htmlParser
}
function isPreOrCode (node) {
return node.nodeName === 'PRE' || node.nodeName === 'CODE'
}
function Node (node, options) {
node.isBlock = isBlock(node);
node.isCode = node.nodeName === 'CODE' || node.parentNode.isCode;
node.isBlank = isBlank(node);
node.flankingWhitespace = flankingWhitespace(node, options);
return node
}
function isBlank (node) {
return (
!isVoid(node) &&
!isMeaningfulWhenBlank(node) &&
/^\s*$/i.test(node.textContent) &&
!hasVoid(node) &&
!hasMeaningfulWhenBlank(node)
)
}
function flankingWhitespace (node, options) {
if (node.isBlock || (options.preformattedCode && node.isCode)) {
return { leading: '', trailing: '' }
}
var edges = edgeWhitespace(node.textContent);
// abandon leading ASCII WS if left-flanked by ASCII WS
if (edges.leadingAscii && isFlankedByWhitespace('left', node, options)) {
edges.leading = edges.leadingNonAscii;
}
// abandon trailing ASCII WS if right-flanked by ASCII WS
if (edges.trailingAscii && isFlankedByWhitespace('right', node, options)) {
edges.trailing = edges.trailingNonAscii;
}
return { leading: edges.leading, trailing: edges.trailing }
}
function edgeWhitespace (string) {
var m = string.match(/^(([ \t\r\n]*)(\s*))[\s\S]*?((\s*?)([ \t\r\n]*))$/);
return {
leading: m[1], // whole string for whitespace-only strings
leadingAscii: m[2],
leadingNonAscii: m[3],
trailing: m[4], // empty for whitespace-only strings
trailingNonAscii: m[5],
trailingAscii: m[6]
}
}
function isFlankedByWhitespace (side, node, options) {
var sibling;
var regExp;
var isFlanked;
if (side === 'left') {
sibling = node.previousSibling;
regExp = / $/;
} else {
sibling = node.nextSibling;
regExp = /^ /;
}
if (sibling) {
if (sibling.nodeType === 3) {
isFlanked = regExp.test(sibling.nodeValue);
} else if (options.preformattedCode && sibling.nodeName === 'CODE') {
isFlanked = false;
} else if (sibling.nodeType === 1 && !isBlock(sibling)) {
isFlanked = regExp.test(sibling.textContent);
}
}
return isFlanked
}
var reduce = Array.prototype.reduce;
var escapes = [
[/\\/g, '\\\\'],
[/\*/g, '\\*'],
[/^-/g, '\\-'],
[/^\+ /g, '\\+ '],
[/^(=+)/g, '\\$1'],
[/^(#{1,6}) /g, '\\$1 '],
[/`/g, '\\`'],
[/^~~~/g, '\\~~~'],
[/\[/g, '\\['],
[/\]/g, '\\]'],
[/^>/g, '\\>'],
[/_/g, '\\_'],
[/^(\d+)\. /g, '$1\\. ']
];
function TurndownService (options) {
if (!(this instanceof TurndownService)) return new TurndownService(options)
var defaults = {
rules: rules$1,
headingStyle: 'setext',
hr: '* * *',
bulletListMarker: '*',
codeBlockStyle: 'indented',
fence: '```',
emDelimiter: '_',
strongDelimiter: '**',
linkStyle: 'inlined',
linkReferenceStyle: 'full',
br: ' ',
preformattedCode: false,
blankReplacement: function (content, node) {
return node.isBlock ? '\n\n' : ''
},
keepReplacement: function (content, node) {
return node.isBlock ? '\n\n' + node.outerHTML + '\n\n' : node.outerHTML
},
defaultReplacement: function (content, node) {
return node.isBlock ? '\n\n' + content + '\n\n' : content
}
};
this.options = extend({}, defaults, options);
this.rules = new Rules(this.options);
}
TurndownService.prototype = {
/**
* The entry point for converting a string or DOM node to Markdown
* @public
* @param {String|HTMLElement} input The string or DOM node to convert
* @returns A Markdown representation of the input
* @type String
*/
turndown: function (input) {
if (!canConvert(input)) {
throw new TypeError(
input + ' is not a string, or an element/document/fragment node.'
)
}
if (input === '') return ''
var output = process$1.call(this, new RootNode(input, this.options));
return postProcess.call(this, output)
},
/**
* Add one or more plugins
* @public
* @param {Function|Array} plugin The plugin or array of plugins to add
* @returns The Turndown instance for chaining
* @type Object
*/
use: function (plugin) {
if (Array.isArray(plugin)) {
for (var i = 0; i < plugin.length; i++) this.use(plugin[i]);
} else if (typeof plugin === 'function') {
plugin(this);
} else {
throw new TypeError('plugin must be a Function or an Array of Functions')
}
return this
},
/**
* Adds a rule
* @public
* @param {String} key The unique key of the rule
* @param {Object} rule The rule
* @returns The Turndown instance for chaining
* @type Object
*/
addRule: function (key, rule) {
this.rules.add(key, rule);
return this
},
/**
* Keep a node (as HTML) that matches the filter
* @public
* @param {String|Array|Function} filter The unique key of the rule
* @returns The Turndown instance for chaining
* @type Object
*/
keep: function (filter) {
this.rules.keep(filter);
return this
},
/**
* Remove a node that matches the filter
* @public
* @param {String|Array|Function} filter The unique key of the rule
* @returns The Turndown instance for chaining
* @type Object
*/
remove: function (filter) {
this.rules.remove(filter);
return this
},
/**
* Escapes Markdown syntax
* @public
* @param {String} string The string to escape
* @returns A string with Markdown syntax escaped
* @type String
*/
escape: function (string) {
return escapes.reduce(function (accumulator, escape) {
return accumulator.replace(escape[0], escape[1])
}, string)
}
};
/**
* Reduces a DOM node down to its Markdown string equivalent
* @private
* @param {HTMLElement} parentNode The node to convert
* @returns A Markdown representation of the node
* @type String
*/
function process$1 (parentNode) {
var self = this;
return reduce.call(parentNode.childNodes, function (output, node) {
node = new Node(node, self.options);
var replacement = '';
if (node.nodeType === 3) {
replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
} else if (node.nodeType === 1) {
replacement = replacementForNode.call(self, node);
}
return join(output, replacement)
}, '')
}
/**
* Appends strings as each rule requires and trims the output
* @private
* @param {String} output The conversion output
* @returns A trimmed version of the ouput
* @type String
*/
function postProcess (output) {
var self = this;
this.rules.forEach(function (rule) {
if (typeof rule.append === 'function') {
output = join(output, rule.append(self.options));
}
});
return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '')
}
/**
* Converts an element node to its Markdown equivalent
* @private
* @param {HTMLElement} node The node to convert
* @returns A Markdown representation of the node
* @type String
*/
function replacementForNode (node) {
var rule = this.rules.forNode(node);
var content = process$1.call(this, node);
var whitespace = node.flankingWhitespace;
if (whitespace.leading || whitespace.trailing) content = content.trim();
return (
whitespace.leading +
rule.replacement(content, node, this.options) +
whitespace.trailing
)
}
/**
* Joins replacement to the current output with appropriate number of new lines
* @private
* @param {String} output The current conversion output
* @param {String} replacement The string to append to the output
* @returns Joined output
* @type String
*/
function join (output, replacement) {
var s1 = trimTrailingNewlines(output);
var s2 = trimLeadingNewlines(replacement);
var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
var separator = '\n\n'.substring(0, nls);
return s1 + separator + s2
}
/**
* Determines whether an input can be converted
* @private
* @param {String|HTMLElement} input Describe this parameter
* @returns Describe what it returns
* @type String|Object|Array|Boolean|Number
*/
function canConvert (input) {
return (
input != null && (
typeof input === 'string' ||
(input.nodeType && (
input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11
))
)
)
}
var turndownPluginGfm_cjs = {};
Object.defineProperty(turndownPluginGfm_cjs, '__esModule', { value: true });
var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
3 years ago
});
}
3 years ago
function strikethrough (turndownService) {
turndownService.addRule('strikethrough', {
filter: ['del', 's', 'strike'],
replacement: function (content) {
return '~' + content + '~'
}
3 years ago
});
}
3 years ago
var indexOf = Array.prototype.indexOf;
var rules = {};
rules.tableCell = {
filter: ['th', 'td'],
replacement: function (content, node) {
return cell(content, node) + spannedCells(node, '')
}
};
rules.tableRow = {
filter: 'tr',
replacement: function (content, node) {
var borderCells = '';
var alignMap = { left: ':--', right: '--:', center: ':-:' };
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = (
node.childNodes[i].getAttribute('align') || ''
).toLowerCase();
if (align) border = alignMap[align] || border;
borderCells += cell(border, node.childNodes[i]) + spannedCells(node.childNodes[i], border);
}
}
3 years ago
return '\n' + content + (borderCells ? '\n' + borderCells : '')
}
};
rules.table = {
// Only convert tables that are not nested in another table, they are kept using `keep` (see below).
// TODO: nested tables should be converted to plain text in a strict (non HTML) gfm
filter: function (node) {
return node.nodeName === 'TABLE' && !isNestedTable(node)
},
replacement: function (content) {
// Ensure there are no blank lines
content = content.replace('\n\n', '\n');
return '\n\n' + content + '\n\n'
}
};
rules.tableSection = {
filter: ['thead', 'tbody', 'tfoot'],
replacement: function (content) {
return content
}
};
rules.captionSection = {
// only return content if caption if the first node immediately after TABLE
filter: 'caption',
replacement: function (content, node) {
if (node.parentNode.nodeName === 'TABLE' && node.parentNode.childNodes[0] === node) return content
return ''
}
};
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
var tableNode = parentNode;
if (parentNode.nodeName === 'THEAD' ||
parentNode.nodeName === 'TFOOT' ||
parentNode.nodeName === 'TBODY') {
tableNode = parentNode.parentNode;
}
return (tableNode.nodeName === 'TABLE' && tableNode.rows[0] === tr)
}
3 years ago
function cell (content, node) {
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';
if (index === 0) prefix = '| ';
// Ensure single line per cell (both windows and unix EoL)
// TODO: allow gfm non-strict mode to replace new lines by `<br/>`
content = content.replace(/\r\n/g, '\n').replace(/\n/g, ' ');
// | must be escaped as \|
content = content.replace(/\|/g, '\\|');
return prefix + content + ' |'
}
function spannedCells (node, spannedCellContent) {
var colspan = node.getAttribute('colspan') || 1;
if (colspan <= 1) return ''
return (' ' + spannedCellContent + ' |').repeat(colspan - 1)
}
function isNestedTable (tableNode) {
var currentNode = tableNode.parentNode;
while (currentNode) {
if (currentNode.nodeName === 'TABLE') return true
currentNode = currentNode.parentNode;
}
return false
}
function tables (turndownService) {
turndownService.keep(function (node) {
return node.nodeName === 'TABLE' && isNestedTable(node)
});
for (var key in rules) turndownService.addRule(key, rules[key]);
}
function taskListItems (turndownService) {
turndownService.addRule('taskListItems', {
filter: function (node) {
return node.type === 'checkbox' && node.parentNode.nodeName === 'LI'
},
replacement: function (content, node) {
return (node.checked ? '[x]' : '[ ]') + ' '
}
3 years ago
});
}
function gfm (turndownService) {
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
var gfm_1 = turndownPluginGfm_cjs.gfm = gfm;
turndownPluginGfm_cjs.highlightedCodeBlock = highlightedCodeBlock;
turndownPluginGfm_cjs.strikethrough = strikethrough;
turndownPluginGfm_cjs.tables = tables;
turndownPluginGfm_cjs.taskListItems = taskListItems;
function parseHtmlContent(content) {
return __awaiter(this, void 0, void 0, function* () {
const gfm = gfm_1;
const turndownService = new TurndownService({
headingStyle: 'atx',
hr: '---',
bulletListMarker: '-',
codeBlockStyle: 'fenced',
emDelimiter: '*',
});
3 years ago
turndownService.use(gfm);
const articleContent = turndownService.turndown(content);
return articleContent;
});
}
class TwitterParser extends Parser {
3 years ago
constructor(app, settings) {
super(app, settings);
this.PATTERN = /(https:\/\/twitter.com\/([a-zA-Z0-9_]+\/)([a-zA-Z0-9_]+\/[a-zA-Z0-9_]+))/;
}
test(url) {
return this.isValidUrl(url) && this.PATTERN.test(url);
}
prepareNote(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = JSON.parse(yield obsidian.request({
method: 'GET',
contentType: 'application/json',
url: `https://publish.twitter.com/oembed?url=${url}`,
}));
const tweetAuthorName = response.author_name;
3 years ago
const content = yield parseHtmlContent(response.html);
const processedContent = this.settings.twitterNote
.replace(/%tweetAuthorName%/g, tweetAuthorName)
.replace(/%tweetURL%/g, response.url)
.replace(/%tweetContent%/g, content);
const fileNameTemplate = this.settings.twitterNoteTitle
.replace(/%tweetAuthorName%/g, tweetAuthorName)
.replace(/%date%/g, this.getFormattedDateForFilename());
const fileName = `${fileNameTemplate}.md`;
return new Note(fileName, processedContent);
});
}
}
var Readability$1 = {exports: {}};
/*eslint-env es6:false*/
(function (module) {
/*
* Copyright (c) 2010 Arc90 Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This code is heavily based on Arc90's readability.js (1.7.1) script
* available at: http://code.google.com/p/arc90labs-readability
*/
/**
* Public constructor.
* @param {HTMLDocument} doc The document to parse.
* @param {Object} options The options object.
*/
function Readability(doc, options) {
// In some older versions, people passed a URI as the first argument. Cope:
if (options && options.documentElement) {
doc = options;
options = arguments[2];
} else if (!doc || !doc.documentElement) {
throw new Error("First argument to Readability constructor should be a document object.");
}
options = options || {};
this._doc = doc;
this._docJSDOMParser = this._doc.firstChild.__JSDOMParser__;
this._articleTitle = null;
this._articleByline = null;
this._articleDir = null;
this._articleSiteName = null;
this._attempts = [];
// Configurable options
this._debug = !!options.debug;
this._maxElemsToParse = options.maxElemsToParse || this.DEFAULT_MAX_ELEMS_TO_PARSE;
this._nbTopCandidates = options.nbTopCandidates || this.DEFAULT_N_TOP_CANDIDATES;
this._charThreshold = options.charThreshold || this.DEFAULT_CHAR_THRESHOLD;
this._classesToPreserve = this.CLASSES_TO_PRESERVE.concat(options.classesToPreserve || []);
this._keepClasses = !!options.keepClasses;
this._serializer = options.serializer || function(el) {
return el.innerHTML;
};
this._disableJSONLD = !!options.disableJSONLD;
// Start with all flags set
this._flags = this.FLAG_STRIP_UNLIKELYS |
this.FLAG_WEIGHT_CLASSES |
this.FLAG_CLEAN_CONDITIONALLY;
// Control whether log messages are sent to the console
if (this._debug) {
let logNode = function(node) {
if (node.nodeType == node.TEXT_NODE) {
return `${node.nodeName} ("${node.textContent}")`;
}
let attrPairs = Array.from(node.attributes || [], function(attr) {
return `${attr.name}="${attr.value}"`;
}).join(" ");
return `<${node.localName} ${attrPairs}>`;
};
this.log = function () {
if (typeof dump !== "undefined") {
var msg = Array.prototype.map.call(arguments, function(x) {
return (x && x.nodeName) ? logNode(x) : x;
}).join(" ");
dump("Reader: (Readability) " + msg + "\n");
} else if (typeof console !== "undefined") {
let args = Array.from(arguments, arg => {
if (arg && arg.nodeType == this.ELEMENT_NODE) {
return logNode(arg);
}
return arg;
});
args.unshift("Reader: (Readability)");
console.log.apply(console, args);
}
};
} else {
this.log = function () {};
}
}
Readability.prototype = {
FLAG_STRIP_UNLIKELYS: 0x1,
FLAG_WEIGHT_CLASSES: 0x2,
FLAG_CLEAN_CONDITIONALLY: 0x4,
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
ELEMENT_NODE: 1,
TEXT_NODE: 3,
// Max number of nodes supported by this parser. Default: 0 (no limit)
DEFAULT_MAX_ELEMS_TO_PARSE: 0,
// The number of top candidates to consider when analysing how
// tight the competition is among candidates.
DEFAULT_N_TOP_CANDIDATES: 5,
// Element tags to score by default.
DEFAULT_TAGS_TO_SCORE: "section,h2,h3,h4,h5,h6,p,td,pre".toUpperCase().split(","),
// The default number of chars an article must have in order to return a result
DEFAULT_CHAR_THRESHOLD: 500,
// All of the regular expressions in use within readability.
// Defined up here so we don't instantiate them repeatedly in loops.
REGEXPS: {
// NOTE: These two regular expressions are duplicated in
// Readability-readerable.js. Please keep both copies in sync.
unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,
okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,
positive: /article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i,
negative: /-ad-|hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i,
extraneous: /print|archive|comment|discuss|e[\-]?mail|share|reply|all|login|sign|single|utility/i,
byline: /byline|author|dateline|writtenby|p-author/i,
replaceFonts: /<(\/?)font[^>]*>/gi,
normalize: /\s{2,}/g,
videos: /\/\/(www\.)?((dailymotion|youtube|youtube-nocookie|player\.vimeo|v\.qq)\.com|(archive|upload\.wikimedia)\.org|player\.twitch\.tv)/i,
shareElements: /(\b|_)(share|sharedaddy)(\b|_)/i,
nextLink: /(next|weiter|continue|>([^\|]|$)|»([^\|]|$))/i,
prevLink: /(prev|earl|old|new|<|«)/i,
tokenize: /\W+/g,
whitespace: /^\s*$/,
hasContent: /\S$/,
hashUrl: /^#.+/,
srcsetUrl: /(\S+)(\s+[\d.]+[xw])?(\s*(?:,|$))/g,
b64DataUrl: /^data:\s*([^\s;,]+)\s*;\s*base64\s*,/i,
// See: https://schema.org/Article
jsonLdArticleTypes: /^Article|AdvertiserContentArticle|NewsArticle|AnalysisNewsArticle|AskPublicNewsArticle|BackgroundNewsArticle|OpinionNewsArticle|ReportageNewsArticle|ReviewNewsArticle|Report|SatiricalArticle|ScholarlyArticle|MedicalScholarlyArticle|SocialMediaPosting|BlogPosting|LiveBlogPosting|DiscussionForumPosting|TechArticle|APIReference$/
},
UNLIKELY_ROLES: [ "menu", "menubar", "complementary", "navigation", "alert", "alertdialog", "dialog" ],
DIV_TO_P_ELEMS: new Set([ "BLOCKQUOTE", "DL", "DIV", "IMG", "OL", "P", "PRE", "TABLE", "UL" ]),
ALTER_TO_DIV_EXCEPTIONS: ["DIV", "ARTICLE", "SECTION", "P"],
PRESENTATIONAL_ATTRIBUTES: [ "align", "background", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "hspace", "rules", "style", "valign", "vspace" ],
DEPRECATED_SIZE_ATTRIBUTE_ELEMS: [ "TABLE", "TH", "TD", "HR", "PRE" ],
// The commented out elements qualify as phrasing content but tend to be
// removed by readability when put into paragraphs, so we ignore them here.
PHRASING_ELEMS: [
// "CANVAS", "IFRAME", "SVG", "VIDEO",
"ABBR", "AUDIO", "B", "BDO", "BR", "BUTTON", "CITE", "CODE", "DATA",
"DATALIST", "DFN", "EM", "EMBED", "I", "IMG", "INPUT", "KBD", "LABEL",
"MARK", "MATH", "METER", "NOSCRIPT", "OBJECT", "OUTPUT", "PROGRESS", "Q",
"RUBY", "SAMP", "SCRIPT", "SELECT", "SMALL", "SPAN", "STRONG", "SUB",
"SUP", "TEXTAREA", "TIME", "VAR", "WBR"
],
// These are the classes that readability sets itself.
CLASSES_TO_PRESERVE: [ "page" ],
// These are the list of HTML entities that need to be escaped.
HTML_ESCAPE_MAP: {
"lt": "<",
"gt": ">",
"amp": "&",
"quot": '"',
"apos": "'",
},
/**
* Run any post-process modifications to article content as necessary.
*
* @param Element
* @return void
**/
_postProcessContent: function(articleContent) {
// Readability cannot open relative uris so we convert them to absolute uris.
this._fixRelativeUris(articleContent);
this._simplifyNestedElements(articleContent);
if (!this._keepClasses) {
// Remove classes.
this._cleanClasses(articleContent);
}
},
/**
* Iterates over a NodeList, calls `filterFn` for each node and removes node
* if function returned `true`.
*
* If function is not passed, removes all the nodes in node list.
*
* @param NodeList nodeList The nodes to operate on
* @param Function filterFn the function to use as a filter
* @return void
*/
_removeNodes: function(nodeList, filterFn) {
// Avoid ever operating on live node lists.
if (this._docJSDOMParser && nodeList._isLiveNodeList) {
throw new Error("Do not pass live node lists to _removeNodes");
}
for (var i = nodeList.length - 1; i >= 0; i--) {
var node = nodeList[i];
var parentNode = node.parentNode;
if (parentNode) {
if (!filterFn || filterFn.call(this, node, i, nodeList)) {
parentNode.removeChild(node);
}
}
}
},
/**
* Iterates over a NodeList, and calls _setNodeTag for each node.
*
* @param NodeList nodeList The nodes to operate on
* @param String newTagName the new tag name to use
* @return void
*/
_replaceNodeTags: function(nodeList, newTagName) {
// Avoid ever operating on live node lists.
if (this._docJSDOMParser && nodeList._isLiveNodeList) {
throw new Error("Do not pass live node lists to _replaceNodeTags");
}
for (const node of nodeList) {
this._setNodeTag(node, newTagName);
}
},
/**
* Iterate over a NodeList, which doesn't natively fully implement the Array
* interface.
*
* For convenience, the current object context is applied to the provided
* iterate function.
*
* @param NodeList nodeList The NodeList.
* @param Function fn The iterate function.
* @return void
*/
_forEachNode: function(nodeList, fn) {
Array.prototype.forEach.call(nodeList, fn, this);
},
/**
* Iterate over a NodeList, and return the first node that passes
* the supplied test function
*
* For convenience, the current object context is applied to the provided
* test function.
*
* @param NodeList nodeList The NodeList.
* @param Function fn The test function.
* @return void
*/
_findNode: function(nodeList, fn) {
return Array.prototype.find.call(nodeList, fn, this);
},
/**
* Iterate over a NodeList, return true if any of the provided iterate
* function calls returns true, false otherwise.
*
* For convenience, the current object context is applied to the
* provided iterate function.
*
* @param NodeList nodeList The NodeList.
* @param Function fn The iterate function.
* @return Boolean
*/
_someNode: function(nodeList, fn) {
return Array.prototype.some.call(nodeList, fn, this);
},
/**
* Iterate over a NodeList, return true if all of the provided iterate
* function calls return true, false otherwise.
*
* For convenience, the current object context is applied to the
* provided iterate function.
*
* @param NodeList nodeList The NodeList.
* @param Function fn The iterate function.
* @return Boolean
*/
_everyNode: function(nodeList, fn) {
return Array.prototype.every.call(nodeList, fn, this);
},
/**
* Concat all nodelists passed as arguments.
*
* @return ...NodeList
* @return Array
*/
_concatNodeLists: function() {
var slice = Array.prototype.slice;
var args = slice.call(arguments);
var nodeLists = args.map(function(list) {
return slice.call(list);
});
return Array.prototype.concat.apply([], nodeLists);
},
_getAllNodesWithTag: function(node, tagNames) {
if (node.querySelectorAll) {
return node.querySelectorAll(tagNames.join(","));
}
return [].concat.apply([], tagNames.map(function(tag) {
var collection = node.getElementsByTagName(tag);
return Array.isArray(collection) ? collection : Array.from(collection);
}));
},
/**
* Removes the class="" attribute from every element in the given
* subtree, except those that match CLASSES_TO_PRESERVE and
* the classesToPreserve array from the options object.
*
* @param Element
* @return void
*/
_cleanClasses: function(node) {
var classesToPreserve = this._classesToPreserve;
var className = (node.getAttribute("class") || "")
.split(/\s+/)
.filter(function(cls) {
return classesToPreserve.indexOf(cls) != -1;
})
.join(" ");
if (className) {
node.setAttribute("class", className);
} else {
node.removeAttribute("class");
}
for (node = node.firstElementChild; node; node = node.nextElementSibling) {
this._cleanClasses(node);
}
},
/**
* Converts each <a> and <img> uri in the given element to an absolute URI,
* ignoring #ref URIs.
*
* @param Element
* @return void
*/
_fixRelativeUris: function(articleContent) {
var baseURI = this._doc.baseURI;
var documentURI = this._doc.documentURI;
function toAbsoluteURI(uri) {
// Leave hash links alone if the base URI matches the document URI:
if (baseURI == documentURI && uri.charAt(0) == "#") {
return uri;
}
// Otherwise, resolve against base URI:
try {
return new URL(uri, baseURI).href;
} catch (ex) {
// Something went wrong, just return the original:
}
return uri;
}
var links = this._getAllNodesWithTag(articleContent, ["a"]);
this._forEachNode(links, function(link) {
var href = link.getAttribute("href");
if (href) {
// Remove links with javascript: URIs, since
// they won't work after scripts have been removed from the page.
if (href.indexOf("javascript:") === 0) {
// if the link only contains simple text content, it can be converted to a text node
if (link.childNodes.length === 1 && link.childNodes[0].nodeType === this.TEXT_NODE) {
var text = this._doc.createTextNode(link.textContent);
link.parentNode.replaceChild(text, link);
} else {
// if the link has multiple children, they should all be preserved
var container = this._doc.createElement("span");
3 years ago
while (link.firstChild) {
container.appendChild(link.firstChild);
}
link.parentNode.replaceChild(container, link);
}
} else {
link.setAttribute("href", toAbsoluteURI(href));
}
}
});
var medias = this._getAllNodesWithTag(articleContent, [
"img", "picture", "figure", "video", "audio", "source"
]);
this._forEachNode(medias, function(media) {
var src = media.getAttribute("src");
var poster = media.getAttribute("poster");
var srcset = media.getAttribute("srcset");
if (src) {
media.setAttribute("src", toAbsoluteURI(src));
}
if (poster) {
media.setAttribute("poster", toAbsoluteURI(poster));
}
if (srcset) {
var newSrcset = srcset.replace(this.REGEXPS.srcsetUrl, function(_, p1, p2, p3) {
return toAbsoluteURI(p1) + (p2 || "") + p3;
});
media.setAttribute("srcset", newSrcset);
}
});
},
_simplifyNestedElements: function(articleContent) {
var node = articleContent;
while (node) {
if (node.parentNode && ["DIV", "SECTION"].includes(node.tagName) && !(node.id && node.id.startsWith("readability"))) {
if (this._isElementWithoutContent(node)) {
node = this._removeAndGetNext(node);
continue;
} else if (this._hasSingleTagInsideElement(node, "DIV") || this._hasSingleTagInsideElement(node, "SECTION")) {
var child = node.children[0];
for (var i = 0; i < node.attributes.length; i++) {
child.setAttribute(node.attributes[i].name, node.attributes[i].value);
}
node.parentNode.replaceChild(child, node);
node = child;
continue;
}
}
node = this._getNextNode(node);
}
},
/**
* Get the article title as an H1.
*
* @return string
**/
_getArticleTitle: function() {
var doc = this._doc;
var curTitle = "";
var origTitle = "";
try {
curTitle = origTitle = doc.title.trim();
// If they had an element with id "title" in their HTML
if (typeof curTitle !== "string")
curTitle = origTitle = this._getInnerText(doc.getElementsByTagName("title")[0]);
} catch (e) {/* ignore exceptions setting the title. */}
var titleHadHierarchicalSeparators = false;
function wordCount(str) {
return str.split(/\s+/).length;
}
// If there's a separator in the title, first remove the final part
if ((/ [\|\-\\\/>»] /).test(curTitle)) {
titleHadHierarchicalSeparators = / [\\\/>»] /.test(curTitle);
curTitle = origTitle.replace(/(.*)[\|\-\\\/>»] .*/gi, "$1");
// If the resulting title is too short (3 words or fewer), remove
// the first part instead:
if (wordCount(curTitle) < 3)
curTitle = origTitle.replace(/[^\|\-\\\/>»]*[\|\-\\\/>»](.*)/gi, "$1");
} else if (curTitle.indexOf(": ") !== -1) {
// Check if we have an heading containing this exact string, so we
// could assume it's the full title.
var headings = this._concatNodeLists(
doc.getElementsByTagName("h1"),
doc.getElementsByTagName("h2")
);
var trimmedTitle = curTitle.trim();
var match = this._someNode(headings, function(heading) {
return heading.textContent.trim() === trimmedTitle;
});
// If we don't, let's extract the title out of the original title string.
if (!match) {
curTitle = origTitle.substring(origTitle.lastIndexOf(":") + 1);
// If the title is now too short, try the first colon instead:
if (wordCount(curTitle) < 3) {
curTitle = origTitle.substring(origTitle.indexOf(":") + 1);
// But if we have too many words before the colon there's something weird
// with the titles and the H tags so let's just use the original title instead
} else if (wordCount(origTitle.substr(0, origTitle.indexOf(":"))) > 5) {
curTitle = origTitle;
}
}
} else if (curTitle.length > 150 || curTitle.length < 15) {
var hOnes = doc.getElementsByTagName("h1");
if (hOnes.length === 1)
curTitle = this._getInnerText(hOnes[0]);
}
curTitle = curTitle.trim().replace(this.REGEXPS.normalize, " ");
// If we now have 4 words or fewer as our title, and either no
// 'hierarchical' separators (\, /, > or ») were found in the original
// title or we decreased the number of words by more than 1 word, use
// the original title.
var curTitleWordCount = wordCount(curTitle);
if (curTitleWordCount <= 4 &&
(!titleHadHierarchicalSeparators ||
curTitleWordCount != wordCount(origTitle.replace(/[\|\-\\\/>»]+/g, "")) - 1)) {
curTitle = origTitle;
}
return curTitle;
},
/**
* Prepare the HTML document for readability to scrape it.
* This includes things like stripping javascript, CSS, and handling terrible markup.
*
* @return void
**/
_prepDocument: function() {
var doc = this._doc;
// Remove all style tags in head
this._removeNodes(this._getAllNodesWithTag(doc, ["style"]));
if (doc.body) {
this._replaceBrs(doc.body);
}
this._replaceNodeTags(this._getAllNodesWithTag(doc, ["font"]), "SPAN");
},
/**
* Finds the next node, starting from the given node, and ignoring
* whitespace in between. If the given node is an element, the same node is
* returned.
*/
_nextNode: function (node) {
var next = node;
while (next
&& (next.nodeType != this.ELEMENT_NODE)
&& this.REGEXPS.whitespace.test(next.textContent)) {
next = next.nextSibling;
}
return next;
},
/**
* Replaces 2 or more successive <br> elements with a single <p>.
* Whitespace between <br> elements are ignored. For example:
* <div>foo<br>bar<br> <br><br>abc</div>
* will become:
* <div>foo<br>bar<p>abc</p></div>
*/
_replaceBrs: function (elem) {
this._forEachNode(this._getAllNodesWithTag(elem, ["br"]), function(br) {
var next = br.nextSibling;
// Whether 2 or more <br> elements have been found and replaced with a
// <p> block.
var replaced = false;
// If we find a <br> chain, remove the <br>s until we hit another node
// or non-whitespace. This leaves behind the first <br> in the chain
// (which will be replaced with a <p> later).
while ((next = this._nextNode(next)) && (next.tagName == "BR")) {
replaced = true;
var brSibling = next.nextSibling;
next.parentNode.removeChild(next);
next = brSibling;
}
// If we removed a <br> chain, replace the remaining <br> with a <p>. Add
// all sibling nodes as children of the <p> until we hit another <br>
// chain.
if (replaced) {
var p = this._doc.createElement("p");
br.parentNode.replaceChild(p, br);
next = p.nextSibling;
while (next) {
// If we've hit another <br><br>, we're done adding children to this <p>.
if (next.tagName == "BR") {
var nextElem = this._nextNode(next.nextSibling);
if (nextElem && nextElem.tagName == "BR")
break;
}
if (!this._isPhrasingContent(next))
break;
// Otherwise, make this node a child of the new <p>.
var sibling = next.nextSibling;
p.appendChild(next);
next = sibling;
}
while (p.lastChild && this._isWhitespace(p.lastChild)) {
p.removeChild(p.lastChild);
}
if (p.parentNode.tagName === "P")
this._setNodeTag(p.parentNode, "DIV");
}
});
},
_setNodeTag: function (node, tag) {
this.log("_setNodeTag", node, tag);
if (this._docJSDOMParser) {
node.localName = tag.toLowerCase();
node.tagName = tag.toUpperCase();
return node;
}
var replacement = node.ownerDocument.createElement(tag);
while (node.firstChild) {
replacement.appendChild(node.firstChild);
}
node.parentNode.replaceChild(replacement, node);
if (node.readability)
replacement.readability = node.readability;
for (var i = 0; i < node.attributes.length; i++) {
try {
replacement.setAttribute(node.attributes[i].name, node.attributes[i].value);
} catch (ex) {
/* it's possible for setAttribute() to throw if the attribute name
* isn't a valid XML Name. Such attributes can however be parsed from
* source in HTML docs, see https://github.com/whatwg/html/issues/4275,
* so we can hit them here and then throw. We don't care about such
* attributes so we ignore them.
*/
}
}
return replacement;
},
/**
* Prepare the article node for display. Clean out any inline styles,
* iframes, forms, strip extraneous <p> tags, etc.
*
* @param Element
* @return void
**/
_prepArticle: function(articleContent) {
this._cleanStyles(articleContent);
// Check for data tables before we continue, to avoid removing items in
// those tables, which will often be isolated even though they're
// visually linked to other content-ful elements (text, images, etc.).
this._markDataTables(articleContent);
this._fixLazyImages(articleContent);
// Clean out junk from the article content
this._cleanConditionally(articleContent, "form");
this._cleanConditionally(articleContent, "fieldset");
this._clean(articleContent, "object");
this._clean(articleContent, "embed");
this._clean(articleContent, "footer");
this._clean(articleContent, "link");
this._clean(articleContent, "aside");
// Clean out elements with little content that have "share" in their id/class combinations from final top candidates,
// which means we don't remove the top candidates even they have "share".
var shareElementThreshold = this.DEFAULT_CHAR_THRESHOLD;
this._forEachNode(articleContent.children, function (topCandidate) {
this._cleanMatchedNodes(topCandidate, function (node, matchString) {
return this.REGEXPS.shareElements.test(matchString) && node.textContent.length < shareElementThreshold;
});
});
this._clean(articleContent, "iframe");
this._clean(articleContent, "input");
this._clean(articleContent, "textarea");
this._clean(articleContent, "select");
this._clean(articleContent, "button");
this._cleanHeaders(articleContent);
// Do these last as the previous stuff may have removed junk
// that will affect these
this._cleanConditionally(articleContent, "table");
this._cleanConditionally(articleContent, "ul");
this._cleanConditionally(articleContent, "div");
// replace H1 with H2 as H1 should be only title that is displayed separately
this._replaceNodeTags(this._getAllNodesWithTag(articleContent, ["h1"]), "h2");
// Remove extra paragraphs
this._removeNodes(this._getAllNodesWithTag(articleContent, ["p"]), function (paragraph) {
var imgCount = paragraph.getElementsByTagName("img").length;
var embedCount = paragraph.getElementsByTagName("embed").length;
var objectCount = paragraph.getElementsByTagName("object").length;
// At this point, nasty iframes have been removed, only remain embedded video ones.
var iframeCount = paragraph.getElementsByTagName("iframe").length;
var totalCount = imgCount + embedCount + objectCount + iframeCount;
return totalCount === 0 && !this._getInnerText(paragraph, false);
});
this._forEachNode(this._getAllNodesWithTag(articleContent, ["br"]), function(br) {
var next = this._nextNode(br.nextSibling);
if (next && next.tagName == "P")
br.parentNode.removeChild(br);
});
// Remove single-cell tables
this._forEachNode(this._getAllNodesWithTag(articleContent, ["table"]), function(table) {
var tbody = this._hasSingleTagInsideElement(table, "TBODY") ? table.firstElementChild : table;
if (this._hasSingleTagInsideElement(tbody, "TR")) {
var row = tbody.firstElementChild;
if (this._hasSingleTagInsideElement(row, "TD")) {
var cell = row.firstElementChild;
cell = this._setNodeTag(cell, this._everyNode(cell.childNodes, this._isPhrasingContent) ? "P" : "DIV");
table.parentNode.replaceChild(cell, table);
}
}
});
},
/**
* Initialize a node with the readability object. Also checks the
* className/id for special names to add to its score.
*
* @param Element
* @return void
**/
_initializeNode: function(node) {
node.readability = {"contentScore": 0};
switch (node.tagName) {
case "DIV":
node.readability.contentScore += 5;
break;
case "PRE":
case "TD":
case "BLOCKQUOTE":
node.readability.contentScore += 3;
break;
case "ADDRESS":
case "OL":
case "UL":
case "DL":
case "DD":
case "DT":
case "LI":
case "FORM":
node.readability.contentScore -= 3;
break;
case "H1":
case "H2":
case "H3":
case "H4":
case "H5":
case "H6":
case "TH":
node.readability.contentScore -= 5;
break;
}
node.readability.contentScore += this._getClassWeight(node);
},
_removeAndGetNext: function(node) {
var nextNode = this._getNextNode(node, true);
node.parentNode.removeChild(node);
return nextNode;
},
/**
* Traverse the DOM from node to node, starting at the node passed in.
* Pass true for the second parameter to indicate this node itself
* (and its kids) are going away, and we want the next node over.
*
* Calling this in a loop will traverse the DOM depth-first.
*/
_getNextNode: function(node, ignoreSelfAndKids) {
// First check for kids if those aren't being ignored
if (!ignoreSelfAndKids && node.firstElementChild) {
return node.firstElementChild;
}
// Then for siblings...
if (node.nextElementSibling) {
return node.nextElementSibling;
}
// And finally, move up the parent chain *and* find a sibling
// (because this is depth-first traversal, we will have already
// seen the parent nodes themselves).
do {
node = node.parentNode;
} while (node && !node.nextElementSibling);
return node && node.nextElementSibling;
},
// compares second text to first one
// 1 = same text, 0 = completely different text
// works the way that it splits both texts into words and then finds words that are unique in second text
// the result is given by the lower length of unique parts
_textSimilarity: function(textA, textB) {
var tokensA = textA.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);
var tokensB = textB.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);
if (!tokensA.length || !tokensB.length) {
return 0;
}
var uniqTokensB = tokensB.filter(token => !tokensA.includes(token));
var distanceB = uniqTokensB.join(" ").length / tokensB.join(" ").length;
return 1 - distanceB;
},
_checkByline: function(node, matchString) {
if (this._articleByline) {
return false;
}
if (node.getAttribute !== undefined) {
var rel = node.getAttribute("rel");
var itemprop = node.getAttribute("itemprop");
}
if ((rel === "author" || (itemprop && itemprop.indexOf("author") !== -1) || this.REGEXPS.byline.test(matchString)) && this._isValidByline(node.textContent)) {
this._articleByline = node.textContent.trim();
return true;
}
return false;
},
_getNodeAncestors: function(node, maxDepth) {
maxDepth = maxDepth || 0;
var i = 0, ancestors = [];
while (node.parentNode) {
ancestors.push(node.parentNode);
if (maxDepth && ++i === maxDepth)
break;
node = node.parentNode;
}
return ancestors;
},
/***
* grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is
* most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
*
* @param page a document to run upon. Needs to be a full document, complete with body.
* @return Element
**/
_grabArticle: function (page) {
this.log("**** grabArticle ****");
var doc = this._doc;
var isPaging = page !== null;
page = page ? page : this._doc.body;
// We can't grab an article if we don't have a page!
if (!page) {
this.log("No body found in document. Abort.");
return null;
}
var pageCacheHtml = page.innerHTML;
while (true) {
this.log("Starting grabArticle loop");
var stripUnlikelyCandidates = this._flagIsActive(this.FLAG_STRIP_UNLIKELYS);
// First, node prepping. Trash nodes that look cruddy (like ones with the
// class name "comment", etc), and turn divs into P tags where they have been
// used inappropriately (as in, where they contain no other block level elements.)
var elementsToScore = [];
var node = this._doc.documentElement;
let shouldRemoveTitleHeader = true;
while (node) {
3 years ago
if (node.tagName === "HTML") {
this._articleLang = node.getAttribute("lang");
}
var matchString = node.className + " " + node.id;
if (!this._isProbablyVisible(node)) {
this.log("Removing hidden node - " + matchString);
node = this._removeAndGetNext(node);
continue;
}
// Check to see if this node is a byline, and remove it if it is.
if (this._checkByline(node, matchString)) {
node = this._removeAndGetNext(node);
continue;
}
if (shouldRemoveTitleHeader && this._headerDuplicatesTitle(node)) {
this.log("Removing header: ", node.textContent.trim(), this._articleTitle.trim());
shouldRemoveTitleHeader = false;
node = this._removeAndGetNext(node);
continue;
}
// Remove unlikely candidates
if (stripUnlikelyCandidates) {
if (this.REGEXPS.unlikelyCandidates.test(matchString) &&
!this.REGEXPS.okMaybeItsACandidate.test(matchString) &&
!this._hasAncestorTag(node, "table") &&
!this._hasAncestorTag(node, "code") &&
node.tagName !== "BODY" &&
node.tagName !== "A") {
this.log("Removing unlikely candidate - " + matchString);
node = this._removeAndGetNext(node);
continue;
}
if (this.UNLIKELY_ROLES.includes(node.getAttribute("role"))) {
this.log("Removing content with role " + node.getAttribute("role") + " - " + matchString);
node = this._removeAndGetNext(node);
continue;
}
}
// Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).
if ((node.tagName === "DIV" || node.tagName === "SECTION" || node.tagName === "HEADER" ||
node.tagName === "H1" || node.tagName === "H2" || node.tagName === "H3" ||
node.tagName === "H4" || node.tagName === "H5" || node.tagName === "H6") &&
this._isElementWithoutContent(node)) {
node = this._removeAndGetNext(node);
continue;
}
if (this.DEFAULT_TAGS_TO_SCORE.indexOf(node.tagName) !== -1) {
elementsToScore.push(node);
}
// Turn all divs that don't have children block level elements into p's
if (node.tagName === "DIV") {
// Put phrasing content into paragraphs.
var p = null;
var childNode = node.firstChild;
while (childNode) {
var nextSibling = childNode.nextSibling;
if (this._isPhrasingContent(childNode)) {
if (p !== null) {
p.appendChild(childNode);
} else if (!this._isWhitespace(childNode)) {
p = doc.createElement("p");
node.replaceChild(p, childNode);
p.appendChild(childNode);
}
} else if (p !== null) {
while (p.lastChild && this._isWhitespace(p.lastChild)) {
p.removeChild(p.lastChild);
}
p = null;
}
childNode = nextSibling;
}
// Sites like http://mobile.slate.com encloses each paragraph with a DIV
// element. DIVs with only a P element inside and no text content can be
// safely converted into plain P elements to avoid confusing the scoring
// algorithm with DIVs with are, in practice, paragraphs.
if (this._hasSingleTagInsideElement(node, "P") && this._getLinkDensity(node) < 0.25) {
var newNode = node.children[0];
node.parentNode.replaceChild(newNode, node);
node = newNode;
elementsToScore.push(node);
} else if (!this._hasChildBlockElement(node)) {
node = this._setNodeTag(node, "P");
elementsToScore.push(node);
}
}
node = this._getNextNode(node);
}
/**
* Loop through all paragraphs, and assign a score to them based on how content-y they look.
* Then add their score to their parent node.
*
* A score is determined by things like number of commas, class names, etc. Maybe eventually link density.
**/
var candidates = [];
this._forEachNode(elementsToScore, function(elementToScore) {
if (!elementToScore.parentNode || typeof(elementToScore.parentNode.tagName) === "undefined")
return;
// If this paragraph is less than 25 characters, don't even count it.
var innerText = this._getInnerText(elementToScore);
if (innerText.length < 25)
return;
// Exclude nodes with no ancestor.
var ancestors = this._getNodeAncestors(elementToScore, 5);
if (ancestors.length === 0)
return;
var contentScore = 0;
// Add a point for the paragraph itself as a base.
contentScore += 1;
// Add points for any commas within this paragraph.
contentScore += innerText.split(",").length;
// For every 100 characters in this paragraph, add another point. Up to 3 points.
contentScore += Math.min(Math.floor(innerText.length / 100), 3);
// Initialize and score ancestors.
this._forEachNode(ancestors, function(ancestor, level) {
if (!ancestor.tagName || !ancestor.parentNode || typeof(ancestor.parentNode.tagName) === "undefined")
return;
if (typeof(ancestor.readability) === "undefined") {
this._initializeNode(ancestor);
candidates.push(ancestor);
}
// Node score divider:
// - parent: 1 (no division)
// - grandparent: 2
// - great grandparent+: ancestor level * 3
if (level === 0)
var scoreDivider = 1;
else if (level === 1)
scoreDivider = 2;
else
scoreDivider = level * 3;
ancestor.readability.contentScore += contentScore / scoreDivider;
});
});
// After we've calculated scores, loop through all of the possible
// candidate nodes we found and find the one with the highest score.
var topCandidates = [];
for (var c = 0, cl = candidates.length; c < cl; c += 1) {
var candidate = candidates[c];
// Scale the final candidates score based on link density. Good content
// should have a relatively small link density (5% or less) and be mostly
// unaffected by this operation.
var candidateScore = candidate.readability.contentScore * (1 - this._getLinkDensity(candidate));
candidate.readability.contentScore = candidateScore;
this.log("Candidate:", candidate, "with score " + candidateScore);
for (var t = 0; t < this._nbTopCandidates; t++) {
var aTopCandidate = topCandidates[t];
if (!aTopCandidate || candidateScore > aTopCandidate.readability.contentScore) {
topCandidates.splice(t, 0, candidate);
if (topCandidates.length > this._nbTopCandidates)
topCandidates.pop();
break;
}
}
}
var topCandidate = topCandidates[0] || null;
var neededToCreateTopCandidate = false;
var parentOfTopCandidate;
// If we still have no top candidate, just use the body as a last resort.
// We also have to copy the body node so it is something we can modify.
if (topCandidate === null || topCandidate.tagName === "BODY") {
// Move all of the page's children into topCandidate
topCandidate = doc.createElement("DIV");
neededToCreateTopCandidate = true;
// Move everything (not just elements, also text nodes etc.) into the container
// so we even include text directly in the body:
3 years ago
while (page.firstChild) {
this.log("Moving child out:", page.firstChild);
topCandidate.appendChild(page.firstChild);
}
page.appendChild(topCandidate);
this._initializeNode(topCandidate);
} else if (topCandidate) {
// Find a better top candidate node if it contains (at least three) nodes which belong to `topCandidates` array
// and whose scores are quite closed with current `topCandidate` node.
var alternativeCandidateAncestors = [];
for (var i = 1; i < topCandidates.length; i++) {
if (topCandidates[i].readability.contentScore / topCandidate.readability.contentScore >= 0.75) {
alternativeCandidateAncestors.push(this._getNodeAncestors(topCandidates[i]));
}
}
var MINIMUM_TOPCANDIDATES = 3;
if (alternativeCandidateAncestors.length >= MINIMUM_TOPCANDIDATES) {
parentOfTopCandidate = topCandidate.parentNode;
while (parentOfTopCandidate.tagName !== "BODY") {
var listsContainingThisAncestor = 0;
for (var ancestorIndex = 0; ancestorIndex < alternativeCandidateAncestors.length && listsContainingThisAncestor < MINIMUM_TOPCANDIDATES; ancestorIndex++) {
listsContainingThisAncestor += Number(alternativeCandidateAncestors[ancestorIndex].includes(parentOfTopCandidate));
}
if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) {
topCandidate = parentOfTopCandidate;
break;
}
parentOfTopCandidate = parentOfTopCandidate.parentNode;
}
}
if (!topCandidate.readability) {
this._initializeNode(topCandidate);
}
// Because of our bonus system, parents of candidates might have scores
// themselves. They get half of the node. There won't be nodes with higher
// scores than our topCandidate, but if we see the score going *up* in the first
// few steps up the tree, that's a decent sign that there might be more content
// lurking in other places that we want to unify in. The sibling stuff
// below does some of that - but only if we've looked high enough up the DOM
// tree.
parentOfTopCandidate = topCandidate.parentNode;
var lastScore = topCandidate.readability.contentScore;
// The scores shouldn't get too low.
var scoreThreshold = lastScore / 3;
while (parentOfTopCandidate.tagName !== "BODY") {
if (!parentOfTopCandidate.readability) {
parentOfTopCandidate = parentOfTopCandidate.parentNode;
continue;
}
var parentScore = parentOfTopCandidate.readability.contentScore;
if (parentScore < scoreThreshold)
break;
if (parentScore > lastScore) {
// Alright! We found a better parent to use.
topCandidate = parentOfTopCandidate;
break;
}
lastScore = parentOfTopCandidate.readability.contentScore;
parentOfTopCandidate = parentOfTopCandidate.parentNode;
}
// If the top candidate is the only child, use parent instead. This will help sibling
// joining logic when adjacent content is actually located in parent's sibling node.
parentOfTopCandidate = topCandidate.parentNode;
while (parentOfTopCandidate.tagName != "BODY" && parentOfTopCandidate.children.length == 1) {
topCandidate = parentOfTopCandidate;
parentOfTopCandidate = topCandidate.parentNode;
}
if (!topCandidate.readability) {
this._initializeNode(topCandidate);
}
}
// Now that we have the top candidate, look through its siblings for content
// that might also be related. Things like preambles, content split by ads
// that we removed, etc.
var articleContent = doc.createElement("DIV");
if (isPaging)
articleContent.id = "readability-content";
var siblingScoreThreshold = Math.max(10, topCandidate.readability.contentScore * 0.2);
// Keep potential top candidate's parent node to try to get text direction of it later.
parentOfTopCandidate = topCandidate.parentNode;
var siblings = parentOfTopCandidate.children;
for (var s = 0, sl = siblings.length; s < sl; s++) {
var sibling = siblings[s];
var append = false;
this.log("Looking at sibling node:", sibling, sibling.readability ? ("with score " + sibling.readability.contentScore) : "");
this.log("Sibling has score", sibling.readability ? sibling.readability.contentScore : "Unknown");
if (sibling === topCandidate) {
append = true;
} else {
var contentBonus = 0;
// Give a bonus if sibling nodes and top candidates have the example same classname
if (sibling.className === topCandidate.className && topCandidate.className !== "")
contentBonus += topCandidate.readability.contentScore * 0.2;
if (sibling.readability &&
((sibling.readability.contentScore + contentBonus) >= siblingScoreThreshold)) {
append = true;
} else if (sibling.nodeName === "P") {
var linkDensity = this._getLinkDensity(sibling);
var nodeContent = this._getInnerText(sibling);
var nodeLength = nodeContent.length;
if (nodeLength > 80 && linkDensity < 0.25) {
append = true;
} else if (nodeLength < 80 && nodeLength > 0 && linkDensity === 0 &&
nodeContent.search(/\.( |$)/) !== -1) {
append = true;
}
}
}
if (append) {
this.log("Appending node:", sibling);
if (this.ALTER_TO_DIV_EXCEPTIONS.indexOf(sibling.nodeName) === -1) {
// We have a node that isn't a common block level element, like a form or td tag.
// Turn it into a div so it doesn't get filtered out later by accident.
this.log("Altering sibling:", sibling, "to div.");
sibling = this._setNodeTag(sibling, "DIV");
}
articleContent.appendChild(sibling);
3 years ago
// Fetch children again to make it compatible
// with DOM parsers without live collection support.
siblings = parentOfTopCandidate.children;
// siblings is a reference to the children array, and
// sibling is removed from the array when we call appendChild().
// As a result, we must revisit this index since the nodes
// have been shifted.
s -= 1;
sl -= 1;
}
}
if (this._debug)
this.log("Article content pre-prep: " + articleContent.innerHTML);
// So we have all of the content that we need. Now we clean it up for presentation.
this._prepArticle(articleContent);
if (this._debug)
this.log("Article content post-prep: " + articleContent.innerHTML);
if (neededToCreateTopCandidate) {
// We already created a fake div thing, and there wouldn't have been any siblings left
// for the previous loop, so there's no point trying to create a new div, and then
// move all the children over. Just assign IDs and class names here. No need to append
// because that already happened anyway.
topCandidate.id = "readability-page-1";
topCandidate.className = "page";
} else {
var div = doc.createElement("DIV");
div.id = "readability-page-1";
div.className = "page";
3 years ago
while (articleContent.firstChild) {
div.appendChild(articleContent.firstChild);
}
articleContent.appendChild(div);
}
if (this._debug)
this.log("Article content after paging: " + articleContent.innerHTML);
var parseSuccessful = true;
// Now that we've gone through the full algorithm, check to see if
// we got any meaningful content. If we didn't, we may need to re-run
// grabArticle with different flags set. This gives us a higher likelihood of
// finding the content, and the sieve approach gives us a higher likelihood of
// finding the -right- content.
var textLength = this._getInnerText(articleContent, true).length;
if (textLength < this._charThreshold) {
parseSuccessful = false;
page.innerHTML = pageCacheHtml;
if (this._flagIsActive(this.FLAG_STRIP_UNLIKELYS)) {
this._removeFlag(this.FLAG_STRIP_UNLIKELYS);
this._attempts.push({articleContent: articleContent, textLength: textLength});
} else if (this._flagIsActive(this.FLAG_WEIGHT_CLASSES)) {
this._removeFlag(this.FLAG_WEIGHT_CLASSES);
this._attempts.push({articleContent: articleContent, textLength: textLength});
} else if (this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY)) {
this._removeFlag(this.FLAG_CLEAN_CONDITIONALLY);
this._attempts.push({articleContent: articleContent, textLength: textLength});
} else {
this._attempts.push({articleContent: articleContent, textLength: textLength});
// No luck after removing flags, just return the longest text we found during the different loops
this._attempts.sort(function (a, b) {
return b.textLength - a.textLength;
});
// But first check if we actually have something
if (!this._attempts[0].textLength) {
return null;
}
articleContent = this._attempts[0].articleContent;
parseSuccessful = true;
}
}
if (parseSuccessful) {
// Find out text direction from ancestors of final top candidate.
var ancestors = [parentOfTopCandidate, topCandidate].concat(this._getNodeAncestors(parentOfTopCandidate));
this._someNode(ancestors, function(ancestor) {
if (!ancestor.tagName)
return false;
var articleDir = ancestor.getAttribute("dir");
if (articleDir) {
this._articleDir = articleDir;
return true;
}
return false;
});
return articleContent;
}
}
},
/**
* Check whether the input string could be a byline.
* This verifies that the input is a string, and that the length
* is less than 100 chars.
*
* @param possibleByline {string} - a string to check whether its a byline.
* @return Boolean - whether the input string is a byline.
*/
_isValidByline: function(byline) {
if (typeof byline == "string" || byline instanceof String) {
byline = byline.trim();
return (byline.length > 0) && (byline.length < 100);
}
return false;
},
/**
* Converts some of the common HTML entities in string to their corresponding characters.
*
* @param str {string} - a string to unescape.
* @return string without HTML entity.
*/
_unescapeHtmlEntities: function(str) {
if (!str) {
return str;
}
var htmlEscapeMap = this.HTML_ESCAPE_MAP;
return str.replace(/&(quot|amp|apos|lt|gt);/g, function(_, tag) {
return htmlEscapeMap[tag];
}).replace(/&#(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/gi, function(_, hex, numStr) {
var num = parseInt(hex || numStr, hex ? 16 : 10);
return String.fromCharCode(num);
});
},
/**
* Try to extract metadata from JSON-LD object.
* For now, only Schema.org objects of type Article or its subtypes are supported.
* @return Object with any metadata that could be extracted (possibly none)
*/
_getJSONLD: function (doc) {
var scripts = this._getAllNodesWithTag(doc, ["script"]);
3 years ago
var metadata;
3 years ago
this._forEachNode(scripts, function(jsonLdElement) {
if (!metadata && jsonLdElement.getAttribute("type") === "application/ld+json") {
try {
// Strip CDATA markers if present
var content = jsonLdElement.textContent.replace(/^\s*<!\[CDATA\[|\]\]>\s*$/g, "");
var parsed = JSON.parse(content);
if (
!parsed["@context"] ||
!parsed["@context"].match(/^https?\:\/\/schema\.org$/)
) {
return;
}
3 years ago
if (!parsed["@type"] && Array.isArray(parsed["@graph"])) {
parsed = parsed["@graph"].find(function(it) {
return (it["@type"] || "").match(
this.REGEXPS.jsonLdArticleTypes
);
});
}
3 years ago
if (
!parsed ||
!parsed["@type"] ||
!parsed["@type"].match(this.REGEXPS.jsonLdArticleTypes)
) {
return;
}
3 years ago
metadata = {};
if (typeof parsed.name === "string" && typeof parsed.headline === "string" && parsed.name !== parsed.headline) {
// we have both name and headline element in the JSON-LD. They should both be the same but some websites like aktualne.cz
// put their own name into "name" and the article title to "headline" which confuses Readability. So we try to check if either
// "name" or "headline" closely matches the html title, and if so, use that one. If not, then we use "name" by default.
var title = this._getArticleTitle();
var nameMatches = this._textSimilarity(parsed.name, title) > 0.75;
var headlineMatches = this._textSimilarity(parsed.headline, title) > 0.75;
if (headlineMatches && !nameMatches) {
metadata.title = parsed.headline;
} else {
metadata.title = parsed.name;
}
} else if (typeof parsed.name === "string") {
metadata.title = parsed.name.trim();
} else if (typeof parsed.headline === "string") {
metadata.title = parsed.headline.trim();
}
if (parsed.author) {
if (typeof parsed.author.name === "string") {
metadata.byline = parsed.author.name.trim();
} else if (Array.isArray(parsed.author) && parsed.author[0] && typeof parsed.author[0].name === "string") {
metadata.byline = parsed.author
.filter(function(author) {
return author && typeof author.name === "string";
})
.map(function(author) {
return author.name.trim();
})
.join(", ");
}
}
if (typeof parsed.description === "string") {
metadata.excerpt = parsed.description.trim();
}
if (
parsed.publisher &&
typeof parsed.publisher.name === "string"
) {
metadata.siteName = parsed.publisher.name.trim();
}
return;
} catch (err) {
this.log(err.message);
}
}
3 years ago
});
return metadata ? metadata : {};
},
/**
* Attempts to get excerpt and byline metadata for the article.
*
* @param {Object} jsonld object containing any metadata that
* could be extracted from JSON-LD object.
*
* @return Object with optional "excerpt" and "byline" properties
*/
_getArticleMetadata: function(jsonld) {
var metadata = {};
var values = {};
var metaElements = this._doc.getElementsByTagName("meta");
// property is a space-separated list of values
var propertyPattern = /\s*(dc|dcterm|og|twitter)\s*:\s*(author|creator|description|title|site_name)\s*/gi;
// name is a single value
var namePattern = /^\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\s*[\.:]\s*)?(author|creator|description|title|site_name)\s*$/i;
// Find description tags.
this._forEachNode(metaElements, function(element) {
var elementName = element.getAttribute("name");
var elementProperty = element.getAttribute("property");
var content = element.getAttribute("content");
if (!content) {
return;
}
var matches = null;
var name = null;
if (elementProperty) {
matches = elementProperty.match(propertyPattern);
if (matches) {
// Convert to lowercase, and remove any whitespace
// so we can match below.
name = matches[0].toLowerCase().replace(/\s/g, "");
// multiple authors
values[name] = content.trim();
}
}
if (!matches && elementName && namePattern.test(elementName)) {
name = elementName;
if (content) {
// Convert to lowercase, remove any whitespace, and convert dots
// to colons so we can match below.
name = name.toLowerCase().replace(/\s/g, "").replace(/\./g, ":");
values[name] = content.trim();
}
}
});
// get title
metadata.title = jsonld.title ||
values["dc:title"] ||
values["dcterm:title"] ||
values["og:title"] ||
values["weibo:article:title"] ||
values["weibo:webpage:title"] ||
values["title"] ||
values["twitter:title"];
if (!metadata.title) {
metadata.title = this._getArticleTitle();
}
// get author
metadata.byline = jsonld.byline ||
values["dc:creator"] ||
values["dcterm:creator"] ||
values["author"];
// get description
metadata.excerpt = jsonld.excerpt ||
values["dc:description"] ||
values["dcterm:description"] ||
values["og:description"] ||
values["weibo:article:description"] ||
values["weibo:webpage:description"] ||
values["description"] ||
values["twitter:description"];
// get site name
metadata.siteName = jsonld.siteName ||
values["og:site_name"];
// in many sites the meta value is escaped with HTML entities,
// so here we need to unescape it
metadata.title = this._unescapeHtmlEntities(metadata.title);
metadata.byline = this._unescapeHtmlEntities(metadata.byline);
metadata.excerpt = this._unescapeHtmlEntities(metadata.excerpt);
metadata.siteName = this._unescapeHtmlEntities(metadata.siteName);
return metadata;
},
/**
* Check if node is image, or if node contains exactly only one image
* whether as a direct child or as its descendants.
*
* @param Element
**/
_isSingleImage: function(node) {
if (node.tagName === "IMG") {
return true;
}
if (node.children.length !== 1 || node.textContent.trim() !== "") {
return false;
}
return this._isSingleImage(node.children[0]);
},
/**
* Find all <noscript> that are located after <img> nodes, and which contain only one
* <img> element. Replace the first image with the image from inside the <noscript> tag,
* and remove the <noscript> tag. This improves the quality of the images we use on
* some sites (e.g. Medium).
*
* @param Element
**/
_unwrapNoscriptImages: function(doc) {
// Find img without source or attributes that might contains image, and remove it.
// This is done to prevent a placeholder img is replaced by img from noscript in next step.
var imgs = Array.from(doc.getElementsByTagName("img"));
this._forEachNode(imgs, function(img) {
for (var i = 0; i < img.attributes.length; i++) {
var attr = img.attributes[i];
switch (attr.name) {
case "src":
case "srcset":
case "data-src":
case "data-srcset":
return;
}
if (/\.(jpg|jpeg|png|webp)/i.test(attr.value)) {
return;
}
}
img.parentNode.removeChild(img);
});
// Next find noscript and try to extract its image
var noscripts = Array.from(doc.getElementsByTagName("noscript"));
this._forEachNode(noscripts, function(noscript) {
// Parse content of noscript and make sure it only contains image
var tmp = doc.createElement("div");
tmp.innerHTML = noscript.innerHTML;
if (!this._isSingleImage(tmp)) {
return;
}
// If noscript has previous sibling and it only contains image,
// replace it with noscript content. However we also keep old
// attributes that might contains image.
var prevElement = noscript.previousElementSibling;
if (prevElement && this._isSingleImage(prevElement)) {
var prevImg = prevElement;
if (prevImg.tagName !== "IMG") {
prevImg = prevElement.getElementsByTagName("img")[0];
}
var newImg = tmp.getElementsByTagName("img")[0];
for (var i = 0; i < prevImg.attributes.length; i++) {
var attr = prevImg.attributes[i];
if (attr.value === "") {
continue;
}
if (attr.name === "src" || attr.name === "srcset" || /\.(jpg|jpeg|png|webp)/i.test(attr.value)) {
if (newImg.getAttribute(attr.name) === attr.value) {
continue;
}
var attrName = attr.name;
if (newImg.hasAttribute(attrName)) {
attrName = "data-old-" + attrName;
}
newImg.setAttribute(attrName, attr.value);
}
}
noscript.parentNode.replaceChild(tmp.firstElementChild, prevElement);
}
});
},
/**
* Removes script tags from the document.
*
* @param Element
**/
_removeScripts: function(doc) {
this._removeNodes(this._getAllNodesWithTag(doc, ["script"]), function(scriptNode) {
scriptNode.nodeValue = "";
scriptNode.removeAttribute("src");
return true;
});
this._removeNodes(this._getAllNodesWithTag(doc, ["noscript"]));
},
/**
* Check if this node has only whitespace and a single element with given tag
* Returns false if the DIV node contains non-empty text nodes
* or if it contains no element with given tag or more than 1 element.
*
* @param Element
* @param string tag of child element
**/
_hasSingleTagInsideElement: function(element, tag) {
// There should be exactly 1 element child with given tag
if (element.children.length != 1 || element.children[0].tagName !== tag) {
return false;
}
// And there should be no text nodes with real content
return !this._someNode(element.childNodes, function(node) {
return node.nodeType === this.TEXT_NODE &&
this.REGEXPS.hasContent.test(node.textContent);
});
},
_isElementWithoutContent: function(node) {
return node.nodeType === this.ELEMENT_NODE &&
node.textContent.trim().length == 0 &&
(node.children.length == 0 ||
node.children.length == node.getElementsByTagName("br").length + node.getElementsByTagName("hr").length);
},
/**
* Determine whether element has any children block level elements.
*
* @param Element
*/
_hasChildBlockElement: function (element) {
return this._someNode(element.childNodes, function(node) {
return this.DIV_TO_P_ELEMS.has(node.tagName) ||
this._hasChildBlockElement(node);
});
},
/***
* Determine if a node qualifies as phrasing content.
* https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
**/
_isPhrasingContent: function(node) {
return node.nodeType === this.TEXT_NODE || this.PHRASING_ELEMS.indexOf(node.tagName) !== -1 ||
((node.tagName === "A" || node.tagName === "DEL" || node.tagName === "INS") &&
this._everyNode(node.childNodes, this._isPhrasingContent));
},
_isWhitespace: function(node) {
return (node.nodeType === this.TEXT_NODE && node.textContent.trim().length === 0) ||
(node.nodeType === this.ELEMENT_NODE && node.tagName === "BR");
},
/**
* Get the inner text of a node - cross browser compatibly.
* This also strips out any excess whitespace to be found.
*
* @param Element
* @param Boolean normalizeSpaces (default: true)
* @return string
**/
_getInnerText: function(e, normalizeSpaces) {
normalizeSpaces = (typeof normalizeSpaces === "undefined") ? true : normalizeSpaces;
var textContent = e.textContent.trim();
if (normalizeSpaces) {
return textContent.replace(this.REGEXPS.normalize, " ");
}
return textContent;
},
/**
* Get the number of times a string s appears in the node e.
*
* @param Element
* @param string - what to split on. Default is ","
* @return number (integer)
**/
_getCharCount: function(e, s) {
s = s || ",";
return this._getInnerText(e).split(s).length - 1;
},
/**
* Remove the style attribute on every e and under.
* TODO: Test if getElementsByTagName(*) is faster.
*
* @param Element
* @return void
**/
_cleanStyles: function(e) {
if (!e || e.tagName.toLowerCase() === "svg")
return;
// Remove `style` and deprecated presentational attributes
for (var i = 0; i < this.PRESENTATIONAL_ATTRIBUTES.length; i++) {
e.removeAttribute(this.PRESENTATIONAL_ATTRIBUTES[i]);
}
if (this.DEPRECATED_SIZE_ATTRIBUTE_ELEMS.indexOf(e.tagName) !== -1) {
e.removeAttribute("width");
e.removeAttribute("height");
}
var cur = e.firstElementChild;
while (cur !== null) {
this._cleanStyles(cur);
cur = cur.nextElementSibling;
}
},
/**
* Get the density of links as a percentage of the content
* This is the amount of text that is inside a link divided by the total text in the node.
*
* @param Element
* @return number (float)
**/
_getLinkDensity: function(element) {
var textLength = this._getInnerText(element).length;
if (textLength === 0)
return 0;
var linkLength = 0;
// XXX implement _reduceNodeList?
this._forEachNode(element.getElementsByTagName("a"), function(linkNode) {
var href = linkNode.getAttribute("href");
var coefficient = href && this.REGEXPS.hashUrl.test(href) ? 0.3 : 1;
linkLength += this._getInnerText(linkNode).length * coefficient;
});
return linkLength / textLength;
},
/**
* Get an elements class/id weight. Uses regular expressions to tell if this
* element looks good or bad.
*
* @param Element
* @return number (Integer)
**/
_getClassWeight: function(e) {
if (!this._flagIsActive(this.FLAG_WEIGHT_CLASSES))
return 0;
var weight = 0;
// Look for a special classname
if (typeof(e.className) === "string" && e.className !== "") {
if (this.REGEXPS.negative.test(e.className))
weight -= 25;
if (this.REGEXPS.positive.test(e.className))
weight += 25;
}
// Look for a special ID
if (typeof(e.id) === "string" && e.id !== "") {
if (this.REGEXPS.negative.test(e.id))
weight -= 25;
if (this.REGEXPS.positive.test(e.id))
weight += 25;
}
return weight;
},
/**
* Clean a node of all elements of type "tag".
* (Unless it's a youtube/vimeo video. People love movies.)
*
* @param Element
* @param string tag to clean
* @return void
**/
_clean: function(e, tag) {
var isEmbed = ["object", "embed", "iframe"].indexOf(tag) !== -1;
this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(element) {
// Allow youtube and vimeo videos through as people usually want to see those.
if (isEmbed) {
// First, check the elements attributes to see if any of them contain youtube or vimeo
for (var i = 0; i < element.attributes.length; i++) {
if (this.REGEXPS.videos.test(element.attributes[i].value)) {
return false;
}
}
// For embed with <object> tag, check inner HTML as well.
if (element.tagName === "object" && this.REGEXPS.videos.test(element.innerHTML)) {
return false;
}
}
return true;
});
},
/**
* Check if a given node has one of its ancestor tag name matching the
* provided one.
* @param HTMLElement node
* @param String tagName
* @param Number maxDepth
* @param Function filterFn a filter to invoke to determine whether this node 'counts'
* @return Boolean
*/
_hasAncestorTag: function(node, tagName, maxDepth, filterFn) {
maxDepth = maxDepth || 3;
tagName = tagName.toUpperCase();
var depth = 0;
while (node.parentNode) {
if (maxDepth > 0 && depth > maxDepth)
return false;
if (node.parentNode.tagName === tagName && (!filterFn || filterFn(node.parentNode)))
return true;
node = node.parentNode;
depth++;
}
return false;
},
/**
* Return an object indicating how many rows and columns this table has.
*/
_getRowAndColumnCount: function(table) {
var rows = 0;
var columns = 0;
var trs = table.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
var rowspan = trs[i].getAttribute("rowspan") || 0;
if (rowspan) {
rowspan = parseInt(rowspan, 10);
}
rows += (rowspan || 1);
// Now look for column-related info
var columnsInThisRow = 0;
var cells = trs[i].getElementsByTagName("td");
for (var j = 0; j < cells.length; j++) {
var colspan = cells[j].getAttribute("colspan") || 0;
if (colspan) {
colspan = parseInt(colspan, 10);
}
columnsInThisRow += (colspan || 1);
}
columns = Math.max(columns, columnsInThisRow);
}
return {rows: rows, columns: columns};
},
/**
* Look for 'data' (as opposed to 'layout') tables, for which we use
* similar checks as
* https://searchfox.org/mozilla-central/rev/f82d5c549f046cb64ce5602bfd894b7ae807c8f8/accessible/generic/TableAccessible.cpp#19
*/
_markDataTables: function(root) {
var tables = root.getElementsByTagName("table");
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
var role = table.getAttribute("role");
if (role == "presentation") {
table._readabilityDataTable = false;
continue;
}
var datatable = table.getAttribute("datatable");
if (datatable == "0") {
table._readabilityDataTable = false;
continue;
}
var summary = table.getAttribute("summary");
if (summary) {
table._readabilityDataTable = true;
continue;
}
var caption = table.getElementsByTagName("caption")[0];
if (caption && caption.childNodes.length > 0) {
table._readabilityDataTable = true;
continue;
}
// If the table has a descendant with any of these tags, consider a data table:
var dataTableDescendants = ["col", "colgroup", "tfoot", "thead", "th"];
var descendantExists = function(tag) {
return !!table.getElementsByTagName(tag)[0];
};
if (dataTableDescendants.some(descendantExists)) {
this.log("Data table because found data-y descendant");
table._readabilityDataTable = true;
continue;
}
// Nested tables indicate a layout table:
if (table.getElementsByTagName("table")[0]) {
table._readabilityDataTable = false;
continue;
}
var sizeInfo = this._getRowAndColumnCount(table);
if (sizeInfo.rows >= 10 || sizeInfo.columns > 4) {
table._readabilityDataTable = true;
continue;
}
// Now just go by size entirely:
table._readabilityDataTable = sizeInfo.rows * sizeInfo.columns > 10;
}
},
/* convert images and figures that have properties like data-src into images that can be loaded without JS */
_fixLazyImages: function (root) {
this._forEachNode(this._getAllNodesWithTag(root, ["img", "picture", "figure"]), function (elem) {
// In some sites (e.g. Kotaku), they put 1px square image as base64 data uri in the src attribute.
// So, here we check if the data uri is too short, just might as well remove it.
if (elem.src && this.REGEXPS.b64DataUrl.test(elem.src)) {
// Make sure it's not SVG, because SVG can have a meaningful image in under 133 bytes.
var parts = this.REGEXPS.b64DataUrl.exec(elem.src);
if (parts[1] === "image/svg+xml") {
return;
}
// Make sure this element has other attributes which contains image.
// If it doesn't, then this src is important and shouldn't be removed.
var srcCouldBeRemoved = false;
for (var i = 0; i < elem.attributes.length; i++) {
var attr = elem.attributes[i];
if (attr.name === "src") {
continue;
}
if (/\.(jpg|jpeg|png|webp)/i.test(attr.value)) {
srcCouldBeRemoved = true;
break;
}
}
// Here we assume if image is less than 100 bytes (or 133B after encoded to base64)
// it will be too small, therefore it might be placeholder image.
if (srcCouldBeRemoved) {
var b64starts = elem.src.search(/base64\s*/i) + 7;
var b64length = elem.src.length - b64starts;
if (b64length < 133) {
elem.removeAttribute("src");
}
}
}
// also check for "null" to work around https://github.com/jsdom/jsdom/issues/2580
if ((elem.src || (elem.srcset && elem.srcset != "null")) && elem.className.toLowerCase().indexOf("lazy") === -1) {
return;
}
for (var j = 0; j < elem.attributes.length; j++) {
attr = elem.attributes[j];
3 years ago
if (attr.name === "src" || attr.name === "srcset" || attr.name === "alt") {
continue;
}
var copyTo = null;
if (/\.(jpg|jpeg|png|webp)\s+\d/.test(attr.value)) {
copyTo = "srcset";
} else if (/^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/.test(attr.value)) {
copyTo = "src";
}
if (copyTo) {
//if this is an img or picture, set the attribute directly
if (elem.tagName === "IMG" || elem.tagName === "PICTURE") {
elem.setAttribute(copyTo, attr.value);
} else if (elem.tagName === "FIGURE" && !this._getAllNodesWithTag(elem, ["img", "picture"]).length) {
//if the item is a <figure> that does not contain an image or picture, create one and place it inside the figure
//see the nytimes-3 testcase for an example
var img = this._doc.createElement("img");
img.setAttribute(copyTo, attr.value);
elem.appendChild(img);
}
}
}
});
},
_getTextDensity: function(e, tags) {
var textLength = this._getInnerText(e, true).length;
if (textLength === 0) {
return 0;
}
var childrenLength = 0;
var children = this._getAllNodesWithTag(e, tags);
this._forEachNode(children, (child) => childrenLength += this._getInnerText(child, true).length);
return childrenLength / textLength;
},
/**
* Clean an element of all tags of type "tag" if they look fishy.
* "Fishy" is an algorithm based on content length, classnames, link density, number of images & embeds, etc.
*
* @return void
**/
_cleanConditionally: function(e, tag) {
if (!this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY))
return;
// Gather counts for other typical elements embedded within.
// Traverse backwards so we can remove nodes at the same time
// without effecting the traversal.
//
// TODO: Consider taking into account original contentScore here.
this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(node) {
// First check if this node IS data table, in which case don't remove it.
var isDataTable = function(t) {
return t._readabilityDataTable;
};
var isList = tag === "ul" || tag === "ol";
if (!isList) {
var listLength = 0;
var listNodes = this._getAllNodesWithTag(node, ["ul", "ol"]);
this._forEachNode(listNodes, (list) => listLength += this._getInnerText(list).length);
isList = listLength / this._getInnerText(node).length > 0.9;
}
if (tag === "table" && isDataTable(node)) {
return false;
}
// Next check if we're inside a data table, in which case don't remove it as well.
if (this._hasAncestorTag(node, "table", -1, isDataTable)) {
return false;
}
if (this._hasAncestorTag(node, "code")) {
return false;
}
var weight = this._getClassWeight(node);
this.log("Cleaning Conditionally", node);
var contentScore = 0;
if (weight + contentScore < 0) {
return true;
}
if (this._getCharCount(node, ",") < 10) {
// If there are not very many commas, and the number of
// non-paragraph elements is more than paragraphs or other
// ominous signs, remove the element.
var p = node.getElementsByTagName("p").length;
var img = node.getElementsByTagName("img").length;
var li = node.getElementsByTagName("li").length - 100;
var input = node.getElementsByTagName("input").length;
var headingDensity = this._getTextDensity(node, ["h1", "h2", "h3", "h4", "h5", "h6"]);
var embedCount = 0;
var embeds = this._getAllNodesWithTag(node, ["object", "embed", "iframe"]);
for (var i = 0; i < embeds.length; i++) {
// If this embed has attribute that matches video regex, don't delete it.
for (var j = 0; j < embeds[i].attributes.length; j++) {
if (this.REGEXPS.videos.test(embeds[i].attributes[j].value)) {
return false;
}
}
// For embed with <object> tag, check inner HTML as well.
if (embeds[i].tagName === "object" && this.REGEXPS.videos.test(embeds[i].innerHTML)) {
return false;
}
embedCount++;
}
var linkDensity = this._getLinkDensity(node);
var contentLength = this._getInnerText(node).length;
var haveToRemove =
(img > 1 && p / img < 0.5 && !this._hasAncestorTag(node, "figure")) ||
(!isList && li > p) ||
(input > Math.floor(p/3)) ||
(!isList && headingDensity < 0.9 && contentLength < 25 && (img === 0 || img > 2) && !this._hasAncestorTag(node, "figure")) ||
(!isList && weight < 25 && linkDensity > 0.2) ||
(weight >= 25 && linkDensity > 0.5) ||
((embedCount === 1 && contentLength < 75) || embedCount > 1);
return haveToRemove;
}
return false;
});
},
/**
* Clean out elements that match the specified conditions
*
* @param Element
* @param Function determines whether a node should be removed
* @return void
**/
_cleanMatchedNodes: function(e, filter) {
var endOfSearchMarkerNode = this._getNextNode(e, true);
var next = this._getNextNode(e);
while (next && next != endOfSearchMarkerNode) {
if (filter.call(this, next, next.className + " " + next.id)) {
next = this._removeAndGetNext(next);
} else {
next = this._getNextNode(next);
}
}
},
/**
* Clean out spurious headers from an Element.
*
* @param Element
* @return void
**/
_cleanHeaders: function(e) {
let headingNodes = this._getAllNodesWithTag(e, ["h1", "h2"]);
this._removeNodes(headingNodes, function(node) {
let shouldRemove = this._getClassWeight(node) < 0;
if (shouldRemove) {
this.log("Removing header with low class weight:", node);
}
return shouldRemove;
});
},
/**
* Check if this node is an H1 or H2 element whose content is mostly
* the same as the article title.
*
* @param Element the node to check.
* @return boolean indicating whether this is a title-like header.
*/
_headerDuplicatesTitle: function(node) {
if (node.tagName != "H1" && node.tagName != "H2") {
return false;
}
var heading = this._getInnerText(node, false);
this.log("Evaluating similarity of header:", heading, this._articleTitle);
return this._textSimilarity(this._articleTitle, heading) > 0.75;
},
_flagIsActive: function(flag) {
return (this._flags & flag) > 0;
},
_removeFlag: function(flag) {
this._flags = this._flags & ~flag;
},
_isProbablyVisible: function(node) {
// Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.
return (!node.style || node.style.display != "none")
&& !node.hasAttribute("hidden")
//check for "fallback-image" so that wikimedia math images are displayed
&& (!node.hasAttribute("aria-hidden") || node.getAttribute("aria-hidden") != "true" || (node.className && node.className.indexOf && node.className.indexOf("fallback-image") !== -1));
},
/**
* Runs readability.
*
* Workflow:
* 1. Prep the document by removing script tags, css, etc.
* 2. Build readability's DOM tree.
* 3. Grab the article content from the current dom tree.
* 4. Replace the current DOM tree with the new one.
* 5. Read peacefully.
*
* @return void
**/
parse: function () {
// Avoid parsing too large documents, as per configuration option
if (this._maxElemsToParse > 0) {
var numTags = this._doc.getElementsByTagName("*").length;
if (numTags > this._maxElemsToParse) {
throw new Error("Aborting parsing document; " + numTags + " elements found");
}
}
// Unwrap image from noscript
this._unwrapNoscriptImages(this._doc);
// Extract JSON-LD metadata before removing scripts
var jsonLd = this._disableJSONLD ? {} : this._getJSONLD(this._doc);
// Remove script tags from the document.
this._removeScripts(this._doc);
this._prepDocument();
var metadata = this._getArticleMetadata(jsonLd);
this._articleTitle = metadata.title;
var articleContent = this._grabArticle();
if (!articleContent)
return null;
this.log("Grabbed: " + articleContent.innerHTML);
this._postProcessContent(articleContent);
// If we haven't found an excerpt in the article's metadata, use the article's
// first paragraph as the excerpt. This is used for displaying a preview of
// the article's content.
if (!metadata.excerpt) {
var paragraphs = articleContent.getElementsByTagName("p");
if (paragraphs.length > 0) {
metadata.excerpt = paragraphs[0].textContent.trim();
}
}
var textContent = articleContent.textContent;
return {
title: this._articleTitle,
byline: metadata.byline || this._articleByline,
dir: this._articleDir,
3 years ago
lang: this._articleLang,
content: this._serializer(articleContent),
textContent: textContent,
length: textContent.length,
excerpt: metadata.excerpt,
siteName: metadata.siteName || this._articleSiteName
};
}
};
{
module.exports = Readability;
}
}(Readability$1));
var ReadabilityReaderable = {exports: {}};
/* eslint-env es6:false */
(function (module) {
/*
* Copyright (c) 2010 Arc90 Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This code is heavily based on Arc90's readability.js (1.7.1) script
* available at: http://code.google.com/p/arc90labs-readability
*/
var REGEXPS = {
// NOTE: These two regular expressions are duplicated in
// Readability.js. Please keep both copies in sync.
unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,
okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,
};
function isNodeVisible(node) {
// Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.
return (!node.style || node.style.display != "none")
&& !node.hasAttribute("hidden")
//check for "fallback-image" so that wikimedia math images are displayed
&& (!node.hasAttribute("aria-hidden") || node.getAttribute("aria-hidden") != "true" || (node.className && node.className.indexOf && node.className.indexOf("fallback-image") !== -1));
}
/**
* Decides whether or not the document is reader-able without parsing the whole thing.
* @param {Object} options Configuration object.
* @param {number} [options.minContentLength=140] The minimum node content length used to decide if the document is readerable.
* @param {number} [options.minScore=20] The minumum cumulated 'score' used to determine if the document is readerable.
* @param {Function} [options.visibilityChecker=isNodeVisible] The function used to determine if a node is visible.
* @return {boolean} Whether or not we suspect Readability.parse() will suceeed at returning an article object.
*/
function isProbablyReaderable(doc, options = {}) {
// For backward compatibility reasons 'options' can either be a configuration object or the function used
// to determine if a node is visible.
if (typeof options == "function") {
options = { visibilityChecker: options };
}
var defaultOptions = { minScore: 20, minContentLength: 140, visibilityChecker: isNodeVisible };
options = Object.assign(defaultOptions, options);
3 years ago
var nodes = doc.querySelectorAll("p, pre, article");
// Get <div> nodes which have <br> node(s) and append them into the `nodes` variable.
// Some articles' DOM structures might look like
// <div>
// Sentences<br>
// <br>
// Sentences<br>
// </div>
var brNodes = doc.querySelectorAll("div > br");
if (brNodes.length) {
var set = new Set(nodes);
[].forEach.call(brNodes, function (node) {
set.add(node.parentNode);
});
nodes = Array.from(set);
}
var score = 0;
// This is a little cheeky, we use the accumulator 'score' to decide what to return from
// this callback:
return [].some.call(nodes, function (node) {
if (!options.visibilityChecker(node)) {
return false;
}
var matchString = node.className + " " + node.id;
if (REGEXPS.unlikelyCandidates.test(matchString) &&
!REGEXPS.okMaybeItsACandidate.test(matchString)) {
return false;
}
if (node.matches("li p")) {
return false;
}
var textContentLength = node.textContent.trim().length;
if (textContentLength < options.minContentLength) {
return false;
}
score += Math.sqrt(textContentLength - options.minContentLength);
if (score > options.minScore) {
return true;
}
return false;
});
}
{
module.exports = isProbablyReaderable;
}
}(ReadabilityReaderable));
var Readability = Readability$1.exports;
var isProbablyReaderable = ReadabilityReaderable.exports;
3 years ago
var readability = {
Readability: Readability,
isProbablyReaderable: isProbablyReaderable
};
var purify = {exports: {}};
/*! @license DOMPurify 2.3.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.6/LICENSE */
(function (module, exports) {
(function (global, factory) {
module.exports = factory() ;
}(commonjsGlobal, function () {
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var hasOwnProperty = Object.hasOwnProperty,
setPrototypeOf = Object.setPrototypeOf,
isFrozen = Object.isFrozen,
getPrototypeOf = Object.getPrototypeOf,
getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
var freeze = Object.freeze,
seal = Object.seal,
create = Object.create; // eslint-disable-line import/no-mutable-exports
var _ref = typeof Reflect !== 'undefined' && Reflect,
apply = _ref.apply,
construct = _ref.construct;
if (!apply) {
apply = function apply(fun, thisValue, args) {
return fun.apply(thisValue, args);
};
}
if (!freeze) {
freeze = function freeze(x) {
return x;
};
}
if (!seal) {
seal = function seal(x) {
return x;
};
}
if (!construct) {
construct = function construct(Func, args) {
return new (Function.prototype.bind.apply(Func, [null].concat(_toConsumableArray(args))))();
};
}
var arrayForEach = unapply(Array.prototype.forEach);
var arrayPop = unapply(Array.prototype.pop);
var arrayPush = unapply(Array.prototype.push);
var stringToLowerCase = unapply(String.prototype.toLowerCase);
var stringMatch = unapply(String.prototype.match);
var stringReplace = unapply(String.prototype.replace);
var stringIndexOf = unapply(String.prototype.indexOf);
var stringTrim = unapply(String.prototype.trim);
var regExpTest = unapply(RegExp.prototype.test);
var typeErrorCreate = unconstruct(TypeError);
function unapply(func) {
return function (thisArg) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return apply(func, thisArg, args);
};
}
function unconstruct(func) {
return function () {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return construct(func, args);
};
}
/* Add properties to a lookup table */
function addToSet(set, array) {
if (setPrototypeOf) {
// Make 'in' and truthy checks like Boolean(set.constructor)
// independent of any properties defined on Object.prototype.
// Prevent prototype setters from intercepting set as a this value.
setPrototypeOf(set, null);
}
var l = array.length;
while (l--) {
var element = array[l];
if (typeof element === 'string') {
var lcElement = stringToLowerCase(element);
if (lcElement !== element) {
// Config presets (e.g. tags.js, attrs.js) are immutable.
if (!isFrozen(array)) {
array[l] = lcElement;
}
element = lcElement;
}
}
3 years ago
set[element] = true;
}
3 years ago
return set;
}
3 years ago
/* Shallow clone an object */
function clone(object) {
var newObject = create(null);
3 years ago
var property = void 0;
for (property in object) {
if (apply(hasOwnProperty, object, [property])) {
newObject[property] = object[property];
}
}
3 years ago
return newObject;
}
3 years ago
/* IE10 doesn't support __lookupGetter__ so lets'
* simulate it. It also automatically checks
* if the prop is function or getter and behaves
* accordingly. */
function lookupGetter(object, prop) {
while (object !== null) {
var desc = getOwnPropertyDescriptor(object, prop);
if (desc) {
if (desc.get) {
return unapply(desc.get);
}
3 years ago
if (typeof desc.value === 'function') {
return unapply(desc.value);
}
}
3 years ago
object = getPrototypeOf(object);
}
3 years ago
function fallbackValue(element) {
console.warn('fallback value for', element);
return null;
}
3 years ago
return fallbackValue;
}
3 years ago
var html = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
3 years ago
// SVG
var svg = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
3 years ago
var svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
3 years ago
// List of SVG elements that are disallowed by default.
// We still need to know them so that we can do namespace
// checks properly in case one wants to add them to
// allow-list.
var svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'fedropshadow', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
3 years ago
var mathMl = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover']);
3 years ago
// Similarly to SVG, we want to know all MathML elements,
// even those that we disallow by default.
var mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
3 years ago
var text = freeze(['#text']);
3 years ago
var html$1 = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
3 years ago
var svg$1 = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
3 years ago
var mathMl$1 = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
3 years ago
var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
3 years ago
// eslint-disable-next-line unicorn/better-regex
var MUSTACHE_EXPR = seal(/\{\{[\s\S]*|[\s\S]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
var ERB_EXPR = seal(/<%[\s\S]*|[\s\S]*%>/gm);
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
var ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
);
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
);
var DOCTYPE_NAME = seal(/^html$/i);
3 years ago
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
3 years ago
function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
3 years ago
var getGlobal = function getGlobal() {
return typeof window === 'undefined' ? null : window;
};
3 years ago
/**
* Creates a no-op policy for internal use only.
* Don't export this function outside this module!
* @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
* @param {Document} document The document object (to determine policy name suffix)
* @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
* are not supported).
*/
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
if ((typeof trustedTypes === 'undefined' ? 'undefined' : _typeof(trustedTypes)) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
return null;
}
3 years ago
// Allow the callers to control the unique policy name
// by adding a data-tt-policy-suffix to the script element with the DOMPurify.
// Policy creation with duplicate names throws in Trusted Types.
var suffix = null;
var ATTR_NAME = 'data-tt-policy-suffix';
if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
suffix = document.currentScript.getAttribute(ATTR_NAME);
}
3 years ago
var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
3 years ago
try {
return trustedTypes.createPolicy(policyName, {
createHTML: function createHTML(html$$1) {
return html$$1;
}
});
} catch (_) {
// Policy creation failed (most likely another DOMPurify script has
// already run). Skip creating the policy, as this will only cause errors
// if TT are enforced.
console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
return null;
}
3 years ago
};
3 years ago
function createDOMPurify() {
var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
3 years ago
var DOMPurify = function DOMPurify(root) {
return createDOMPurify(root);
};
3 years ago
/**
* Version label, exposed for easier checks
* if DOMPurify is up to date or not
*/
DOMPurify.version = '2.3.6';
3 years ago
/**
* Array of elements that DOMPurify removed during sanitation.
* Empty if nothing was removed.
*/
DOMPurify.removed = [];
3 years ago
if (!window || !window.document || window.document.nodeType !== 9) {
// Not running in a browser, provide a factory function
// so that you can pass your own Window
DOMPurify.isSupported = false;
3 years ago
return DOMPurify;
}
var originalDocument = window.document;
var document = window.document;
var DocumentFragment = window.DocumentFragment,
HTMLTemplateElement = window.HTMLTemplateElement,
Node = window.Node,
Element = window.Element,
NodeFilter = window.NodeFilter,
_window$NamedNodeMap = window.NamedNodeMap,
NamedNodeMap = _window$NamedNodeMap === undefined ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
HTMLFormElement = window.HTMLFormElement,
DOMParser = window.DOMParser,
trustedTypes = window.trustedTypes;
var ElementPrototype = Element.prototype;
var cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
var getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
var getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
var getParentNode = lookupGetter(ElementPrototype, 'parentNode');
// As per issue #47, the web-components registry is inherited by a
// new document created via createHTMLDocument. As per the spec
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
// a new empty registry is used when creating a template contents owner
// document, so we use that as our parent document to ensure nothing
// is inherited.
if (typeof HTMLTemplateElement === 'function') {
var template = document.createElement('template');
if (template.content && template.content.ownerDocument) {
document = template.content.ownerDocument;
}
}
3 years ago
var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
3 years ago
var _document = document,
implementation = _document.implementation,
createNodeIterator = _document.createNodeIterator,
createDocumentFragment = _document.createDocumentFragment,
getElementsByTagName = _document.getElementsByTagName;
var importNode = originalDocument.importNode;
3 years ago
var documentMode = {};
try {
documentMode = clone(document).documentMode ? document.documentMode : {};
} catch (_) {}
var hooks = {};
/**
* Expose whether this browser supports running the full DOMPurify.
*/
DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
var MUSTACHE_EXPR$$1 = MUSTACHE_EXPR,
ERB_EXPR$$1 = ERB_EXPR,
DATA_ATTR$$1 = DATA_ATTR,
ARIA_ATTR$$1 = ARIA_ATTR,
IS_SCRIPT_OR_DATA$$1 = IS_SCRIPT_OR_DATA,
ATTR_WHITESPACE$$1 = ATTR_WHITESPACE;
var IS_ALLOWED_URI$$1 = IS_ALLOWED_URI;
/**
* We consider the elements and attributes below to be safe. Ideally
* don't add any new ones but feel free to remove unwanted ones.
*/
/* allowed element names */
var ALLOWED_TAGS = null;
var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(html), _toConsumableArray$1(svg), _toConsumableArray$1(svgFilters), _toConsumableArray$1(mathMl), _toConsumableArray$1(text)));
/* Allowed attribute names */
var ALLOWED_ATTR = null;
var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray$1(html$1), _toConsumableArray$1(svg$1), _toConsumableArray$1(mathMl$1), _toConsumableArray$1(xml)));
/*
* Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
* @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
* @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
* @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
*/
var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
tagNameCheck: {
writable: true,
configurable: false,
enumerable: true,
value: null
},
attributeNameCheck: {
writable: true,
configurable: false,
enumerable: true,
value: null
},
allowCustomizedBuiltInElements: {
writable: true,
configurable: false,
enumerable: true,
value: false
}
}));
3 years ago
/* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
var FORBID_TAGS = null;
3 years ago
/* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
var FORBID_ATTR = null;
3 years ago
/* Decide if ARIA attributes are okay */
var ALLOW_ARIA_ATTR = true;
3 years ago
/* Decide if custom data attributes are okay */
var ALLOW_DATA_ATTR = true;
3 years ago
/* Decide if unknown protocols are okay */
var ALLOW_UNKNOWN_PROTOCOLS = false;
/* Output should be safe for common template engines.
* This means, DOMPurify removes data attributes, mustaches and ERB
*/
var SAFE_FOR_TEMPLATES = false;
/* Decide if document with <html>... should be returned */
var WHOLE_DOCUMENT = false;
/* Track whether config is already set on this instance of DOMPurify. */
var SET_CONFIG = false;
/* Decide if all elements (e.g. style, script) must be children of
* document.body. By default, browsers might move them to document.head */
var FORCE_BODY = false;
3 years ago
/* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
* string (or a TrustedHTML object if Trusted Types are supported).
* If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
*/
var RETURN_DOM = false;
3 years ago
/* Decide if a DOM `DocumentFragment` should be returned, instead of a html
* string (or a TrustedHTML object if Trusted Types are supported) */
var RETURN_DOM_FRAGMENT = false;
3 years ago
/* Try to return a Trusted Type object instead of a string, return a string in
* case Trusted Types are not supported */
var RETURN_TRUSTED_TYPE = false;
3 years ago
/* Output should be free from DOM clobbering attacks? */
var SANITIZE_DOM = true;
3 years ago
/* Keep element content when removing element? */
var KEEP_CONTENT = true;
3 years ago
/* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
* of importing it into a new Document and returning a sanitized copy */
var IN_PLACE = false;
3 years ago
/* Allow usage of profiles like html, svg and mathMl */
var USE_PROFILES = {};
3 years ago
/* Tags to ignore content of when KEEP_CONTENT is true */
var FORBID_CONTENTS = null;
var DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
3 years ago
/* Tags that are safe for data: URIs */
var DATA_URI_TAGS = null;
var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
3 years ago
/* Attributes safe for values like "javascript:" */
var URI_SAFE_ATTRIBUTES = null;
var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
3 years ago
var MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
/* Document namespace */
var NAMESPACE = HTML_NAMESPACE;
var IS_EMPTY_INPUT = false;
3 years ago
/* Parsing of strict XHTML documents */
var PARSER_MEDIA_TYPE = void 0;
var SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
var DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
var transformCaseFunc = void 0;
3 years ago
/* Keep a reference to config to pass to hooks */
var CONFIG = null;
3 years ago
/* Ideally, do not touch anything below this line */
/* ______________________________________________ */
3 years ago
var formElement = document.createElement('form');
3 years ago
var isRegexOrFunction = function isRegexOrFunction(testValue) {
return testValue instanceof RegExp || testValue instanceof Function;
};
3 years ago
/**
* _parseConfig
*
* @param {Object} cfg optional config literal
*/
// eslint-disable-next-line complexity
var _parseConfig = function _parseConfig(cfg) {
if (CONFIG && CONFIG === cfg) {
return;
}
3 years ago
/* Shield configuration object from tampering */
if (!cfg || (typeof cfg === 'undefined' ? 'undefined' : _typeof(cfg)) !== 'object') {
cfg = {};
}
3 years ago
/* Shield configuration object from prototype pollution */
cfg = clone(cfg);
/* Set configuration parameters */
ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS) : DEFAULT_FORBID_CONTENTS;
FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
RETURN_DOM = cfg.RETURN_DOM || false; // Default false
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
FORCE_BODY = cfg.FORCE_BODY || false; // Default false
SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
IN_PLACE = cfg.IN_PLACE || false; // Default false
IS_ALLOWED_URI$$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$$1;
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
}
3 years ago
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
}
3 years ago
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
}
3 years ago
PARSER_MEDIA_TYPE =
// eslint-disable-next-line unicorn/prefer-includes
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE;
3 years ago
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
return x;
} : stringToLowerCase;
3 years ago
if (SAFE_FOR_TEMPLATES) {
ALLOW_DATA_ATTR = false;
}
3 years ago
if (RETURN_DOM_FRAGMENT) {
RETURN_DOM = true;
}
3 years ago
/* Parse profile info */
if (USE_PROFILES) {
ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(text)));
ALLOWED_ATTR = [];
if (USE_PROFILES.html === true) {
addToSet(ALLOWED_TAGS, html);
addToSet(ALLOWED_ATTR, html$1);
}
3 years ago
if (USE_PROFILES.svg === true) {
addToSet(ALLOWED_TAGS, svg);
addToSet(ALLOWED_ATTR, svg$1);
addToSet(ALLOWED_ATTR, xml);
}
3 years ago
if (USE_PROFILES.svgFilters === true) {
addToSet(ALLOWED_TAGS, svgFilters);
addToSet(ALLOWED_ATTR, svg$1);
addToSet(ALLOWED_ATTR, xml);
}
3 years ago
if (USE_PROFILES.mathMl === true) {
addToSet(ALLOWED_TAGS, mathMl);
addToSet(ALLOWED_ATTR, mathMl$1);
addToSet(ALLOWED_ATTR, xml);
}
}
3 years ago
/* Merge configuration parameters */
if (cfg.ADD_TAGS) {
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
ALLOWED_TAGS = clone(ALLOWED_TAGS);
}
3 years ago
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
}
3 years ago
if (cfg.ADD_ATTR) {
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
ALLOWED_ATTR = clone(ALLOWED_ATTR);
}
3 years ago
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
}
3 years ago
if (cfg.ADD_URI_SAFE_ATTR) {
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
}
3 years ago
if (cfg.FORBID_CONTENTS) {
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
FORBID_CONTENTS = clone(FORBID_CONTENTS);
}
3 years ago
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS);
}
3 years ago
/* Add #text in case KEEP_CONTENT is set to true */
if (KEEP_CONTENT) {
ALLOWED_TAGS['#text'] = true;
}
3 years ago
/* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
if (WHOLE_DOCUMENT) {
addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
}
3 years ago
/* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
if (ALLOWED_TAGS.table) {
addToSet(ALLOWED_TAGS, ['tbody']);
delete FORBID_TAGS.tbody;
}
3 years ago
// Prevent further manipulation of configuration.
// Not available in IE8, Safari 5, etc.
if (freeze) {
freeze(cfg);
}
CONFIG = cfg;
};
var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
/* Keep track of all possible SVG and MathML tags
* so that we can perform the namespace checks
* correctly. */
var ALL_SVG_TAGS = addToSet({}, svg);
addToSet(ALL_SVG_TAGS, svgFilters);
addToSet(ALL_SVG_TAGS, svgDisallowed);
var ALL_MATHML_TAGS = addToSet({}, mathMl);
addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
/**
*
*
* @param {Element} element a DOM element whose namespace is being checked
* @returns {boolean} Return false if the element has a
* namespace that a spec-compliant parser would never
* return. Return true otherwise.
*/
var _checkValidNamespace = function _checkValidNamespace(element) {
var parent = getParentNode(element);
// In JSDOM, if we're inside shadow DOM, then parentNode
// can be null. We just simulate parent in this case.
if (!parent || !parent.tagName) {
parent = {
namespaceURI: HTML_NAMESPACE,
tagName: 'template'
};
}
var tagName = stringToLowerCase(element.tagName);
var parentTagName = stringToLowerCase(parent.tagName);
if (element.namespaceURI === SVG_NAMESPACE) {
// The only way to switch from HTML namespace to SVG
// is via <svg>. If it happens via any other tag, then
// it should be killed.
if (parent.namespaceURI === HTML_NAMESPACE) {
return tagName === 'svg';
}
3 years ago
// The only way to switch from MathML to SVG is via
// svg if parent is either <annotation-xml> or MathML
// text integration points.
if (parent.namespaceURI === MATHML_NAMESPACE) {
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
}
// We only allow elements that are defined in SVG
// spec. All others are disallowed in SVG namespace.
return Boolean(ALL_SVG_TAGS[tagName]);
}
3 years ago
if (element.namespaceURI === MATHML_NAMESPACE) {
// The only way to switch from HTML namespace to MathML
// is via <math>. If it happens via any other tag, then
// it should be killed.
if (parent.namespaceURI === HTML_NAMESPACE) {
return tagName === 'math';
}
// The only way to switch from SVG to MathML is via
// <math> and HTML integration points
if (parent.namespaceURI === SVG_NAMESPACE) {
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
}
// We only allow elements that are defined in MathML
// spec. All others are disallowed in MathML namespace.
return Boolean(ALL_MATHML_TAGS[tagName]);
}
if (element.namespaceURI === HTML_NAMESPACE) {
// The only way to switch from SVG to HTML is via
// HTML integration points, and from MathML to HTML
// is via MathML text integration points
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
return false;
}
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
return false;
}
// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erronously deleted from
// HTML namespace.
var commonSvgAndHTMLElements = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
// We disallow tags that are specific for MathML
// or SVG and should never appear in HTML namespace
return !ALL_MATHML_TAGS[tagName] && (commonSvgAndHTMLElements[tagName] || !ALL_SVG_TAGS[tagName]);
}
// The code should never reach this place (this means
// that the element somehow got namespace that is not
// HTML, SVG or MathML). Return false just in case.
return false;
};
/**
* _forceRemove
*
* @param {Node} node a DOM node
*/
var _forceRemove = function _forceRemove(node) {
arrayPush(DOMPurify.removed, { element: node });
try {
// eslint-disable-next-line unicorn/prefer-dom-node-remove
node.parentNode.removeChild(node);
} catch (_) {
try {
node.outerHTML = emptyHTML;
} catch (_) {
node.remove();
}
}
};
/**
* _removeAttribute
*
* @param {String} name an Attribute name
* @param {Node} node a DOM node
*/
var _removeAttribute = function _removeAttribute(name, node) {
try {
arrayPush(DOMPurify.removed, {
attribute: node.getAttributeNode(name),
from: node
});
} catch (_) {
arrayPush(DOMPurify.removed, {
attribute: null,
from: node
});
}
node.removeAttribute(name);
3 years ago
// We void attribute values for unremovable "is"" attributes
if (name === 'is' && !ALLOWED_ATTR[name]) {
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
try {
_forceRemove(node);
} catch (_) {}
} else {
try {
node.setAttribute(name, '');
} catch (_) {}
}
}
};
3 years ago
/**
* _initDocument
*
* @param {String} dirty a string of dirty markup
* @return {Document} a DOM, filled with the dirty markup
*/
var _initDocument = function _initDocument(dirty) {
/* Create a HTML document */
var doc = void 0;
var leadingWhitespace = void 0;
if (FORCE_BODY) {
dirty = '<remove></remove>' + dirty;
} else {
/* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
var matches = stringMatch(dirty, /^[\r\n\t ]+/);
leadingWhitespace = matches && matches[0];
}
3 years ago
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
}
3 years ago
var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
/*
* Use the DOMParser API by default, fallback later if needs be
* DOMParser not work for svg when has multiple root element.
*/
if (NAMESPACE === HTML_NAMESPACE) {
try {
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
} catch (_) {}
}
3 years ago
/* Use createHTMLDocument in case DOMParser is not available */
if (!doc || !doc.documentElement) {
doc = implementation.createDocument(NAMESPACE, 'template', null);
try {
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? '' : dirtyPayload;
} catch (_) {
// Syntax error if dirtyPayload is invalid xml
}
}
3 years ago
var body = doc.body || doc.documentElement;
3 years ago
if (dirty && leadingWhitespace) {
body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
}
3 years ago
/* Work on whole document or just its body */
if (NAMESPACE === HTML_NAMESPACE) {
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
}
3 years ago
return WHOLE_DOCUMENT ? doc.documentElement : body;
};
3 years ago
/**
* _createIterator
*
* @param {Document} root document/fragment to create iterator for
* @return {Iterator} iterator instance
*/
var _createIterator = function _createIterator(root) {
return createNodeIterator.call(root.ownerDocument || root, root,
// eslint-disable-next-line no-bitwise
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
};
3 years ago
/**
* _isClobbered
*
* @param {Node} elm element to check for clobbering attacks
* @return {Boolean} true if clobbered, false if safe
*/
var _isClobbered = function _isClobbered(elm) {
return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function');
};
3 years ago
/**
* _isNode
*
* @param {Node} obj object to check whether it's a DOM node
* @return {Boolean} true is object is a DOM node
*/
var _isNode = function _isNode(object) {
return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? object instanceof Node : object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
};
3 years ago
/**
* _executeHook
* Execute user configurable hooks
*
* @param {String} entryPoint Name of the hook's entry point
* @param {Node} currentNode node to work on with the hook
* @param {Object} data additional hook parameters
*/
var _executeHook = function _executeHook(entryPoint, currentNode, data) {
if (!hooks[entryPoint]) {
return;
}
3 years ago
arrayForEach(hooks[entryPoint], function (hook) {
hook.call(DOMPurify, currentNode, data, CONFIG);
});
};
3 years ago
/**
* _sanitizeElements
*
* @protect nodeName
* @protect textContent
* @protect removeChild
*
* @param {Node} currentNode to check for permission to exist
* @return {Boolean} true if node was killed, false if left alive
*/
var _sanitizeElements = function _sanitizeElements(currentNode) {
var content = void 0;
/* Execute a hook if present */
_executeHook('beforeSanitizeElements', currentNode, null);
/* Check if element is clobbered or can clobber */
if (_isClobbered(currentNode)) {
_forceRemove(currentNode);
return true;
}
3 years ago
/* Check if tagname contains Unicode */
if (stringMatch(currentNode.nodeName, /[\u0080-\uFFFF]/)) {
_forceRemove(currentNode);
return true;
}
3 years ago
/* Now let's check the element's type and name */
var tagName = transformCaseFunc(currentNode.nodeName);
3 years ago
/* Execute a hook if present */
_executeHook('uponSanitizeElement', currentNode, {
tagName: tagName,
allowedTags: ALLOWED_TAGS
});
3 years ago
/* Detect mXSS attempts abusing namespace confusion */
if (!_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
_forceRemove(currentNode);
return true;
}
3 years ago
/* Mitigate a problem with templates inside select */
if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
_forceRemove(currentNode);
return true;
}
3 years ago
/* Remove element if anything forbids its presence */
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
/* Check if we have a custom element to handle */
if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
}
3 years ago
/* Keep content except for bad-listed elements */
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
var parentNode = getParentNode(currentNode) || currentNode.parentNode;
var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
3 years ago
if (childNodes && parentNode) {
var childCount = childNodes.length;
3 years ago
for (var i = childCount - 1; i >= 0; --i) {
parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
}
}
}
3 years ago
_forceRemove(currentNode);
return true;
}
3 years ago
/* Check whether element has a valid namespace */
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
_forceRemove(currentNode);
return true;
}
3 years ago
if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
_forceRemove(currentNode);
return true;
}
3 years ago
/* Sanitize element content to be template-safe */
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
/* Get the element's text content */
content = currentNode.textContent;
content = stringReplace(content, MUSTACHE_EXPR$$1, ' ');
content = stringReplace(content, ERB_EXPR$$1, ' ');
if (currentNode.textContent !== content) {
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
currentNode.textContent = content;
}
}
3 years ago
/* Execute a hook if present */
_executeHook('afterSanitizeElements', currentNode, null);
3 years ago
return false;
};
3 years ago
/**
* _isValidAttribute
*
* @param {string} lcTag Lowercase tag name of containing element.
* @param {string} lcName Lowercase attribute name.
* @param {string} value Attribute value.
* @return {Boolean} Returns true if `value` is valid, otherwise false.
*/
// eslint-disable-next-line complexity
var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
/* Make sure attribute cannot clobber */
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
return false;
}
3 years ago
/* Allow valid data-* attributes: At least one character after "-"
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
We don't need to check the value; it's always URI safe. */
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$$1, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
if (
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
_basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||
// Alternative, second condition checks if it's an `is`-attribute, AND
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
return false;
}
/* Check value is safe. First, is attr inert? If so, is safe */
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$$1, stringReplace(value, ATTR_WHITESPACE$$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$$1, stringReplace(value, ATTR_WHITESPACE$$1, ''))) ; else if (!value) ; else {
return false;
}
3 years ago
return true;
};
/**
* _basicCustomElementCheck
* checks if at least one dash is included in tagName, and it's not the first char
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
* @param {string} tagName name of the tag of the node to sanitize
*/
var _basicCustomElementTest = function _basicCustomElementTest(tagName) {
return tagName.indexOf('-') > 0;
};
3 years ago
/**
* _sanitizeAttributes
*
* @protect attributes
* @protect nodeName
* @protect removeAttribute
* @protect setAttribute
*
* @param {Node} currentNode to sanitize
*/
var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
var attr = void 0;
var value = void 0;
var lcName = void 0;
var l = void 0;
/* Execute a hook if present */
_executeHook('beforeSanitizeAttributes', currentNode, null);
var attributes = currentNode.attributes;
/* Check if we have attributes; if not we might have a text node */
if (!attributes) {
return;
}
3 years ago
var hookEvent = {
attrName: '',
attrValue: '',
keepAttr: true,
allowedAttributes: ALLOWED_ATTR
};
l = attributes.length;
/* Go backwards over all attributes; safely remove bad ones */
while (l--) {
attr = attributes[l];
var _attr = attr,
name = _attr.name,
namespaceURI = _attr.namespaceURI;
value = stringTrim(attr.value);
lcName = transformCaseFunc(name);
/* Execute a hook if present */
hookEvent.attrName = lcName;
hookEvent.attrValue = value;
hookEvent.keepAttr = true;
hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
_executeHook('uponSanitizeAttribute', currentNode, hookEvent);
value = hookEvent.attrValue;
/* Did the hooks approve of the attribute? */
if (hookEvent.forceKeepAttr) {
continue;
}
3 years ago
/* Remove attribute */
_removeAttribute(name, currentNode);
3 years ago
/* Did the hooks approve of the attribute? */
if (!hookEvent.keepAttr) {
continue;
}
3 years ago
/* Work around a security issue in jQuery 3.0 */
if (regExpTest(/\/>/i, value)) {
_removeAttribute(name, currentNode);
continue;
}
3 years ago
/* Sanitize attribute content to be template-safe */
if (SAFE_FOR_TEMPLATES) {
value = stringReplace(value, MUSTACHE_EXPR$$1, ' ');
value = stringReplace(value, ERB_EXPR$$1, ' ');
}
3 years ago
/* Is `value` valid for this attribute? */
var lcTag = transformCaseFunc(currentNode.nodeName);
if (!_isValidAttribute(lcTag, lcName, value)) {
continue;
}
3 years ago
/* Handle invalid data-* attribute set by try-catching it */
try {
if (namespaceURI) {
currentNode.setAttributeNS(namespaceURI, name, value);
} else {
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
currentNode.setAttribute(name, value);
}
3 years ago
arrayPop(DOMPurify.removed);
} catch (_) {}
}
3 years ago
/* Execute a hook if present */
_executeHook('afterSanitizeAttributes', currentNode, null);
};
3 years ago
/**
* _sanitizeShadowDOM
*
* @param {DocumentFragment} fragment to iterate over recursively
*/
var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
var shadowNode = void 0;
var shadowIterator = _createIterator(fragment);
3 years ago
/* Execute a hook if present */
_executeHook('beforeSanitizeShadowDOM', fragment, null);
3 years ago
while (shadowNode = shadowIterator.nextNode()) {
/* Execute a hook if present */
_executeHook('uponSanitizeShadowNode', shadowNode, null);
3 years ago
/* Sanitize tags and elements */
if (_sanitizeElements(shadowNode)) {
continue;
}
3 years ago
/* Deep shadow DOM detected */
if (shadowNode.content instanceof DocumentFragment) {
_sanitizeShadowDOM(shadowNode.content);
}
3 years ago
/* Check attributes, sanitize if necessary */
_sanitizeAttributes(shadowNode);
}
3 years ago
/* Execute a hook if present */
_executeHook('afterSanitizeShadowDOM', fragment, null);
};
3 years ago
/**
* Sanitize
* Public method providing core sanitation functionality
*
* @param {String|Node} dirty string or DOM node
* @param {Object} configuration object
*/
// eslint-disable-next-line complexity
DOMPurify.sanitize = function (dirty, cfg) {
var body = void 0;
var importedNode = void 0;
var currentNode = void 0;
var oldNode = void 0;
var returnNode = void 0;
/* Make sure we have a string to sanitize.
DO NOT return early, as this will return the wrong type if
the user has requested a DOM object rather than a string */
IS_EMPTY_INPUT = !dirty;
if (IS_EMPTY_INPUT) {
dirty = '<!-->';
}
3 years ago
/* Stringify, in case dirty is an object */
if (typeof dirty !== 'string' && !_isNode(dirty)) {
// eslint-disable-next-line no-negated-condition
if (typeof dirty.toString !== 'function') {
throw typeErrorCreate('toString is not a function');
} else {
dirty = dirty.toString();
if (typeof dirty !== 'string') {
throw typeErrorCreate('dirty is not a string, aborting');
}
}
}
3 years ago
/* Check we can run. Otherwise fall back or ignore */
if (!DOMPurify.isSupported) {
if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
if (typeof dirty === 'string') {
return window.toStaticHTML(dirty);
}
3 years ago
if (_isNode(dirty)) {
return window.toStaticHTML(dirty.outerHTML);
}
}
3 years ago
return dirty;
}
3 years ago
/* Assign config vars */
if (!SET_CONFIG) {
_parseConfig(cfg);
}
3 years ago
/* Clean up removed elements */
DOMPurify.removed = [];
3 years ago
/* Check if dirty is correctly typed for IN_PLACE */
if (typeof dirty === 'string') {
IN_PLACE = false;
}
3 years ago
if (IN_PLACE) {
/* Do some early pre-sanitization to avoid unsafe root nodes */
if (dirty.nodeName) {
var tagName = transformCaseFunc(dirty.nodeName);
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
}
}
} else if (dirty instanceof Node) {
/* If dirty is a DOM element, append to an empty document to avoid
elements being stripped by the parser */
body = _initDocument('<!---->');
importedNode = body.ownerDocument.importNode(dirty, true);
if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
/* Node is already a body, use as is */
body = importedNode;
} else if (importedNode.nodeName === 'HTML') {
body = importedNode;
} else {
// eslint-disable-next-line unicorn/prefer-dom-node-append
body.appendChild(importedNode);
}
} else {
/* Exit directly if we have nothing to do */
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
// eslint-disable-next-line unicorn/prefer-includes
dirty.indexOf('<') === -1) {
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
}
3 years ago
/* Initialize the document to work on */
body = _initDocument(dirty);
3 years ago
/* Check we have a DOM node from the data */
if (!body) {
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
}
}
3 years ago
/* Remove first element node (ours) if FORCE_BODY is set */
if (body && FORCE_BODY) {
_forceRemove(body.firstChild);
}
3 years ago
/* Get node iterator */
var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
3 years ago
/* Now start iterating over the created document */
while (currentNode = nodeIterator.nextNode()) {
/* Fix IE's strange behavior with manipulated textNodes #89 */
if (currentNode.nodeType === 3 && currentNode === oldNode) {
continue;
}
3 years ago
/* Sanitize tags and elements */
if (_sanitizeElements(currentNode)) {
continue;
}
3 years ago
/* Shadow DOM detected, sanitize it */
if (currentNode.content instanceof DocumentFragment) {
_sanitizeShadowDOM(currentNode.content);
}
/* Check attributes, sanitize if necessary */
_sanitizeAttributes(currentNode);
3 years ago
oldNode = currentNode;
}
3 years ago
oldNode = null;
3 years ago
/* If we sanitized `dirty` in-place, return it. */
if (IN_PLACE) {
return dirty;
}
3 years ago
/* Return sanitized string or DOM */
if (RETURN_DOM) {
if (RETURN_DOM_FRAGMENT) {
returnNode = createDocumentFragment.call(body.ownerDocument);
3 years ago
while (body.firstChild) {
// eslint-disable-next-line unicorn/prefer-dom-node-append
returnNode.appendChild(body.firstChild);
}
} else {
returnNode = body;
}
3 years ago
if (ALLOWED_ATTR.shadowroot) {
/*
AdoptNode() is not used because internal state is not reset
(e.g. the past names map of a HTMLFormElement), this is safe
in theory but we would rather not risk another attack vector.
The state that is cloned by importNode() is explicitly defined
by the specs.
*/
returnNode = importNode.call(originalDocument, returnNode, true);
}
3 years ago
return returnNode;
}
3 years ago
var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
/* Serialize doctype if allowed */
if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
}
3 years ago
/* Sanitize final string template-safe */
if (SAFE_FOR_TEMPLATES) {
serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$$1, ' ');
serializedHTML = stringReplace(serializedHTML, ERB_EXPR$$1, ' ');
}
3 years ago
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
};
3 years ago
/**
* Public method to set the configuration once
* setConfig
*
* @param {Object} cfg configuration object
*/
DOMPurify.setConfig = function (cfg) {
_parseConfig(cfg);
SET_CONFIG = true;
};
3 years ago
/**
* Public method to remove the configuration
* clearConfig
*
*/
DOMPurify.clearConfig = function () {
CONFIG = null;
SET_CONFIG = false;
};
3 years ago
/**
* Public method to check if an attribute value is valid.
* Uses last set config, if any. Otherwise, uses config defaults.
* isValidAttribute
*
* @param {string} tag Tag name of containing element.
* @param {string} attr Attribute name.
* @param {string} value Attribute value.
* @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
*/
DOMPurify.isValidAttribute = function (tag, attr, value) {
/* Initialize shared config vars if necessary. */
if (!CONFIG) {
_parseConfig({});
}
3 years ago
var lcTag = transformCaseFunc(tag);
var lcName = transformCaseFunc(attr);
return _isValidAttribute(lcTag, lcName, value);
};
3 years ago
/**
* AddHook
* Public method to add DOMPurify hooks
*
* @param {String} entryPoint entry point for the hook to add
* @param {Function} hookFunction function to execute
*/
DOMPurify.addHook = function (entryPoint, hookFunction) {
if (typeof hookFunction !== 'function') {
return;
}
3 years ago
hooks[entryPoint] = hooks[entryPoint] || [];
arrayPush(hooks[entryPoint], hookFunction);
};
/**
* RemoveHook
* Public method to remove a DOMPurify hook at a given entryPoint
* (pops it from the stack of hooks if more are present)
*
* @param {String} entryPoint entry point for the hook to remove
*/
DOMPurify.removeHook = function (entryPoint) {
if (hooks[entryPoint]) {
arrayPop(hooks[entryPoint]);
}
};
/**
* RemoveHooks
* Public method to remove all DOMPurify hooks at a given entryPoint
*
* @param {String} entryPoint entry point for the hooks to remove
*/
DOMPurify.removeHooks = function (entryPoint) {
if (hooks[entryPoint]) {
hooks[entryPoint] = [];
}
};
/**
* RemoveAllHooks
* Public method to remove all DOMPurify hooks
*
*/
DOMPurify.removeAllHooks = function () {
hooks = {};
};
return DOMPurify;
}
3 years ago
var purify = createDOMPurify();
3 years ago
return purify;
3 years ago
}));
3 years ago
}(purify));
var browser = window.DOMPurify || (window.DOMPurify = purify.exports.default || purify.exports);
class WebsiteParser extends Parser {
3 years ago
constructor(app, settings) {
super(app, settings);
}
test(url) {
return this.isValidUrl(url);
}
prepareNote(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield obsidian.request({ method: 'GET', url });
3 years ago
const document = new DOMParser().parseFromString(response, 'text/html');
// Set base to allow Readability to resolve relative path's
3 years ago
const baseEl = document.createElement('base');
baseEl.setAttribute('href', getBaseUrl(url));
3 years ago
document.head.append(baseEl);
const cleanDocumentBody = browser.sanitize(document.body.innerHTML);
document.body.innerHTML = cleanDocumentBody;
if (!readability.isProbablyReaderable(document)) {
new obsidian.Notice('@mozilla/readability considers this document to unlikely be readerable.');
}
const readableDocument = new readability.Readability(document).parse();
return (readableDocument === null || readableDocument === void 0 ? void 0 : readableDocument.content)
? yield this.parsableArticle(this.app, readableDocument, url)
: this.notParsableArticle(url);
});
}
3 years ago
parsableArticle(app, article, url) {
return __awaiter(this, void 0, void 0, function* () {
const title = article.title || 'No title';
let content = yield parseHtmlContent(article.content);
if (this.settings.downloadImages) {
content = yield replaceImages(app, content, this.settings.assetsDir);
}
const processedContent = this.settings.parsableArticleNote
.replace(/%articleTitle%/g, title)
.replace(/%articleURL%/g, url)
.replace(/%articleContent%/g, content);
const fileNameTemplate = this.settings.parseableArticleNoteTitle
.replace(/%title%/g, title);
const fileName = `${fileNameTemplate}.md`;
return new Note(fileName, processedContent);
});
}
notParsableArticle(url) {
console.error('Website not parseable');
const content = this.settings.notParsableArticleNote.replace('%articleURL%', url);
3 years ago
const fileNameTemplate = this.settings.notParsableArticleNote
.replace(/%date%/g, this.getFormattedDateForFilename());
const fileName = `${fileNameTemplate}.md`;
return new Note(fileName, content);
}
}
class TextSnippetParser extends Parser {
3 years ago
constructor(app, settings) {
super(app, settings);
}
test() {
return true;
}
prepareNote(text) {
return __awaiter(this, void 0, void 0, function* () {
3 years ago
const fileName = `${this.getFormattedDateForFilename()}.md`;
const content = this.settings.textSnippetNote.replace(/%content%/g, text);
return new Note(fileName, content);
});
}
}
3 years ago
class ReadItLaterSettingsTab extends obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: 'Settings for the ReadItLater plugin.' });
new obsidian.Setting(containerEl)
.setName('Inbox dir')
.setDesc('Enter valid folder name. For nested folders use this format: Folder A/Folder B. If no folder is enetred, new note will be created in vault root.')
.addText((text) => text
.setPlaceholder('Defaults to root')
.setValue(this.plugin.settings.inboxDir || DEFAULT_SETTINGS.inboxDir)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.inboxDir = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Open new note')
.setDesc('If enabled, new note will open in current workspace')
.addToggle((toggle) => toggle
.setValue(this.plugin.settings.openNewNote || DEFAULT_SETTINGS.openNewNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.openNewNote = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Download images')
.setDesc('If this is true, the used images are downloaded to the defined folder')
.addToggle((toggle) => toggle
.setValue(this.plugin.settings.downloadImages || DEFAULT_SETTINGS.downloadImages)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.downloadImages = value;
assetDirSetting.setDisabled(!value);
yield this.plugin.saveSettings();
})));
const assetDirSetting = new obsidian.Setting(containerEl)
.setName('Assets dir')
.setDesc('Enter valid folder name. For nested folders use this format: Folder A/Folder B. If no folder is enetred, new note will be created in vault root.')
.addText((text) => text
.setPlaceholder('Defaults to root')
.setValue(this.plugin.settings.assetsDir || DEFAULT_SETTINGS.inboxDir + '/assets')
.setDisabled(!this.plugin.settings.downloadImages)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.assetsDir = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Youtube note template title')
.setDesc('Available variables: %title%')
.addText((text) => text
.setPlaceholder('Defaults to %title%')
.setValue(this.plugin.settings.youtubeNoteTitle || DEFAULT_SETTINGS.youtubeNoteTitle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.youtubeNoteTitle = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Youtube note template')
.setDesc('Available variables: %videoTitle%, %videoURL%, %videoId%, %videoPlayer%')
.addTextArea((textarea) => {
textarea
.setValue(this.plugin.settings.youtubeNote || DEFAULT_SETTINGS.youtubeNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.youtubeNote = value;
yield this.plugin.saveSettings();
}));
textarea.inputEl.rows = 10;
textarea.inputEl.cols = 25;
});
new obsidian.Setting(containerEl)
.setName('Twitter note template title')
.setDesc('Available variables: %tweetAuthorName%, %date%')
.addText((text) => text
.setPlaceholder('Defaults to %tweetAuthorName%')
.setValue(this.plugin.settings.twitterNoteTitle || DEFAULT_SETTINGS.twitterNoteTitle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.twitterNoteTitle = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Twitter note template')
.setDesc('Available variables: %tweetAuthorName%, %tweetURL%, %tweetContent%')
.addTextArea((textarea) => {
textarea
.setValue(this.plugin.settings.twitterNote || DEFAULT_SETTINGS.twitterNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.twitterNote = value;
yield this.plugin.saveSettings();
}));
textarea.inputEl.rows = 10;
textarea.inputEl.cols = 25;
});
new obsidian.Setting(containerEl)
.setName('Parsable article note template title')
.setDesc('Available variables: %title%')
.addText((text) => text
.setPlaceholder('Defaults to %title%')
.setValue(this.plugin.settings.parseableArticleNoteTitle || DEFAULT_SETTINGS.parseableArticleNoteTitle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.parseableArticleNoteTitle = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Parsable article note template')
.setDesc('Available variables: %articleTitle%, %articleURL%, %articleContent%')
.addTextArea((textarea) => {
textarea
.setValue(this.plugin.settings.parsableArticleNote || DEFAULT_SETTINGS.parsableArticleNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.parsableArticleNote = value;
yield this.plugin.saveSettings();
}));
textarea.inputEl.rows = 10;
textarea.inputEl.cols = 25;
});
new obsidian.Setting(containerEl)
.setName('Not paresable article note template title')
.setDesc('Available variables: %date%')
.addText((text) => text
.setPlaceholder(`Defaults to 'Article %date%'`)
.setValue(this.plugin.settings.notParseableArticleNoteTitle ||
DEFAULT_SETTINGS.notParseableArticleNoteTitle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.notParseableArticleNoteTitle = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Not parseable article note template')
.setDesc('Available variables: %articleURL%')
.addTextArea((textarea) => {
textarea
.setValue(this.plugin.settings.notParsableArticleNote || DEFAULT_SETTINGS.notParsableArticleNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.notParsableArticleNote = value;
yield this.plugin.saveSettings();
}));
textarea.inputEl.rows = 10;
textarea.inputEl.cols = 25;
});
new obsidian.Setting(containerEl)
.setName('Text snippet note template title')
.setDesc('Available variables: %date%')
.addText((text) => text
.setPlaceholder(`Defaults to 'Notice %date%'`)
.setValue(this.plugin.settings.textSnippetNoteTitle || DEFAULT_SETTINGS.textSnippetNoteTitle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.textSnippetNoteTitle = value;
yield this.plugin.saveSettings();
})));
new obsidian.Setting(containerEl)
.setName('Text snippet note template')
.setDesc('Available variables: %content%')
.addTextArea((textarea) => {
textarea
.setValue(this.plugin.settings.textSnippetNote || DEFAULT_SETTINGS.textSnippetNote)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.textSnippetNote = value;
yield this.plugin.saveSettings();
}));
textarea.inputEl.rows = 10;
textarea.inputEl.cols = 25;
});
}
}
class ReadItLaterPlugin extends obsidian.Plugin {
onload() {
return __awaiter(this, void 0, void 0, function* () {
yield this.loadSettings();
this.parsers = [
3 years ago
new YoutubeParser(this.app, this.settings),
new TwitterParser(this.app, this.settings),
new WebsiteParser(this.app, this.settings),
new TextSnippetParser(this.app, this.settings),
];
obsidian.addIcon('read-it-later', clipboardIcon);
this.addRibbonIcon('read-it-later', 'ReadItLater: Save clipboard', () => __awaiter(this, void 0, void 0, function* () {
yield this.processClipboard();
}));
this.addCommand({
id: 'save-clipboard-to-notice',
name: 'Save clipboard',
callback: () => __awaiter(this, void 0, void 0, function* () {
yield this.processClipboard();
}),
});
this.addSettingTab(new ReadItLaterSettingsTab(this.app, this));
});
}
loadSettings() {
return __awaiter(this, void 0, void 0, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __awaiter(this, void 0, void 0, function* () {
yield this.saveData(this.settings);
});
}
processClipboard() {
return __awaiter(this, void 0, void 0, function* () {
const clipboardContent = yield navigator.clipboard.readText();
for (const parser of this.parsers) {
if (parser.test(clipboardContent)) {
const note = yield parser.prepareNote(clipboardContent);
yield this.writeFile(note.fileName, note.content);
break;
}
}
});
}
writeFile(fileName, content) {
return __awaiter(this, void 0, void 0, function* () {
let filePath;
fileName = normalizeFilename(fileName);
3 years ago
yield checkAndCreateFolder(this.app.vault, this.settings.inboxDir);
if (this.settings.inboxDir) {
filePath = obsidian.normalizePath(`${this.settings.inboxDir}/${fileName}`);
}
else {
filePath = obsidian.normalizePath(`/${fileName}`);
}
if (yield this.app.vault.adapter.exists(filePath)) {
new obsidian.Notice(`${fileName} already exists!`);
}
else {
const newFile = yield this.app.vault.create(filePath, content);
if (this.settings.openNewNote) {
this.app.workspace.getLeaf(false).openFile(newFile);
}
new obsidian.Notice(`${fileName} created successful`);
}
});
}
}
const clipboardIcon = `
<svg fill="currentColor" stroke="currentColor" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m365.9,144.9c-12.3,0-24.2,1.8-35.4,5.2v-114.7h-96.9l7.3-35.4h-150.2l6.8,35.4h-97.5v454.6h330.5v-102.1c11.2,3.4 23.1,5.2 35.4,5.2 68.8-0.1 124.1-56.4 124.1-124.1 0-67.8-55.3-124.1-124.1-124.1zm-150.1-124l-10.4,50h-79.2l-9.4-50h99zm93.8,448.2h-288.7v-412.8h80.7l6.8,35.4h113.6l7.3-35.4h80.3v102.2c-27.3,14-48.8,37.9-59.7,66.7h-200.9v20.8h195c-1.4,7.4-2.2,15.1-2.2,22.9 0,13.4 2.2,26.4 6.2,38.6h-199v20.9h208.1c12,21.8 30.3,39.7 52.5,51.1v89.6zm56.3-98c-57.3,0-103.2-46.9-103.2-103.2s46.9-103.2 103.2-103.2c57.3,0 103.2,46.9 103.2,103.2s-45.8,103.2-103.2,103.2z"/>
<polygon points="426.4,223.1 346.1,303.4 313.8,271.1 299.2,285.7 346.1,332.6 441,237.7 "/>
<rect width="233.5" x="49" y="143.9" height="20.9"/>
<rect width="233.5" x="49" y="388.9" height="20.9"/>
</g>
</svg>`;
module.exports = ReadItLaterPlugin;
3 years ago
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsIm5vZGVfbW9kdWxlcy9Ac2luZHJlc29yaHVzL2lzL2Rpc3QvaW5kZXguanMiLCJub2RlX21vZHVsZXMvcC1jYW5jZWxhYmxlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2RlZmVyLXRvLWNvbm5lY3QvZGlzdC9zb3VyY2UvaW5kZXguanMiLCJub2RlX21vZHVsZXMvQHN6bWFyY3phay9odHRwLXRpbWVyL2Rpc3Qvc291cmNlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2NhY2hlYWJsZS1sb29rdXAvc291cmNlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL25vcm1hbGl6ZS11cmwvaW5kZXguanMiLCJub2RlX21vZHVsZXMvd3JhcHB5L3dyYXBweS5qcyIsIm5vZGVfbW9kdWxlcy9vbmNlL29uY2UuanMiLCJub2RlX21vZHVsZXMvZW5kLW9mLXN0cmVhbS9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9wdW1wL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2dldC1zdHJlYW0vYnVmZmVyLXN0cmVhbS5qcyIsIm5vZGVfbW9kdWxlcy9nZXQtc3RyZWFtL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2h0dHAtY2FjaGUtc2VtYW50aWNzL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2xvd2VyY2FzZS1rZXlzL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL3Jlc3BvbnNlbGlrZS9zcmMvaW5kZXguanMiLCJub2RlX21vZHVsZXMvbWltaWMtcmVzcG9uc2UvaW5kZXguanMiLCJub2RlX21vZHVsZXMvY2xvbmUtcmVzcG9uc2Uvc3JjL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2pzb24tYnVmZmVyL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2tleXYvc3JjL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2NhY2hlYWJsZS1yZXF1ZXN0L3NyYy9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9kZWNvbXByZXNzLXJlc3BvbnNlL25vZGVfbW9kdWxlcy9taW1pYy1yZXNwb25zZS9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9kZWNvbXByZXNzLXJlc3BvbnNlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9odHRwMi13cmFwcGVyL3NvdXJjZS9hZ2VudC5qcyIsIm5vZGVfbW9kdWxlcy9odHRwMi13cmFwcGVyL3NvdXJjZS9pbmNvbWluZy1tZXNzYWdlLmpzIiwibm9kZV9tb2R1bGVzL2h0dHAyLXdyYXBwZXIvc291cmNlL3V0aWxzL3VybC10by1vcHRpb25zLmpzIiwibm9kZV9tb2R1bGVzL2h0dHAyLXdyYXBwZXIvc291cmNlL3V0aWxzL3Byb3h5LWV2ZW50cy5qcyIsIm5vZGVfbW9kdWxlcy9odHRwMi13cmFwcGVyL3NvdXJjZS91dGlscy9pcy1yZXF1ZXN0LXBzZXVkby1oZWFkZXIuanMiLCJub2RlX21vZHVsZXMvaHR0cDItd3JhcHBlci9zb3VyY2UvdXRpbHMvZXJyb3JzLmpzIiwibm9kZV9tb2R1bGVzL2h0dHAyLXdyYXBwZXIvc291cmNlL2NsaWVudC1yZXF1ZXN0LmpzIiwibm9kZV9tb2R1bGVzL3Jlc29sdmUtYWxwbi9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9odHRwMi13cmFwcGVyL3NvdXJjZS91dGlscy9jYWxjdWxhdGUtc2VydmVyLW5hbWUuanMiLCJub2RlX21vZHVsZXMvaHR0cDItd3JhcHBlci9zb3VyY2UvYXV0by5qcyIsIm5vZGVfbW9kdWxlcy9odHRwMi13cmFwcGVyL3NvdXJjZS9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9nb3QvZGlzdC9zb3VyY2UvY29yZS91dGlscy9pcy1mb3JtLWRhdGEuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2NvcmUvdXRpbHMvZ2V0LWJvZHktc2l6ZS5qcyIsIm5vZGVfbW9kdWxlcy9nb3QvZGlzdC9zb3VyY2UvY29yZS91dGlscy9wcm94eS1ldmVudHMuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2NvcmUvdXRpbHMvdW5oYW5kbGUuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2NvcmUvdXRpbHMvdGltZWQtb3V0LmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL3V0aWxzL3VybC10by1vcHRpb25zLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL3V0aWxzL29wdGlvbnMtdG8tdXJsLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL3V0aWxzL3dlYWthYmxlLW1hcC5qcyIsIm5vZGVfbW9kdWxlcy9nb3QvZGlzdC9zb3VyY2UvY29yZS91dGlscy9nZXQtYnVmZmVyLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL3V0aWxzL2Rucy1pcC12ZXJzaW9uLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL3V0aWxzL2lzLXJlc3BvbnNlLW9rLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS91dGlscy9kZXByZWNhdGlvbi13YXJuaW5nLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9hcy1wcm9taXNlL25vcm1hbGl6ZS1hcmd1bWVudHMuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2NvcmUvY2FsY3VsYXRlLXJldHJ5LWRlbGF5LmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jb3JlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9hcy1wcm9taXNlL3R5cGVzLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9hcy1wcm9taXNlL3BhcnNlLWJvZHkuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2FzLXByb21pc2UvaW5kZXguanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2FzLXByb21pc2UvY3JlYXRlLXJlamVjdGlvbi5qcyIsIm5vZGVfbW9kdWxlcy9nb3QvZGlzdC9zb3VyY2UvdXRpbHMvZGVlcC1mcmVlemUuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL3R5cGVzLmpzIiwibm9kZV9tb2R1bGVzL2dvdC9kaXN0L3NvdXJjZS9jcmVhdGUuanMiLCJub2RlX21vZHVsZXMvZ290L2Rpc3Qvc291cmNlL2luZGV4LmpzIiwibm9kZV9tb2R1bGVzL21pbWUtZGIvaW5kZXguanMiLCJub2RlX21vZHVsZXMvbWltZS10eXBlcy9pbmRleC5qcyIsInNyYy9oZWxwZXJzL2Rvd25sb2FkSW1hZ2UudHMiLCJzcmMvaGVscGVycy9jaGVja0FuZENyZWF0ZUZvbGRlci50cyIsInNyYy9