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.6 to 0.1.0

example/example.js

10

is-base64.js

@@ -15,9 +15,13 @@ (function(root) {

var regex = /^(data:\w+\/[a-zA-Z\+\-\.]+;base64,)?(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/gi;
var regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\/]{3}=)?';
if (opts.mime) {
regex = '(data:\\w+\\/[a-zA-Z\\+\\-\\.]+;base64,)?' + regex
}
if (opts.paddingRequired === false) {
regex = /^(data:\w+\/[a-zA-Z\+\-\.]+;base64,)?(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}(==)?|[A-Za-z0-9+\/]{3}=?)?$/gi;
regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?'
}
return regex.test(v);
return (new RegExp('^' + regex + '$', 'gi')).test(v);
}

@@ -24,0 +28,0 @@

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

@@ -18,3 +18,4 @@ "main": "is-base64.js",

"predicate",
"base64"
"base64",
"mime"
],

@@ -28,4 +29,4 @@ "author": "Miguel Mota <hello@miguelmota.com> (http://www.miguelmota.com/)",

"devDependencies": {
"tape": "^3.0.3"
"tape": "^4.9.1"
}
}

@@ -20,3 +20,4 @@ # is-base64

console.log(isBase64(string)); // true
console.log(isBase64(stringWithMime)); // true
console.log(isBase64(stringWithMime)); // false
console.log(isBase64(stringWithMime, {mime: true})); // true
console.log(isBase64('1342234')); // false

@@ -40,2 +41,4 @@ console.log(isBase64('afQ$%rfew')); // false

- [options.paddingRequired=true] {boolean} - check for padding
- [options.mime=false] {boolean} - returns true for valid strings with mime
- [options.allowBlank=true] {boolean} - returns true for empty string

@@ -42,0 +45,0 @@ # License

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

test('isBase64', function (t) {
t.plan(21);
t.plan(25);

@@ -15,5 +15,7 @@ var pngString = 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQAQMAAAD1s08VAAAAA1BMVEX/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4GsTfAAGc95RKAAAAAElFTkSuQmCC';

t.equal(isBase64(pngString), true);
t.equal(isBase64(pngStringWithMime), true);
t.equal(isBase64(pngStringWithMime), false);
t.equal(isBase64(pngStringWithMime, {mime: true}), true);
t.equal(isBase64(jpgString), true);
t.equal(isBase64(jpgStringWithMime), true);
t.equal(isBase64(jpgStringWithMime), false);
t.equal(isBase64(jpgStringWithMime, {mime: true}), true);

@@ -25,6 +27,6 @@ // helper for creating fake valid mime strings

// 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(createMimeString('application/vnd.apple.installer+xml'), {mime: true}), true);
t.equal(isBase64(createMimeString('image/svg+xml'), {mime: true}), true);
t.equal(isBase64(createMimeString('application/set-payment-initiation'), {mime: true}), true);
t.equal(isBase64(createMimeString('image/vnd.adobe.photoshop'), {mime: true}), true);

@@ -40,2 +42,4 @@ t.equal(isBase64('1342234'), false);

t.equal(isBase64('uuLMhh==', {paddingRequired: true}), true);
t.equal(isBase64('data:image/png;base64,uuLMhh==', {paddingRequired: true}), false);
t.equal(isBase64('data:image/png;base64,uuLMhh==', {paddingRequired: true, mime: true}), true);
t.equal(isBase64(''), true);

@@ -42,0 +46,0 @@ t.equal(isBase64('', {allowBlank: false}), 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