Comparing version 0.0.1 to 0.0.2
@@ -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/AAAZ4gk3AAAAh0lEQVR42u3BMQEAAADCoPVPbQlPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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MDP/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); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7899
0
70
1
- Removedtape@^3.0.3
- Removeddeep-equal@0.2.2(transitive)
- Removeddefined@0.0.0(transitive)
- Removedglob@3.2.11(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedobject-inspect@0.4.0(transitive)
- Removedresumer@0.0.0(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedtape@3.6.1(transitive)
- Removedthrough@2.3.8(transitive)