Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-base64

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-base64 - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

4

is-base64.js

@@ -5,4 +5,4 @@ (function(root) {

function isBase64(v) {
var re = /^(data:\w+\/png;base64,)?([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/gi;
return re.test(v);
var regex = /^(data:\w+\/[a-zA-Z\+\-\.]+;base64,)?([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/gi;
return regex.test(v);
}

@@ -9,0 +9,0 @@

{
"name": "is-base64",
"version": "0.0.1",
"version": "0.0.2",
"description": "Predicate that returns true if base64 string.",

@@ -26,5 +26,5 @@ "main": "is-base64.js",

"homepage": "https://github.com/miguelmota/is-base64",
"dependencies": {
"devDependencies": {
"tape": "^3.0.3"
}
}

@@ -5,10 +5,25 @@ var test = require('tape');

test('isBase64', function (t) {
t.plan(5);
t.plan(11);
var string = 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQAQMAAAD1s08VAAAAA1BMVEX/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4GsTfAAGc95RKAAAAAElFTkSuQmCC';
var pngString = 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQAQMAAAD1s08VAAAAA1BMVEX/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAA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gYIhQODg4UFA4ODg4UEQwMDAwMEREMDAwMDAwRDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDP/AABEIAAYABgMBIgACEQEDEQH/xABVAAEBAAAAAAAAAAAAAAAAAAAAAxAAAQQCAwEAAAAAAAAAAAAAAgABAxQEIxIkMxMBAQAAAAAAAAAAAAAAAAAAAAARAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AIE7MwkbOUJDJWx+ZjXATitx2/h2bEWvX5Y0npQ7aIiD/9k=';
var stringWithMime = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAALQAQMAAAD1s08VAAAAA1BMVEX/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4GsTfAAGc95RKAAAAAElFTkSuQmCC';
// Test agains real images
t.equal(isBase64(pngString), true);
t.equal(isBase64(pngStringWithMime), true);
t.equal(isBase64(jpgString), true);
t.equal(isBase64(jpgStringWithMime), true);
t.equal(isBase64(string), true);
t.equal(isBase64(stringWithMime), true);
// helper for creating fake valid mime strings
const createMimeString = (mime) => `data:${mime};base64,${pngString}`;
// Random complex mime types taken from:
// http://www.freeformatter.com/mime-types-list.html
t.equal(isBase64(createMimeString('application/vnd.apple.installer+xml')), true);
t.equal(isBase64(createMimeString('image/svg+xml')), true);
t.equal(isBase64(createMimeString('application/set-payment-initiation')), true);
t.equal(isBase64(createMimeString('image/vnd.adobe.photoshop')), true);
t.equal(isBase64('1342234'), false);

@@ -15,0 +30,0 @@ t.equal(isBase64('afQ$%rfew'), false);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc