{"_id":"data-urls","_rev":"198209","name":"data-urls","description":"Parses data: URLs","dist-tags":{"latest":"4.0.0"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"time":{"modified":"2023-03-20T08:11:23.000Z","created":"2018-01-31T22:31:54.529Z","4.0.0":"2023-01-03T02:27:49.741Z","3.0.2":"2022-04-25T00:45:15.708Z","3.0.1":"2021-10-06T17:03:00.337Z","3.0.0":"2021-07-19T19:07:45.540Z","2.0.0":"2020-01-02T20:33:59.814Z","1.1.0":"2018-10-26T13:05:29.091Z","1.0.1":"2018-08-18T21:22:26.198Z","1.0.0":"2018-01-31T22:31:54.529Z"},"users":{},"author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"versions":{"4.0.0":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"4.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"dependencies":{"abab":"^2.0.6","whatwg-mimetype":"^3.0.0","whatwg-url":"^12.0.0"},"devDependencies":{"@domenic/eslint-config":"^3.0.0","eslint":"^8.31.0","jest":"^29.3.1","minipass-fetch":"^3.0.1"},"engines":{"node":">=14"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"gitHead":"55b4e54384921231893545e2c592afdb5685a986","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@4.0.0","_nodeVersion":"19.1.0","_npmVersion":"8.19.3","dist":{"shasum":"333a454eca6f9a5b7b0f1013ff89074c3f522dd4","size":3565,"noattachment":false,"key":"/data-urls/-/data-urls-4.0.0.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-4.0.0.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_4.0.0_1672712869607_0.6585516810430649"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-01-03T02:30:40.779Z","publish_time":1672712869741,"_cnpm_publish_time":1672712869741},"3.0.2":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"3.0.2","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"dependencies":{"abab":"^2.0.6","whatwg-mimetype":"^3.0.0","whatwg-url":"^11.0.0"},"devDependencies":{"@domenic/eslint-config":"^2.0.0","eslint":"^8.14.0","jest":"^27.5.1","minipass-fetch":"^2.1.0"},"engines":{"node":">=12"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"gitHead":"f061877a7d517b3160ce7a7752fee0262308886c","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@3.0.2","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"shasum":"9cf24a477ae22bcef5cd5f6f0bfbc1d2d3be9143","size":3565,"noattachment":false,"key":"/data-urls/-/data-urls-3.0.2.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-3.0.2.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_3.0.2_1650847515533_0.35206335376716824"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-04-25T00:45:20.278Z","publish_time":1650847515708,"_cnpm_publish_time":1650847515708},"3.0.1":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"3.0.1","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"dependencies":{"abab":"^2.0.3","whatwg-mimetype":"^3.0.0","whatwg-url":"^10.0.0"},"devDependencies":{"@domenic/eslint-config":"^1.4.0","eslint":"^7.32.0","jest":"^27.2.4","minipass-fetch":"^1.4.1"},"engines":{"node":">=12"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"gitHead":"fb6402d4529a23ceeebaa82876cf6d473c3f936d","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@3.0.1","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"shasum":"597fc2ae30f8bc4dbcf731fcd1b1954353afc6f8","size":3567,"noattachment":false,"key":"/data-urls/-/data-urls-3.0.1.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-3.0.1.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_3.0.1_1633539780228_0.7045257317898264"},"_hasShrinkwrap":false,"publish_time":1633539780337,"_cnpm_publish_time":1633539780337,"_cnpmcore_publish_time":"2021-12-16T10:07:13.034Z"},"3.0.0":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"3.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"dependencies":{"abab":"^2.0.3","whatwg-mimetype":"^2.3.0","whatwg-url":"^9.0.0"},"devDependencies":{"@domenic/eslint-config":"^1.2.0","eslint":"^7.29.0","jest":"^27.0.5","node-fetch":"^2.6.1"},"engines":{"node":">=12"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"gitHead":"32acfcccdce72dd5e3932935296e3778ce62aa7d","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@3.0.0","_nodeVersion":"16.4.0","_npmVersion":"7.18.1","dist":{"shasum":"3ff551c986d7c6234a0ac4bbf20a269e1cd6b378","size":3578,"noattachment":false,"key":"/data-urls/-/data-urls-3.0.0.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-3.0.0.tgz"},"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_3.0.0_1626721665395_0.1851254701290712"},"_hasShrinkwrap":false,"publish_time":1626721665540,"_cnpm_publish_time":1626721665540,"_cnpmcore_publish_time":"2021-12-16T10:07:13.238Z"},"2.0.0":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"2.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"dependencies":{"abab":"^2.0.3","whatwg-mimetype":"^2.3.0","whatwg-url":"^8.0.0"},"devDependencies":{"eslint":"^6.8.0","jest":"^24.9.0","request":"^2.88.0"},"engines":{"node":">=10"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"gitHead":"f7d60e8f5f990ebbddbea956dd561870b5370445","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@2.0.0","_nodeVersion":"12.1.0","_npmVersion":"6.9.0","dist":{"shasum":"156485a72963a970f5d5821aaf642bef2bf2db9b","size":3562,"noattachment":false,"key":"/data-urls/-/data-urls-2.0.0.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-2.0.0.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmUser":{"name":"domenic","email":"d@domenic.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_2.0.0_1577997239716_0.9784558077583854"},"_hasShrinkwrap":false,"publish_time":1577997239814,"_cnpm_publish_time":1577997239814,"_cnpmcore_publish_time":"2021-12-16T10:07:13.514Z"},"1.1.0":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"1.1.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"devDependencies":{"eslint":"^5.7.0","jest":"^23.6.0","request":"^2.88.0"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/(?!(abab/lib/atob.js))"]},"dependencies":{"abab":"^2.0.0","whatwg-mimetype":"^2.2.0","whatwg-url":"^7.0.0"},"gitHead":"f42daf4c31a7ed00295993990ebbd2901bee168f","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@1.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"15ee0582baa5e22bb59c77140da8f9c76963bbfe","size":3550,"noattachment":false,"key":"/data-urls/-/data-urls-1.1.0.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-1.1.0.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_1.1.0_1540559128977_0.9896566440878478"},"_hasShrinkwrap":false,"publish_time":1540559129091,"_cnpm_publish_time":1540559129091,"_cnpmcore_publish_time":"2021-12-16T10:07:13.707Z"},"1.0.1":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"1.0.1","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","files":["lib/"],"scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"devDependencies":{"eslint":"^5.4.0","jest":"^23.5.0","request":"^2.88.0"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"]},"dependencies":{"abab":"^2.0.0","whatwg-mimetype":"^2.1.0","whatwg-url":"^7.0.0"},"gitHead":"ef1f61395cf0afdbbf04274509332becdd7eb4e1","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@1.0.1","_npmVersion":"6.2.0","_nodeVersion":"10.8.0","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"d416ac3896918f29ca84d81085bc3705834da579","size":3498,"noattachment":false,"key":"/data-urls/-/data-urls-1.0.1.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-1.0.1.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls_1.0.1_1534627346113_0.8636024731783971"},"_hasShrinkwrap":false,"publish_time":1534627346198,"_cnpm_publish_time":1534627346198,"_cnpmcore_publish_time":"2021-12-16T10:07:13.900Z"},"1.0.0":{"name":"data-urls","description":"Parses data: URLs","keywords":["data url","data uri","data:","http","fetch","whatwg"],"version":"1.0.0","author":{"name":"Domenic Denicola","email":"d@domenic.me","url":"https://domenic.me/"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jsdom/data-urls.git"},"main":"lib/parser.js","files":["lib/"],"scripts":{"test":"jest","coverage":"jest --coverage","lint":"eslint .","pretest":"node scripts/get-latest-platform-tests.js"},"devDependencies":{"eslint":"^4.13.0","jest":"^21.2.1","request":"^2.83.0"},"jest":{"coverageDirectory":"coverage","coverageReporters":["lcov","text-summary"],"testEnvironment":"node","testMatch":["<rootDir>/test/**/*.js"]},"dependencies":{"abab":"^1.0.4","whatwg-mimetype":"^2.0.0","whatwg-url":"^6.4.0"},"gitHead":"bd0705722c8992f48c9a9e2aa15e24189164a9ed","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"homepage":"https://github.com/jsdom/data-urls#readme","_id":"data-urls@1.0.0","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"domenic","email":"d@domenic.me"},"dist":{"shasum":"24802de4e81c298ea8a9388bb0d8e461c774684f","size":3527,"noattachment":false,"key":"/data-urls/-/data-urls-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/data-urls/download/data-urls-1.0.0.tgz"},"maintainers":[{"name":"domenic","email":""},{"name":"joris-van-der-wel","email":""},{"name":"sebmaster","email":""},{"name":"timothygu","email":""},{"name":"tmpvar","email":""},{"name":"zirro","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/data-urls-1.0.0.tgz_1517437914250_0.16816337523050606"},"directories":{},"publish_time":1517437914529,"_hasShrinkwrap":false,"_cnpm_publish_time":1517437914529,"_cnpmcore_publish_time":"2021-12-16T10:07:14.090Z"}},"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. We suggest using the [whatwg-encoding](https://www.npmjs.com/package/whatwg-encoding) package as follows:\n\n```js\nconst parseDataURL = require(\"data-urls\");\nconst { labelToName, decode } = require(\"whatwg-encoding\");\n\nconst dataURL = parseDataURL(arbitraryString);\n\n// If there's no charset parameter, let's just hope it's UTF-8; that seems like a good guess.\nconst encodingName = labelToName(dataURL.mimeType.parameters.get(\"charset\") || \"utf-8\");\nconst bodyDecoded = decode(dataURL.body, encodingName);\n```\n\nThis is especially important since the default, if no parseable MIME type is given, is \"US-ASCII\", [aka windows-1252](https://encoding.spec.whatwg.org/#names-and-labels), not UTF-8 like you might asume. So for example given an `arbitraryString` of `\"data:,Héllo!\"`, 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://github.com/jsdom/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","_attachments":{},"homepage":"https://github.com/jsdom/data-urls#readme","bugs":{"url":"https://github.com/jsdom/data-urls/issues"},"license":"MIT"}