{"c8":{"exclude":["scripts/","test/"],"reporter":["html"]},"_id":"data-urls@8.0.0","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"dist":{"shasum":"d4e925beae8249dbe99a1defed36cebb9cc7a84c","tarball":"http://registry-npm.ywwl.com/data-urls/download/data-urls-8.0.0.tgz","fileCount":5,"integrity":"sha512-JQUCCK+/CAGbGGx618PlFZMXH81Jtj7t73CHv9dd/zVWvxgGT2zLFRjnKb+Ng46GIwcy+f7f88qd4duqllK+WQ==","signatures":[{"sig":"MEUCIBzFAMzsBUqKxmwtU9ZOQTbRbd8Iz9CE+d2JPM+8k0GnAiEA1IfmEGfVsa0kSUYPDwY3xSoIguhl34aIL51wWqLLPtE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBFb/Rgkl9+D757EKPiYPqcSKYL4cWyypgzOZ8WdYsG2AiB1a1PQ7lIJ2UNe4Hs7e1MIr8PhAvu/9AFAfE+wSS2kxQ=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/data-urls@8.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":8329,"size":3732,"noattachment":false,"key":"/data-urls/-/data-urls-8.0.0.tgz"},"main":"lib/parser.js","name":"data-urls","author":{"url":"https://domenic.me/","name":"Domenic Denicola","email":"d@domenic.me"},"engines":{"node":"^22.14.0 || >=24.0.0"},"gitHead":"5bd3a2081dea4a58722ed314adc0962f7fbe5740","license":"MIT","scripts":{"lint":"eslint","test":"node --test","pretest":"node scripts/get-latest-platform-tests.mjs","coverage":"c8 node --test --experimental-test-coverage"},"version":"8.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"b1df1ea3-1619-4cf1-ae9d-fa878179e210"}},"homepage":"https://github.com/jsdom/data-urls#readme","keywords":["data url","data uri","data:","http","fetch","whatwg"],"repository":{"url":"git+https://github.com/jsdom/data-urls.git","type":"git"},"_npmVersion":"11.19.0","description":"Parses data: URLs","directories":{},"maintainers":[{"name":"timothygu","email":"timothygu99@gmail.com"},{"name":"domenic","email":"d@domenic.me"},{"name":"sebmaster","email":"sebmaster16@gmail.com"},{"name":"zirro","email":"code@zirro.se"},{"name":"tmpvar","email":"tmpvar@gmail.com"},{"name":"joris-van-der-wel","email":"joris@jorisvanderwel.com"}],"_nodeVersion":"24.21.0","dependencies":{"whatwg-url":"^17.1.2","whatwg-mimetype":"^5.0.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","eslint":"^10.12.0","globals":"^17.13.0","@domenic/eslint-config":"^5.1.0","@stylistic/eslint-plugin":"^5.10.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/data-urls_8.0.0_1791099615055_0.8008256719522109"},"readme":"# Parse `data:` URLs\n\nThis package helps you parse `data:` URLs [according to the WHATWG Fetch Standard](https://fetch.spec.whatwg.org/#data-urls):\n\n```js\nconst parseDataURL = require(\"data-urls\");\n\nconst textExample = parseDataURL(\"data:,Hello%2C%20World!\");\nconsole.log(textExample.mimeType.toString()); // \"text/plain;charset=US-ASCII\"\nconsole.log(textExample.body);                // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ]\n\nconst htmlExample = parseDataURL(\"data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E\");\nconsole.log(htmlExample.mimeType.toString()); // \"text/html\"\nconsole.log(htmlExample.body);                // Uint8Array(22) [ 60, 104, 49, 62, 72, 101, … ]\n\nconst pngExample = parseDataURL(\"data:image/png;base64,iVBORw0KGgoAAA\" +\n                                \"ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4\" +\n                                \"//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU\" +\n                                \"5ErkJggg==\");\nconsole.log(pngExample.mimeType.toString()); // \"image/png\"\nconsole.log(pngExample.body);                // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ]\n```\n\n## API\n\nThis package's main module's default export is a function that accepts a string and returns a `{ mimeType, body }` object, or `null` if the result cannot be parsed as a `data:` URL.\n\n- The `mimeType` property is an instance of [whatwg-mimetype](https://www.npmjs.com/package/whatwg-mimetype)'s `MIMEType` class.\n- The `body` property is a `Uint8Array` instance.\n\nAs shown in the examples above, you can easily get a stringified version of the MIME type using its `toString()` method. Read on for more on getting the stringified version of the body.\n\n### Decoding the body\n\nTo decode the body bytes of a parsed data URL, you'll need to use the `charset` parameter of the MIME type, if any. This contains an encoding [label](https://encoding.spec.whatwg.org/#label); there are [various possible labels](https://encoding.spec.whatwg.org/#names-and-labels) for a given encoding. You can use the [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder) API for this:\n\n```js\nconst parseDataURL = require(\"data-urls\");\n\nconst dataURL = parseDataURL(arbitraryString);\n\n// If there's no charset parameter, e.g. if `arbitraryString` is `\"data:text/plain,H%C3%A9llo!\"`,\n// then let's guess UTF-8.\nconst encodingLabel = dataURL.mimeType.parameters.get(\"charset\") ?? \"utf-8\";\nconst decoder = new TextDecoder(encodingLabel);\n\nconst bodyDecoded = decoder.decode(dataURL.body);\n```\n\n(Note that as of the time of this writing in 2026-01, Node.js's built-in `TextDecoder` has many correctness bugs, so we suggest using the polyfill from the [`@exodus/bytes`](https://www.npmjs.com/package/@exodus/bytes) package until they are fixed.)\n\nUsing the parsed charset is quite important, since [the spec requires](https://fetch.spec.whatwg.org/#data-url-processor) that if no parseable MIME type is given, the default is `\"US-ASCII\"`, [aka windows-1252](https://encoding.spec.whatwg.org/#note-latin1-ascii)—not UTF-8, like you might asume. So for example, given an `arbitraryString` of `\"data:,H%E9llo!\"`, the above code snippet will correctly produce a `bodyDecoded` of `\"Héllo!\"` by using the windows-1252 decoder, whereas if you used a UTF-8 decoder you'd get back `\"H�llo!\"`.\n\n### Advanced functionality: parsing from a URL record\n\nIf you are using the [`whatwg-url`](https://www.npmjs.com/package/whatwg-url) package, you may already have a \"URL record\" object on hand, as produced by that package's `parseURL` export. In that case, you can use this package's `fromURLRecord` export to save a bit of work:\n\n```js\nconst { parseURL } = require(\"whatwg-url\");\nconst dataURLFromURLRecord = require(\"data-urls\").fromURLRecord;\n\nconst urlRecord = parseURL(\"data:,Hello%2C%20World!\");\nconst dataURL = dataURLFromURLRecord(urlRecord);\n```\n\nIn practice, we expect this functionality only to be used by consumers like [jsdom](https://www.npmjs.com/package/jsdom), which are using these packages at a very low level.\n","publish_time":1791099615148,"_cnpm_publish_time":1791099615148,"dist-tags":{"latest":"8.0.0"}}