Last active
July 23, 2023 21:18
-
-
Save ffflabs/e929979125358e979eb1db6a9a4b106e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="readXlsxFile.js"></script> | |
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css" /> | |
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jq-3.3.1/dt-1.10.22/datatables.min.js"></script> | |
<div class="container mt-5"> | |
<div class="row"> | |
<div class="col-md-3"></div> | |
<div class="col-md-3"> | |
<input class="form-control" type="file" id="input" accept=".xls,.xlsx" /> | |
</div> | |
<div class="col-md-2"> | |
<button class="btn btn-primary" id="button">Convert</button> | |
</div> | |
<div class="col-md-12"> | |
<pre id="jsondata"></pre> | |
</div> | |
</div> | |
</div> | |
<div class="container"> | |
<table id="control" class="display" style="width: 100%;"></table> | |
</div> | |
<script> | |
let selectedFile; | |
console.log(window.XLSX); | |
document.getElementById('input').addEventListener("change", (event) => { | |
selectedFile = event.target.files[0]; | |
if (!selectedFile) return; | |
let fileReader = new FileReader(); | |
fileReader.readAsArrayBuffer(selectedFile); | |
fileReader.onload = (event) => { | |
let data = event.target.result; | |
console.log(data); | |
/*let workbook = XLSX.read(data, { | |
type: "binary" | |
}); | |
workbook.SheetNames.forEach(sheet => { | |
let rowObject = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheet]); | |
data = rowObject; | |
console.log(rowObject); | |
document.getElementById("jsondata").innerHTML = JSON.stringify(rowObject, undefined, 4) | |
});*/ | |
} | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f = () => { | |
var exports = {}; | |
var module = { exports }; | |
"use strict"; | |
var __create = Object.create; | |
var __defProp = Object.defineProperty; | |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | |
var __getOwnPropNames = Object.getOwnPropertyNames; | |
var __getProtoOf = Object.getPrototypeOf; | |
var __hasOwnProp = Object.prototype.hasOwnProperty; | |
var __commonJS = (cb, mod) => function __require() { | |
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | |
}; | |
var __export = (target, all) => { | |
for (var name in all) | |
__defProp(target, name, { get: all[name], enumerable: true }); | |
}; | |
var __copyProps = (to, from, except, desc) => { | |
if (from && typeof from === "object" || typeof from === "function") { | |
for (let key of __getOwnPropNames(from)) | |
if (!__hasOwnProp.call(to, key) && key !== except) | |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | |
} | |
return to; | |
}; | |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | |
// If the importer is in node compatibility mode or this is not an ESM | |
// file that has been converted to a CommonJS file using a Babel- | |
// compatible transform (i.e. "__esModule" has not been set), then set | |
// "default" to the CommonJS "module.exports" for node compatibility. | |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | |
mod | |
)); | |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | |
// ../../node_modules/xmldom/lib/entities.js | |
var require_entities = __commonJS({ | |
"../../node_modules/xmldom/lib/entities.js"(exports) { | |
exports.entityMap = { | |
lt: "<", | |
gt: ">", | |
amp: "&", | |
quot: '"', | |
apos: "'", | |
Agrave: "\xC0", | |
Aacute: "\xC1", | |
Acirc: "\xC2", | |
Atilde: "\xC3", | |
Auml: "\xC4", | |
Aring: "\xC5", | |
AElig: "\xC6", | |
Ccedil: "\xC7", | |
Egrave: "\xC8", | |
Eacute: "\xC9", | |
Ecirc: "\xCA", | |
Euml: "\xCB", | |
Igrave: "\xCC", | |
Iacute: "\xCD", | |
Icirc: "\xCE", | |
Iuml: "\xCF", | |
ETH: "\xD0", | |
Ntilde: "\xD1", | |
Ograve: "\xD2", | |
Oacute: "\xD3", | |
Ocirc: "\xD4", | |
Otilde: "\xD5", | |
Ouml: "\xD6", | |
Oslash: "\xD8", | |
Ugrave: "\xD9", | |
Uacute: "\xDA", | |
Ucirc: "\xDB", | |
Uuml: "\xDC", | |
Yacute: "\xDD", | |
THORN: "\xDE", | |
szlig: "\xDF", | |
agrave: "\xE0", | |
aacute: "\xE1", | |
acirc: "\xE2", | |
atilde: "\xE3", | |
auml: "\xE4", | |
aring: "\xE5", | |
aelig: "\xE6", | |
ccedil: "\xE7", | |
egrave: "\xE8", | |
eacute: "\xE9", | |
ecirc: "\xEA", | |
euml: "\xEB", | |
igrave: "\xEC", | |
iacute: "\xED", | |
icirc: "\xEE", | |
iuml: "\xEF", | |
eth: "\xF0", | |
ntilde: "\xF1", | |
ograve: "\xF2", | |
oacute: "\xF3", | |
ocirc: "\xF4", | |
otilde: "\xF5", | |
ouml: "\xF6", | |
oslash: "\xF8", | |
ugrave: "\xF9", | |
uacute: "\xFA", | |
ucirc: "\xFB", | |
uuml: "\xFC", | |
yacute: "\xFD", | |
thorn: "\xFE", | |
yuml: "\xFF", | |
nbsp: "\xA0", | |
iexcl: "\xA1", | |
cent: "\xA2", | |
pound: "\xA3", | |
curren: "\xA4", | |
yen: "\xA5", | |
brvbar: "\xA6", | |
sect: "\xA7", | |
uml: "\xA8", | |
copy: "\xA9", | |
ordf: "\xAA", | |
laquo: "\xAB", | |
not: "\xAC", | |
shy: "\xAD\xAD", | |
reg: "\xAE", | |
macr: "\xAF", | |
deg: "\xB0", | |
plusmn: "\xB1", | |
sup2: "\xB2", | |
sup3: "\xB3", | |
acute: "\xB4", | |
micro: "\xB5", | |
para: "\xB6", | |
middot: "\xB7", | |
cedil: "\xB8", | |
sup1: "\xB9", | |
ordm: "\xBA", | |
raquo: "\xBB", | |
frac14: "\xBC", | |
frac12: "\xBD", | |
frac34: "\xBE", | |
iquest: "\xBF", | |
times: "\xD7", | |
divide: "\xF7", | |
forall: "\u2200", | |
part: "\u2202", | |
exist: "\u2203", | |
empty: "\u2205", | |
nabla: "\u2207", | |
isin: "\u2208", | |
notin: "\u2209", | |
ni: "\u220B", | |
prod: "\u220F", | |
sum: "\u2211", | |
minus: "\u2212", | |
lowast: "\u2217", | |
radic: "\u221A", | |
prop: "\u221D", | |
infin: "\u221E", | |
ang: "\u2220", | |
and: "\u2227", | |
or: "\u2228", | |
cap: "\u2229", | |
cup: "\u222A", | |
"int": "\u222B", | |
there4: "\u2234", | |
sim: "\u223C", | |
cong: "\u2245", | |
asymp: "\u2248", | |
ne: "\u2260", | |
equiv: "\u2261", | |
le: "\u2264", | |
ge: "\u2265", | |
sub: "\u2282", | |
sup: "\u2283", | |
nsub: "\u2284", | |
sube: "\u2286", | |
supe: "\u2287", | |
oplus: "\u2295", | |
otimes: "\u2297", | |
perp: "\u22A5", | |
sdot: "\u22C5", | |
Alpha: "\u0391", | |
Beta: "\u0392", | |
Gamma: "\u0393", | |
Delta: "\u0394", | |
Epsilon: "\u0395", | |
Zeta: "\u0396", | |
Eta: "\u0397", | |
Theta: "\u0398", | |
Iota: "\u0399", | |
Kappa: "\u039A", | |
Lambda: "\u039B", | |
Mu: "\u039C", | |
Nu: "\u039D", | |
Xi: "\u039E", | |
Omicron: "\u039F", | |
Pi: "\u03A0", | |
Rho: "\u03A1", | |
Sigma: "\u03A3", | |
Tau: "\u03A4", | |
Upsilon: "\u03A5", | |
Phi: "\u03A6", | |
Chi: "\u03A7", | |
Psi: "\u03A8", | |
Omega: "\u03A9", | |
alpha: "\u03B1", | |
beta: "\u03B2", | |
gamma: "\u03B3", | |
delta: "\u03B4", | |
epsilon: "\u03B5", | |
zeta: "\u03B6", | |
eta: "\u03B7", | |
theta: "\u03B8", | |
iota: "\u03B9", | |
kappa: "\u03BA", | |
lambda: "\u03BB", | |
mu: "\u03BC", | |
nu: "\u03BD", | |
xi: "\u03BE", | |
omicron: "\u03BF", | |
pi: "\u03C0", | |
rho: "\u03C1", | |
sigmaf: "\u03C2", | |
sigma: "\u03C3", | |
tau: "\u03C4", | |
upsilon: "\u03C5", | |
phi: "\u03C6", | |
chi: "\u03C7", | |
psi: "\u03C8", | |
omega: "\u03C9", | |
thetasym: "\u03D1", | |
upsih: "\u03D2", | |
piv: "\u03D6", | |
OElig: "\u0152", | |
oelig: "\u0153", | |
Scaron: "\u0160", | |
scaron: "\u0161", | |
Yuml: "\u0178", | |
fnof: "\u0192", | |
circ: "\u02C6", | |
tilde: "\u02DC", | |
ensp: "\u2002", | |
emsp: "\u2003", | |
thinsp: "\u2009", | |
zwnj: "\u200C", | |
zwj: "\u200D", | |
lrm: "\u200E", | |
rlm: "\u200F", | |
ndash: "\u2013", | |
mdash: "\u2014", | |
lsquo: "\u2018", | |
rsquo: "\u2019", | |
sbquo: "\u201A", | |
ldquo: "\u201C", | |
rdquo: "\u201D", | |
bdquo: "\u201E", | |
dagger: "\u2020", | |
Dagger: "\u2021", | |
bull: "\u2022", | |
hellip: "\u2026", | |
permil: "\u2030", | |
prime: "\u2032", | |
Prime: "\u2033", | |
lsaquo: "\u2039", | |
rsaquo: "\u203A", | |
oline: "\u203E", | |
euro: "\u20AC", | |
trade: "\u2122", | |
larr: "\u2190", | |
uarr: "\u2191", | |
rarr: "\u2192", | |
darr: "\u2193", | |
harr: "\u2194", | |
crarr: "\u21B5", | |
lceil: "\u2308", | |
rceil: "\u2309", | |
lfloor: "\u230A", | |
rfloor: "\u230B", | |
loz: "\u25CA", | |
spades: "\u2660", | |
clubs: "\u2663", | |
hearts: "\u2665", | |
diams: "\u2666" | |
}; | |
} | |
}); | |
// ../../node_modules/xmldom/lib/sax.js | |
var require_sax = __commonJS({ | |
"../../node_modules/xmldom/lib/sax.js"(exports) { | |
var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/; | |
var nameChar = new RegExp("[\\-\\.0-9" + nameStartChar.source.slice(1, -1) + "\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"); | |
var tagNamePattern = new RegExp("^" + nameStartChar.source + nameChar.source + "*(?::" + nameStartChar.source + nameChar.source + "*)?$"); | |
var S_TAG = 0; | |
var S_ATTR = 1; | |
var S_ATTR_SPACE = 2; | |
var S_EQ = 3; | |
var S_ATTR_NOQUOT_VALUE = 4; | |
var S_ATTR_END = 5; | |
var S_TAG_SPACE = 6; | |
var S_TAG_CLOSE = 7; | |
function ParseError(message, locator) { | |
this.message = message; | |
this.locator = locator; | |
if (Error.captureStackTrace) | |
Error.captureStackTrace(this, ParseError); | |
} | |
ParseError.prototype = new Error(); | |
ParseError.prototype.name = ParseError.name; | |
function XMLReader() { | |
} | |
XMLReader.prototype = { | |
parse: function (source, defaultNSMap, entityMap) { | |
var domBuilder = this.domBuilder; | |
domBuilder.startDocument(); | |
_copy(defaultNSMap, defaultNSMap = {}); | |
parse( | |
source, | |
defaultNSMap, | |
entityMap, | |
domBuilder, | |
this.errorHandler | |
); | |
domBuilder.endDocument(); | |
} | |
}; | |
function parse(source, defaultNSMapCopy, entityMap, domBuilder, errorHandler) { | |
function fixedFromCharCode(code) { | |
if (code > 65535) { | |
code -= 65536; | |
var surrogate1 = 55296 + (code >> 10), surrogate2 = 56320 + (code & 1023); | |
return String.fromCharCode(surrogate1, surrogate2); | |
} else { | |
return String.fromCharCode(code); | |
} | |
} | |
function entityReplacer(a2) { | |
var k = a2.slice(1, -1); | |
if (k in entityMap) { | |
return entityMap[k]; | |
} else if (k.charAt(0) === "#") { | |
return fixedFromCharCode(parseInt(k.substr(1).replace("x", "0x"))); | |
} else { | |
errorHandler.error("entity not found:" + a2); | |
return a2; | |
} | |
} | |
function appendText(end2) { | |
if (end2 > start) { | |
var xt = source.substring(start, end2).replace(/&#?\w+;/g, entityReplacer); | |
locator && position(start); | |
domBuilder.characters(xt, 0, end2 - start); | |
start = end2; | |
} | |
} | |
function position(p, m) { | |
while (p >= lineEnd && (m = linePattern.exec(source))) { | |
lineStart = m.index; | |
lineEnd = lineStart + m[0].length; | |
locator.lineNumber++; | |
} | |
locator.columnNumber = p - lineStart + 1; | |
} | |
var lineStart = 0; | |
var lineEnd = 0; | |
var linePattern = /.*(?:\r\n?|\n)|.*$/g; | |
var locator = domBuilder.locator; | |
var parseStack = [{ currentNSMap: defaultNSMapCopy }]; | |
var closeMap = {}; | |
var start = 0; | |
while (true) { | |
try { | |
var tagStart = source.indexOf("<", start); | |
if (tagStart < 0) { | |
if (!source.substr(start).match(/^\s*$/)) { | |
var doc = domBuilder.doc; | |
var text = doc.createTextNode(source.substr(start)); | |
doc.appendChild(text); | |
domBuilder.currentElement = text; | |
} | |
return; | |
} | |
if (tagStart > start) { | |
appendText(tagStart); | |
} | |
switch (source.charAt(tagStart + 1)) { | |
case "/": | |
var end = source.indexOf(">", tagStart + 3); | |
var tagName = source.substring(tagStart + 2, end); | |
var config = parseStack.pop(); | |
if (end < 0) { | |
tagName = source.substring(tagStart + 2).replace(/[\s<].*/, ""); | |
errorHandler.error("end tag name: " + tagName + " is not complete:" + config.tagName); | |
end = tagStart + 1 + tagName.length; | |
} else if (tagName.match(/\s</)) { | |
tagName = tagName.replace(/[\s<].*/, ""); | |
errorHandler.error("end tag name: " + tagName + " maybe not complete"); | |
end = tagStart + 1 + tagName.length; | |
} | |
var localNSMap = config.localNSMap; | |
var endMatch = config.tagName == tagName; | |
var endIgnoreCaseMach = endMatch || config.tagName && config.tagName.toLowerCase() == tagName.toLowerCase(); | |
if (endIgnoreCaseMach) { | |
domBuilder.endElement(config.uri, config.localName, tagName); | |
if (localNSMap) { | |
for (var prefix in localNSMap) { | |
domBuilder.endPrefixMapping(prefix); | |
} | |
} | |
if (!endMatch) { | |
errorHandler.fatalError("end tag name: " + tagName + " is not match the current start tagName:" + config.tagName); | |
} | |
} else { | |
parseStack.push(config); | |
} | |
end++; | |
break; | |
case "?": | |
locator && position(tagStart); | |
end = parseInstruction(source, tagStart, domBuilder); | |
break; | |
case "!": | |
locator && position(tagStart); | |
end = parseDCC(source, tagStart, domBuilder, errorHandler); | |
break; | |
default: | |
locator && position(tagStart); | |
var el = new ElementAttributes(); | |
var currentNSMap = parseStack[parseStack.length - 1].currentNSMap; | |
var end = parseElementStartPart(source, tagStart, el, currentNSMap, entityReplacer, errorHandler); | |
var len = el.length; | |
if (!el.closed && fixSelfClosed(source, end, el.tagName, closeMap)) { | |
el.closed = true; | |
if (!entityMap.nbsp) { | |
errorHandler.warning("unclosed xml attribute"); | |
} | |
} | |
if (locator && len) { | |
var locator2 = copyLocator(locator, {}); | |
for (var i2 = 0; i2 < len; i2++) { | |
var a = el[i2]; | |
position(a.offset); | |
a.locator = copyLocator(locator, {}); | |
} | |
domBuilder.locator = locator2; | |
if (appendElement(el, domBuilder, currentNSMap)) { | |
parseStack.push(el); | |
} | |
domBuilder.locator = locator; | |
} else { | |
if (appendElement(el, domBuilder, currentNSMap)) { | |
parseStack.push(el); | |
} | |
} | |
if (el.uri === "http://www.w3.org/1999/xhtml" && !el.closed) { | |
end = parseHtmlSpecialContent(source, end, el.tagName, entityReplacer, domBuilder); | |
} else { | |
end++; | |
} | |
} | |
} catch (e) { | |
if (e instanceof ParseError) { | |
throw e; | |
} | |
errorHandler.error("element parse error: " + e); | |
end = -1; | |
} | |
if (end > start) { | |
start = end; | |
} else { | |
appendText(Math.max(tagStart, start) + 1); | |
} | |
} | |
} | |
function copyLocator(f, t) { | |
t.lineNumber = f.lineNumber; | |
t.columnNumber = f.columnNumber; | |
return t; | |
} | |
function parseElementStartPart(source, start, el, currentNSMap, entityReplacer, errorHandler) { | |
function addAttribute(qname, value2, startIndex) { | |
if (qname in el.attributeNames) | |
errorHandler.fatalError("Attribute " + qname + " redefined"); | |
el.addValue(qname, value2, startIndex); | |
} | |
var attrName; | |
var value; | |
var p = ++start; | |
var s = S_TAG; | |
while (true) { | |
var c = source.charAt(p); | |
switch (c) { | |
case "=": | |
if (s === S_ATTR) { | |
attrName = source.slice(start, p); | |
s = S_EQ; | |
} else if (s === S_ATTR_SPACE) { | |
s = S_EQ; | |
} else { | |
throw new Error("attribute equal must after attrName"); | |
} | |
break; | |
case "'": | |
case '"': | |
if (s === S_EQ || s === S_ATTR) { | |
if (s === S_ATTR) { | |
errorHandler.warning('attribute value must after "="'); | |
attrName = source.slice(start, p); | |
} | |
start = p + 1; | |
p = source.indexOf(c, start); | |
if (p > 0) { | |
value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer); | |
addAttribute(attrName, value, start - 1); | |
s = S_ATTR_END; | |
} else { | |
throw new Error("attribute value no end '" + c + "' match"); | |
} | |
} else if (s == S_ATTR_NOQUOT_VALUE) { | |
value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer); | |
addAttribute(attrName, value, start); | |
errorHandler.warning('attribute "' + attrName + '" missed start quot(' + c + ")!!"); | |
start = p + 1; | |
s = S_ATTR_END; | |
} else { | |
throw new Error('attribute value must after "="'); | |
} | |
break; | |
case "/": | |
switch (s) { | |
case S_TAG: | |
el.setTagName(source.slice(start, p)); | |
case S_ATTR_END: | |
case S_TAG_SPACE: | |
case S_TAG_CLOSE: | |
s = S_TAG_CLOSE; | |
el.closed = true; | |
case S_ATTR_NOQUOT_VALUE: | |
case S_ATTR: | |
case S_ATTR_SPACE: | |
break; | |
default: | |
throw new Error("attribute invalid close char('/')"); | |
} | |
break; | |
case "": | |
errorHandler.error("unexpected end of input"); | |
if (s == S_TAG) { | |
el.setTagName(source.slice(start, p)); | |
} | |
return p; | |
case ">": | |
switch (s) { | |
case S_TAG: | |
el.setTagName(source.slice(start, p)); | |
case S_ATTR_END: | |
case S_TAG_SPACE: | |
case S_TAG_CLOSE: | |
break; | |
case S_ATTR_NOQUOT_VALUE: | |
case S_ATTR: | |
value = source.slice(start, p); | |
if (value.slice(-1) === "/") { | |
el.closed = true; | |
value = value.slice(0, -1); | |
} | |
case S_ATTR_SPACE: | |
if (s === S_ATTR_SPACE) { | |
value = attrName; | |
} | |
if (s == S_ATTR_NOQUOT_VALUE) { | |
errorHandler.warning('attribute "' + value + '" missed quot(")!'); | |
addAttribute(attrName, value.replace(/&#?\w+;/g, entityReplacer), start); | |
} else { | |
if (currentNSMap[""] !== "http://www.w3.org/1999/xhtml" || !value.match(/^(?:disabled|checked|selected)$/i)) { | |
errorHandler.warning('attribute "' + value + '" missed value!! "' + value + '" instead!!'); | |
} | |
addAttribute(value, value, start); | |
} | |
break; | |
case S_EQ: | |
throw new Error("attribute value missed!!"); | |
} | |
return p; | |
case "\x80": | |
c = " "; | |
default: | |
if (c <= " ") { | |
switch (s) { | |
case S_TAG: | |
el.setTagName(source.slice(start, p)); | |
s = S_TAG_SPACE; | |
break; | |
case S_ATTR: | |
attrName = source.slice(start, p); | |
s = S_ATTR_SPACE; | |
break; | |
case S_ATTR_NOQUOT_VALUE: | |
var value = source.slice(start, p).replace(/&#?\w+;/g, entityReplacer); | |
errorHandler.warning('attribute "' + value + '" missed quot(")!!'); | |
addAttribute(attrName, value, start); | |
case S_ATTR_END: | |
s = S_TAG_SPACE; | |
break; | |
} | |
} else { | |
switch (s) { | |
case S_ATTR_SPACE: | |
var tagName = el.tagName; | |
if (currentNSMap[""] !== "http://www.w3.org/1999/xhtml" || !attrName.match(/^(?:disabled|checked|selected)$/i)) { | |
errorHandler.warning('attribute "' + attrName + '" missed value!! "' + attrName + '" instead2!!'); | |
} | |
addAttribute(attrName, attrName, start); | |
start = p; | |
s = S_ATTR; | |
break; | |
case S_ATTR_END: | |
errorHandler.warning('attribute space is required"' + attrName + '"!!'); | |
case S_TAG_SPACE: | |
s = S_ATTR; | |
start = p; | |
break; | |
case S_EQ: | |
s = S_ATTR_NOQUOT_VALUE; | |
start = p; | |
break; | |
case S_TAG_CLOSE: | |
throw new Error("elements closed character '/' and '>' must be connected to"); | |
} | |
} | |
} | |
p++; | |
} | |
} | |
function appendElement(el, domBuilder, currentNSMap) { | |
var tagName = el.tagName; | |
var localNSMap = null; | |
var i2 = el.length; | |
while (i2--) { | |
var a = el[i2]; | |
var qName = a.qName; | |
var value = a.value; | |
var nsp = qName.indexOf(":"); | |
if (nsp > 0) { | |
var prefix = a.prefix = qName.slice(0, nsp); | |
var localName = qName.slice(nsp + 1); | |
var nsPrefix = prefix === "xmlns" && localName; | |
} else { | |
localName = qName; | |
prefix = null; | |
nsPrefix = qName === "xmlns" && ""; | |
} | |
a.localName = localName; | |
if (nsPrefix !== false) { | |
if (localNSMap == null) { | |
localNSMap = {}; | |
_copy(currentNSMap, currentNSMap = {}); | |
} | |
currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value; | |
a.uri = "http://www.w3.org/2000/xmlns/"; | |
domBuilder.startPrefixMapping(nsPrefix, value); | |
} | |
} | |
var i2 = el.length; | |
while (i2--) { | |
a = el[i2]; | |
var prefix = a.prefix; | |
if (prefix) { | |
if (prefix === "xml") { | |
a.uri = "http://www.w3.org/XML/1998/namespace"; | |
} | |
if (prefix !== "xmlns") { | |
a.uri = currentNSMap[prefix || ""]; | |
} | |
} | |
} | |
var nsp = tagName.indexOf(":"); | |
if (nsp > 0) { | |
prefix = el.prefix = tagName.slice(0, nsp); | |
localName = el.localName = tagName.slice(nsp + 1); | |
} else { | |
prefix = null; | |
localName = el.localName = tagName; | |
} | |
var ns = el.uri = currentNSMap[prefix || ""]; | |
domBuilder.startElement(ns, localName, tagName, el); | |
if (el.closed) { | |
domBuilder.endElement(ns, localName, tagName); | |
if (localNSMap) { | |
for (prefix in localNSMap) { | |
domBuilder.endPrefixMapping(prefix); | |
} | |
} | |
} else { | |
el.currentNSMap = currentNSMap; | |
el.localNSMap = localNSMap; | |
return true; | |
} | |
} | |
function parseHtmlSpecialContent(source, elStartEnd, tagName, entityReplacer, domBuilder) { | |
if (/^(?:script|textarea)$/i.test(tagName)) { | |
var elEndStart = source.indexOf("</" + tagName + ">", elStartEnd); | |
var text = source.substring(elStartEnd + 1, elEndStart); | |
if (/[&<]/.test(text)) { | |
if (/^script$/i.test(tagName)) { | |
domBuilder.characters(text, 0, text.length); | |
return elEndStart; | |
} | |
text = text.replace(/&#?\w+;/g, entityReplacer); | |
domBuilder.characters(text, 0, text.length); | |
return elEndStart; | |
} | |
} | |
return elStartEnd + 1; | |
} | |
function fixSelfClosed(source, elStartEnd, tagName, closeMap) { | |
var pos = closeMap[tagName]; | |
if (pos == null) { | |
pos = source.lastIndexOf("</" + tagName + ">"); | |
if (pos < elStartEnd) { | |
pos = source.lastIndexOf("</" + tagName); | |
} | |
closeMap[tagName] = pos; | |
} | |
return pos < elStartEnd; | |
} | |
function _copy(source, target) { | |
for (var n in source) { | |
target[n] = source[n]; | |
} | |
} | |
function parseDCC(source, start, domBuilder, errorHandler) { | |
var next = source.charAt(start + 2); | |
switch (next) { | |
case "-": | |
if (source.charAt(start + 3) === "-") { | |
var end = source.indexOf("-->", start + 4); | |
if (end > start) { | |
domBuilder.comment(source, start + 4, end - start - 4); | |
return end + 3; | |
} else { | |
errorHandler.error("Unclosed comment"); | |
return -1; | |
} | |
} else { | |
return -1; | |
} | |
default: | |
if (source.substr(start + 3, 6) == "CDATA[") { | |
var end = source.indexOf("]]>", start + 9); | |
domBuilder.startCDATA(); | |
domBuilder.characters(source, start + 9, end - start - 9); | |
domBuilder.endCDATA(); | |
return end + 3; | |
} | |
var matchs = split(source, start); | |
var len = matchs.length; | |
if (len > 1 && /!doctype/i.test(matchs[0][0])) { | |
var name = matchs[1][0]; | |
var pubid = false; | |
var sysid = false; | |
if (len > 3) { | |
if (/^public$/i.test(matchs[2][0])) { | |
pubid = matchs[3][0]; | |
sysid = len > 4 && matchs[4][0]; | |
} else if (/^system$/i.test(matchs[2][0])) { | |
sysid = matchs[3][0]; | |
} | |
} | |
var lastMatch = matchs[len - 1]; | |
domBuilder.startDTD(name, pubid, sysid); | |
domBuilder.endDTD(); | |
return lastMatch.index + lastMatch[0].length; | |
} | |
} | |
return -1; | |
} | |
function parseInstruction(source, start, domBuilder) { | |
var end = source.indexOf("?>", start); | |
if (end) { | |
var match = source.substring(start, end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/); | |
if (match) { | |
var len = match[0].length; | |
domBuilder.processingInstruction(match[1], match[2]); | |
return end + 2; | |
} else { | |
return -1; | |
} | |
} | |
return -1; | |
} | |
function ElementAttributes() { | |
this.attributeNames = {}; | |
} | |
ElementAttributes.prototype = { | |
setTagName: function (tagName) { | |
if (!tagNamePattern.test(tagName)) { | |
throw new Error("invalid tagName:" + tagName); | |
} | |
this.tagName = tagName; | |
}, | |
addValue: function (qName, value, offset) { | |
if (!tagNamePattern.test(qName)) { | |
throw new Error("invalid attribute:" + qName); | |
} | |
this.attributeNames[qName] = this.length; | |
this[this.length++] = { qName, value, offset }; | |
}, | |
length: 0, | |
getLocalName: function (i2) { | |
return this[i2].localName; | |
}, | |
getLocator: function (i2) { | |
return this[i2].locator; | |
}, | |
getQName: function (i2) { | |
return this[i2].qName; | |
}, | |
getURI: function (i2) { | |
return this[i2].uri; | |
}, | |
getValue: function (i2) { | |
return this[i2].value; | |
} | |
// ,getIndex:function(uri, localName)){ | |
// if(localName){ | |
// | |
// }else{ | |
// var qName = uri | |
// } | |
// }, | |
// getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))}, | |
// getType:function(uri,localName){} | |
// getType:function(i){}, | |
}; | |
function split(source, start) { | |
var match; | |
var buf = []; | |
var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g; | |
reg.lastIndex = start; | |
reg.exec(source); | |
while (match = reg.exec(source)) { | |
buf.push(match); | |
if (match[1]) | |
return buf; | |
} | |
} | |
exports.XMLReader = XMLReader; | |
exports.ParseError = ParseError; | |
} | |
}); | |
// ../../node_modules/xmldom/lib/dom.js | |
var require_dom = __commonJS({ | |
"../../node_modules/xmldom/lib/dom.js"(exports) { | |
function copy(src, dest) { | |
for (var p in src) { | |
dest[p] = src[p]; | |
} | |
} | |
function _extends(Class, Super) { | |
var pt = Class.prototype; | |
if (!(pt instanceof Super)) { | |
let t2 = function () { | |
}; | |
var t = t2; | |
; | |
t2.prototype = Super.prototype; | |
t2 = new t2(); | |
copy(pt, t2); | |
Class.prototype = pt = t2; | |
} | |
if (pt.constructor != Class) { | |
if (typeof Class != "function") { | |
console.error("unknow Class:" + Class); | |
} | |
pt.constructor = Class; | |
} | |
} | |
var htmlns = "http://www.w3.org/1999/xhtml"; | |
var NodeType = {}; | |
var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1; | |
var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2; | |
var TEXT_NODE = NodeType.TEXT_NODE = 3; | |
var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4; | |
var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5; | |
var ENTITY_NODE = NodeType.ENTITY_NODE = 6; | |
var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7; | |
var COMMENT_NODE = NodeType.COMMENT_NODE = 8; | |
var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9; | |
var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10; | |
var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11; | |
var NOTATION_NODE = NodeType.NOTATION_NODE = 12; | |
var ExceptionCode = {}; | |
var ExceptionMessage = {}; | |
var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = (ExceptionMessage[1] = "Index size error", 1); | |
var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = (ExceptionMessage[2] = "DOMString size error", 2); | |
var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = (ExceptionMessage[3] = "Hierarchy request error", 3); | |
var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = (ExceptionMessage[4] = "Wrong document", 4); | |
var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = (ExceptionMessage[5] = "Invalid character", 5); | |
var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = (ExceptionMessage[6] = "No data allowed", 6); | |
var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = (ExceptionMessage[7] = "No modification allowed", 7); | |
var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = (ExceptionMessage[8] = "Not found", 8); | |
var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = (ExceptionMessage[9] = "Not supported", 9); | |
var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = (ExceptionMessage[10] = "Attribute in use", 10); | |
var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = (ExceptionMessage[11] = "Invalid state", 11); | |
var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = (ExceptionMessage[12] = "Syntax error", 12); | |
var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = (ExceptionMessage[13] = "Invalid modification", 13); | |
var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = (ExceptionMessage[14] = "Invalid namespace", 14); | |
var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = (ExceptionMessage[15] = "Invalid access", 15); | |
function DOMException(code, message) { | |
if (message instanceof Error) { | |
var error = message; | |
} else { | |
error = this; | |
Error.call(this, ExceptionMessage[code]); | |
this.message = ExceptionMessage[code]; | |
if (Error.captureStackTrace) | |
Error.captureStackTrace(this, DOMException); | |
} | |
error.code = code; | |
if (message) | |
this.message = this.message + ": " + message; | |
return error; | |
} | |
DOMException.prototype = Error.prototype; | |
copy(ExceptionCode, DOMException); | |
function NodeList() { | |
} | |
NodeList.prototype = { | |
/** | |
* The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive. | |
* @standard level1 | |
*/ | |
length: 0, | |
/** | |
* Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null. | |
* @standard level1 | |
* @param index unsigned long | |
* Index into the collection. | |
* @return Node | |
* The node at the indexth position in the NodeList, or null if that is not a valid index. | |
*/ | |
item: function (index) { | |
return this[index] || null; | |
}, | |
toString: function (isHTML, nodeFilter) { | |
for (var buf = [], i2 = 0; i2 < this.length; i2++) { | |
serializeToString(this[i2], buf, isHTML, nodeFilter); | |
} | |
return buf.join(""); | |
} | |
}; | |
function LiveNodeList(node, refresh) { | |
this._node = node; | |
this._refresh = refresh; | |
_updateLiveList(this); | |
} | |
function _updateLiveList(list) { | |
var inc = list._node._inc || list._node.ownerDocument._inc; | |
if (list._inc != inc) { | |
var ls = list._refresh(list._node); | |
__set__(list, "length", ls.length); | |
copy(ls, list); | |
list._inc = inc; | |
} | |
} | |
LiveNodeList.prototype.item = function (i2) { | |
_updateLiveList(this); | |
return this[i2]; | |
}; | |
_extends(LiveNodeList, NodeList); | |
function NamedNodeMap() { | |
} | |
function _findNodeIndex(list, node) { | |
var i2 = list.length; | |
while (i2--) { | |
if (list[i2] === node) { | |
return i2; | |
} | |
} | |
} | |
function _addNamedNode(el, list, newAttr, oldAttr) { | |
if (oldAttr) { | |
list[_findNodeIndex(list, oldAttr)] = newAttr; | |
} else { | |
list[list.length++] = newAttr; | |
} | |
if (el) { | |
newAttr.ownerElement = el; | |
var doc = el.ownerDocument; | |
if (doc) { | |
oldAttr && _onRemoveAttribute(doc, el, oldAttr); | |
_onAddAttribute(doc, el, newAttr); | |
} | |
} | |
} | |
function _removeNamedNode(el, list, attr) { | |
var i2 = _findNodeIndex(list, attr); | |
if (i2 >= 0) { | |
var lastIndex = list.length - 1; | |
while (i2 < lastIndex) { | |
list[i2] = list[++i2]; | |
} | |
list.length = lastIndex; | |
if (el) { | |
var doc = el.ownerDocument; | |
if (doc) { | |
_onRemoveAttribute(doc, el, attr); | |
attr.ownerElement = null; | |
} | |
} | |
} else { | |
throw DOMException(NOT_FOUND_ERR, new Error(el.tagName + "@" + attr)); | |
} | |
} | |
NamedNodeMap.prototype = { | |
length: 0, | |
item: NodeList.prototype.item, | |
getNamedItem: function (key) { | |
var i2 = this.length; | |
while (i2--) { | |
var attr = this[i2]; | |
if (attr.nodeName == key) { | |
return attr; | |
} | |
} | |
}, | |
setNamedItem: function (attr) { | |
var el = attr.ownerElement; | |
if (el && el != this._ownerElement) { | |
throw new DOMException(INUSE_ATTRIBUTE_ERR); | |
} | |
var oldAttr = this.getNamedItem(attr.nodeName); | |
_addNamedNode(this._ownerElement, this, attr, oldAttr); | |
return oldAttr; | |
}, | |
/* returns Node */ | |
setNamedItemNS: function (attr) { | |
var el = attr.ownerElement, oldAttr; | |
if (el && el != this._ownerElement) { | |
throw new DOMException(INUSE_ATTRIBUTE_ERR); | |
} | |
oldAttr = this.getNamedItemNS(attr.namespaceURI, attr.localName); | |
_addNamedNode(this._ownerElement, this, attr, oldAttr); | |
return oldAttr; | |
}, | |
/* returns Node */ | |
removeNamedItem: function (key) { | |
var attr = this.getNamedItem(key); | |
_removeNamedNode(this._ownerElement, this, attr); | |
return attr; | |
}, | |
// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR | |
//for level2 | |
removeNamedItemNS: function (namespaceURI, localName) { | |
var attr = this.getNamedItemNS(namespaceURI, localName); | |
_removeNamedNode(this._ownerElement, this, attr); | |
return attr; | |
}, | |
getNamedItemNS: function (namespaceURI, localName) { | |
var i2 = this.length; | |
while (i2--) { | |
var node = this[i2]; | |
if (node.localName == localName && node.namespaceURI == namespaceURI) { | |
return node; | |
} | |
} | |
return null; | |
} | |
}; | |
function DOMImplementation(features) { | |
this._features = {}; | |
if (features) { | |
for (var feature in features) { | |
this._features = features[feature]; | |
} | |
} | |
} | |
DOMImplementation.prototype = { | |
hasFeature: function (feature, version) { | |
var versions = this._features[feature.toLowerCase()]; | |
if (versions && (!version || version in versions)) { | |
return true; | |
} else { | |
return false; | |
} | |
}, | |
// Introduced in DOM Level 2: | |
createDocument: function (namespaceURI, qualifiedName, doctype) { | |
var doc = new Document(); | |
doc.implementation = this; | |
doc.childNodes = new NodeList(); | |
doc.doctype = doctype; | |
if (doctype) { | |
doc.appendChild(doctype); | |
} | |
if (qualifiedName) { | |
var root = doc.createElementNS(namespaceURI, qualifiedName); | |
doc.appendChild(root); | |
} | |
return doc; | |
}, | |
// Introduced in DOM Level 2: | |
createDocumentType: function (qualifiedName, publicId, systemId) { | |
var node = new DocumentType(); | |
node.name = qualifiedName; | |
node.nodeName = qualifiedName; | |
node.publicId = publicId; | |
node.systemId = systemId; | |
return node; | |
} | |
}; | |
function Node() { | |
} | |
Node.prototype = { | |
firstChild: null, | |
lastChild: null, | |
previousSibling: null, | |
nextSibling: null, | |
attributes: null, | |
parentNode: null, | |
childNodes: null, | |
ownerDocument: null, | |
nodeValue: null, | |
namespaceURI: null, | |
prefix: null, | |
localName: null, | |
// Modified in DOM Level 2: | |
insertBefore: function (newChild, refChild) { | |
return _insertBefore(this, newChild, refChild); | |
}, | |
replaceChild: function (newChild, oldChild) { | |
this.insertBefore(newChild, oldChild); | |
if (oldChild) { | |
this.removeChild(oldChild); | |
} | |
}, | |
removeChild: function (oldChild) { | |
return _removeChild(this, oldChild); | |
}, | |
appendChild: function (newChild) { | |
return this.insertBefore(newChild, null); | |
}, | |
hasChildNodes: function () { | |
return this.firstChild != null; | |
}, | |
cloneNode: function (deep) { | |
return cloneNode(this.ownerDocument || this, this, deep); | |
}, | |
// Modified in DOM Level 2: | |
normalize: function () { | |
var child = this.firstChild; | |
while (child) { | |
var next = child.nextSibling; | |
if (next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE) { | |
this.removeChild(next); | |
child.appendData(next.data); | |
} else { | |
child.normalize(); | |
child = next; | |
} | |
} | |
}, | |
// Introduced in DOM Level 2: | |
isSupported: function (feature, version) { | |
return this.ownerDocument.implementation.hasFeature(feature, version); | |
}, | |
// Introduced in DOM Level 2: | |
hasAttributes: function () { | |
return this.attributes.length > 0; | |
}, | |
lookupPrefix: function (namespaceURI) { | |
var el = this; | |
while (el) { | |
var map2 = el._nsMap; | |
if (map2) { | |
for (var n in map2) { | |
if (map2[n] == namespaceURI) { | |
return n; | |
} | |
} | |
} | |
el = el.nodeType == ATTRIBUTE_NODE ? el.ownerDocument : el.parentNode; | |
} | |
return null; | |
}, | |
// Introduced in DOM Level 3: | |
lookupNamespaceURI: function (prefix) { | |
var el = this; | |
while (el) { | |
var map2 = el._nsMap; | |
if (map2) { | |
if (prefix in map2) { | |
return map2[prefix]; | |
} | |
} | |
el = el.nodeType == ATTRIBUTE_NODE ? el.ownerDocument : el.parentNode; | |
} | |
return null; | |
}, | |
// Introduced in DOM Level 3: | |
isDefaultNamespace: function (namespaceURI) { | |
var prefix = this.lookupPrefix(namespaceURI); | |
return prefix == null; | |
} | |
}; | |
function _xmlEncoder(c) { | |
return c == "<" && "<" || c == ">" && ">" || c == "&" && "&" || c == '"' && """ || "&#" + c.charCodeAt() + ";"; | |
} | |
copy(NodeType, Node); | |
copy(NodeType, Node.prototype); | |
function _visitNode(node, callback) { | |
if (callback(node)) { | |
return true; | |
} | |
if (node = node.firstChild) { | |
do { | |
if (_visitNode(node, callback)) { | |
return true; | |
} | |
} while (node = node.nextSibling); | |
} | |
} | |
function Document() { | |
} | |
function _onAddAttribute(doc, el, newAttr) { | |
doc && doc._inc++; | |
var ns = newAttr.namespaceURI; | |
if (ns == "http://www.w3.org/2000/xmlns/") { | |
el._nsMap[newAttr.prefix ? newAttr.localName : ""] = newAttr.value; | |
} | |
} | |
function _onRemoveAttribute(doc, el, newAttr, remove) { | |
doc && doc._inc++; | |
var ns = newAttr.namespaceURI; | |
if (ns == "http://www.w3.org/2000/xmlns/") { | |
delete el._nsMap[newAttr.prefix ? newAttr.localName : ""]; | |
} | |
} | |
function _onUpdateChild(doc, el, newChild) { | |
if (doc && doc._inc) { | |
doc._inc++; | |
var cs = el.childNodes; | |
if (newChild) { | |
cs[cs.length++] = newChild; | |
} else { | |
var child = el.firstChild; | |
var i2 = 0; | |
while (child) { | |
cs[i2++] = child; | |
child = child.nextSibling; | |
} | |
cs.length = i2; | |
} | |
} | |
} | |
function _removeChild(parentNode, child) { | |
var previous = child.previousSibling; | |
var next = child.nextSibling; | |
if (previous) { | |
previous.nextSibling = next; | |
} else { | |
parentNode.firstChild = next; | |
} | |
if (next) { | |
next.previousSibling = previous; | |
} else { | |
parentNode.lastChild = previous; | |
} | |
_onUpdateChild(parentNode.ownerDocument, parentNode); | |
return child; | |
} | |
function _insertBefore(parentNode, newChild, nextChild) { | |
var cp = newChild.parentNode; | |
if (cp) { | |
cp.removeChild(newChild); | |
} | |
if (newChild.nodeType === DOCUMENT_FRAGMENT_NODE) { | |
var newFirst = newChild.firstChild; | |
if (newFirst == null) { | |
return newChild; | |
} | |
var newLast = newChild.lastChild; | |
} else { | |
newFirst = newLast = newChild; | |
} | |
var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild; | |
newFirst.previousSibling = pre; | |
newLast.nextSibling = nextChild; | |
if (pre) { | |
pre.nextSibling = newFirst; | |
} else { | |
parentNode.firstChild = newFirst; | |
} | |
if (nextChild == null) { | |
parentNode.lastChild = newLast; | |
} else { | |
nextChild.previousSibling = newLast; | |
} | |
do { | |
newFirst.parentNode = parentNode; | |
} while (newFirst !== newLast && (newFirst = newFirst.nextSibling)); | |
_onUpdateChild(parentNode.ownerDocument || parentNode, parentNode); | |
if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) { | |
newChild.firstChild = newChild.lastChild = null; | |
} | |
return newChild; | |
} | |
function _appendSingleChild(parentNode, newChild) { | |
var cp = newChild.parentNode; | |
if (cp) { | |
var pre = parentNode.lastChild; | |
cp.removeChild(newChild); | |
var pre = parentNode.lastChild; | |
} | |
var pre = parentNode.lastChild; | |
newChild.parentNode = parentNode; | |
newChild.previousSibling = pre; | |
newChild.nextSibling = null; | |
if (pre) { | |
pre.nextSibling = newChild; | |
} else { | |
parentNode.firstChild = newChild; | |
} | |
parentNode.lastChild = newChild; | |
_onUpdateChild(parentNode.ownerDocument, parentNode, newChild); | |
return newChild; | |
} | |
Document.prototype = { | |
//implementation : null, | |
nodeName: "#document", | |
nodeType: DOCUMENT_NODE, | |
doctype: null, | |
documentElement: null, | |
_inc: 1, | |
insertBefore: function (newChild, refChild) { | |
if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) { | |
var child = newChild.firstChild; | |
while (child) { | |
var next = child.nextSibling; | |
this.insertBefore(child, refChild); | |
child = next; | |
} | |
return newChild; | |
} | |
if (this.documentElement == null && newChild.nodeType == ELEMENT_NODE) { | |
this.documentElement = newChild; | |
} | |
return _insertBefore(this, newChild, refChild), newChild.ownerDocument = this, newChild; | |
}, | |
removeChild: function (oldChild) { | |
if (this.documentElement == oldChild) { | |
this.documentElement = null; | |
} | |
return _removeChild(this, oldChild); | |
}, | |
// Introduced in DOM Level 2: | |
importNode: function (importedNode, deep) { | |
return importNode(this, importedNode, deep); | |
}, | |
// Introduced in DOM Level 2: | |
getElementById: function (id) { | |
var rtv = null; | |
_visitNode(this.documentElement, function (node) { | |
if (node.nodeType == ELEMENT_NODE) { | |
if (node.getAttribute("id") == id) { | |
rtv = node; | |
return true; | |
} | |
} | |
}); | |
return rtv; | |
}, | |
getElementsByClassName: function (className) { | |
var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)"); | |
return new LiveNodeList(this, function (base) { | |
var ls = []; | |
_visitNode(base.documentElement, function (node) { | |
if (node !== base && node.nodeType == ELEMENT_NODE) { | |
if (pattern.test(node.getAttribute("class"))) { | |
ls.push(node); | |
} | |
} | |
}); | |
return ls; | |
}); | |
}, | |
//document factory method: | |
createElement: function (tagName) { | |
var node = new Element(); | |
node.ownerDocument = this; | |
node.nodeName = tagName; | |
node.tagName = tagName; | |
node.childNodes = new NodeList(); | |
var attrs = node.attributes = new NamedNodeMap(); | |
attrs._ownerElement = node; | |
return node; | |
}, | |
createDocumentFragment: function () { | |
var node = new DocumentFragment(); | |
node.ownerDocument = this; | |
node.childNodes = new NodeList(); | |
return node; | |
}, | |
createTextNode: function (data) { | |
var node = new Text(); | |
node.ownerDocument = this; | |
node.appendData(data); | |
return node; | |
}, | |
createComment: function (data) { | |
var node = new Comment(); | |
node.ownerDocument = this; | |
node.appendData(data); | |
return node; | |
}, | |
createCDATASection: function (data) { | |
var node = new CDATASection(); | |
node.ownerDocument = this; | |
node.appendData(data); | |
return node; | |
}, | |
createProcessingInstruction: function (target, data) { | |
var node = new ProcessingInstruction(); | |
node.ownerDocument = this; | |
node.tagName = node.target = target; | |
node.nodeValue = node.data = data; | |
return node; | |
}, | |
createAttribute: function (name) { | |
var node = new Attr(); | |
node.ownerDocument = this; | |
node.name = name; | |
node.nodeName = name; | |
node.localName = name; | |
node.specified = true; | |
return node; | |
}, | |
createEntityReference: function (name) { | |
var node = new EntityReference(); | |
node.ownerDocument = this; | |
node.nodeName = name; | |
return node; | |
}, | |
// Introduced in DOM Level 2: | |
createElementNS: function (namespaceURI, qualifiedName) { | |
var node = new Element(); | |
var pl = qualifiedName.split(":"); | |
var attrs = node.attributes = new NamedNodeMap(); | |
node.childNodes = new NodeList(); | |
node.ownerDocument = this; | |
node.nodeName = qualifiedName; | |
node.tagName = qualifiedName; | |
node.namespaceURI = namespaceURI; | |
if (pl.length == 2) { | |
node.prefix = pl[0]; | |
node.localName = pl[1]; | |
} else { | |
node.localName = qualifiedName; | |
} | |
attrs._ownerElement = node; | |
return node; | |
}, | |
// Introduced in DOM Level 2: | |
createAttributeNS: function (namespaceURI, qualifiedName) { | |
var node = new Attr(); | |
var pl = qualifiedName.split(":"); | |
node.ownerDocument = this; | |
node.nodeName = qualifiedName; | |
node.name = qualifiedName; | |
node.namespaceURI = namespaceURI; | |
node.specified = true; | |
if (pl.length == 2) { | |
node.prefix = pl[0]; | |
node.localName = pl[1]; | |
} else { | |
node.localName = qualifiedName; | |
} | |
return node; | |
} | |
}; | |
_extends(Document, Node); | |
function Element() { | |
this._nsMap = {}; | |
} | |
Element.prototype = { | |
nodeType: ELEMENT_NODE, | |
hasAttribute: function (name) { | |
return this.getAttributeNode(name) != null; | |
}, | |
getAttribute: function (name) { | |
var attr = this.getAttributeNode(name); | |
return attr && attr.value || ""; | |
}, | |
getAttributeNode: function (name) { | |
return this.attributes.getNamedItem(name); | |
}, | |
setAttribute: function (name, value) { | |
var attr = this.ownerDocument.createAttribute(name); | |
attr.value = attr.nodeValue = "" + value; | |
this.setAttributeNode(attr); | |
}, | |
removeAttribute: function (name) { | |
var attr = this.getAttributeNode(name); | |
attr && this.removeAttributeNode(attr); | |
}, | |
//four real opeartion method | |
appendChild: function (newChild) { | |
if (newChild.nodeType === DOCUMENT_FRAGMENT_NODE) { | |
return this.insertBefore(newChild, null); | |
} else { | |
return _appendSingleChild(this, newChild); | |
} | |
}, | |
setAttributeNode: function (newAttr) { | |
return this.attributes.setNamedItem(newAttr); | |
}, | |
setAttributeNodeNS: function (newAttr) { | |
return this.attributes.setNamedItemNS(newAttr); | |
}, | |
removeAttributeNode: function (oldAttr) { | |
return this.attributes.removeNamedItem(oldAttr.nodeName); | |
}, | |
//get real attribute name,and remove it by removeAttributeNode | |
removeAttributeNS: function (namespaceURI, localName) { | |
var old = this.getAttributeNodeNS(namespaceURI, localName); | |
old && this.removeAttributeNode(old); | |
}, | |
hasAttributeNS: function (namespaceURI, localName) { | |
return this.getAttributeNodeNS(namespaceURI, localName) != null; | |
}, | |
getAttributeNS: function (namespaceURI, localName) { | |
var attr = this.getAttributeNodeNS(namespaceURI, localName); | |
return attr && attr.value || ""; | |
}, | |
setAttributeNS: function (namespaceURI, qualifiedName, value) { | |
var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName); | |
attr.value = attr.nodeValue = "" + value; | |
this.setAttributeNode(attr); | |
}, | |
getAttributeNodeNS: function (namespaceURI, localName) { | |
return this.attributes.getNamedItemNS(namespaceURI, localName); | |
}, | |
getElementsByTagName: function (tagName) { | |
return new LiveNodeList(this, function (base) { | |
var ls = []; | |
_visitNode(base, function (node) { | |
if (node !== base && node.nodeType == ELEMENT_NODE && (tagName === "*" || node.tagName == tagName)) { | |
ls.push(node); | |
} | |
}); | |
return ls; | |
}); | |
}, | |
getElementsByTagNameNS: function (namespaceURI, localName) { | |
return new LiveNodeList(this, function (base) { | |
var ls = []; | |
_visitNode(base, function (node) { | |
if (node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === "*" || node.namespaceURI === namespaceURI) && (localName === "*" || node.localName == localName)) { | |
ls.push(node); | |
} | |
}); | |
return ls; | |
}); | |
} | |
}; | |
Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName; | |
Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS; | |
_extends(Element, Node); | |
function Attr() { | |
} | |
Attr.prototype.nodeType = ATTRIBUTE_NODE; | |
_extends(Attr, Node); | |
function CharacterData() { | |
} | |
CharacterData.prototype = { | |
data: "", | |
substringData: function (offset, count) { | |
return this.data.substring(offset, offset + count); | |
}, | |
appendData: function (text) { | |
text = this.data + text; | |
this.nodeValue = this.data = text; | |
this.length = text.length; | |
}, | |
insertData: function (offset, text) { | |
this.replaceData(offset, 0, text); | |
}, | |
appendChild: function (newChild) { | |
throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR]); | |
}, | |
deleteData: function (offset, count) { | |
this.replaceData(offset, count, ""); | |
}, | |
replaceData: function (offset, count, text) { | |
var start = this.data.substring(0, offset); | |
var end = this.data.substring(offset + count); | |
text = start + text + end; | |
this.nodeValue = this.data = text; | |
this.length = text.length; | |
} | |
}; | |
_extends(CharacterData, Node); | |
function Text() { | |
} | |
Text.prototype = { | |
nodeName: "#text", | |
nodeType: TEXT_NODE, | |
splitText: function (offset) { | |
var text = this.data; | |
var newText = text.substring(offset); | |
text = text.substring(0, offset); | |
this.data = this.nodeValue = text; | |
this.length = text.length; | |
var newNode = this.ownerDocument.createTextNode(newText); | |
if (this.parentNode) { | |
this.parentNode.insertBefore(newNode, this.nextSibling); | |
} | |
return newNode; | |
} | |
}; | |
_extends(Text, CharacterData); | |
function Comment() { | |
} | |
Comment.prototype = { | |
nodeName: "#comment", | |
nodeType: COMMENT_NODE | |
}; | |
_extends(Comment, CharacterData); | |
function CDATASection() { | |
} | |
CDATASection.prototype = { | |
nodeName: "#cdata-section", | |
nodeType: CDATA_SECTION_NODE | |
}; | |
_extends(CDATASection, CharacterData); | |
function DocumentType() { | |
} | |
DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE; | |
_extends(DocumentType, Node); | |
function Notation() { | |
} | |
Notation.prototype.nodeType = NOTATION_NODE; | |
_extends(Notation, Node); | |
function Entity() { | |
} | |
Entity.prototype.nodeType = ENTITY_NODE; | |
_extends(Entity, Node); | |
function EntityReference() { | |
} | |
EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE; | |
_extends(EntityReference, Node); | |
function DocumentFragment() { | |
} | |
DocumentFragment.prototype.nodeName = "#document-fragment"; | |
DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE; | |
_extends(DocumentFragment, Node); | |
function ProcessingInstruction() { | |
} | |
ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE; | |
_extends(ProcessingInstruction, Node); | |
function XMLSerializer() { | |
} | |
XMLSerializer.prototype.serializeToString = function (node, isHtml, nodeFilter) { | |
return nodeSerializeToString.call(node, isHtml, nodeFilter); | |
}; | |
Node.prototype.toString = nodeSerializeToString; | |
function nodeSerializeToString(isHtml, nodeFilter) { | |
var buf = []; | |
var refNode = this.nodeType == 9 && this.documentElement || this; | |
var prefix = refNode.prefix; | |
var uri = refNode.namespaceURI; | |
if (uri && prefix == null) { | |
var prefix = refNode.lookupPrefix(uri); | |
if (prefix == null) { | |
var visibleNamespaces = [ | |
{ namespace: uri, prefix: null } | |
//{namespace:uri,prefix:''} | |
]; | |
} | |
} | |
serializeToString(this, buf, isHtml, nodeFilter, visibleNamespaces); | |
return buf.join(""); | |
} | |
function needNamespaceDefine(node, isHTML, visibleNamespaces) { | |
var prefix = node.prefix || ""; | |
var uri = node.namespaceURI; | |
if (!prefix && !uri) { | |
return false; | |
} | |
if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace" || uri == "http://www.w3.org/2000/xmlns/") { | |
return false; | |
} | |
var i2 = visibleNamespaces.length; | |
while (i2--) { | |
var ns = visibleNamespaces[i2]; | |
if (ns.prefix == prefix) { | |
return ns.namespace != uri; | |
} | |
} | |
return true; | |
} | |
function serializeToString(node, buf, isHTML, nodeFilter, visibleNamespaces) { | |
if (nodeFilter) { | |
node = nodeFilter(node); | |
if (node) { | |
if (typeof node == "string") { | |
buf.push(node); | |
return; | |
} | |
} else { | |
return; | |
} | |
} | |
switch (node.nodeType) { | |
case ELEMENT_NODE: | |
if (!visibleNamespaces) | |
visibleNamespaces = []; | |
var startVisibleNamespaces = visibleNamespaces.length; | |
var attrs = node.attributes; | |
var len = attrs.length; | |
var child = node.firstChild; | |
var nodeName = node.tagName; | |
isHTML = htmlns === node.namespaceURI || isHTML; | |
buf.push("<", nodeName); | |
for (var i2 = 0; i2 < len; i2++) { | |
var attr = attrs.item(i2); | |
if (attr.prefix == "xmlns") { | |
visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value }); | |
} else if (attr.nodeName == "xmlns") { | |
visibleNamespaces.push({ prefix: "", namespace: attr.value }); | |
} | |
} | |
for (var i2 = 0; i2 < len; i2++) { | |
var attr = attrs.item(i2); | |
if (needNamespaceDefine(attr, isHTML, visibleNamespaces)) { | |
var prefix = attr.prefix || ""; | |
var uri = attr.namespaceURI; | |
var ns = prefix ? " xmlns:" + prefix : " xmlns"; | |
buf.push(ns, '="', uri, '"'); | |
visibleNamespaces.push({ prefix, namespace: uri }); | |
} | |
serializeToString(attr, buf, isHTML, nodeFilter, visibleNamespaces); | |
} | |
if (needNamespaceDefine(node, isHTML, visibleNamespaces)) { | |
var prefix = node.prefix || ""; | |
var uri = node.namespaceURI; | |
if (uri) { | |
var ns = prefix ? " xmlns:" + prefix : " xmlns"; | |
buf.push(ns, '="', uri, '"'); | |
visibleNamespaces.push({ prefix, namespace: uri }); | |
} | |
} | |
if (child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)) { | |
buf.push(">"); | |
if (isHTML && /^script$/i.test(nodeName)) { | |
while (child) { | |
if (child.data) { | |
buf.push(child.data); | |
} else { | |
serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces); | |
} | |
child = child.nextSibling; | |
} | |
} else { | |
while (child) { | |
serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces); | |
child = child.nextSibling; | |
} | |
} | |
buf.push("</", nodeName, ">"); | |
} else { | |
buf.push("/>"); | |
} | |
return; | |
case DOCUMENT_NODE: | |
case DOCUMENT_FRAGMENT_NODE: | |
var child = node.firstChild; | |
while (child) { | |
serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces); | |
child = child.nextSibling; | |
} | |
return; | |
case ATTRIBUTE_NODE: | |
return buf.push(" ", node.name, '="', node.value.replace(/[<&"]/g, _xmlEncoder), '"'); | |
case TEXT_NODE: | |
return buf.push( | |
node.data.replace(/[<&]/g, _xmlEncoder).replace(/]]>/g, "]]>") | |
); | |
case CDATA_SECTION_NODE: | |
return buf.push("<![CDATA[", node.data, "]]>"); | |
case COMMENT_NODE: | |
return buf.push("<!--", node.data, "-->"); | |
case DOCUMENT_TYPE_NODE: | |
var pubid = node.publicId; | |
var sysid = node.systemId; | |
buf.push("<!DOCTYPE ", node.name); | |
if (pubid) { | |
buf.push(" PUBLIC ", pubid); | |
if (sysid && sysid != ".") { | |
buf.push(" ", sysid); | |
} | |
buf.push(">"); | |
} else if (sysid && sysid != ".") { | |
buf.push(" SYSTEM ", sysid, ">"); | |
} else { | |
var sub = node.internalSubset; | |
if (sub) { | |
buf.push(" [", sub, "]"); | |
} | |
buf.push(">"); | |
} | |
return; | |
case PROCESSING_INSTRUCTION_NODE: | |
return buf.push("<?", node.target, " ", node.data, "?>"); | |
case ENTITY_REFERENCE_NODE: | |
return buf.push("&", node.nodeName, ";"); | |
default: | |
buf.push("??", node.nodeName); | |
} | |
} | |
function importNode(doc, node, deep) { | |
var node2; | |
switch (node.nodeType) { | |
case ELEMENT_NODE: | |
node2 = node.cloneNode(false); | |
node2.ownerDocument = doc; | |
case DOCUMENT_FRAGMENT_NODE: | |
break; | |
case ATTRIBUTE_NODE: | |
deep = true; | |
break; | |
} | |
if (!node2) { | |
node2 = node.cloneNode(false); | |
} | |
node2.ownerDocument = doc; | |
node2.parentNode = null; | |
if (deep) { | |
var child = node.firstChild; | |
while (child) { | |
node2.appendChild(importNode(doc, child, deep)); | |
child = child.nextSibling; | |
} | |
} | |
return node2; | |
} | |
function cloneNode(doc, node, deep) { | |
var node2 = new node.constructor(); | |
for (var n in node) { | |
var v = node[n]; | |
if (typeof v != "object") { | |
if (v != node2[n]) { | |
node2[n] = v; | |
} | |
} | |
} | |
if (node.childNodes) { | |
node2.childNodes = new NodeList(); | |
} | |
node2.ownerDocument = doc; | |
switch (node2.nodeType) { | |
case ELEMENT_NODE: | |
var attrs = node.attributes; | |
var attrs2 = node2.attributes = new NamedNodeMap(); | |
var len = attrs.length; | |
attrs2._ownerElement = node2; | |
for (var i2 = 0; i2 < len; i2++) { | |
node2.setAttributeNode(cloneNode(doc, attrs.item(i2), true)); | |
} | |
break; | |
; | |
case ATTRIBUTE_NODE: | |
deep = true; | |
} | |
if (deep) { | |
var child = node.firstChild; | |
while (child) { | |
node2.appendChild(cloneNode(doc, child, deep)); | |
child = child.nextSibling; | |
} | |
} | |
return node2; | |
} | |
function __set__(object, key, value) { | |
object[key] = value; | |
} | |
try { | |
if (Object.defineProperty) { | |
let getTextContent2 = function (node) { | |
switch (node.nodeType) { | |
case ELEMENT_NODE: | |
case DOCUMENT_FRAGMENT_NODE: | |
var buf = []; | |
node = node.firstChild; | |
while (node) { | |
if (node.nodeType !== 7 && node.nodeType !== 8) { | |
buf.push(getTextContent2(node)); | |
} | |
node = node.nextSibling; | |
} | |
return buf.join(""); | |
default: | |
return node.nodeValue; | |
} | |
}; | |
getTextContent = getTextContent2; | |
Object.defineProperty(LiveNodeList.prototype, "length", { | |
get: function () { | |
_updateLiveList(this); | |
return this.$$length; | |
} | |
}); | |
Object.defineProperty(Node.prototype, "textContent", { | |
get: function () { | |
return getTextContent2(this); | |
}, | |
set: function (data) { | |
switch (this.nodeType) { | |
case ELEMENT_NODE: | |
case DOCUMENT_FRAGMENT_NODE: | |
while (this.firstChild) { | |
this.removeChild(this.firstChild); | |
} | |
if (data || String(data)) { | |
this.appendChild(this.ownerDocument.createTextNode(data)); | |
} | |
break; | |
default: | |
this.data = data; | |
this.value = data; | |
this.nodeValue = data; | |
} | |
} | |
}); | |
__set__ = function (object, key, value) { | |
object["$$" + key] = value; | |
}; | |
} | |
} catch (e) { | |
} | |
var getTextContent; | |
exports.Node = Node; | |
exports.DOMException = DOMException; | |
exports.DOMImplementation = DOMImplementation; | |
exports.XMLSerializer = XMLSerializer; | |
} | |
}); | |
// ../../node_modules/xmldom/lib/dom-parser.js | |
var require_dom_parser = __commonJS({ | |
"../../node_modules/xmldom/lib/dom-parser.js"(exports) { | |
function DOMParser2(options) { | |
this.options = options || { locator: {} }; | |
} | |
DOMParser2.prototype.parseFromString = function (source, mimeType) { | |
var options = this.options; | |
var sax2 = new XMLReader(); | |
var domBuilder = options.domBuilder || new DOMHandler(); | |
var errorHandler = options.errorHandler; | |
var locator = options.locator; | |
var defaultNSMap = options.xmlns || {}; | |
var isHTML = /\/x?html?$/.test(mimeType); | |
var entityMap = isHTML ? htmlEntity.entityMap : { "lt": "<", "gt": ">", "amp": "&", "quot": '"', "apos": "'" }; | |
if (locator) { | |
domBuilder.setDocumentLocator(locator); | |
} | |
sax2.errorHandler = buildErrorHandler(errorHandler, domBuilder, locator); | |
sax2.domBuilder = options.domBuilder || domBuilder; | |
if (isHTML) { | |
defaultNSMap[""] = "http://www.w3.org/1999/xhtml"; | |
} | |
defaultNSMap.xml = defaultNSMap.xml || "http://www.w3.org/XML/1998/namespace"; | |
if (source && typeof source === "string") { | |
sax2.parse(source, defaultNSMap, entityMap); | |
} else { | |
sax2.errorHandler.error("invalid doc source"); | |
} | |
return domBuilder.doc; | |
}; | |
function buildErrorHandler(errorImpl, domBuilder, locator) { | |
if (!errorImpl) { | |
if (domBuilder instanceof DOMHandler) { | |
return domBuilder; | |
} | |
errorImpl = domBuilder; | |
} | |
var errorHandler = {}; | |
var isCallback = errorImpl instanceof Function; | |
locator = locator || {}; | |
function build(key) { | |
var fn = errorImpl[key]; | |
if (!fn && isCallback) { | |
fn = errorImpl.length == 2 ? function (msg) { | |
errorImpl(key, msg); | |
} : errorImpl; | |
} | |
errorHandler[key] = fn && function (msg) { | |
fn("[xmldom " + key + "] " + msg + _locator(locator)); | |
} || function () { | |
}; | |
} | |
build("warning"); | |
build("error"); | |
build("fatalError"); | |
return errorHandler; | |
} | |
function DOMHandler() { | |
this.cdata = false; | |
} | |
function position(locator, node) { | |
node.lineNumber = locator.lineNumber; | |
node.columnNumber = locator.columnNumber; | |
} | |
DOMHandler.prototype = { | |
startDocument: function () { | |
this.doc = new DOMImplementation().createDocument(null, null, null); | |
if (this.locator) { | |
this.doc.documentURI = this.locator.systemId; | |
} | |
}, | |
startElement: function (namespaceURI, localName, qName, attrs) { | |
var doc = this.doc; | |
var el = doc.createElementNS(namespaceURI, qName || localName); | |
var len = attrs.length; | |
appendElement(this, el); | |
this.currentElement = el; | |
this.locator && position(this.locator, el); | |
for (var i2 = 0; i2 < len; i2++) { | |
var namespaceURI = attrs.getURI(i2); | |
var value = attrs.getValue(i2); | |
var qName = attrs.getQName(i2); | |
var attr = doc.createAttributeNS(namespaceURI, qName); | |
this.locator && position(attrs.getLocator(i2), attr); | |
attr.value = attr.nodeValue = value; | |
el.setAttributeNode(attr); | |
} | |
}, | |
endElement: function (namespaceURI, localName, qName) { | |
var current = this.currentElement; | |
var tagName = current.tagName; | |
this.currentElement = current.parentNode; | |
}, | |
startPrefixMapping: function (prefix, uri) { | |
}, | |
endPrefixMapping: function (prefix) { | |
}, | |
processingInstruction: function (target, data) { | |
var ins = this.doc.createProcessingInstruction(target, data); | |
this.locator && position(this.locator, ins); | |
appendElement(this, ins); | |
}, | |
ignorableWhitespace: function (ch, start, length) { | |
}, | |
characters: function (chars, start, length) { | |
chars = _toString.apply(this, arguments); | |
if (chars) { | |
if (this.cdata) { | |
var charNode = this.doc.createCDATASection(chars); | |
} else { | |
var charNode = this.doc.createTextNode(chars); | |
} | |
if (this.currentElement) { | |
this.currentElement.appendChild(charNode); | |
} else if (/^\s*$/.test(chars)) { | |
this.doc.appendChild(charNode); | |
} | |
this.locator && position(this.locator, charNode); | |
} | |
}, | |
skippedEntity: function (name) { | |
}, | |
endDocument: function () { | |
this.doc.normalize(); | |
}, | |
setDocumentLocator: function (locator) { | |
if (this.locator = locator) { | |
locator.lineNumber = 0; | |
} | |
}, | |
//LexicalHandler | |
comment: function (chars, start, length) { | |
chars = _toString.apply(this, arguments); | |
var comm = this.doc.createComment(chars); | |
this.locator && position(this.locator, comm); | |
appendElement(this, comm); | |
}, | |
startCDATA: function () { | |
this.cdata = true; | |
}, | |
endCDATA: function () { | |
this.cdata = false; | |
}, | |
startDTD: function (name, publicId, systemId) { | |
var impl = this.doc.implementation; | |
if (impl && impl.createDocumentType) { | |
var dt = impl.createDocumentType(name, publicId, systemId); | |
this.locator && position(this.locator, dt); | |
appendElement(this, dt); | |
} | |
}, | |
/** | |
* @see org.xml.sax.ErrorHandler | |
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html | |
*/ | |
warning: function (error) { | |
console.warn("[xmldom warning] " + error, _locator(this.locator)); | |
}, | |
error: function (error) { | |
console.error("[xmldom error] " + error, _locator(this.locator)); | |
}, | |
fatalError: function (error) { | |
throw new ParseError(error, this.locator); | |
} | |
}; | |
function _locator(l) { | |
if (l) { | |
return "\n@" + (l.systemId || "") + "#[line:" + l.lineNumber + ",col:" + l.columnNumber + "]"; | |
} | |
} | |
function _toString(chars, start, length) { | |
if (typeof chars == "string") { | |
return chars.substr(start, length); | |
} else { | |
if (chars.length >= start + length || start) { | |
return new java.lang.String(chars, start, length) + ""; | |
} | |
return chars; | |
} | |
} | |
"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g, function (key) { | |
DOMHandler.prototype[key] = function () { | |
return null; | |
}; | |
}); | |
function appendElement(hander, node) { | |
if (!hander.currentElement) { | |
hander.doc.appendChild(node); | |
} else { | |
hander.currentElement.appendChild(node); | |
} | |
} | |
var htmlEntity = require_entities(); | |
var sax = require_sax(); | |
var XMLReader = sax.XMLReader; | |
var ParseError = sax.ParseError; | |
var DOMImplementation = exports.DOMImplementation = require_dom().DOMImplementation; | |
exports.XMLSerializer = require_dom().XMLSerializer; | |
exports.DOMParser = DOMParser2; | |
exports.__DOMHandler = DOMHandler; | |
} | |
}); | |
// src/etf_providers/spdr/readXlsxFileBrowser.ts | |
var readXlsxFileBrowser_exports = {}; | |
__export(readXlsxFileBrowser_exports, { | |
Email: () => Email, | |
Integer: () => Integer, | |
URL: () => URL2, | |
default: () => readXlsxFile, | |
parseExcelDate: () => parseExcelDate, | |
readSheetNames: () => readSheetNames | |
}); | |
module.exports = __toCommonJS(readXlsxFileBrowser_exports); | |
var import_xmldom = __toESM(require_dom_parser(), 1); | |
var xmlBrowser_default = { | |
createDocument(content) { | |
return new import_xmldom.DOMParser().parseFromString(content.trim(), "text/xml"); | |
} | |
}; | |
var u8 = Uint8Array; | |
var u16 = Uint16Array; | |
var u32 = Uint32Array; | |
var fleb = new u8([ | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
1, | |
1, | |
1, | |
1, | |
2, | |
2, | |
2, | |
2, | |
3, | |
3, | |
3, | |
3, | |
4, | |
4, | |
4, | |
4, | |
5, | |
5, | |
5, | |
5, | |
0, | |
/* unused */ | |
0, | |
0, | |
/* impossible */ | |
0 | |
]); | |
var fdeb = new u8([ | |
0, | |
0, | |
0, | |
0, | |
1, | |
1, | |
2, | |
2, | |
3, | |
3, | |
4, | |
4, | |
5, | |
5, | |
6, | |
6, | |
7, | |
7, | |
8, | |
8, | |
9, | |
9, | |
10, | |
10, | |
11, | |
11, | |
12, | |
12, | |
13, | |
13, | |
/* unused */ | |
0, | |
0 | |
]); | |
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); | |
var freb = function (eb, start) { | |
var b = new u16(31); | |
for (var i2 = 0; i2 < 31; ++i2) { | |
b[i2] = start += 1 << eb[i2 - 1]; | |
} | |
var r = new u32(b[30]); | |
for (var i2 = 1; i2 < 30; ++i2) { | |
for (var j = b[i2]; j < b[i2 + 1]; ++j) { | |
r[j] = j - b[i2] << 5 | i2; | |
} | |
} | |
return [b, r]; | |
}; | |
var _a = freb(fleb, 2); | |
var fl = _a[0]; | |
var revfl = _a[1]; | |
fl[28] = 258, revfl[258] = 28; | |
var _b = freb(fdeb, 0); | |
var fd = _b[0]; | |
var revfd = _b[1]; | |
var rev = new u16(32768); | |
for (i = 0; i < 32768; ++i) { | |
x = (i & 43690) >>> 1 | (i & 21845) << 1; | |
x = (x & 52428) >>> 2 | (x & 13107) << 2; | |
x = (x & 61680) >>> 4 | (x & 3855) << 4; | |
rev[i] = ((x & 65280) >>> 8 | (x & 255) << 8) >>> 1; | |
} | |
var x; | |
var i; | |
var hMap = function (cd, mb, r) { | |
var s = cd.length; | |
var i2 = 0; | |
var l = new u16(mb); | |
for (; i2 < s; ++i2) { | |
if (cd[i2]) | |
++l[cd[i2] - 1]; | |
} | |
var le = new u16(mb); | |
for (i2 = 0; i2 < mb; ++i2) { | |
le[i2] = le[i2 - 1] + l[i2 - 1] << 1; | |
} | |
var co; | |
if (r) { | |
co = new u16(1 << mb); | |
var rvb = 15 - mb; | |
for (i2 = 0; i2 < s; ++i2) { | |
if (cd[i2]) { | |
var sv = i2 << 4 | cd[i2]; | |
var r_1 = mb - cd[i2]; | |
var v = le[cd[i2] - 1]++ << r_1; | |
for (var m = v | (1 << r_1) - 1; v <= m; ++v) { | |
co[rev[v] >>> rvb] = sv; | |
} | |
} | |
} | |
} else { | |
co = new u16(s); | |
for (i2 = 0; i2 < s; ++i2) { | |
if (cd[i2]) { | |
co[i2] = rev[le[cd[i2] - 1]++] >>> 15 - cd[i2]; | |
} | |
} | |
} | |
return co; | |
}; | |
var flt = new u8(288); | |
for (i = 0; i < 144; ++i) | |
flt[i] = 8; | |
var i; | |
for (i = 144; i < 256; ++i) | |
flt[i] = 9; | |
var i; | |
for (i = 256; i < 280; ++i) | |
flt[i] = 7; | |
var i; | |
for (i = 280; i < 288; ++i) | |
flt[i] = 8; | |
var i; | |
var fdt = new u8(32); | |
for (i = 0; i < 32; ++i) | |
fdt[i] = 5; | |
var i; | |
var flrm = /* @__PURE__ */ hMap(flt, 9, 1); | |
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1); | |
var max = function (a) { | |
var m = a[0]; | |
for (var i2 = 1; i2 < a.length; ++i2) { | |
if (a[i2] > m) | |
m = a[i2]; | |
} | |
return m; | |
}; | |
var bits = function (d, p, m) { | |
var o = p / 8 | 0; | |
return (d[o] | d[o + 1] << 8) >> (p & 7) & m; | |
}; | |
var bits16 = function (d, p) { | |
var o = p / 8 | 0; | |
return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7); | |
}; | |
var shft = function (p) { | |
return (p + 7) / 8 | 0; | |
}; | |
var slc = function (v, s, e) { | |
if (s == null || s < 0) | |
s = 0; | |
if (e == null || e > v.length) | |
e = v.length; | |
var n = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e - s); | |
n.set(v.subarray(s, e)); | |
return n; | |
}; | |
var ec = [ | |
"unexpected EOF", | |
"invalid block type", | |
"invalid length/literal", | |
"invalid distance", | |
"stream finished", | |
"no stream handler", | |
, | |
"no callback", | |
"invalid UTF-8 data", | |
"extra field too long", | |
"date not in range 1980-2099", | |
"filename too long", | |
"stream finishing", | |
"invalid zip data" | |
// determined by unknown compression method | |
]; | |
var err = function (ind, msg, nt) { | |
var e = new Error(msg || ec[ind]); | |
e.code = ind; | |
if (Error.captureStackTrace) | |
Error.captureStackTrace(e, err); | |
if (!nt) | |
throw e; | |
return e; | |
}; | |
var inflt = function (dat, buf, st) { | |
var sl = dat.length; | |
if (!sl || st && st.f && !st.l) | |
return buf || new u8(0); | |
var noBuf = !buf || st; | |
var noSt = !st || st.i; | |
if (!st) | |
st = {}; | |
if (!buf) | |
buf = new u8(sl * 3); | |
var cbuf = function (l2) { | |
var bl = buf.length; | |
if (l2 > bl) { | |
var nbuf = new u8(Math.max(bl * 2, l2)); | |
nbuf.set(buf); | |
buf = nbuf; | |
} | |
}; | |
var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n; | |
var tbts = sl * 8; | |
do { | |
if (!lm) { | |
final = bits(dat, pos, 1); | |
var type = bits(dat, pos + 1, 3); | |
pos += 3; | |
if (!type) { | |
var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l; | |
if (t > sl) { | |
if (noSt) | |
err(0); | |
break; | |
} | |
if (noBuf) | |
cbuf(bt + l); | |
buf.set(dat.subarray(s, t), bt); | |
st.b = bt += l, st.p = pos = t * 8, st.f = final; | |
continue; | |
} else if (type == 1) | |
lm = flrm, dm = fdrm, lbt = 9, dbt = 5; | |
else if (type == 2) { | |
var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4; | |
var tl = hLit + bits(dat, pos + 5, 31) + 1; | |
pos += 14; | |
var ldt = new u8(tl); | |
var clt = new u8(19); | |
for (var i2 = 0; i2 < hcLen; ++i2) { | |
clt[clim[i2]] = bits(dat, pos + i2 * 3, 7); | |
} | |
pos += hcLen * 3; | |
var clb = max(clt), clbmsk = (1 << clb) - 1; | |
var clm = hMap(clt, clb, 1); | |
for (var i2 = 0; i2 < tl;) { | |
var r = clm[bits(dat, pos, clbmsk)]; | |
pos += r & 15; | |
var s = r >>> 4; | |
if (s < 16) { | |
ldt[i2++] = s; | |
} else { | |
var c = 0, n = 0; | |
if (s == 16) | |
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i2 - 1]; | |
else if (s == 17) | |
n = 3 + bits(dat, pos, 7), pos += 3; | |
else if (s == 18) | |
n = 11 + bits(dat, pos, 127), pos += 7; | |
while (n--) | |
ldt[i2++] = c; | |
} | |
} | |
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit); | |
lbt = max(lt); | |
dbt = max(dt); | |
lm = hMap(lt, lbt, 1); | |
dm = hMap(dt, dbt, 1); | |
} else | |
err(1); | |
if (pos > tbts) { | |
if (noSt) | |
err(0); | |
break; | |
} | |
} | |
if (noBuf) | |
cbuf(bt + 131072); | |
var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1; | |
var lpos = pos; | |
for (; ; lpos = pos) { | |
var c = lm[bits16(dat, pos) & lms], sym = c >>> 4; | |
pos += c & 15; | |
if (pos > tbts) { | |
if (noSt) | |
err(0); | |
break; | |
} | |
if (!c) | |
err(2); | |
if (sym < 256) | |
buf[bt++] = sym; | |
else if (sym == 256) { | |
lpos = pos, lm = null; | |
break; | |
} else { | |
var add = sym - 254; | |
if (sym > 264) { | |
var i2 = sym - 257, b = fleb[i2]; | |
add = bits(dat, pos, (1 << b) - 1) + fl[i2]; | |
pos += b; | |
} | |
var d = dm[bits16(dat, pos) & dms], dsym = d >>> 4; | |
if (!d) | |
err(3); | |
pos += d & 15; | |
var dt = fd[dsym]; | |
if (dsym > 3) { | |
var b = fdeb[dsym]; | |
dt += bits16(dat, pos) & (1 << b) - 1, pos += b; | |
} | |
if (pos > tbts) { | |
if (noSt) | |
err(0); | |
break; | |
} | |
if (noBuf) | |
cbuf(bt + 131072); | |
var end = bt + add; | |
for (; bt < end; bt += 4) { | |
buf[bt] = buf[bt - dt]; | |
buf[bt + 1] = buf[bt + 1 - dt]; | |
buf[bt + 2] = buf[bt + 2 - dt]; | |
buf[bt + 3] = buf[bt + 3 - dt]; | |
} | |
bt = end; | |
} | |
} | |
st.l = lm, st.p = lpos, st.b = bt, st.f = final; | |
if (lm) | |
final = 1, st.m = lbt, st.d = dm, st.n = dbt; | |
} while (!final); | |
return bt == buf.length ? buf : slc(buf, 0, bt); | |
}; | |
var et = /* @__PURE__ */ new u8(0); | |
var b2 = function (d, b) { | |
return d[b] | d[b + 1] << 8; | |
}; | |
var b4 = function (d, b) { | |
return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0; | |
}; | |
var b8 = function (d, b) { | |
return b4(d, b) + b4(d, b + 4) * 4294967296; | |
}; | |
function inflateSync(data, out) { | |
return inflt(data, out); | |
} | |
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder(); | |
var tds = 0; | |
try { | |
td.decode(et, { stream: true }); | |
tds = 1; | |
} catch (e) { | |
} | |
var dutf8 = function (d) { | |
for (var r = "", i2 = 0; ;) { | |
var c = d[i2++]; | |
var eb = (c > 127) + (c > 223) + (c > 239); | |
if (i2 + eb > d.length) | |
return [r, slc(d, i2 - 1)]; | |
if (!eb) | |
r += String.fromCharCode(c); | |
else if (eb == 3) { | |
c = ((c & 15) << 18 | (d[i2++] & 63) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023); | |
} else if (eb & 1) | |
r += String.fromCharCode((c & 31) << 6 | d[i2++] & 63); | |
else | |
r += String.fromCharCode((c & 15) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63); | |
} | |
}; | |
function strFromU8(dat, latin1) { | |
if (latin1) { | |
var r = ""; | |
for (var i2 = 0; i2 < dat.length; i2 += 16384) | |
r += String.fromCharCode.apply(null, dat.subarray(i2, i2 + 16384)); | |
return r; | |
} else if (td) | |
return td.decode(dat); | |
else { | |
var _a2 = dutf8(dat), out = _a2[0], ext = _a2[1]; | |
if (ext.length) | |
err(8); | |
return out; | |
} | |
} | |
var slzh = function (d, b) { | |
return b + 30 + b2(d, b + 26) + b2(d, b + 28); | |
}; | |
var zh = function (d, b, z) { | |
var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20); | |
var _a2 = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a2[0], su = _a2[1], off = _a2[2]; | |
return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off]; | |
}; | |
var z64e = function (d, b) { | |
for (; b2(d, b) != 1; b += 4 + b2(d, b + 2)) | |
; | |
return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)]; | |
}; | |
function unzipSync(data, opts) { | |
var files = {}; | |
var e = data.length - 22; | |
for (; b4(data, e) != 101010256; --e) { | |
if (!e || data.length - e > 65558) | |
err(13); | |
} | |
; | |
var c = b2(data, e + 8); | |
if (!c) | |
return {}; | |
var o = b4(data, e + 16); | |
var z = o == 4294967295 || c == 65535; | |
if (z) { | |
var ze = b4(data, e - 12); | |
z = b4(data, ze) == 101075792; | |
if (z) { | |
c = b4(data, ze + 32); | |
o = b4(data, ze + 48); | |
} | |
} | |
var fltr = opts && opts.filter; | |
for (var i2 = 0; i2 < c; ++i2) { | |
var _a2 = zh(data, o, z), c_2 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off); | |
o = no; | |
if (!fltr || fltr({ | |
name: fn, | |
size: sc, | |
originalSize: su, | |
compression: c_2 | |
})) { | |
if (!c_2) | |
files[fn] = slc(data, b, b + sc); | |
else if (c_2 == 8) | |
files[fn] = inflateSync(data.subarray(b, b + sc), new u8(su)); | |
else | |
err(14, "unknown compression type " + c_2); | |
} | |
} | |
return files; | |
} | |
function unpackXlsxFile(input) { | |
return unpackXlsxArrayBuffer(input); | |
} | |
function unpackXlsxArrayBuffer(arrayBuffer) { | |
const archive = new Uint8Array(arrayBuffer); | |
const contents = unzipSync(archive); | |
return Promise.resolve(getContents(contents)); | |
} | |
function getContents(contents) { | |
const unzippedFiles = []; | |
for (const key of Object.keys(contents)) { | |
unzippedFiles[key] = strFromU8(contents[key]); | |
} | |
return unzippedFiles; | |
} | |
function findChild(node, tagName) { | |
let i2 = 0; | |
while (i2 < node.childNodes.length) { | |
const childNode = node.childNodes[i2]; | |
if (childNode.nodeType === 1 && getTagName(childNode) === tagName) { | |
return childNode; | |
} | |
i2++; | |
} | |
} | |
function findChildren(node, tagName) { | |
const results = []; | |
let i2 = 0; | |
while (i2 < node.childNodes.length) { | |
const childNode = node.childNodes[i2]; | |
if (childNode.nodeType === 1 && getTagName(childNode) === tagName) { | |
results.push(childNode); | |
} | |
i2++; | |
} | |
return results; | |
} | |
function forEach(node, tagName, func) { | |
let i2 = 0; | |
while (i2 < node.childNodes.length) { | |
const childNode = node.childNodes[i2]; | |
if (tagName) { | |
if (childNode.nodeType === 1 && getTagName(childNode) === tagName) { | |
func(childNode, i2); | |
} | |
} else { | |
func(childNode, i2); | |
} | |
i2++; | |
} | |
} | |
function map(node, tagName, func) { | |
const results = []; | |
forEach(node, tagName, (node2, i2) => { | |
results.push(func(node2, i2)); | |
}); | |
return results; | |
} | |
var NAMESPACE_REG_EXP = /.+\:/; | |
function getTagName(element) { | |
return element.tagName.replace(NAMESPACE_REG_EXP, ""); | |
} | |
function getOuterXml(node) { | |
if (node.nodeType !== 1) { | |
return node.textContent; | |
} | |
let xml = "<" + getTagName(node); | |
let j = 0; | |
while (j < node.attributes.length) { | |
xml += " " + node.attributes[j].name + '="' + node.attributes[j].value + '"'; | |
j++; | |
} | |
xml += ">"; | |
let i2 = 0; | |
while (i2 < node.childNodes.length) { | |
xml += getOuterXml(node.childNodes[i2]); | |
i2++; | |
} | |
xml += "</" + getTagName(node) + ">"; | |
return xml; | |
} | |
function getCells(document) { | |
const worksheet = document.documentElement; | |
const sheetData = findChild(worksheet, "sheetData"); | |
const cells = []; | |
forEach(sheetData, "row", (row) => { | |
forEach(row, "c", (cell) => { | |
cells.push(cell); | |
}); | |
}); | |
return cells; | |
} | |
function getCellValue(document, node) { | |
return findChild(node, "v"); | |
} | |
function getCellInlineStringValue(document, node) { | |
if (node.firstChild && getTagName(node.firstChild) === "is" && node.firstChild.firstChild && getTagName(node.firstChild.firstChild) === "t") { | |
return node.firstChild.firstChild.textContent; | |
} | |
} | |
function getDimensions(document) { | |
const worksheet = document.documentElement; | |
const dimensions = findChild(worksheet, "dimension"); | |
if (dimensions) { | |
return dimensions.getAttribute("ref"); | |
} | |
} | |
function getBaseStyles(document) { | |
const styleSheet = document.documentElement; | |
const cellStyleXfs = findChild(styleSheet, "cellStyleXfs"); | |
if (cellStyleXfs) { | |
return findChildren(cellStyleXfs, "xf"); | |
} | |
return []; | |
} | |
function getCellStyles(document) { | |
const styleSheet = document.documentElement; | |
const cellXfs = findChild(styleSheet, "cellXfs"); | |
if (!cellXfs) { | |
return []; | |
} | |
return findChildren(cellXfs, "xf"); | |
} | |
function getNumberFormats(document) { | |
const styleSheet = document.documentElement; | |
let numberFormats = []; | |
const numFmts = findChild(styleSheet, "numFmts"); | |
if (numFmts) { | |
return findChildren(numFmts, "numFmt"); | |
} | |
return []; | |
} | |
function getSharedStrings(document) { | |
const sst = document.documentElement; | |
return map(sst, "si", (string) => { | |
const t = findChild(string, "t"); | |
if (t) { | |
return t.textContent; | |
} | |
let value = ""; | |
forEach(string, "r", (r) => { | |
value += findChild(r, "t").textContent; | |
}); | |
return value; | |
}); | |
} | |
function getWorkbookProperties(document) { | |
const workbook = document.documentElement; | |
return findChild(workbook, "workbookPr"); | |
} | |
function getRelationships(document) { | |
const relationships = document.documentElement; | |
return findChildren(relationships, "Relationship"); | |
} | |
function getSheets(document) { | |
const workbook = document.documentElement; | |
const sheets = findChild(workbook, "sheets"); | |
return findChildren(sheets, "sheet"); | |
} | |
function parseProperties(content, xml) { | |
const book = xml.createDocument(content); | |
const properties = {}; | |
const workbookProperties = getWorkbookProperties(book); | |
if (workbookProperties && workbookProperties.getAttribute("date1904") === "1") { | |
properties.epoch1904 = true; | |
} | |
properties.sheets = []; | |
const addSheetInfo = (sheet) => { | |
if (sheet.getAttribute("name")) { | |
properties.sheets.push({ | |
id: sheet.getAttribute("sheetId"), | |
name: sheet.getAttribute("name"), | |
relationId: sheet.getAttribute("r:id") | |
}); | |
} | |
}; | |
getSheets(book).forEach(addSheetInfo); | |
return properties; | |
} | |
function parseFilePaths(content, xml) { | |
const document = xml.createDocument(content); | |
const filePaths = { | |
sheets: {}, | |
sharedStrings: void 0, | |
styles: void 0 | |
}; | |
const addFilePathInfo = (relationship) => { | |
const filePath = relationship.getAttribute("Target"); | |
const fileType = relationship.getAttribute("Type"); | |
switch (fileType) { | |
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles": | |
filePaths.styles = getFilePath(filePath); | |
break; | |
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings": | |
filePaths.sharedStrings = getFilePath(filePath); | |
break; | |
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet": | |
filePaths.sheets[relationship.getAttribute("Id")] = getFilePath(filePath); | |
break; | |
} | |
}; | |
getRelationships(document).forEach(addFilePathInfo); | |
return filePaths; | |
} | |
function getFilePath(path) { | |
if (path[0] === "/") { | |
return path.slice("/".length); | |
} | |
return "xl/" + path; | |
} | |
function parseStyles(content, xml) { | |
if (!content) { | |
return {}; | |
} | |
const doc = xml.createDocument(content); | |
const baseStyles = getBaseStyles(doc).map(parseCellStyle); | |
const numberFormats = getNumberFormats(doc).map(parseNumberFormatStyle).reduce((formats, format) => { | |
formats[format.id] = format; | |
return formats; | |
}, []); | |
const getCellStyle = (xf) => { | |
if (xf.hasAttribute("xfId")) { | |
return { | |
...baseStyles[xf.xfId], | |
...parseCellStyle(xf, numberFormats) | |
}; | |
} | |
return parseCellStyle(xf, numberFormats); | |
}; | |
return getCellStyles(doc).map(getCellStyle); | |
} | |
function parseNumberFormatStyle(numFmt) { | |
return { | |
id: numFmt.getAttribute("numFmtId"), | |
template: numFmt.getAttribute("formatCode") | |
}; | |
} | |
function parseCellStyle(xf, numFmts) { | |
const style = {}; | |
if (xf.hasAttribute("numFmtId")) { | |
const numberFormatId = xf.getAttribute("numFmtId"); | |
if (numFmts[numberFormatId]) { | |
style.numberFormat = numFmts[numberFormatId]; | |
} else { | |
style.numberFormat = { id: numberFormatId }; | |
} | |
} | |
return style; | |
} | |
function parseSharedStrings(content, xml) { | |
if (!content) { | |
return []; | |
} | |
return getSharedStrings(xml.createDocument(content)); | |
} | |
function parseExcelDate(excelSerialDate, options) { | |
if (options && options.epoch1904) { | |
excelSerialDate += 1462; | |
} | |
const daysBeforeUnixEpoch = 70 * 365 + 19; | |
const hour = 60 * 60 * 1e3; | |
return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour)); | |
} | |
function isDateTimestamp(value, styleId, styles, options) { | |
if (styleId) { | |
const style = styles[styleId]; | |
if (!style) { | |
throw new Error(`Cell style not found: ${styleId}`); | |
} | |
if (!style.numberFormat) { | |
return false; | |
} | |
if ( | |
// Whether it's a "number format" that's conventionally used for storing date timestamps. | |
BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(Number(style.numberFormat.id)) >= 0 || // Whether it's a "number format" that uses a "formatting template" | |
// that the developer is certain is a date formatting template. | |
options.dateFormat && style.numberFormat.template === options.dateFormat || // Whether the "smart formatting template" feature is not disabled | |
// and it has detected that it's a date formatting template by looking at it. | |
options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template) | |
) { | |
return true; | |
} | |
} | |
} | |
var BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57]; | |
var DATE_FORMAT_WEIRD_PREFIX = /^\[\$-414\]/; | |
var DATE_FORMAT_WEIRD_POSTFIX = /;@$/; | |
function isDateTemplate(template) { | |
template = template.toLowerCase(); | |
template = template.replace(DATE_FORMAT_WEIRD_PREFIX, ""); | |
template = template.replace(DATE_FORMAT_WEIRD_POSTFIX, ""); | |
const tokens = template.split(/\W+/); | |
for (const token of tokens) { | |
if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
var DATE_TEMPLATE_TOKENS = [ | |
// Seconds (min two digits). Example: "05". | |
"ss", | |
// Minutes (min two digits). Example: "05". Could also be "Months". Weird. | |
"mm", | |
// Hours. Example: "1". | |
"h", | |
// Hours (min two digits). Example: "01". | |
"hh", | |
// "AM" part of "AM/PM". Lowercased just in case. | |
"am", | |
// "PM" part of "AM/PM". Lowercased just in case. | |
"pm", | |
// Day. Example: "1" | |
"d", | |
// Day (min two digits). Example: "01" | |
"dd", | |
// Month (numeric). Example: "1". | |
"m", | |
// Month (numeric, min two digits). Example: "01". Could also be "Minutes". Weird. | |
"mm", | |
// Month (shortened month name). Example: "Jan". | |
"mmm", | |
// Month (full month name). Example: "January". | |
"mmmm", | |
// Two-digit year. Example: "20". | |
"yy", | |
// Full year. Example: "2020". | |
"yyyy", | |
// I don't have any idea what "e" means. | |
// It's used in "built-in" XLSX formats: | |
// * 27 '[$-404]e/m/d'; | |
// * 36 '[$-404]e/m/d'; | |
// * 50 '[$-404]e/m/d'; | |
// * 57 '[$-404]e/m/d'; | |
"e" | |
]; | |
function parseCellValue(value, type, { | |
getInlineStringValue, | |
getInlineStringXml, | |
getStyleId, | |
styles, | |
values, | |
properties, | |
options | |
}) { | |
if (!type) { | |
type = "n"; | |
} | |
switch (type) { | |
case "str": | |
value = parseString(value, options); | |
break; | |
case "inlineStr": | |
value = getInlineStringValue(); | |
if (value === void 0) { | |
throw new Error(`Unsupported "inline string" cell value structure: ${getInlineStringXml()}`); | |
} | |
value = parseString(value, options); | |
break; | |
case "s": | |
const sharedStringIndex = Number(value); | |
if (isNaN(sharedStringIndex)) { | |
throw new Error(`Invalid "shared" string index: ${value}`); | |
} | |
if (sharedStringIndex >= values.length) { | |
throw new Error(`An out-of-bounds "shared" string index: ${value}`); | |
} | |
value = values[sharedStringIndex]; | |
value = parseString(value, options); | |
break; | |
case "b": | |
if (value === "1") { | |
value = true; | |
} else if (value === "0") { | |
value = false; | |
} else { | |
throw new Error(`Unsupported "boolean" cell value: ${value}`); | |
} | |
break; | |
case "z": | |
value = void 0; | |
break; | |
case "e": | |
value = decodeError(value); | |
break; | |
case "d": | |
if (value === void 0) { | |
break; | |
} | |
const parsedDate = new Date(value); | |
if (isNaN(parsedDate.valueOf())) { | |
throw new Error(`Unsupported "date" cell value: ${value}`); | |
} | |
value = parsedDate; | |
break; | |
case "n": | |
if (value === void 0) { | |
break; | |
} | |
const parsedNumber = Number(value); | |
if (isNaN(parsedNumber)) { | |
throw new Error(`Invalid "numeric" cell value: ${value}`); | |
} | |
value = parsedNumber; | |
if (isDateTimestamp(value, getStyleId(), styles, options)) { | |
value = parseExcelDate(value, properties); | |
} | |
break; | |
default: | |
throw new TypeError(`Cell type not supported: ${type}`); | |
} | |
if (value === void 0) { | |
value = null; | |
} | |
return value; | |
} | |
function decodeError(errorCode) { | |
switch (errorCode) { | |
case 0: | |
return "#NULL!"; | |
case 7: | |
return "#DIV/0!"; | |
case 15: | |
return "#VALUE!"; | |
case 23: | |
return "#REF!"; | |
case 29: | |
return "#NAME?"; | |
case 36: | |
return "#NUM!"; | |
case 42: | |
return "#N/A"; | |
case 43: | |
return "#GETTING_DATA"; | |
default: | |
return `#ERROR_${errorCode}`; | |
} | |
} | |
function parseString(value, options) { | |
if (options.trim !== false) { | |
value = value.trim(); | |
} | |
if (value === "") { | |
value = void 0; | |
} | |
return value; | |
} | |
var LETTERS = ["", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; | |
function calculateDimensions(cells) { | |
const comparator = (a, b) => a - b; | |
const allRows = cells.map((cell) => cell.row).sort(comparator); | |
const allCols = cells.map((cell) => cell.column).sort(comparator); | |
const minRow = allRows[0]; | |
const maxRow = allRows[allRows.length - 1]; | |
const minCol = allCols[0]; | |
const maxCol = allCols[allCols.length - 1]; | |
return [ | |
{ row: minRow, column: minCol }, | |
{ row: maxRow, column: maxCol } | |
]; | |
} | |
function columnLettersToNumber(columnLetters) { | |
let n = 0; | |
let i2 = 0; | |
while (i2 < columnLetters.length) { | |
n *= 26; | |
n += LETTERS.indexOf(columnLetters[i2]); | |
i2++; | |
} | |
return n; | |
} | |
function parseCellCoordinates(coords) { | |
coords = coords.split(/(\d+)/); | |
return [ | |
// Row. | |
parseInt(coords[1]), | |
// Column. | |
columnLettersToNumber(coords[0].trim()) | |
]; | |
} | |
function parseCell(node, sheet, xml, values, styles, properties, options) { | |
const coords = parseCellCoordinates(node.getAttribute("r")); | |
const valueElement = getCellValue(sheet, node); | |
let value = valueElement && valueElement.textContent; | |
let type; | |
if (node.hasAttribute("t")) { | |
type = node.getAttribute("t"); | |
} | |
return { | |
row: coords[0], | |
column: coords[1], | |
value: parseCellValue(value, type, { | |
getInlineStringValue: () => getCellInlineStringValue(sheet, node), | |
getInlineStringXml: () => getOuterXml(node), | |
getStyleId: () => node.getAttribute("s"), | |
styles, | |
values, | |
properties, | |
options | |
}) | |
}; | |
} | |
function parseCells(sheet, xml, values, styles, properties, options) { | |
const cells = getCells(sheet); | |
if (cells.length === 0) { | |
return []; | |
} | |
return cells.map((node) => { | |
return parseCell(node, sheet, xml, values, styles, properties, options); | |
}); | |
} | |
function parseDimensions(sheet) { | |
let dimensions = getDimensions(sheet); | |
if (dimensions) { | |
dimensions = dimensions.split(":").map(parseCellCoordinates).map(([row, column]) => ({ | |
row, | |
column | |
})); | |
if (dimensions.length === 1) { | |
dimensions = [dimensions[0], dimensions[0]]; | |
} | |
return dimensions; | |
} | |
} | |
function parseSheet(content, xml, values, styles, properties, options) { | |
const sheet = xml.createDocument(content); | |
const cells = parseCells(sheet, xml, values, styles, properties, options); | |
const dimensions = parseDimensions(sheet) || calculateDimensions(cells); | |
return { cells, dimensions }; | |
} | |
function dropEmptyRows(data, { | |
rowMap, | |
accessor = (_) => _, | |
onlyTrimAtTheEnd | |
} = {}) { | |
let i2 = data.length - 1; | |
while (i2 >= 0) { | |
let empty = true; | |
for (const cell of data[i2]) { | |
if (accessor(cell) !== null) { | |
empty = false; | |
break; | |
} | |
} | |
if (empty) { | |
data.splice(i2, 1); | |
if (rowMap) { | |
rowMap.splice(i2, 1); | |
} | |
} else if (onlyTrimAtTheEnd) { | |
break; | |
} | |
i2--; | |
} | |
return data; | |
} | |
function dropEmptyColumns(data, { | |
accessor = (_) => _, | |
onlyTrimAtTheEnd | |
} = {}) { | |
let i2 = data[0].length - 1; | |
while (i2 >= 0) { | |
let empty = true; | |
for (const row of data) { | |
if (accessor(row[i2]) !== null) { | |
empty = false; | |
break; | |
} | |
} | |
if (empty) { | |
let j = 0; | |
while (j < data.length) { | |
data[j].splice(i2, 1); | |
j++; | |
} | |
} else if (onlyTrimAtTheEnd) { | |
break; | |
} | |
i2--; | |
} | |
return data; | |
} | |
function getData(sheet, options) { | |
const { dimensions, cells } = sheet; | |
if (cells.length === 0) { | |
return []; | |
} | |
const [leftTop, rightBottom] = dimensions; | |
const colsCount = rightBottom.column; | |
const rowsCount = rightBottom.row; | |
let data = new Array(rowsCount); | |
let i2 = 0; | |
while (i2 < rowsCount) { | |
data[i2] = new Array(colsCount); | |
let j = 0; | |
while (j < colsCount) { | |
data[i2][j] = null; | |
j++; | |
} | |
i2++; | |
} | |
for (const cell of cells) { | |
const rowIndex = cell.row - 1; | |
const columnIndex = cell.column - 1; | |
if (columnIndex < colsCount && rowIndex < rowsCount) { | |
data[rowIndex][columnIndex] = cell.value; | |
} | |
} | |
const { rowMap } = options; | |
if (rowMap) { | |
let i22 = 0; | |
while (i22 < data.length) { | |
rowMap[i22] = i22; | |
i22++; | |
} | |
} | |
data = dropEmptyRows( | |
dropEmptyColumns(data, { onlyTrimAtTheEnd: true }), | |
{ onlyTrimAtTheEnd: true, rowMap } | |
); | |
if (options.transformData) { | |
data = options.transformData(data); | |
} | |
return data; | |
} | |
function readXlsx(contents, xml, options = {}) { | |
if (!options.sheet) { | |
options = { | |
sheet: 1, | |
...options | |
}; | |
} | |
const getXmlFileContent = (filePath) => { | |
if (!contents[filePath]) { | |
throw new Error(`"${filePath}" file not found inside the *.xlsx file zip archive`); | |
} | |
return contents[filePath]; | |
}; | |
const filePaths = parseFilePaths(getXmlFileContent("xl/_rels/workbook.xml.rels"), xml); | |
const values = filePaths.sharedStrings ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml) : []; | |
const styles = filePaths.styles ? parseStyles(getXmlFileContent(filePaths.styles), xml) : {}; | |
const properties = parseProperties(getXmlFileContent("xl/workbook.xml"), xml); | |
if (options.getSheets) { | |
return properties.sheets.map(({ name }) => ({ | |
name | |
})); | |
} | |
const sheetId = getSheetId(options.sheet, properties.sheets); | |
if (!sheetId || !filePaths.sheets[sheetId]) { | |
throw createSheetNotFoundError(options.sheet, properties.sheets); | |
} | |
const sheet = parseSheet( | |
getXmlFileContent(filePaths.sheets[sheetId]), | |
xml, | |
values, | |
styles, | |
properties, | |
options | |
); | |
const data = getData(sheet, options); | |
if (options.properties) { | |
return { | |
data, | |
properties | |
}; | |
} | |
return data; | |
} | |
function getSheetId(sheet, sheets) { | |
if (typeof sheet === "number") { | |
const _sheet = sheets[sheet - 1]; | |
return _sheet && _sheet.relationId; | |
} | |
for (const _sheet of sheets) { | |
if (_sheet.name === sheet) { | |
return _sheet.relationId; | |
} | |
} | |
} | |
function createSheetNotFoundError(sheet, sheets) { | |
const sheetsList = sheets && sheets.map((sheet2, i2) => `"${sheet2.name}" (#${i2 + 1})`).join(", "); | |
return new Error(`Sheet ${typeof sheet === "number" ? "#" + sheet : '"' + sheet + '"'} not found in the *.xlsx file.${sheets ? " Available sheets: " + sheetsList + "." : ""}`); | |
} | |
var InvalidError = class extends Error { | |
constructor(reason) { | |
super("invalid"); | |
this.reason = reason; | |
} | |
}; | |
function NumberType(value) { | |
if (typeof value === "string") { | |
const stringifiedValue = value; | |
value = Number(value); | |
if (String(value) !== stringifiedValue) { | |
throw new InvalidError("not_a_number"); | |
} | |
} | |
if (typeof value !== "number") { | |
throw new InvalidError("not_a_number"); | |
} | |
if (isNaN(value)) { | |
throw new InvalidError("invalid_number"); | |
} | |
if (!isFinite(value)) { | |
throw new InvalidError("out_of_bounds"); | |
} | |
return value; | |
} | |
function StringType(value) { | |
if (typeof value === "string") { | |
return value; | |
} | |
if (typeof value === "number") { | |
if (isNaN(value)) { | |
throw new InvalidError("invalid_number"); | |
} | |
if (!isFinite(value)) { | |
throw new InvalidError("out_of_bounds"); | |
} | |
return String(value); | |
} | |
throw new InvalidError("not_a_string"); | |
} | |
function BooleanType(value) { | |
if (typeof value === "boolean") { | |
return value; | |
} | |
throw new InvalidError("not_a_boolean"); | |
} | |
function DateType(value, { properties }) { | |
if (value instanceof Date) { | |
if (isNaN(value.valueOf())) { | |
throw new InvalidError("out_of_bounds"); | |
} | |
return value; | |
} | |
if (typeof value === "number") { | |
if (isNaN(value)) { | |
throw new InvalidError("invalid_number"); | |
} | |
if (!isFinite(value)) { | |
throw new InvalidError("out_of_bounds"); | |
} | |
const date = parseExcelDate(value, properties); | |
if (isNaN(date.valueOf())) { | |
throw new InvalidError("out_of_bounds"); | |
} | |
return date; | |
} | |
throw new InvalidError("not_a_date"); | |
} | |
var DEFAULT_OPTIONS = { | |
isColumnOriented: false | |
}; | |
function convertToJson_default(data, schema, options) { | |
if (options) { | |
options = { | |
...DEFAULT_OPTIONS, | |
...options | |
}; | |
} else { | |
options = DEFAULT_OPTIONS; | |
} | |
const { | |
isColumnOriented, | |
rowMap, | |
ignoreEmptyRows | |
} = options; | |
validateSchema(schema); | |
if (isColumnOriented) { | |
data = transpose(data); | |
} | |
const columns = data[0]; | |
const results = []; | |
const errors = []; | |
for (let i2 = 1; i2 < data.length; i2++) { | |
const result = read(schema, data[i2], i2, columns, errors, options); | |
if (result !== null || ignoreEmptyRows === false) { | |
results.push(result); | |
} | |
} | |
if (rowMap) { | |
for (const error of errors) { | |
error.row = rowMap[error.row - 1] + 1; | |
} | |
} | |
return { | |
rows: results, | |
errors | |
}; | |
} | |
function read(schema, row, rowIndex, columns, errors, options) { | |
const object = {}; | |
let isEmptyObject = true; | |
for (const key of Object.keys(schema)) { | |
const schemaEntry = schema[key]; | |
const isNestedSchema = typeof schemaEntry.type === "object" && !Array.isArray(schemaEntry.type); | |
let rawValue = row[columns.indexOf(key)]; | |
if (rawValue === void 0) { | |
rawValue = null; | |
} | |
let value; | |
let error; | |
let reason; | |
if (isNestedSchema) { | |
value = read(schemaEntry.type, row, rowIndex, columns, errors, options); | |
} else { | |
if (rawValue === null) { | |
value = null; | |
} else if (Array.isArray(schemaEntry.type)) { | |
let notEmpty = false; | |
const array = parseArray(rawValue).map((_value) => { | |
const result = parseValue(_value, schemaEntry, options); | |
if (result.error) { | |
value = _value; | |
error = result.error; | |
reason = result.reason; | |
} | |
if (result.value !== null) { | |
notEmpty = true; | |
} | |
return result.value; | |
}); | |
if (!error) { | |
value = notEmpty ? array : null; | |
} | |
} else { | |
const result = parseValue(rawValue, schemaEntry, options); | |
error = result.error; | |
reason = result.reason; | |
value = error ? rawValue : result.value; | |
} | |
} | |
if (!error && value === null && schemaEntry.required) { | |
error = "required"; | |
} | |
if (error) { | |
error = { | |
error, | |
row: rowIndex + 1, | |
column: key, | |
value | |
}; | |
if (reason) { | |
error.reason = reason; | |
} | |
if (schemaEntry.type) { | |
error.type = schemaEntry.type; | |
} | |
errors.push(error); | |
} else { | |
if (isEmptyObject && value !== null) { | |
isEmptyObject = false; | |
} | |
if (value !== null || options.includeNullValues) { | |
object[schemaEntry.prop] = value; | |
} | |
} | |
} | |
if (isEmptyObject) { | |
return null; | |
} | |
return object; | |
} | |
function parseValue(value, schemaEntry, options) { | |
if (value === null) { | |
return { value: null }; | |
} | |
let result; | |
if (schemaEntry.parse) { | |
result = parseCustomValue(value, schemaEntry.parse); | |
} else if (schemaEntry.type) { | |
result = parseValueOfType( | |
value, | |
// Supports parsing array types. | |
// See `parseArray()` function for more details. | |
// Example `type`: String[] | |
// Input: 'Barack Obama, "String, with, colons", Donald Trump' | |
// Output: ['Barack Obama', 'String, with, colons', 'Donald Trump'] | |
Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type, | |
options | |
); | |
} else { | |
result = { value }; | |
} | |
if (result.error) { | |
return result; | |
} | |
if (result.value !== null) { | |
if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) { | |
return { error: "invalid", reason: "unknown" }; | |
} | |
if (schemaEntry.validate) { | |
try { | |
schemaEntry.validate(result.value); | |
} catch (error) { | |
return { error: error.message }; | |
} | |
} | |
} | |
return result; | |
} | |
function parseCustomValue(value, parse) { | |
try { | |
value = parse(value); | |
if (value === void 0) { | |
return { value: null }; | |
} | |
return { value }; | |
} catch (error) { | |
const result = { error: error.message }; | |
if (error.reason) { | |
result.reason = error.reason; | |
} | |
return result; | |
} | |
} | |
function parseValueOfType(value, type, options) { | |
switch (type) { | |
case String: | |
return parseCustomValue(value, StringType); | |
case Number: | |
return parseCustomValue(value, NumberType); | |
case Date: | |
return parseCustomValue(value, (value2) => DateType(value2, { properties: options.properties })); | |
case Boolean: | |
return parseCustomValue(value, BooleanType); | |
default: | |
if (typeof type === "function") { | |
return parseCustomValue(value, type); | |
} | |
throw new Error(`Unsupported schema type: ${type && type.name || type}`); | |
} | |
} | |
function getBlock(string, endCharacter, startIndex) { | |
let i2 = 0; | |
let substring = ""; | |
let character; | |
while (startIndex + i2 < string.length) { | |
const character2 = string[startIndex + i2]; | |
if (character2 === endCharacter) { | |
return [substring, i2]; | |
} else if (character2 === '"') { | |
const block = getBlock(string, '"', startIndex + i2 + 1); | |
substring += block[0]; | |
i2 += '"'.length + block[1] + '"'.length; | |
} else { | |
substring += character2; | |
i2++; | |
} | |
} | |
return [substring, i2]; | |
} | |
function parseArray(string) { | |
const blocks = []; | |
let index = 0; | |
while (index < string.length) { | |
const [substring, length] = getBlock(string, ",", index); | |
index += length + ",".length; | |
blocks.push(substring.trim()); | |
} | |
return blocks; | |
} | |
var transpose = (array) => array[0].map((_, i2) => array.map((row) => row[i2])); | |
function validateSchema(schema) { | |
for (const key of Object.keys(schema)) { | |
const entry = schema[key]; | |
if (!entry.prop) { | |
throw new Error(`"prop" not defined for schema entry "${key}".`); | |
} | |
} | |
} | |
function convertMapToSchema(map2) { | |
const schema = {}; | |
for (const key of Object.keys(map2)) { | |
let prop = map2[key]; | |
let type; | |
if (typeof prop === "object") { | |
prop = Object.keys(map2[key])[0]; | |
type = convertMapToSchema(map2[key][prop]); | |
} | |
schema[key] = { | |
prop | |
}; | |
if (type) { | |
schema[key].type = type; | |
} | |
} | |
return schema; | |
} | |
function readXlsxFileContents(entries, xml, { schema, map: map2, ...options }) { | |
if (!schema && map2) { | |
schema = convertMapToSchema(map2); | |
} | |
const result = readXlsx(entries, xml, { ...options, properties: schema || options.properties }); | |
if (schema) { | |
return convertToJson_default(result.data, schema, { ...options, properties: result.properties }); | |
} | |
return result; | |
} | |
function readXlsxFile(file, options = {}) { | |
return unpackXlsxFile(file).then((entries) => readXlsxFileContents(entries, xmlBrowser_default, options)); | |
} | |
function readSheetNames(file) { | |
return readXlsxFile(file, { getSheets: true }).then((sheets) => sheets.map((sheet) => sheet.name)); | |
} | |
function Integer(value) { | |
value = NumberType(value); | |
if (!isInteger(value)) { | |
throw new InvalidError("not_an_integer"); | |
} | |
return value; | |
} | |
function isInteger(x2) { | |
return (x2 | 0) === x2; | |
} | |
function Email(value) { | |
if (typeof value === "string") { | |
if (isEmail(value)) { | |
return value; | |
} | |
throw new InvalidError("not_an_email"); | |
} | |
throw new InvalidError("not_a_string"); | |
} | |
var regexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; | |
function isEmail(value) { | |
return regexp.test(value); | |
} | |
function URL2(value) { | |
if (typeof value === "string") { | |
if (isURL(value)) { | |
return value; | |
} | |
throw new InvalidError("not_a_url"); | |
} | |
throw new InvalidError("not_a_string"); | |
} | |
var regexp2 = /^(?:(?:(?:https?|ftp):)?\/\/)(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)*(?:[a-z\u00a1-\uffff]{2,}))(?::\d{2,5})?(?:[/?#]\S*)?$/i; | |
function isURL(value) { | |
return regexp2.test(value); | |
} | |
if (typeof module.exports == "object" && typeof exports == "object") { | |
var __cp = (to, from, except, desc) => { | |
if ((from && typeof from === "object") || typeof from === "function") { | |
for (let key of Object.getOwnPropertyNames(from)) { | |
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except) | |
Object.defineProperty(to, key, { | |
get: () => from[key], | |
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable, | |
}); | |
} | |
} | |
return to; | |
}; | |
module.exports = __cp(module.exports, exports); | |
} | |
return module.exports; | |
}; | |
globalThis.readXlsxFile = f(); | |
console.log({ readXlsxFile: globalThis.readXlsxFile }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment