UNPKG

1.11 kBJavaScriptView Raw
1const h54sError = require('../error.js');
2
3/**
4* h54s SAS Files object constructor
5* @constructor
6*
7*@param {file} file - File added when object is created
8*@param {string} macroName - macro name
9*
10*/
11function Files(file, macroName) {
12 this._files = {};
13
14 Files.prototype.add.call(this, file, macroName);
15}
16
17/**
18* Add file to files object
19* @param {file} file - Instance of JavaScript File object
20* @param {string} macroName - Sas macro name
21*
22*/
23Files.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
44module.exports = Files;