
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
valid-data-url
Advanced tools
The valid-data-url npm package is a utility for validating whether a given string is a valid data URL. Data URLs are used to embed small files inline in documents.
Validate Data URL
This feature allows you to check if a given string is a valid data URL. The code sample demonstrates how to use the valid-data-url package to validate a base64 encoded data URL.
const validDataUrl = require('valid-data-url');
const url = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==';
const isValid = validDataUrl(url);
console.log(isValid); // true
The data-uri-to-buffer package converts a Data URI to a Buffer. While it does not directly validate data URLs, it can be used to parse and handle data URLs, which can be useful in conjunction with validation.
The dataurl package provides utilities for parsing and serializing data URLs. It offers more comprehensive functionality compared to valid-data-url, including the ability to extract and manipulate the content of data URLs.
The is-data-uri package is another utility for checking if a string is a valid data URI. It offers similar functionality to valid-data-url but may have different performance characteristics or additional features.
Based on Brian Grinstead's solution https://gist.github.com/bgrins/6194623. Special thanks to Jamie Davis for helping to fix ReDoS exploit.
The "data" URL scheme is described here RFC2397
dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype := [ type "/" subtype ] *( ";" parameter )
data := *urlchar
parameter := attribute "=" value
where urlchar
is imported from RFC2396, and type
, subtype
, attribute
and value
are the corresponding tokens from RFC2045, represented using URL escaped encoding of RFC2396 as necessary.
Attribute values in RFC2045 are allowed to be either represented as tokens or as quoted strings. However, within a data
URL, the quoted-string
representation would be awkward, since the quote mark is itself not a valid urlchar. For this reason, parameter values should use the URL Escaped encoding instead of quoted string if the parameter values contain any tspecial
.
The ;base64
extension is distinguishable from a content-type parameter by the fact that it doesn't have a following =
sign.
npm install valid-data-url
'use strict';
var validDataUrl = require('valid-data-url');
var isValid = validDataUrl('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D'); // true
The original author is Brian Grinstead
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5.0.0 (2023-08-08)
<a name="4.0.1"></a>
FAQs
Detect if a string is a data URL
The npm package valid-data-url receives a total of 897,153 weekly downloads. As such, valid-data-url popularity was classified as popular.
We found that valid-data-url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.