1 | const h54sError = require('../error.js');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function Files(file, macroName) {
|
12 | this._files = {};
|
13 |
|
14 | Files.prototype.add.call(this, file, macroName);
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Files.prototype.add = function(file, macroName) {
|
24 | if(file && macroName) {
|
25 | if(!(file instanceof File || file instanceof Blob)) {
|
26 | throw new h54sError('argumentError', 'First argument must be instance of File object');
|
27 | }
|
28 | if(typeof macroName !== 'string') {
|
29 | throw new h54sError('argumentError', 'Second argument must be string');
|
30 | }
|
31 | if(!isNaN(macroName[macroName.length - 1])) {
|
32 | throw new h54sError('argumentError', 'Macro name cannot have number at the end');
|
33 | }
|
34 | } else {
|
35 | throw new h54sError('argumentError', 'Missing arguments');
|
36 | }
|
37 |
|
38 | this._files[macroName] = [
|
39 | 'FILE',
|
40 | file
|
41 | ];
|
42 | };
|
43 |
|
44 | module.exports = Files;
|