![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
valid-data-url
Advanced tools
Package description
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.
Changelog
0.1.6 (2018-03-09)
<a name="0.1.5"></a>
Readme
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.
FAQs
Detect if a string is a data URL
The npm package valid-data-url receives a total of 564,414 weekly downloads. As such, valid-data-url popularity was classified as popular.
We found that valid-data-url demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.