Gathering detailed insights and metrics for data-urls
Gathering detailed insights and metrics for data-urls
Gathering detailed insights and metrics for data-urls
Gathering detailed insights and metrics for data-urls
@types/data-urls
TypeScript definitions for data-urls
@readme/data-urls
A utility for parsing and validating data URLs.
parse-data-urls
<description>
dauria
Node.js module for Data URI applications. It performs conversions between Node.js Buffers and RFC2397-compliant Data URIs, or vice versa.
npm install data-urls
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
84.7
Quality
81.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,839,861,228
Last Day
1,473,777
Last Week
27,318,588
Last Month
119,847,962
Last Year
1,201,906,886
MIT License
74 Stars
36 Commits
16 Forks
5 Watchers
1 Branches
6 Contributors
Updated on May 30, 2025
Minified
Minified + Gzipped
Latest Version
5.0.0
Package Id
data-urls@5.0.0
Unpacked Size
7.65 kB
Size
3.39 kB
File Count
5
NPM Version
10.2.0
Node Version
21.1.0
Published on
Nov 11, 2023
Cumulative downloads
Total Downloads
2
3
data:
URLsThis package helps you parse data:
URLs according to the WHATWG Fetch Standard:
1const parseDataURL = require("data-urls"); 2 3const textExample = parseDataURL("data:,Hello%2C%20World!"); 4console.log(textExample.mimeType.toString()); // "text/plain;charset=US-ASCII" 5console.log(textExample.body); // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ] 6 7const htmlExample = parseDataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E"); 8console.log(htmlExample.mimeType.toString()); // "text/html" 9console.log(htmlExample.body); // Uint8Array(22) [ 60, 104, 49, 62, 72, 101, … ] 10 11const pngExample = parseDataURL("data:image/png;base64,iVBORw0KGgoAAA" + 12 "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" + 13 "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" + 14 "5ErkJggg=="); 15console.log(pngExample.mimeType.toString()); // "image/png" 16console.log(pngExample.body); // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ]
This 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.
mimeType
property is an instance of whatwg-mimetype's MIMEType
class.body
property is a Uint8Array
instance.As 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.
To 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; there are various possible labels for a given encoding. We suggest using the whatwg-encoding package as follows:
1const parseDataURL = require("data-urls"); 2const { labelToName, decode } = require("whatwg-encoding"); 3 4const dataURL = parseDataURL(arbitraryString); 5 6// If there's no charset parameter, let's just hope it's UTF-8; that seems like a good guess. 7const encodingName = labelToName(dataURL.mimeType.parameters.get("charset") || "utf-8"); 8const bodyDecoded = decode(dataURL.body, encodingName);
This is especially important since the default, if no parseable MIME type is given, is "US-ASCII", aka windows-1252, 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!"
.
If you are using the 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:
1const { parseURL } = require("whatwg-url"); 2const dataURLFromURLRecord = require("data-urls").fromURLRecord; 3 4const urlRecord = parseURL("data:,Hello%2C%20World!"); 5const dataURL = dataURLFromURLRecord(urlRecord);
In practice, we expect this functionality only to be used by consumers like jsdom, which are using these packages at a very low level.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-13.4%
1,473,777
Compared to previous day
Last Week
-9.7%
27,318,588
Compared to previous week
Last Month
4.2%
119,847,962
Compared to previous month
Last Year
19.9%
1,201,906,886
Compared to previous year