rehype-citation
Version:
rehype plugin to add citation and bibliography from bibtex files
1 lines • 555 kB
Source Map (JSON)
{"version":3,"file":"cite.mjs","sources":["../../src/citation-js/core/Cite/log.js","../../src/citation-js/core/Cite/validate.js","../../src/citation-js/core/Cite/options.js","../../src/citation-js/core/plugins/input/dataType.js","../../src/citation-js/core/plugins/input/graph.js","../../src/citation-js/core/logger.js","../../src/citation-js/core/plugins/input/type.js","../../src/citation-js/core/plugins/input/parser.js","../../src/citation-js/core/plugins/input/csl.js","../../src/citation-js/core/util/csl.js","../../src/citation-js/core/util/deepCopy.js","../../node_modules/base64-js/index.js","../../node_modules/ieee754/index.js","../../node_modules/buffer/index.js","../../node_modules/sync-fetch/browser.js","../../node_modules/fetch-ponyfill/build/fetch-browser.js","../../src/citation-js/core/util/fetchFile.js","../../src/citation-js/core/util/fetchId.js","../../src/citation-js/core/util/register.js","../../src/citation-js/core/util/grammar.js","../../src/citation-js/core/util/translator.js","../../src/citation-js/core/plugins/input/chain.js","../../src/citation-js/core/plugins/input/data.js","../../src/citation-js/core/plugins/input/register.js","../../src/citation-js/core/plugins/input/index.js","../../src/citation-js/core/Cite/set.js","../../src/citation-js/core/plugin-common/output/label.js","../../src/citation-js/core/Cite/sort.js","../../src/citation-js/core/plugins/output.js","../../src/citation-js/core/Cite/get.js","../../src/citation-js/core/Cite/async.js","../../src/citation-js/core/Cite/index.js","../../src/citation-js/core/plugins/dict.js","../../src/citation-js/core/plugins/config.js","../../src/citation-js/core/plugins/index.js","../../src/citation-js/core/plugin-common/input/empty.js","../../src/citation-js/core/plugin-common/input/json.js","../../src/citation-js/core/plugin-common/input/index.js","../../src/citation-js/core/plugin-common/input/jquery.js","../../src/citation-js/core/plugin-common/input/html.js","../../src/citation-js/core/plugin-common/output/json.js","../../src/citation-js/plugin-bibjson/json.js","../../src/citation-js/core/plugin-common/index.js","../../src/citation-js/core/plugin-common/output/index.js","../../src/citation-js/plugin-bibjson/index.js","../../node_modules/moo/moo.js","../../src/citation-js/plugin-bibtex/mapping/biblatexTypes.js","../../src/citation-js/plugin-bibtex/mapping/bibtexTypes.js","../../src/citation-js/plugin-bibtex/input/constants.js","../../src/citation-js/plugin-bibtex/input/required.js","../../src/citation-js/plugin-bibtex/input/fieldTypes.js","../../src/citation-js/plugin-bibtex/input/unicode.js","../../src/citation-js/plugin-bibtex/config.js","../../src/citation-js/plugin-bibtex/input/file.js","../../src/citation-js/plugin-bibtex/input/bibtxt.js","../../src/citation-js/plugin-bibtex/mapping/shared.js","../../src/citation-js/plugin-bibtex/mapping/biblatex.js","../../src/citation-js/plugin-bibtex/mapping/bibtex.js","../../src/citation-js/plugin-bibtex/mapping/crossref.js","../../src/citation-js/plugin-bibtex/mapping/index.js","../../src/citation-js/plugin-bibtex/input/name.js","../../src/citation-js/plugin-bibtex/input/value.js","../../src/citation-js/plugin-bibtex/input/entries.js","../../src/citation-js/plugin-bibtex/input/index.js","../../src/citation-js/plugin-bibtex/output/value.js","../../src/citation-js/plugin-bibtex/output/entries.js","../../src/citation-js/plugin-bibtex/output/bibtex.js","../../src/citation-js/plugin-bibtex/output/index.js","../../src/citation-js/plugin-bibtex/output/bibtxt.js","../../src/citation-js/plugin-bibtex/index.js","../../src/citation-js/plugin-csl/locales.js","../../src/citation-js/plugin-csl/styles.js","../../src/citation-js/plugin-csl/engines.js","../../src/citation-js/plugin-csl/bibliography.js","../../src/citation-js/plugin-csl/citation.js","../../src/citation-js/plugin-csl/index.js","../../src/citation-js/plugin-csl/attr.js","../../src/citation-js/plugin-yaml/index.js","../../src/citation-js/plugin-cff/index.js","../../src/cite.js"],"sourcesContent":["function currentVersion() {\n return this.log.length\n}\nfunction retrieveVersion(versnum = 1) {\n if (versnum <= 0 || versnum > this.currentVersion()) {\n return null\n } else {\n const [data, options] = this.log[versnum - 1]\n const image = new this.constructor(JSON.parse(data), JSON.parse(options))\n image.log = this.log.slice(0, versnum)\n return image\n }\n}\nfunction undo(number = 1) {\n return this.retrieveVersion(this.currentVersion() - number)\n}\nfunction retrieveLastVersion() {\n return this.retrieveVersion(this.currentVersion())\n}\nfunction save() {\n this.log.push([JSON.stringify(this.data), JSON.stringify(this._options)])\n return this\n}\nexport { currentVersion, retrieveVersion, retrieveLastVersion, undo, save }\n","const formats = ['real', 'string']\nconst types = ['json', 'html', 'string', 'rtf']\nconst styles = ['csl', 'bibtex', 'bibtxt', 'citation-*', 'ris', 'ndjson']\nconst wrapperTypes = ['string', 'function']\nexport function validateOutputOptions(options) {\n if (typeof options !== 'object') {\n throw new TypeError('Options not an object!')\n }\n const { format, type, style, lang, append, prepend } = options\n if (format && !formats.includes(format)) {\n throw new TypeError(`Option format (\"${format}\") should be one of: ${formats}`)\n } else if (type && !types.includes(type)) {\n throw new TypeError(`Option type (\"${type}\") should be one of: ${types}`)\n } else if (style && !styles.includes(style) && !/^citation/.test(style)) {\n throw new TypeError(`Option style (\"${style}\") should be one of: ${styles}`)\n } else if (lang && typeof lang !== 'string') {\n throw new TypeError(`Option lang should be a string, but is a ${typeof lang}`)\n } else if (prepend && !wrapperTypes.includes(typeof prepend)) {\n throw new TypeError(\n `Option prepend should be a string or a function, but is a ${typeof prepend}`\n )\n } else if (append && !wrapperTypes.includes(typeof append)) {\n throw new TypeError(`Option append should be a string or a function, but is a ${typeof append}`)\n }\n if (/^citation/.test(style) && type === 'json') {\n throw new Error(`Combination type/style of json/citation-* is not valid: ${type}/${style}`)\n }\n return true\n}\nexport function validateOptions(options) {\n if (typeof options !== 'object') {\n throw new TypeError('Options should be an object')\n }\n if (options.output) {\n validateOutputOptions(options.output)\n } else if (options.maxChainLength && typeof options.maxChainLength !== 'number') {\n throw new TypeError('Option maxChainLength should be a number')\n } else if (options.forceType && typeof options.forceType !== 'string') {\n throw new TypeError('Option forceType should be a string')\n } else if (options.generateGraph != null && typeof options.generateGraph !== 'boolean') {\n throw new TypeError('Option generateGraph should be a boolean')\n } else if (options.strict != null && typeof options.strict !== 'boolean') {\n throw new TypeError('Option strict should be a boolean')\n } else if (options.target != null && typeof options.target !== 'string') {\n throw new TypeError('Option target should be a boolean')\n }\n return true\n}\n","import { validateOutputOptions as validate } from './validate.js'\nconst defaultOptions = {\n format: 'real',\n type: 'json',\n style: 'csl',\n lang: 'en-US',\n}\nfunction options(options, log) {\n validate(options)\n if (log) {\n this.save()\n }\n Object.assign(this._options, options)\n return this\n}\nexport { options, defaultOptions }\n","export function typeOf(thing) {\n switch (thing) {\n case undefined:\n return 'Undefined'\n case null:\n return 'Null'\n default:\n return thing.constructor.name\n }\n}\nexport function dataTypeOf(thing) {\n switch (typeof thing) {\n case 'string':\n return 'String'\n case 'object':\n if (Array.isArray(thing)) {\n return 'Array'\n } else if (typeOf(thing) === 'Object') {\n return 'SimpleObject'\n } else if (typeOf(thing) !== 'Null') {\n return 'ComplexObject'\n }\n default:\n return 'Primitive'\n }\n}\n","export function applyGraph(entry, graph) {\n if (entry._graph) {\n const index = graph.findIndex(({ type }) => type === '@else/list+object')\n if (index !== -1) {\n graph.splice(index + 1, 0, ...entry._graph.slice(0, -1))\n }\n }\n entry._graph = graph\n return entry\n}\nexport function removeGraph(entry) {\n delete entry._graph\n return entry\n}\n","const logger = {\n _output(level, scope, msg) {\n this._log.push(scope, msg)\n if (this._levels.indexOf(level) < this._levels.indexOf(this.level)) {\n return\n }\n this._console.log(scope, ...msg)\n },\n _console: null,\n _log: [],\n _levels: ['http', 'debug', 'unmapped', 'info', 'warn', 'error', 'silent'],\n level: 'silent',\n}\nfor (const level of logger._levels) {\n logger[level] = (scope, ...msg) => logger._output(level, scope, msg)\n}\nif (typeof console.Console === 'function') {\n logger._console = new console.Console(process.stderr)\n} else {\n logger._console = console\n}\nexport default logger\n","import logger from '../../logger.js'\nimport { dataTypeOf } from './dataType.js'\nconst types = {}\nconst dataTypes = {}\nconst unregExts = {}\nfunction parseNativeTypes(input, dataType) {\n switch (dataType) {\n case 'Array':\n if (input.length === 0 || input.every((entry) => type(entry) === '@csl/object')) {\n return '@csl/list+object'\n } else {\n return '@else/list+object'\n }\n case 'SimpleObject':\n case 'ComplexObject':\n return '@csl/object'\n default:\n return '@invalid'\n }\n}\nfunction matchType(typeList = [], data) {\n for (const type of typeList) {\n if (types[type].predicate(data)) {\n return matchType(types[type].extensions, data) || type\n }\n }\n}\nexport function type(input) {\n const dataType = dataTypeOf(input)\n if (dataType === 'Array' && input.length === 0) {\n return parseNativeTypes(input, dataType)\n }\n const match = matchType(dataTypes[dataType], input)\n return match || parseNativeTypes(input, dataType)\n}\nexport function addTypeParser(format, { dataType, predicate, extends: extend }) {\n let extensions = []\n if (format in unregExts) {\n extensions = unregExts[format]\n delete unregExts[format]\n logger.debug(\n '[core]',\n `Subclasses \"${extensions}\" finally registered to parent type \"${format}\"`\n )\n }\n const object = {\n predicate,\n extensions,\n }\n types[format] = object\n if (extend) {\n const parentTypeParser = types[extend]\n if (parentTypeParser) {\n parentTypeParser.extensions.push(format)\n } else {\n if (!unregExts[extend]) {\n unregExts[extend] = []\n }\n unregExts[extend].push(format)\n logger.debug('[core]', `Subclass \"${format}\" is waiting on parent type \"${extend}\"`)\n }\n } else {\n const typeList = dataTypes[dataType] || (dataTypes[dataType] = [])\n typeList.push(format)\n }\n}\nexport function hasTypeParser(type) {\n return Object.prototype.hasOwnProperty.call(types, type)\n}\nexport function removeTypeParser(type) {\n delete types[type]\n const typeLists = [\n ...Object.keys(dataTypes).map((key) => dataTypes[key]),\n ...Object.keys(types)\n .map((type) => types[type].extensions)\n .filter((list) => list.length > 0),\n ]\n typeLists.forEach((typeList) => {\n const index = typeList.indexOf(type)\n if (index > -1) {\n typeList.splice(index, 1)\n }\n })\n}\nexport function listTypeParser() {\n return Object.keys(types)\n}\nexport function treeTypeParser() {\n const attachNode = (name) => ({\n name,\n children: types[name].extensions.map(attachNode),\n })\n return {\n name: 'Type tree',\n children: Object.keys(dataTypes).map((name) => ({\n name,\n children: dataTypes[name].map(attachNode),\n })),\n }\n}\nexport const typeMatcher = /^(?:@(.+?))(?:\\/(?:(.+?)\\+)?(?:(.+)))?$/\n","// @ts-nocheck\nfunction _defineProperty(obj, key, value) {\n key = _toPropertyKey(key)\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true,\n })\n } else {\n obj[key] = value\n }\n return obj\n}\nfunction _toPropertyKey(t) {\n var i = _toPrimitive(t, 'string')\n return 'symbol' == typeof i ? i : i + ''\n}\nfunction _toPrimitive(t, r) {\n if ('object' != typeof t || !t) return t\n var e = t[Symbol.toPrimitive]\n if (void 0 !== e) {\n var i = e.call(t, r || 'default')\n if ('object' != typeof i) return i\n throw new TypeError('@@toPrimitive must return a primitive value.')\n }\n return ('string' === r ? String : Number)(t)\n}\nimport { type, typeMatcher } from './type.js'\nclass TypeParser {\n constructor(data) {\n _defineProperty(this, 'validDataTypes', [\n 'String',\n 'Array',\n 'SimpleObject',\n 'ComplexObject',\n 'Primitive',\n ])\n this.data = data\n }\n validateDataType() {\n const dataType = this.data.dataType\n if (dataType && !this.validDataTypes.includes(dataType)) {\n throw new RangeError(`dataType was ${dataType}; expected one of ${this.validDataTypes}`)\n }\n }\n validateParseType() {\n const predicate = this.data.predicate\n if (predicate && !(predicate instanceof RegExp || typeof predicate === 'function')) {\n throw new TypeError(`predicate was ${typeof predicate}; expected RegExp or function`)\n }\n }\n validateTokenList() {\n const tokenList = this.data.tokenList\n if (tokenList && typeof tokenList !== 'object') {\n throw new TypeError(`tokenList was ${typeof tokenList}; expected object or RegExp`)\n }\n }\n validatePropertyConstraint() {\n const propertyConstraint = this.data.propertyConstraint\n if (propertyConstraint && typeof propertyConstraint !== 'object') {\n throw new TypeError(\n `propertyConstraint was ${typeof propertyConstraint}; expected array or object`\n )\n }\n }\n validateElementConstraint() {\n const elementConstraint = this.data.elementConstraint\n if (elementConstraint && typeof elementConstraint !== 'string') {\n throw new TypeError(`elementConstraint was ${typeof elementConstraint}; expected string`)\n }\n }\n validateExtends() {\n const extend = this.data.extends\n if (extend && typeof extend !== 'string') {\n throw new TypeError(`extends was ${typeof extend}; expected string`)\n }\n }\n validate() {\n if (this.data === null || typeof this.data !== 'object') {\n throw new TypeError(`typeParser was ${typeof this.data}; expected object`)\n }\n this.validateDataType()\n this.validateParseType()\n this.validateTokenList()\n this.validatePropertyConstraint()\n this.validateElementConstraint()\n this.validateExtends()\n }\n parseTokenList() {\n let tokenList = this.data.tokenList\n if (!tokenList) {\n return []\n } else if (tokenList instanceof RegExp) {\n tokenList = {\n token: tokenList,\n }\n }\n const { token, split = /\\s+/, trim = true, every = true } = tokenList\n const trimInput = (input) => (trim ? input.trim() : input)\n const testTokens = every ? 'every' : 'some'\n const predicate = (input) =>\n trimInput(input)\n .split(split)\n [testTokens]((part) => token.test(part))\n return [predicate]\n }\n parsePropertyConstraint() {\n const constraints = [].concat(this.data.propertyConstraint || [])\n return constraints.map(({ props, match, value }) => {\n props = [].concat(props)\n switch (match) {\n case 'any':\n case 'some':\n return (input) => props.some((prop) => prop in input && (!value || value(input[prop])))\n case 'none':\n return (input) => !props.some((prop) => prop in input && (!value || value(input[prop])))\n case 'every':\n default:\n return (input) => props.every((prop) => prop in input && (!value || value(input[prop])))\n }\n })\n }\n parseElementConstraint() {\n const constraint = this.data.elementConstraint\n return !constraint ? [] : [(input) => input.every((entry) => type(entry) === constraint)]\n }\n parsePredicate() {\n if (this.data.predicate instanceof RegExp) {\n return [this.data.predicate.test.bind(this.data.predicate)]\n } else if (this.data.predicate) {\n return [this.data.predicate]\n } else {\n return []\n }\n }\n getCombinedPredicate() {\n const predicates = [\n ...this.parsePredicate(),\n ...this.parseTokenList(),\n ...this.parsePropertyConstraint(),\n ...this.parseElementConstraint(),\n ]\n if (predicates.length === 0) {\n return () => true\n } else if (predicates.length === 1) {\n return predicates[0]\n } else {\n return (input) => predicates.every((predicate) => predicate(input))\n }\n }\n getDataType() {\n if (this.data.dataType) {\n return this.data.dataType\n } else if (this.data.predicate instanceof RegExp) {\n return 'String'\n } else if (this.data.tokenList) {\n return 'String'\n } else if (this.data.elementConstraint) {\n return 'Array'\n } else {\n return 'Primitive'\n }\n }\n get dataType() {\n return this.getDataType()\n }\n get predicate() {\n return this.getCombinedPredicate()\n }\n get extends() {\n return this.data.extends\n }\n}\nclass DataParser {\n constructor(parser, { async } = {}) {\n this.parser = parser\n this.async = async\n }\n validate() {\n const parser = this.parser\n if (typeof parser !== 'function') {\n throw new TypeError(`parser was ${typeof parser}; expected function`)\n }\n }\n}\nclass FormatParser {\n constructor(format, parsers = {}) {\n this.format = format\n if (parsers.parseType) {\n this.typeParser = new TypeParser(parsers.parseType)\n }\n if (parsers.parse) {\n this.dataParser = new DataParser(parsers.parse, {\n async: false,\n })\n }\n if (parsers.parseAsync) {\n this.asyncDataParser = new DataParser(parsers.parseAsync, {\n async: true,\n })\n }\n }\n validateFormat() {\n const format = this.format\n if (!typeMatcher.test(format)) {\n throw new TypeError(`format name was \"${format}\"; didn't match expected pattern`)\n }\n }\n validate() {\n this.validateFormat()\n if (this.typeParser) {\n this.typeParser.validate()\n }\n if (this.dataParser) {\n this.dataParser.validate()\n }\n if (this.asyncDataParser) {\n this.asyncDataParser.validate()\n }\n }\n}\nexport { TypeParser, DataParser, FormatParser }\n","function ownKeys(e, r) {\n var t = Object.keys(e)\n if (Object.getOwnPropertySymbols) {\n var o = Object.getOwnPropertySymbols(e)\n r &&\n (o = o.filter(function (r) {\n return Object.getOwnPropertyDescriptor(e, r).enumerable\n })),\n t.push.apply(t, o)\n }\n return t\n}\nfunction _objectSpread(e) {\n for (var r = 1; r < arguments.length; r++) {\n var t = null != arguments[r] ? arguments[r] : {}\n r % 2\n ? ownKeys(Object(t), !0).forEach(function (r) {\n _defineProperty(e, r, t[r])\n })\n : Object.getOwnPropertyDescriptors\n ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))\n : ownKeys(Object(t)).forEach(function (r) {\n Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r))\n })\n }\n return e\n}\nfunction _defineProperty(obj, key, value) {\n key = _toPropertyKey(key)\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true,\n })\n } else {\n obj[key] = value\n }\n return obj\n}\nfunction _toPropertyKey(t) {\n var i = _toPrimitive(t, 'string')\n return 'symbol' == typeof i ? i : i + ''\n}\nfunction _toPrimitive(t, r) {\n if ('object' != typeof t || !t) return t\n var e = t[Symbol.toPrimitive]\n if (void 0 !== e) {\n var i = e.call(t, r || 'default')\n if ('object' != typeof i) return i\n throw new TypeError('@@toPrimitive must return a primitive value.')\n }\n return ('string' === r ? String : Number)(t)\n}\nimport { parse as parseName } from '@citation-js/name'\nconst NAME = 1\nconst NAME_LIST = 2\nconst DATE = 3\nconst TYPE = 4\nconst entryTypes = {\n article: true,\n 'article-journal': true,\n 'article-magazine': true,\n 'article-newspaper': true,\n bill: true,\n book: true,\n broadcast: true,\n chapter: true,\n classic: true,\n collection: true,\n dataset: true,\n document: true,\n entry: true,\n 'entry-dictionary': true,\n 'entry-encyclopedia': true,\n event: true,\n figure: true,\n graphic: true,\n hearing: true,\n interview: true,\n legal_case: true,\n legislation: true,\n manuscript: true,\n map: true,\n motion_picture: true,\n musical_score: true,\n pamphlet: true,\n 'paper-conference': true,\n patent: true,\n performance: true,\n periodical: true,\n personal_communication: true,\n post: true,\n 'post-weblog': true,\n regulation: true,\n report: true,\n review: true,\n 'review-book': true,\n software: true,\n song: true,\n speech: true,\n standard: true,\n thesis: true,\n treaty: true,\n webpage: true,\n 'journal-article': 'article-journal',\n 'book-chapter': 'chapter',\n 'posted-content': 'manuscript',\n 'proceedings-article': 'paper-conference',\n dissertation: 'thesis',\n}\nconst fieldTypes = {\n author: NAME_LIST,\n chair: NAME_LIST,\n 'collection-editor': NAME_LIST,\n compiler: NAME_LIST,\n composer: NAME_LIST,\n 'container-author': NAME_LIST,\n contributor: NAME_LIST,\n curator: NAME_LIST,\n director: NAME_LIST,\n editor: NAME_LIST,\n 'editorial-director': NAME_LIST,\n 'executive-producer': NAME_LIST,\n guest: NAME_LIST,\n host: NAME_LIST,\n interviewer: NAME_LIST,\n illustrator: NAME_LIST,\n narrator: NAME_LIST,\n organizer: NAME_LIST,\n 'original-author': NAME_LIST,\n performer: NAME_LIST,\n producer: NAME_LIST,\n 'reviewed-author': NAME_LIST,\n recipient: NAME_LIST,\n 'script-writer': NAME_LIST,\n 'series-creator': NAME_LIST,\n translator: NAME_LIST,\n accessed: DATE,\n 'available-date': DATE,\n container: DATE,\n 'event-date': DATE,\n issued: DATE,\n 'original-date': DATE,\n submitted: DATE,\n type: TYPE,\n categories: 'object',\n custom: 'object',\n id: ['string', 'number'],\n language: 'string',\n journalAbbreviation: 'string',\n shortTitle: 'string',\n abstract: 'string',\n annote: 'string',\n archive: 'string',\n archive_collection: 'string',\n archive_location: 'string',\n 'archive-place': 'string',\n authority: 'string',\n 'call-number': 'string',\n 'chapter-number': 'string',\n 'citation-number': 'string',\n 'citation-key': 'string',\n 'citation-label': 'string',\n 'collection-number': 'string',\n 'collection-title': 'string',\n 'container-title': 'string',\n 'container-title-short': 'string',\n dimensions: 'string',\n division: 'string',\n DOI: 'string',\n edition: ['string', 'number'],\n event: 'string',\n 'event-title': 'string',\n 'event-place': 'string',\n 'first-reference-note-number': 'string',\n genre: 'string',\n ISBN: 'string',\n ISSN: 'string',\n issue: ['string', 'number'],\n jurisdiction: 'string',\n keyword: 'string',\n locator: 'string',\n medium: 'string',\n note: 'string',\n number: ['string', 'number'],\n 'number-of-pages': 'string',\n 'number-of-volumes': ['string', 'number'],\n 'original-publisher': 'string',\n 'original-publisher-place': 'string',\n 'original-title': 'string',\n page: 'string',\n 'page-first': 'string',\n 'part-number': ['string', 'number'],\n 'part-title': 'string',\n PMCID: 'string',\n PMID: 'string',\n printing: 'string',\n publisher: 'string',\n 'publisher-place': 'string',\n references: 'string',\n 'reviewed-title': 'string',\n 'reviewed-genre': 'string',\n scale: 'string',\n section: 'string',\n source: 'string',\n status: 'string',\n supplement: ['string', 'number'],\n title: 'string',\n 'title-short': 'string',\n URL: 'string',\n version: 'string',\n volume: ['string', 'number'],\n 'volume-title': 'string',\n 'volume-title-short': 'string',\n 'year-suffix': 'string',\n}\nfunction correctName(name, bestGuessConversions) {\n if (typeof name === 'object' && name !== null && (name.literal || name.given || name.family)) {\n if (name.ORCID || name.orcid || name._ORCID) {\n name = _objectSpread(\n {\n _orcid: name.ORCID || name.orcid || name._ORCID,\n },\n name\n )\n delete name.ORCID\n delete name.orcid\n delete name._ORCID\n }\n return name\n } else if (!bestGuessConversions) {\n return undefined\n } else if (typeof name === 'string') {\n return parseName(name)\n }\n}\nfunction correctNameList(nameList, bestGuessConversions) {\n if (nameList instanceof Array) {\n const names = nameList.map((name) => correctName(name, bestGuessConversions)).filter(Boolean)\n return names.length ? names : undefined\n }\n}\nfunction correctDateParts(dateParts, bestGuessConversions) {\n if (dateParts.every((part) => typeof part === 'number')) {\n return dateParts\n } else if (!bestGuessConversions || dateParts.some((part) => isNaN(parseInt(part)))) {\n return undefined\n } else {\n return dateParts.map((part) => parseInt(part))\n }\n}\nfunction correctDate(date, bestGuessConversions) {\n const dp = 'date-parts'\n if (typeof date !== 'object' || date === null) {\n return undefined\n } else if (date[dp] instanceof Array && date[dp].every((part) => part instanceof Array)) {\n const range = date[dp]\n .map((dateParts) => correctDateParts(dateParts, bestGuessConversions))\n .filter(Boolean)\n return range.length\n ? _objectSpread(\n _objectSpread({}, date),\n {},\n {\n 'date-parts': range,\n }\n )\n : undefined\n } else if (date instanceof Array && date.every((part) => part[dp] instanceof Array)) {\n const range = date\n .map((dateParts) => correctDateParts(dateParts[dp], bestGuessConversions))\n .filter(Boolean)\n return range.length\n ? {\n 'date-parts': range,\n }\n : undefined\n } else if (date[dp] instanceof Array) {\n const dateParts = correctDateParts(date[dp], bestGuessConversions)\n return (\n dateParts && {\n 'date-parts': [dateParts],\n }\n )\n } else if ('literal' in date || 'raw' in date) {\n return date\n }\n}\nfunction correctType(type, bestGuessConversions) {\n type = correctField('language', type, bestGuessConversions)\n if (entryTypes[type] === true) {\n return type\n }\n if (bestGuessConversions) {\n if (type in entryTypes) {\n return entryTypes[type]\n } else if (type.toLowerCase() !== type) {\n return correctType(type.toLowerCase(), bestGuessConversions)\n }\n }\n return undefined\n}\nfunction correctField(fieldName, value, bestGuessConversions) {\n const fieldType = [].concat(fieldTypes[fieldName])\n switch (fieldTypes[fieldName]) {\n case NAME:\n return correctName(value, bestGuessConversions)\n case NAME_LIST:\n return correctNameList(value, bestGuessConversions)\n case DATE:\n return correctDate(value, bestGuessConversions)\n case TYPE:\n return correctType(value, bestGuessConversions)\n }\n if (bestGuessConversions) {\n if (\n typeof value === 'string' &&\n fieldType.includes('number') &&\n !fieldType.includes('string') &&\n !isNaN(+value)\n ) {\n return parseFloat(value)\n } else if (\n typeof value === 'number' &&\n fieldType.includes('string') &&\n !fieldType.includes('number')\n ) {\n return value.toString()\n } else if (Array.isArray(value) && value.length) {\n return correctField(fieldName, value[0], bestGuessConversions)\n }\n }\n if (fieldType.includes(typeof value)) {\n return value\n }\n}\nfunction parseCsl(data, bestGuessConversions = true) {\n return data.map(function (entry) {\n const clean = {}\n for (const field in entry) {\n const correction = correctField(field, entry[field], bestGuessConversions)\n if (correction !== undefined) {\n clean[field] = correction\n }\n }\n return clean\n })\n}\nexport { parseCsl as clean }\n","function ownKeys(e, r) {\n var t = Object.keys(e)\n if (Object.getOwnPropertySymbols) {\n var o = Object.getOwnPropertySymbols(e)\n r &&\n (o = o.filter(function (r) {\n return Object.getOwnPropertyDescriptor(e, r).enumerable\n })),\n t.push.apply(t, o)\n }\n return t\n}\nfunction _objectSpread(e) {\n for (var r = 1; r < arguments.length; r++) {\n var t = null != arguments[r] ? arguments[r] : {}\n r % 2\n ? ownKeys(Object(t), !0).forEach(function (r) {\n _defineProperty(e, r, t[r])\n })\n : Object.getOwnPropertyDescriptors\n ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))\n : ownKeys(Object(t)).forEach(function (r) {\n Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r))\n })\n }\n return e\n}\nfunction _defineProperty(obj, key, value) {\n key = _toPropertyKey(key)\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true,\n })\n } else {\n obj[key] = value\n }\n return obj\n}\nfunction _toPropertyKey(t) {\n var i = _toPrimitive(t, 'string')\n return 'symbol' == typeof i ? i : i + ''\n}\nfunction _toPrimitive(t, r) {\n if ('object' != typeof t || !t) return t\n var e = t[Symbol.toPrimitive]\n if (void 0 !== e) {\n var i = e.call(t, r || 'default')\n if ('object' != typeof i) return i\n throw new TypeError('@@toPrimitive must return a primitive value.')\n }\n return ('string' === r ? String : Number)(t)\n}\nexport function upgradeCsl(item) {\n if (Array.isArray(item)) {\n return item.map(upgradeCsl)\n }\n item = _objectSpread({}, item)\n if ('event' in item) {\n item['event-title'] = item.event\n delete item.event\n }\n if (item.type === 'book' && 'version' in item) {\n item.type = 'software'\n }\n return item\n}\nexport function downgradeCsl(item) {\n if (Array.isArray(item)) {\n return item.map(downgradeCsl)\n }\n item = _objectSpread({}, item)\n if ('event-title' in item) {\n item.event = item['event-title']\n delete item['event-title']\n }\n if (item.type === 'software') {\n item.type = 'book'\n }\n return item\n}\n","export function deepCopy(value, seen = new Set()) {\n if (\n typeof value !== 'object' ||\n value === null ||\n (value.constructor !== Object && value.constructor !== Array)\n ) {\n return value\n }\n if (seen.has(value)) {\n throw new TypeError('Recursively copying circular structure')\n }\n seen.add(value)\n let copy\n if (value.constructor === Array) {\n copy = value.map((value) => deepCopy(value, seen))\n } else {\n const object = {}\n for (const key in value) {\n object[key] = deepCopy(value[key], seen)\n }\n copy = object\n }\n seen.delete(value)\n return copy\n}\nexport default deepCopy\n","'use strict'\n\nexports.byteLength = byteLength\nexports.toByteArray = toByteArray\nexports.fromByteArray = fromByteArray\n\nvar lookup = []\nvar revLookup = []\nvar Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array\n\nvar code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'\nfor (var i = 0, len = code.length; i < len; ++i) {\n lookup[i] = code[i]\n revLookup[code.charCodeAt(i)] = i\n}\n\n// Support decoding URL-safe base64 strings, as Node.js does.\n// See: https://en.wikipedia.org/wiki/Base64#URL_applications\nrevLookup['-'.charCodeAt(0)] = 62\nrevLookup['_'.charCodeAt(0)] = 63\n\nfunction getLens (b64) {\n var len = b64.length\n\n if (len % 4 > 0) {\n throw new Error('Invalid string. Length must be a multiple of 4')\n }\n\n // Trim off extra bytes after placeholder bytes are found\n // See: https://github.com/beatgammit/base64-js/issues/42\n var validLen = b64.indexOf('=')\n if (validLen === -1) validLen = len\n\n var placeHoldersLen = validLen === len\n ? 0\n : 4 - (validLen % 4)\n\n return [validLen, placeHoldersLen]\n}\n\n// base64 is 4/3 + up to two characters of the original data\nfunction byteLength (b64) {\n var lens = getLens(b64)\n var validLen = lens[0]\n var placeHoldersLen = lens[1]\n return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen\n}\n\nfunction _byteLength (b64, validLen, placeHoldersLen) {\n return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen\n}\n\nfunction toByteArray (b64) {\n var tmp\n var lens = getLens(b64)\n var validLen = lens[0]\n var placeHoldersLen = lens[1]\n\n var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))\n\n var curByte = 0\n\n // if there are placeholders, only get up to the last complete 4 chars\n var len = placeHoldersLen > 0\n ? validLen - 4\n : validLen\n\n var i\n for (i = 0; i < len; i += 4) {\n tmp =\n (revLookup[b64.charCodeAt(i)] << 18) |\n (revLookup[b64.charCodeAt(i + 1)] << 12) |\n (revLookup[b64.charCodeAt(i + 2)] << 6) |\n revLookup[b64.charCodeAt(i + 3)]\n arr[curByte++] = (tmp >> 16) & 0xFF\n arr[curByte++] = (tmp >> 8) & 0xFF\n arr[curByte++] = tmp & 0xFF\n }\n\n if (placeHoldersLen === 2) {\n tmp =\n (revLookup[b64.charCodeAt(i)] << 2) |\n (revLookup[b64.charCodeAt(i + 1)] >> 4)\n arr[curByte++] = tmp & 0xFF\n }\n\n if (placeHoldersLen === 1) {\n tmp =\n (revLookup[b64.charCodeAt(i)] << 10) |\n (revLookup[b64.charCodeAt(i + 1)] << 4) |\n (revLookup[b64.charCodeAt(i + 2)] >> 2)\n arr[curByte++] = (tmp >> 8) & 0xFF\n arr[curByte++] = tmp & 0xFF\n }\n\n return arr\n}\n\nfunction tripletToBase64 (num) {\n return lookup[num >> 18 & 0x3F] +\n lookup[num >> 12 & 0x3F] +\n lookup[num >> 6 & 0x3F] +\n lookup[num & 0x3F]\n}\n\nfunction encodeChunk (uint8, start, end) {\n var tmp\n var output = []\n for (var i = start; i < end; i += 3) {\n tmp =\n ((uint8[i] << 16) & 0xFF0000) +\n ((uint8[i + 1] << 8) & 0xFF00) +\n (uint8[i + 2] & 0xFF)\n output.push(tripletToBase64(tmp))\n }\n return output.join('')\n}\n\nfunction fromByteArray (uint8) {\n var tmp\n var len = uint8.length\n var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes\n var parts = []\n var maxChunkLength = 16383 // must be multiple of 3\n\n // go through the array every three bytes, we'll deal with trailing stuff later\n for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))\n }\n\n // pad the end with zeros, but make sure to not forget the extra bytes\n if (extraBytes === 1) {\n tmp = uint8[len - 1]\n parts.push(\n lookup[tmp >> 2] +\n lookup[(tmp << 4) & 0x3F] +\n '=='\n )\n } else if (extraBytes === 2) {\n tmp = (uint8[len - 2] << 8) + uint8[len - 1]\n parts.push(\n lookup[tmp >> 10] +\n lookup[(tmp >> 4) & 0x3F] +\n lookup[(tmp << 2) & 0x3F] +\n '='\n )\n }\n\n return parts.join('')\n}\n","/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */\nexports.read = function (buffer, offset, isLE, mLen, nBytes) {\n var e, m\n var eLen = (nBytes * 8) - mLen - 1\n var eMax = (1 << eLen) - 1\n var eBias = eMax >> 1\n var nBits = -7\n var i = isLE ? (nBytes - 1) : 0\n var d = isLE ? -1 : 1\n var s = buffer[offset + i]\n\n i += d\n\n e = s & ((1 << (-nBits)) - 1)\n s >>= (-nBits)\n nBits += eLen\n for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n m = e & ((1 << (-nBits)) - 1)\n e >>= (-nBits)\n nBits += mLen\n for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n if (e === 0) {\n e = 1 - eBias\n } else if (e === eMax) {\n return m ? NaN : ((s ? -1 : 1) * Infinity)\n } else {\n m = m + Math.pow(2, mLen)\n e = e - eBias\n }\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen)\n}\n\nexports.write = function (buffer, value, offset, isLE, mLen, nBytes) {\n var e, m, c\n var eLen = (nBytes * 8) - mLen - 1\n var eMax = (1 << eLen) - 1\n var eBias = eMax >> 1\n var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)\n var i = isLE ? 0 : (nBytes - 1)\n var d = isLE ? 1 : -1\n var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0\n\n value = Math.abs(value)\n\n if (isNaN(value) || value === Infinity) {\n m = isNaN(value) ? 1 : 0\n e = eMax\n } else {\n e = Math.floor(Math.log(value) / Math.LN2)\n if (value * (c = Math.pow(2, -e)) < 1) {\n e--\n c *= 2\n }\n if (e + eBias >= 1) {\n value += rt / c\n } else {\n value += rt * Math.pow(2, 1 - eBias)\n }\n if (value * c >= 2) {\n e++\n c /= 2\n }\n\n if (e + eBias >= eMax) {\n m = 0\n e = eMax\n } else if (e + eBias >= 1) {\n m = ((value * c) - 1) * Math.pow(2, mLen)\n e = e + eBias\n } else {\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)\n e = 0\n }\n }\n\n for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}\n\n e = (e << mLen) | m\n eLen += mLen\n for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}\n\n buffer[offset + i - d] |= s * 128\n}\n","/*!\n * The buffer module from node.js, for the browser.\n *\n * @author Feross Aboukhadijeh <https://feross.org>\n * @license MIT\n */\n/* eslint-disable no-proto */\n\n'use strict'\n\nvar base64 = require('base64-js')\nvar ieee754 = require('ieee754')\nvar customInspectSymbol =\n (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation\n ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation\n : null\n\nexports.Buffer = Buffer\nexports.SlowBuffer = SlowBuffer\nexports.INSPECT_MAX_BYTES = 50\n\nvar K_MAX_LENGTH = 0x7fffffff\nexports.kMaxLength = K_MAX_LENGTH\n\n/**\n * If `Buffer.TYPED_ARRAY_SUPPORT`:\n * === true Use Uint8Array implementation (fastest)\n * === false Print warning and recommend using `buffer` v4.x which has an Object\n * implementation (most compatible, even IE6)\n *\n * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,\n * Opera 11.6+, iOS 4.2+.\n *\n * We report that the browser does not support typed arrays if the are not subclassable\n * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`\n * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support\n * for __proto__ and has a buggy typed array implementation.\n */\nBuffer.TYPED_ARRAY_SUPPORT = typedArraySupport()\n\nif (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&\n typeof console.error === 'function') {\n console.error(\n 'This browser lacks typed array (Uint8Array) support which is required by ' +\n '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'\n )\n}\n\nfunction typedArraySupport () {\n // Can typed array instances can be augmented?\n try {\n var arr = new Uint8Array(1)\n var proto = { foo: function () { return 42 } }\n Object.setPrototypeOf(proto, Uint8Array.prototype)\n Object.setPrototypeOf(arr, proto)\n return arr.foo() === 42\n } catch (e) {\n return false\n }\n}\n\nObject.defineProperty(Buffer.prototype, 'parent', {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined\n return this.buffer\n }\n})\n\nObject.defineProperty(Buffer.prototype, 'offset', {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined\n return this.byteOffset\n }\n})\n\nfunction createBuffer (length) {\n if (length > K_MAX_LENGTH) {\n throw new RangeError('The value \"' + length + '\" is invalid for option \"size\"')\n }\n // Return an augmented `Uint8Array` instance\n var buf = new Uint8Array(length)\n Object.setPrototypeOf(buf, Buffer.prototype)\n return buf\n}\n\n/**\n * The Buffer constructor returns instances of `Uint8Array` that have their\n * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of\n * `Uint8Array`, so the returned instances will have all the node `Buffer` methods\n * and the `Uint8Array` methods. Square bracket notation works as expected -- it\n * returns a single octet.\n *\n * The `Uint8Array` prototype remains unmodified.\n */\n\nfunction Buffer (arg, encodingOrOffset, length) {\n // Common case.\n if (typeof arg === 'number') {\n if (typeof encodingOrOffset === 'string') {\n throw new TypeError(\n 'The \"string\" argument must be of type string. Received type number'\n )\n }\n return allocUnsafe(arg)\n }\n return from(arg, encodingOrOffset, length)\n}\n\nBuffer.poolSize = 8192 // not used by this implementation\n\nfunction from (value, encodingOrOffset, length) {\n if (typeof value === 'string') {\n return fromString(value, encodingOrOffset)\n }\n\n if (ArrayBuffer.isView(value)) {\n return fromArrayView(value)\n }\n\n if (value == null) {\n throw new TypeError(\n 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +\n 'or Array-like Object. Received type ' + (typeof value)\n )\n }\n\n if (isInstance(value, ArrayBuffer) ||\n (value && isInstance(value.buffer, ArrayBuffer))) {\n return fromArrayBuffer(value, encodingOrOffset, length)\n }\n\n if (typeof SharedArrayBuffer !== 'undefined' &&\n (isInstance(value, SharedArrayBuffer) ||\n (value && isInstance(value.buffer, SharedArrayBuffer)))) {\n return fromArrayBuffer(value, encodingOrOffset, length)\n }\n\n if (typeof value === 'number') {\n throw new TypeError(\n 'The \"value\" argument must not be of type number. Received type number'\n )\n }\n\n var valueOf = value.valueOf && value.valueOf()\n if (valueOf != null && valueOf !== value) {\n return Buffer.from(valueOf, encodingOrOffset, length)\n }\n\n var b = fromObject(value)\n if (b) return b\n\n if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&\n typeof value[Symbol.toPrimitive] === 'function') {\n return Buffer.from(\n value[Symbol.toPrimitive]('string'), encodingOrOffset, length\n )\n }\n\n throw new TypeError(\n 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +\n 'or Array-like Object. Received type ' + (typeof value)\n )\n}\n\n/**\n * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError\n * if value is a number.\n * Buffer.from(str[, encoding])\n * Buffer.from(array)\n * Buffer.from(buffer)\n * Buffer.from(arrayBuffer[, byteOffset[, length]])\n **/\nBuffer.from = function (value, encodingOrOffset, length) {\n return from(value, encodingOrOffset, length)\n}\n\n// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:\n// https://github.com/feross/buffer/pull/148\nObject.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)\nObject.setPrototypeOf(Buffer, Uint8Array)\n\nfunction assertSize (size) {\n if (typeof size !== 'number') {\n throw new TypeError('\"size\" argument must be of type number')\n } else if (size < 0) {\n throw new RangeError('The value \"' + size + '\" is invalid for option \"size\"')\n }\n}\n\nfunction alloc (size, fill, encoding) {\n assertSize(size)\n if (size <= 0) {\n return createBuffer(size)\n }\n if (fill !== undefined) {\n // Only pay attention to encoding if it's a string. This\n // prevents accidentally sending in a number that would\n // be interpreted as a start offset.\n return typeof encoding === 'string'\n ? createBuffer(size).fill(fill, encoding)\n : createBuffer(size).fill(fill)\n }\n return createBuffer(size)\n}\n\n/**\n * Creates a new filled Buffer instance.\n * alloc(size[, fill[, encoding]])\n **/\nBuffer.alloc = function (size, fill, encoding) {\n return alloc(size, fill, encoding)\n}\n\nfunction allocUnsafe (size) {\n assertSize(size)\n return createBuffer(size < 0 ? 0 : checked(size) | 0)\n}\n\n/**\n * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.\n * */\nBuffer.allocUnsafe = function (size) {\n return allocUnsafe(size)\n}\n/**\n * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.\n */\nBuffer.allocUnsafeSlow = function (size) {\n return allocUnsafe(size)\n}\n\nfunction fromString (string, encoding) {\n if (typeof encoding !== 'string' || encoding === '') {\n encoding = 'utf8'\n }\n\n if (!Buffer.isEncoding(encoding)) {\n throw new TypeError('Unknown encoding: ' + encoding)\n }\n\n var length = byteLength(string, encoding) | 0\n var buf = createBuffer(length)\n\n var actual = buf.write(string, encoding)\n\n if (actual !== length) {\n // Writing a hex string, for example, that contains invalid characters will\n // cause everything after the first invalid character to be ignored. (e.g.\n // 'abxxcd' will be treated as 'ab')\n buf = buf.slice(0, actual)\n }\n\n return buf\n}\n\nfunction fromArrayLike (array) {\n var length = array.length < 0 ? 0 : checked(array.length) | 0\n var buf = createBuffer(length)\n for (var i = 0; i < length; i += 1) {\n buf[i] = array[i] & 255\n }\n return buf\n}\n\nfunction fromArrayView (arrayView) {\n if (isInstance(arrayView, Uint8Array)) {\n var copy = new Uint8Array(arrayView)\n return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)\n }\n return fromArrayLike(arrayView)\n}\n\nfunction fromArrayBuffer (array, byteOffset, length) {\n if (byteOffset < 0 || array.byteLength < byteOffset) {\n throw new RangeError('\"offset\" is outside of buffer bounds')\n }\n\n if (array.byteLength < byteOffset + (length || 0)) {\n throw new RangeError('\"length\" is outside of buffer bounds')\n }\n\n var buf\n if (byteOffset === undefined && length === undefined) {\n buf = new Uint8Array(array)\n } else if (length === undefined) {\n buf = new Uint8Array(array, byteOffset)\n } else {\n buf = new Uint8Array(array, byteOffset, length)\n }\n\n // Return an augmented `Uint8Array` instance\n Object.setPrototypeOf(buf, Buffer.prototype)\n\n return buf\n}\n\nfunction fromObject (obj) {\n if (Buffer.isBuffer(obj)) {\n var len = checked(obj.length) | 0\n var buf = createBuffer(len)\n\n if (buf.length === 0) {\n return buf\n }\n\n obj.copy(buf, 0, 0, len)\n return buf\n }\n\n if (obj.length !== undefined) {\n if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {\n return createBuffer(0)\n }\n return fromArrayLike(obj)\n }\n\n if (obj.type === 'Buffer' && Array.isArray(obj.data)) {\n return fromArrayLike(obj.data)\n }\n}\n\nfunction checked (length) {\n // Note: cannot use `length < K_MAX_LENGTH` here because that fails when\n // length is NaN (which is otherwise coerced to zero.)\n if (length >= K_MAX_LENGTH) {\n throw new RangeError('Attempt to allocate Buffer larger than maximum ' +\n 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')\n }\n return length | 0\n}\n\nfunction SlowBuffer (length) {\n if (+length != length) { // eslint-disable-line eqeqeq\n length = 0\n }\n return Buffer.alloc(+length)\n}\n\nBuffer.isBuffer = function isBuffer (b) {\n return b != null && b._isBuffer === true &&\n b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false\n}\n\nBuffer.compare = function compare (a, b) {\n if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)\n if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)\n if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {\n throw new TypeError(\n 'The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array'\n )\n }\n\n if (a === b) return 0\n\n var x = a.length\n var y = b.length\n\n for (var i = 0, len = Math.min(x, y); i < len; ++i) {\n if (a[i] !== b[i]) {\n x = a[i]\n y = b[i]\n break\n }\n }\n\n if (x < y) return -1\n if (y < x) return 1\n return 0\n}\n\nBuffer.isEncoding = function isEncoding (encoding) {\n switch (String(encoding).toLowerCase()) {\n case 'hex':\n case 'utf8':\n case 'utf-8':\n case 'ascii':\n case 'latin1':\n case 'binary':\n case 'base64':\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return true\n default:\n return false\n }\n}\n\nBuffer.concat = function concat (list, length) {\n if (!Array.isArray(list)) {\n throw new TypeError('\"list\" argument must be an Array of Buffers')\n }\n\n if (list.length === 0) {\n return Buffer.alloc(0)\n }\n\n var i\n if (length === undefined) {\n length = 0\n for (i = 0; i < list.length; ++i) {\n length += list[i].length\n }\n }\n\n var buffer = Buffer.allocUnsafe(length)\n var pos = 0\n for (i = 0; i < list.length; ++i) {\n var buf = list[i]\n if (isInstance(buf, Uint8Array)) {\n if (pos + buf.length > buffer.length) {\n Buffer.from(buf).copy(buffer, pos)\n } else {\n Uint8Array.prototype.set.call(\n buffer,\n buf,\n pos\n )\n }\n } else if (!Buffer.isBuffer(buf)) {\n thro