{"name":"@web/parse5-utils","version":"1.2.2","keywords":["web","node","parse5","utils"],"author":{"name":"modern-web"},"license":"MIT","_id":"@web/parse5-utils@1.2.2","maintainers":[{"name":"d4kmor","email":"d4kmor@gmail.com"},{"name":"passle","email":"pascalschilp@gmail.com"},{"name":"jorenbroekema","email":"joren.broekema@gmail.com"},{"name":"bennyp","email":"web@bennypowers.com"},{"name":"larsdenbakker","email":"larsdenbakker@gmail.com"},{"name":"westbrook","email":"westbrook.johnson@gmail.com"},{"name":"modern-web","email":"hello@modern-web.dev"}],"homepage":"https://github.com/modernweb-dev/web/tree/master/packages/parse5-utils","bugs":{"url":"https://github.com/modernweb-dev/web/issues"},"dist":{"shasum":"33eec93321eb07cf364651c131b980a7afd8c4d7","tarball":"http://registry-npm.ywwl.com/@web/parse5-utils/download/@web/parse5-utils-1.2.2.tgz","fileCount":8,"integrity":"sha512-B68DoJ5qF8Cu3o7nDA2RQTCf9bslVz2b0WHTk3qir5YCbWfhnPEGhDOedOjbE8xDiHqgzI1zXQsJ2+655aluLA==","signatures":[{"sig":"MEUCIQCAyxtxxhOImZkP/JtT4x9uyaGImniR/nYhcCBGkpd84AIgfNvNJHdlEI/LKh+iA62H1o9o8J4oWElP6UISOJYHGnQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25412,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgSIrZCRA9TVsSAnZWagAAm4wP/jeGtisfvuurVgkpuJWC\nN8Psk8MDhxgaFrMPlypPom5xo8kobCITzwOpBM5Nhj/qbgM8wyKL+w3+trhB\n3vqqoKL3hFUkEKtNtke4Hc4++am2DZwlrmthMnO8e7aUCfIU5sbfFlEk5eo4\nLpOFn4064+gB7KkVRP5ud1dgePt/tHGDFwz4iF5ILrj3tU+cH95bMUE13q08\nNYbqpiDlptpdVigXrgASzD5TZ39Rdpv162QGcF63YGbhvex/OLM98eIICOOE\na3gFwXqY3l8jXYUmuXAnIQkw8+vz79ww8nr+QIkDpynwMYwehnZER1eEHcXq\nBHRVHeYQIoCvUKFpJco+vxn9TGl2E6tqvvWOoEwYJXqRM+eEV+TDvzOQs2/U\nIusrxgq7YvqWpPVblMZZAeTsCMvlkBbm82arWnwrOLDiGzBN/rqIIctcZOhz\nr6GefLx9G++dLjfsmM9Ofcq+4dDR9AVpXDX0ZfODc2BTnydtUhlaJdFbqP15\nB42ozKaZzVjoeE0LXW2PajN262j6h+fiRf+YZ35ikopLmeYKShA6b7i02nv9\nHvkTKAJG9bgOu5ie3sL62/6pSVLQsZCEMfpDg1NOnDs5blRdt/2xlYs4qmR7\n9uhJ5bM5ck85Ju46G++ytSWOYpfKiISBSmie6Ql7lNv/Pw8ggCXxXA4I+Ytm\nqPKI\r\n=HpJ1\r\n-----END PGP SIGNATURE-----\r\n","size":5809,"noattachment":false,"key":"/@web/parse5-utils/-/@web/parse5-utils-1.2.2.tgz"},"main":"src/index.js","engines":{"node":">=10.0.0"},"exports":{".":{"import":"./index.mjs","require":"./src/index.js"}},"scripts":{"test":"mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register","build":"tsc","test:watch":"mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch"},"_npmUser":{"name":"modern-web","email":"hello@modern-web.dev"},"repository":{"url":"git+https://github.com/modernweb-dev/web.git","type":"git","directory":"packages/parse5-utils"},"_npmVersion":"6.14.11","description":"Utils for using parse5","directories":{},"_nodeVersion":"12.21.0","dependencies":{"parse5":"^6.0.1","@types/parse5":"^5.0.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/html-minifier-terser":"^5.1.1"},"_npmOperationalInternal":{"tmp":"tmp/parse5-utils_1.2.2_1615366872715_0.9016512921338209","host":"s3://npm-registry-packages"},"readme":"# parse5-utils\n\nUtils for using parse5.\n\n## Usage\n\nExamples:\n\n```js\nimport { parse } from 'parse5';\nimport { createElement, getTagName, appendChild, findElement } from '@web/parse5-utils';\n\nconst doc = parse(`\n  <html>\n    <body>\n      <my-element></my-element>\n      <div id=\"foo\"></div>\n    </body>\n  </html>`);\n\nconst body = findElement(doc, e => getTagName(e) === 'body');\nconst script = createElement('script', { src: './foo.js' });\nappendChild(body, script);\n```\n\n```js\nimport { parse } from 'parse5';\nimport { getTagName, getAttribute, findElements } from '@web/parse5-utils';\n\nconst doc = parse(`\n  <html>\n    <body>\n      <script src=\"./a.js\"></script>\n      <script type=\"module\" src=\"./b.js\"></script>\n      <script type=\"module\" src=\"./c.js\"></script>\n    </body>\n  </html>`);\n\nconst allModuleScripts = findElements(\n  doc,\n  e => getTagName(e) === 'script' && getAttribute(e, 'type') === 'module',\n);\n```\n\n`appendToDocument` and `prependToDocument` will inject a snippet of HTML into the page, making sure it is executed last or first respectively.\n\nIt tries to avoid changing the formatting of the original file, using parse5 to find out the location of `body` and `head` tags and string concatenation in the original code to do the actual injection. In case of incomplete or invalid HTML it may fall back parse5 to generate a valid document and inject using AST manipulation.\n\n```js\nimport { prependToDocument, appendToDocument } from '@web/parse5-utils';\n\nconst html = '<html><body></body></html>';\nconst htmlWithInjectedScript = appendToDocument(\n  html,\n  '<scrip type=\"module\" src=\"./injected-script.js\"></script>',\n);\n```\n\n## Available functions\n\n- createDocument\n- createDocumentFragment\n- createElement\n- createScript\n- createCommentNode\n- appendChild\n- insertBefore\n- setTemplateContent\n- getTemplateContent\n- setDocumentType\n- setDocumentMode\n- getDocumentMode\n- detachNode\n- insertText\n- insertTextBefore\n- adoptAttributes\n- getFirstChild\n- getChildNodes\n- getParentNode\n- getAttrList\n- getTagName\n- getNamespaceURI\n- getTextNodeContent\n- getCommentNodeContent\n- getDocumentTypeNodeName\n- getDocumentTypeNodePublicId\n- getDocumentTypeNodeSystemId\n- isTextNode\n- isCommentNode\n- isDocumentTypeNode\n- isElementNode\n- setNodeSourceCodeLocation\n- getNodeSourceCodeLocation\n- updateNodeSourceCodeLocation\n- isHtmlFragment\n- hasAttribute\n- getAttribute\n- getAttributes\n- setAttribute\n- setAttributes\n- removeAttribute\n- setTextContent\n- getTextContent\n- remove\n- findNode\n- findNodes\n- findElement\n- findElements\n- prepend\n- prependToDocument\n- appendToDocument\n","publish_time":1615366872835,"_cnpm_publish_time":1615366872835,"dist-tags":{"canary":"0.0.0-canary-20240219104536","latest":"3.0.1"}}