Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  first time map generation
  builded files
  - changed style for output log - added header generation - reintent
  added gulp-header
  fix package.json format
  updated version in bower and package json
  - refactoring and reintenting - removed $log dependencies
  updated package json
  • Loading branch information
marchrius committed Mar 17, 2017
2 parents d1592fc + 1d76550 commit 9eac9bc
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 241 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "angular-mimetype",
"version": "0.0.3",
"description": "An angular plugin that check the image header of a given file/string/Blog",
"main": "angular-mimetype.js",
"authors": [
Expand Down
167 changes: 85 additions & 82 deletions dist/angular-mimetype.js
Original file line number Diff line number Diff line change
@@ -1,150 +1,148 @@
/**
* angular-mimetype - An angular plugin to check the mimetype of a given String/Base64/ArrayBuffer
* @version v0.0.3
* @author Matteo Gaggiano <m.gaggiano@marchrius.org> (https://marchrius.org/blog)
* @link https://marchrius.org/blog
* @maintainers
*
* @license MIT
*/
(function() {
'use strict';

angular
.module('mg.mimetype', ['mg.mimetype.filters', 'mg.mimetype.directives', 'mg.mimetype.constants']);
angular.module('mg.mimetype', ['mg.mimetype.filters', 'mg.mimetype.directives', 'mg.mimetype.constants']);

})();
(function () {
(function() {
'use strict';

angular
.module('mg.mimetype.constants', []);

angular.module('mg.mimetype.constants', []);

})();
(function() {
'use strict';

angular
.module('mg.mimetype.directives', []);

angular.module('mg.mimetype.directives', []);

})();
(function () {
(function() {
'use strict';

angular
.module('mg.mimetype.providers', []);

angular.module('mg.mimetype.filters', ['mg.mimetype.utils', 'mg.mimetype.constants']);

})();
(function() {
'use strict';


angular
.module('mg.mimetype.filters', ['mg.mimetype.utils', 'mg.mimetype.constants']);
angular.module('mg.mimetype.utils', []);

})();
(function() {
'use strict';

angular.module('mg.mimetype.utils', []);
angular.module('mg.mimetype.providers', []);

})();
(function () {
(function() {
'use strict';

angular
.module('mg.mimetype.constants')
.constant('fileType',
{
angular.module('mg.mimetype.constants')
.constant('fileType', {
// .PNG....
"iVBORw0KGgo": {
"regex":"^89504E470D0A1A0A",
"regex": "^89504E470D0A1A0A",
"name": "png",
"type": "image/png",
"offset": "0"
},
"/9j/": [
// ÿØÿÛ
{
"regex" : "^FFD8FFDB",
"regex": "^FFD8FFDB",
"name": "jpeg",
"type": "image/jpeg",
"offset":"0"
"offset": "0"
},
// ÿØÿà ..JF IF..
{
"regex" : "^FFD8FFE0[0-9a-fA-F]{4}4A4649460001",
"regex": "^FFD8FFE0[0-9a-fA-F]{4}4A4649460001",
"name": "jfif",
"type": "image/jpeg",
"offset":"0"
"offset": "0"
},
// ÿØÿá ..Ex if..
{
"regex" : "^FFD8FFE1[0-9a-fA-F]{4}457869660000",
"regex": "^FFD8FFE1[0-9a-fA-F]{4}457869660000",
"name": "exif",
"type": "image/jpeg",
"offset":"0"
"offset": "0"
},
],
// %PDF
"JVBERg": {
"regex":"^25504446",
"name":"pdf",
"type":"application/pdf",
"offset":"0"
"regex": "^25504446",
"name": "pdf",
"type": "application/pdf",
"offset": "0"
},
"R0lGOD": [
// GIF87a
{
"regex":"^474946383761",
"name":"gif",
"type":"image/gif",
"offset":"0"
"regex": "^474946383761",
"name": "gif",
"type": "image/gif",
"offset": "0"
},
// GIF89a
{
"regex":"^474946383961",
"name":"gif",
"type":"image/gif",
"offset":"0"
"regex": "^474946383961",
"name": "gif",
"type": "image/gif",
"offset": "0"
}
],
// II*.
"SUkqAA": {
"regex":"^49492A00",
"name":"",
"type":"image/tiff",
"offset":"0"
"regex": "^49492A00",
"name": "",
"type": "image/tiff",
"offset": "0"
},
// MM.*
"TU0AKg": {
"regex":"^4D4D002A",
"name":"",
"type":"image/tiff",
"offset":"0"
"regex": "^4D4D002A",
"name": "",
"type": "image/tiff",
"offset": "0"
},
"AAABAA": {
"regex":"^00000100",
"name":"ico",
"type":"image/ico",
"offset":"0"
"regex": "^00000100",
"name": "ico",
"type": "image/ico",
"offset": "0"
},
// 8BPS
"OEJQUw": {
"regex":"",
"name":"psd",
"type":"",
"offset":""
"regex": "",
"name": "psd",
"type": "",
"offset": ""
}
});
})();
(function() {
'use strict';

angular
.module('mg.mimetype.providers')
angular.module('mg.mimetype.providers')
.provider('$mimeType', mimeTypeProvider);

function mimeTypeProvider($log) {
$log.debug("mimeTypeProvider initialized.");
}
function mimeTypeProvider() {}

})();
(function() {
'use strict';

angular
.module('mg.mimetype.utils')
angular.module('mg.mimetype.utils')
.service('$util', UtilService);

function UtilService() {
Expand All @@ -154,11 +152,10 @@
service.base64ToHex = base64ToHex;
service.hop = hop;
service.escapeRegExp = escapeRegExp;

function hexToBase64(str) {
return btoa(String.fromCharCode.apply(null,
str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))
);
str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}

function base64ToHex(str, flag) {
Expand All @@ -175,22 +172,22 @@
return Object.prototype.hasOwnProperty.call(obj, key);
}

function escapeRegExp(string){
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

return service;
}
})();
(function () {
(function() {
'use strict';

angular.module('mg.mimetype.filters')
.filter('mimetype', function ($log, $util, fileType) {
.filter('mimetype', function($util, fileType) {

var MAX_LEN = 255;
var EMPTY_STRING = "".toString();

return function mimeTypeFilter() {
var args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
var input = args[0];
Expand All @@ -209,12 +206,14 @@
function fromString(input) {
if (typeof input === 'undefined')
return EMPTY_STRING;
var found = null, obj = null, part, hex, res;
for(var prop in fileType) {
var found = null,
obj = null,
part, hex, res;
for (var prop in fileType) {
if ($util.hop(fileType, prop) && input.startsWith(prop)) {
obj = fileType[prop];
if (angular.isArray(obj)) {
for(var i = 0; i < obj.length; i++) {
for (var i = 0; i < obj.length; i++) {
part = input.substr(0, MAX_LEN);
hex = $util.base64ToHex(part, false).toUpperCase();
res = test(obj[i].regex, hex);
Expand All @@ -238,20 +237,22 @@
function test(regStr, compStr) {
return (new RegExp(regStr)).test(compStr);
}
});
});
})();
if (!window.atob) {
var tableStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var table = tableStr.split("");

window.atob = function (base64) {
window.atob = function(base64) {
if (/(=[^=]+|={3,})$/.test(base64)) throw new Error("String contains an invalid character");
base64 = base64.replace(/=/g, "");
var n = base64.length & 3;
if (n === 1) throw new Error("String contains an invalid character");
for (var i = 0, j = 0, len = base64.length / 4, bin = []; i < len; ++i) {
var a = tableStr.indexOf(base64[j++] || "A"), b = tableStr.indexOf(base64[j++] || "A");
var c = tableStr.indexOf(base64[j++] || "A"), d = tableStr.indexOf(base64[j++] || "A");
var a = tableStr.indexOf(base64[j++] || "A"),
b = tableStr.indexOf(base64[j++] || "A");
var c = tableStr.indexOf(base64[j++] || "A"),
d = tableStr.indexOf(base64[j++] || "A");
if ((a | b | c | d) < 0) throw new Error("String contains an invalid character");
bin[bin.length] = ((a << 2) | (b >> 4)) & 255;
bin[bin.length] = ((b << 4) | (c >> 2)) & 255;
Expand All @@ -260,13 +261,15 @@ if (!window.atob) {
return String.fromCharCode.apply(null, bin).substr(0, bin.length + n - 4);
};

window.btoa = function (bin) {
window.btoa = function(bin) {
for (var i = 0, j = 0, len = bin.length / 3, base64 = []; i < len; ++i) {
var a = bin.charCodeAt(j++), b = bin.charCodeAt(j++), c = bin.charCodeAt(j++);
var a = bin.charCodeAt(j++),
b = bin.charCodeAt(j++),
c = bin.charCodeAt(j++);
if ((a | b | c) > 255) throw new Error("String contains an invalid character");
base64[base64.length] = table[a >> 2] + table[((a << 4) & 63) | (b >> 4)] +
(isNaN(b) ? "=" : table[((b << 2) & 63) | (c >> 6)]) +
(isNaN(b + c) ? "=" : table[c & 63]);
(isNaN(b) ? "=" : table[((b << 2) & 63) | (c >> 6)]) +
(isNaN(b + c) ? "=" : table[c & 63]);
}
return base64.join("");
};
Expand Down
12 changes: 11 additions & 1 deletion dist/angular-mimetype.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9eac9bc

Please sign in to comment.