-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
46 lines (42 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const canvas = require('canvas');
const imageType = require('image-type');
function overrideWindow() {
const doc = {};
doc.createElement = function(tag) {
return (tag !== 'canvas') ?
false :
new canvas;
};
return {
document: doc
}
}
function overrideFileReader() {
const FileReader = function() {};
FileReader.prototype.readAsDataURL = function(buffer) {
this.onload({
target: {
result: 'data:image/' + imageType(buffer) + ';base64,' + buffer.toString('base64')
}
});
};
return FileReader;
}
function overrideImage() {
const Image = canvas.Image;
Image.prototype.setAttribute = function() {};
return Image;
}
module.exports = function() {
if (typeof window === "undefined") {
global.window = overrideWindow()
}
if (typeof FileReader === "undefined") {
global.FileReader = overrideFileReader()
}
if (typeof Image === "undefined") {
global.Image = overrideImage()
}
const resemblejs = require('resemblejs');
return resemblejs.apply(this, arguments);
};