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EAAa,EAAgB,EACnC,IAAI,EAAO,GAIX,OAFA,EAAO,GAAQ,IAEN,cAAgB,OACvB,EAAK,SAAQ,IACX,GAAU,EAAO,EAAS,EAAM,EAAc,IAEzC,KAGJ,GAAQ,EAAK,QAChB,EAAO,EAAK,OAGV,IACF,EAAS,GAAG,KAAc,IACtB,EAAK,QAAiC,iBAAhB,EAAK,SAC7B,EAAO,OAAO,KAAK,EAAK,QACxB,EAAK,SAAQ,IACX,GAAU,IAAI,KAAO,KAAK,UAAU,OAAO,EAAK,OAAO,MAAQ,MAKjE,SAAgD,KAAT,IAEhB,iBAAT,GAChB,EAAO,OAAO,KAAK,GACnB,EAAK,SAAQ,IACX,MAAM,EAAQ,EAAK,GACnB,OAAQ,GACN,IAAK,QACL,IAAK,SAEH,MAEF,IAAK,QACL,IAAK,UACH,GAAQ,EAAO,EAAO,KAAM,GAC5B,MAEF,IAAK,UACH,GAAQ,EAAO,EAAO,SAAU,GAChC,MAEF,IAAK,SACH,GAAQ,GAAG,aAAsB,OACjC,MAEF,QACE,GAAQ,EAAO,EAAO,EAAK,GAC/B,KAGF,GAAQ,EAAa,EAAO,IAK1B,GAFA,EACE,EACQ,IAAI,IAAO,IAAiB,MAAkB,KAC/C,EACC,KAEA,MAAM,KAGR,EAEL,EACT,CACO,CAAO,EAAK,EAAU,GAC/B,EAEA,OAAO,QAAU","file":"/npm/xml-flow@1.0.4/lib/xml-flow.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/xml-flow@1.0.4/lib/xml-flow.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* eslint complexity: 0 */\nconst { EventEmitter } = require('events');\nconst sax = require('sax');\nconst helper = require('./helper');\n\nconst ALWAYS = 1;\nconst SOMETIMES = 0;\nconst NEVER = -1;\n\nconst defaults = {\n  preserveMarkup: SOMETIMES,\n  simplifyNodes: true,\n  useArrays: SOMETIMES,\n  lowercase: true,\n  trim: true,\n  normalize: true,\n  cdataAsText: false,\n  strict: false\n};\n\n/**\n * @param ReadSteam inStream the stream to be parsed\n */\nconst flow = function xmlFlow(inStream, options = defaults) {\n  const emitter = new EventEmitter();\n  const stack = [];\n  const opts = Object.assign({}, defaults, options);\n  const {\n    preserveMarkup,\n    simplifyNodes,\n    useArrays,\n    lowercase,\n    trim,\n    normalize,\n    cdataAsText,\n    strict\n  } = opts;\n  let topNode = null;\n  let currentCdata = null;\n\n  const saxStream = sax.createStream(strict, { lowercase, trim, normalize, cdataAsText });\n\n  saxStream.on('opentag', node => {\n    //Ignore nodes we don't care about.\n    if (stack.length === 0 && !emitter.listeners(`tag:${node.name}`).length) {\n      return;\n    }\n\n    //@TODO: If useArrays is set to flow.NEVER and this tag is already\n    //a member of last, we could ignore it and not mess\n\n    topNode = {\n      $name: node.name,\n      $attrs: node.attributes\n    };\n\n    //If useArrays is set to flow.NEVER, we don't want $markup\n    if (useArrays > NEVER) {\n      topNode.$markup = [];\n    }\n\n    stack.push(topNode);\n  });\n\n  saxStream.on('text', text => {\n    if (topNode) {\n      if (useArrays > NEVER) {\n        topNode.$markup.push(text);\n      } else if (topNode.$text) {\n        topNode.$text += text;\n      } else {\n        topNode.$text = text;\n      }\n    }\n  });\n\n  saxStream.on('opencdata', () => {\n    if (topNode) {\n      if (!cdataAsText) {\n        currentCdata = {\n          $name: '$cdata',\n          text: ''\n        };\n        if (useArrays > NEVER) {\n          topNode.$markup.push(currentCdata);\n        } else {\n          topNode.$cdata = currentCdata;\n        }\n      }\n    }\n  });\n\n  saxStream.on('cdata', text => {\n    if (topNode) {\n      if (currentCdata !== null) {\n        currentCdata.text += text;\n      } else if (useArrays > NEVER) {\n        topNode.$markup.push(text);\n      } else if (topNode.$text) {\n        topNode.$text += text;\n      } else {\n        topNode.$text = text;\n      }\n    }\n  });\n\n  saxStream.on('closecdata', () => {\n    currentCdata = null;\n  });\n\n  saxStream.on('script', script => {\n    if (topNode) {\n      topNode.$script = script;\n    }\n  });\n\n  saxStream.on('closetag', tagName => {\n    let compressed;\n    let newTop = null;\n    const keepArrays = useArrays > SOMETIMES;\n\n\n    //If we're not going to send out a node, goodbye!\n    if (stack.length === 0) return;\n\n    //Objectify Markup if needed...\n    if (useArrays > NEVER) {\n      if (preserveMarkup <= NEVER) {\n        topNode.$markup = helper.condenseArray(topNode.$markup);\n        topNode = helper.objectifyMarkup(topNode, keepArrays);\n      } else if (preserveMarkup === SOMETIMES) {\n        compressed = helper.condenseArray(topNode.$markup);\n        if (helper.shouldObjectifyMarkup(compressed)) {\n          topNode.$markup = compressed;\n          topNode = helper.objectifyMarkup(topNode, keepArrays);\n        }\n      }\n    }\n\n    //emit the node if there are listeners\n    if (emitter.listeners(`tag:${tagName}`).length) {\n      emitter.emit(\n        `tag:${tagName}`,\n        simplifyNodes ? helper.simplifyNode(topNode, false, useArrays > SOMETIMES) : topNode\n      );\n    }\n\n    //Pop stack, and add to parent node\n    stack.pop();\n    if (stack.length > 0) {\n      newTop = stack[stack.length - 1];\n      if (useArrays > NEVER) {\n        newTop.$markup.push(topNode);\n      } else if (!newTop[tagName]) {\n        newTop[tagName] = helper.simplifyNode(topNode, true);\n      }\n    }\n    topNode = newTop;\n  });\n\n  saxStream.on('end', () => {\n    emitter.emit('end');\n  });\n\n  saxStream.on('error', error => {\n    emitter.emit('error', error);\n  });\n\n  inStream.pipe(saxStream);\n\n  emitter.pause = function pause() {\n    inStream.pause();\n  };\n\n  emitter.resume = function resume() {\n    inStream.resume();\n  };\n\n  return emitter;\n};\n\nflow.ALWAYS = ALWAYS;\nflow.SOMETIMES = SOMETIMES;\nflow.NEVER = NEVER;\n\nflow.toXml = function toXml(obj, {\n  indent = '',\n  selfClosing = true,\n  escape = helper.escape,\n  nodeName\n} = {}) {\n  const carriageReturn = indent ? '\\n' : '';\n\n  function getXml(node, nodeName, currentIndent) {\n    let output = '';\n    let keys;\n    let name = nodeName;\n    const thisIndent = currentIndent ? carriageReturn + currentIndent : '';\n    const nextIndent = currentIndent + indent;\n    let guts = '';\n\n    node = node || '';\n\n    if (node.constructor === Array) {\n      node.forEach(subNode => {\n        output += getXml(subNode, name, currentIndent);\n      });\n      return output;\n    }\n\n    if (!name && node.$name) {\n      name = node.$name;\n    }\n\n    if (name) {\n      output = `${thisIndent}<${name}`;\n      if (node.$attrs && typeof node.$attrs === 'object') {\n        keys = Object.keys(node.$attrs);\n        keys.forEach(key => {\n          output += ` ${key}=${JSON.stringify(String(node.$attrs[key]))}`;\n        });\n      }\n    }\n\n    if (node === null || node === undefined || node === '') {\n      //do nothing. Empty on purpose\n    } else if (typeof node === 'object') {\n      keys = Object.keys(node);\n      keys.forEach(key => {\n        const value = node[key];\n        switch (key) {\n          case '$name':\n          case '$attrs':\n          //Do nothing. Already taken care of\n            break;\n\n          case '$text':\n          case '$markup':\n            guts += getXml(value, null, nextIndent);\n            break;\n\n          case '$script':\n            guts += getXml(value, 'script', nextIndent);\n            break;\n\n          case '$cdata':\n            guts += `${thisIndent}<![CDATA[${value}]]>`;\n            break;\n\n          default:\n            guts += getXml(value, key, nextIndent);\n        }\n      });\n    } else {\n      guts += thisIndent + escape(node);\n    }\n\n    if (name) {\n      if (guts) {\n        output += `>${guts}${carriageReturn}${currentIndent}</${name}>`;\n      } else if (selfClosing) {\n        output += '/>';\n      } else {\n        output += `></${name}>`;\n      }\n    } else {\n      output += guts;\n    }\n    return output;\n  }\n  return getXml(obj, nodeName, '');\n};\n\nmodule.exports = flow;\n"]}