Lutz Roeder 6 лет назад
Родитель
Сommit
aa80ddb43d
28 измененных файлов с 453 добавлено и 453 удалено
  1. 43 44
      src/app.js
  2. 9 9
      src/base.js
  3. 17 17
      src/bson.js
  4. 13 13
      src/caffe.js
  5. 18 17
      src/caffe2.js
  6. 12 12
      src/cntk.js
  7. 26 25
      src/coreml.js
  8. 7 7
      src/darknet.js
  9. 11 11
      src/dl4j.js
  10. 7 9
      src/flux.js
  11. 9 9
      src/gzip.js
  12. 20 18
      src/keras.js
  13. 6 6
      src/mlnet.js
  14. 13 13
      src/mxnet.js
  15. 20 19
      src/ncnn.js
  16. 12 13
      src/onnx.js
  17. 5 5
      src/openvino.js
  18. 6 6
      src/paddle.js
  19. 3 3
      src/python.js
  20. 14 14
      src/pytorch.js
  21. 9 9
      src/sklearn.js
  22. 7 7
      src/tar.js
  23. 38 35
      src/tf.js
  24. 10 10
      src/tflite.js
  25. 7 6
      src/torch.js
  26. 21 21
      src/torchscript.js
  27. 23 23
      src/view.js
  28. 67 72
      test/test.js

+ 43 - 44
src/app.js

@@ -24,13 +24,13 @@ class Application {
         }
 
         electron.app.on('second-instance', (event, commandLine, workingDirectory) => {
-            let currentDirectory = process.cwd();
+            const currentDirectory = process.cwd();
             process.chdir(workingDirectory);
-            let open = this._parseCommandLine(commandLine);
+            const open = this._parseCommandLine(commandLine);
             process.chdir(currentDirectory);
             if (!open) {
                 if (this._views.count > 0) {
-                    let view = this._views.item(0);
+                    const view = this._views.item(0);
                     if (view) {
                         view.restore();
                     }
@@ -43,7 +43,7 @@ class Application {
         });
 
         electron.ipcMain.on('drop-files', (e, data) => {
-            let files = data.files.filter((file) => fs.statSync(file).isFile());
+            const files = data.files.filter((file) => fs.statSync(file).isFile());
             this._dropFiles(e.sender, files);
         });
 
@@ -76,7 +76,7 @@ class Application {
         if (argv.length > 1) {
             for (let arg of argv.slice(1)) {
                 if (!arg.startsWith('-')) {
-                    let extension = arg.split('.').pop().toLowerCase();
+                    const extension = arg.split('.').pop().toLowerCase();
                     if (extension != '' && extension != 'js' && fs.existsSync(arg) && fs.statSync(arg).isFile()) {
                         this._openFile(arg);
                         open = true;
@@ -97,7 +97,7 @@ class Application {
             let openFileQueue = this._openFileQueue;
             this._openFileQueue = null;
             while (openFileQueue.length > 0) {
-                let file = openFileQueue.shift();
+                const file = openFileQueue.shift();
                 this._openFile(file);
             }
         }
@@ -114,7 +114,7 @@ class Application {
     }
 
     _openFileDialog() {
-        let showOpenDialogOptions = { 
+        const showOpenDialogOptions = { 
             properties: [ 'openFile' ], 
             filters: [
                 { name: 'All Model Files',  extensions: [ 
@@ -164,8 +164,7 @@ class Application {
     }
 
     _loadFile(file, view) {
-        let recents = this._configuration.get('recents');
-        recents = recents.filter(recent => file != recent.path);
+        const recents = this._configuration.get('recents').filter(recent => file != recent.path);
         view.open(file);
         recents.unshift({ path: file });
         if (recents.length > 9) {
@@ -192,13 +191,13 @@ class Application {
         let view = this._views.activeView;
         if (view && view.path) {
             let defaultPath = 'Untitled';
-            let file = view.path;
-            let lastIndex = file.lastIndexOf('.');
+            const file = view.path;
+            const lastIndex = file.lastIndexOf('.');
             if (lastIndex != -1) {
                 defaultPath = file.substring(0, lastIndex);
             }
-            let owner = electron.BrowserWindow.getFocusedWindow();
-            let showSaveDialogOptions = {
+            const owner = electron.BrowserWindow.getFocusedWindow();
+            const showSaveDialogOptions = {
                 title: 'Export',
                 defaultPath: defaultPath,
                 buttonLabel: 'Export',
@@ -216,7 +215,7 @@ class Application {
     }
 
     execute(command, data) {
-        let view = this._views.activeView;
+        const view = this._views.activeView;
         if (view) {
             view.execute(command, data || {});
         }
@@ -224,7 +223,7 @@ class Application {
     }
 
     _reload() {
-        let view = this._views.activeView;
+        const view = this._views.activeView;
         if (view && view.path) {
             this._loadFile(view.path, view);
         }
@@ -234,8 +233,8 @@ class Application {
         if (!electron.app.isPackaged) {
             return;
         }
-        let autoUpdater = updater.autoUpdater;
-        let promise = autoUpdater.checkForUpdates();
+        const autoUpdater = updater.autoUpdater;
+        const promise = autoUpdater.checkForUpdates();
         if (promise) {
             promise.catch((error) => {
                 console.log(error.message);
@@ -245,9 +244,9 @@ class Application {
 
     get package() { 
         if (!this._package) {
-            let appPath = electron.app.getAppPath();
-            let file = appPath + '/package.json'; 
-            let data = fs.readFileSync(file);
+            const appPath = electron.app.getAppPath();
+            const file = appPath + '/package.json'; 
+            const data = fs.readFileSync(file);
             this._package = JSON.parse(data);
             this._package.date = new Date(fs.statSync(file).mtime);
         }
@@ -255,9 +254,9 @@ class Application {
     }
 
     _about() {
-        let owner = electron.BrowserWindow.getFocusedWindow();
-        let author = this.package.author;
-        let date = this.package.date;
+        const owner = electron.BrowserWindow.getFocusedWindow();
+        const author = this.package.author;
+        const date = this.package.date;
         let details = [];
         details.push('Version ' + electron.app.getVersion());
         if (author && author.name && date) {
@@ -274,15 +273,15 @@ class Application {
     }
 
     _updateMenu() {
-        let context = {};
-        context.window = electron.BrowserWindow.getFocusedWindow();
-        context.webContents = context.window ? context.window.webContents : null; 
-        context.view = this._views.activeView;
-        this._menu.update(context);
+        const window = electron.BrowserWindow.getFocusedWindow();
+        this._menu.update({
+            window: window,
+            webContents: window ? window.webContents : null,
+            view: this._views.activeView
+        });
     }
 
     _resetMenu() {
-
         let menuRecentsTemplate = [];
         if (this._configuration.has('recents')) {
             let recents = this._configuration.get('recents');
@@ -292,7 +291,7 @@ class Application {
             }
             this._configuration.set('recents', recents);
             for (let i = 0; i < recents.length; i++) {
-                let recent = recents[i];
+                const recent = recents[i];
                 menuRecentsTemplate.push({
                     file: recent.path,
                     label: Application.minimizePath(recent.path),
@@ -392,7 +391,7 @@ class Application {
             ]
         });
     
-        let viewTemplate = {
+        const viewTemplate = {
             label: '&View',
             submenu: [
                 {
@@ -463,7 +462,7 @@ class Application {
             });
         }
 
-        let helpSubmenu = [
+        const helpSubmenu = [
             {
                 label: '&Search Feature Requests',
                 click: () => { electron.shell.openExternal('https://www.github.com/' + this.package.repository + '/issues'); }
@@ -487,7 +486,7 @@ class Application {
             submenu: helpSubmenu
         });
 
-        let commandTable = new Map();
+        const commandTable = new Map();
         commandTable.set('file.export', {
             enabled: (context) => { return context.view && context.view.path ? true : false; }
         });
@@ -540,9 +539,9 @@ class Application {
 
     static minimizePath(file) {
         if (process.platform != 'win32') {
-            let home = os.homedir();
-            if (file.startsWith(home)) {
-                return '~' + file.substring(home.length);
+            const homeDir = os.homedir();
+            if (file.startsWith(homeDir)) {
+                return '~' + file.substring(homeDir.length);
             }
         }
         return file;
@@ -612,7 +611,7 @@ class View {
                 electron.shell.openExternal(url);
             }
         });
-        let location = url.format({
+        const location = url.format({
             pathname: path.join(__dirname, 'electron.html'),
             protocol: 'file:',
             slashes: true
@@ -637,7 +636,7 @@ class View {
             this._window.webContents.on('dom-ready', () => {
                 this._window.webContents.send("open", { file: file });
             });
-            let location = url.format({
+            const location = url.format({
                 pathname: path.join(__dirname, 'electron.html'),
                 protocol: 'file:',
                 slashes: true
@@ -723,7 +722,7 @@ class ViewCollection {
     }
 
     openView() {
-        let view = new View(this);
+        const view = new View(this);
         view.on('activated', (sender) => {
             this._activeView = sender;
             this._raise('active-view-changed', { activeView: this._activeView });
@@ -789,7 +788,7 @@ class ConfigurationService {
 
     load() {
         this._data = { 'recents': [] };
-        let dir = electron.app.getPath('userData');
+        const dir = electron.app.getPath('userData');
         if (dir && dir.length > 0) {
             let file = path.join(dir, 'configuration.json'); 
             if (fs.existsSync(file)) {
@@ -808,7 +807,7 @@ class ConfigurationService {
 
     save() {
         if (this._data) {
-            let data = JSON.stringify(this._data);
+            const data = JSON.stringify(this._data);
             if (data) {
                 let dir = electron.app.getPath('userData');
                 if (dir && dir.length > 0) {
@@ -870,8 +869,8 @@ class MenuService {
     _updateLabel(context) {
         let rebuild = false;
         for (let entry of this._commandTable.entries()) {
-            let menuItem = this._menu.getMenuItemById(entry[0]);
-            let command = entry[1];
+            const menuItem = this._menu.getMenuItemById(entry[0]);
+            const command = entry[1];
             if (command && command.label) {
                 let label = command.label(context);
                 if (label != menuItem.label) {
@@ -887,7 +886,7 @@ class MenuService {
 
     _updateEnabled(context) {
         for (let entry of this._commandTable.entries()) {
-            let menuItem = this._menu.getMenuItemById(entry[0]);
+            const menuItem = this._menu.getMenuItemById(entry[0]);
             if (menuItem) {
                 let command = entry[1];
                 if (command.enabled) {

+ 9 - 9
src/base.js

@@ -8,8 +8,8 @@ if (typeof window !== 'undefined' && typeof window.Long != 'undefined') {
 
 if (!DataView.prototype.getFloat16) {
     DataView.prototype.getFloat16 = function(byteOffset, littleEndian) {
-        let value = this.getUint16(byteOffset, littleEndian);
-        let e = (value & 0x7C00) >> 10;
+        const value = this.getUint16(byteOffset, littleEndian);
+        const e = (value & 0x7C00) >> 10;
         let f = value & 0x03FF;
         if (e == 0) {
             f = 0.00006103515625 * (f / 1024);
@@ -34,10 +34,10 @@ if (!DataView.prototype.setFloat16) {
     DataView.prototype.setFloat16 = function(byteOffset, value, littleEndian) {
         DataView.__float16_float[0] = value;
         value = DataView.__float16_int[0];
-        let s = (value >>> 16) & 0x8000;
-        let e = (value >>> 23) & 0xff;
-        let f = value & 0x7fffff;
-        let v = s | DataView.__float16_base[e] | (f >> DataView.__float16_shift[e]);
+        const s = (value >>> 16) & 0x8000;
+        const e = (value >>> 23) & 0xff;
+        const f = value & 0x7fffff;
+        const v = s | DataView.__float16_base[e] | (f >> DataView.__float16_shift[e]);
         this.setUint16(byteOffset, v, littleEndian);
     };
     DataView.__float16_float = new Float32Array(1);
@@ -72,15 +72,15 @@ if (!DataView.prototype.setFloat16) {
 if (!DataView.prototype.getBits) {
     DataView.prototype.getBits = function(offset, bits /*, signed */) {
         offset = offset * bits;
-        let available = (this.byteLength << 3) - offset;
+        const available = (this.byteLength << 3) - offset;
         if (bits > available) {
             throw new RangeError();
         }
         let value = 0;
         let index = 0;
         while (index < bits) {
-            let remainder = offset & 7;
-            let size = Math.min(bits - index, 8 - remainder);
+            const remainder = offset & 7;
+            const size = Math.min(bits - index, 8 - remainder);
             value <<= size;
             value |= (this.getUint8(offset >> 3) >> (8 - size - remainder)) & ~(0xff << size);
             offset += size;

+ 17 - 17
src/bson.js

@@ -22,19 +22,19 @@ bson.Reader = class {
     }
 
     document(isArray) {
-        let start = this._position;
-        let size = this.int32();
+        const start = this._position;
+        const size = this.int32();
         if (size < 5 || start + size > this._buffer.length || this._buffer[start + size - 1] != 0x00) {
             throw new bson.Reader('Invalid BSON size.');
         }
         let element = isArray ? [] : {};
         let index = 0;
         for (;;) {
-            var type = this.byte();
+            const type = this.byte();
             if (type == 0x00) {
                 break;
             }
-            let key = this.cstring();
+            const key = this.cstring();
             let value = null;
             switch (type) {
                 case 0x01:
@@ -85,15 +85,15 @@ bson.Reader = class {
     }
 
     cstring() {
-        var end = this._buffer.indexOf(0x00, this._position);
-        let value = this._asciiDecoder.decode(this._buffer.subarray(this._position, end));
+        const end = this._buffer.indexOf(0x00, this._position);
+        const value = this._asciiDecoder.decode(this._buffer.subarray(this._position, end));
         this._position = end + 1;
         return value;
     }
 
     string() {
-        let end = this.int32() + this._position - 1;
-        let value = this._utf8Decoder.decode(this._buffer.subarray(this._position, end));
+        const end = this.int32() + this._position - 1;
+        const value = this._utf8Decoder.decode(this._buffer.subarray(this._position, end));
         this._position = end;
         if (this.byte() != '0x00') {
             throw new bson.Error('String missing terminal 0.');
@@ -102,9 +102,9 @@ bson.Reader = class {
     }
 
     binary() {
-        let size = this.int32();
-        let subtype = this.byte();
-        let data = this._buffer.subarray(this._position, this._position + size);
+        const size = this.int32();
+        const subtype = this.byte();
+        const data = this._buffer.subarray(this._position, this._position + size);
         this._position += size;
         switch (subtype) {
             case 0x00:
@@ -115,7 +115,7 @@ bson.Reader = class {
     }
     
     boolean()  {
-        let value = this.byte();
+        const value = this.byte();
         switch (value) {
             case 0x00: return false;
             case 0x01: return true;
@@ -128,21 +128,21 @@ bson.Reader = class {
     }
 
     int32() {
-        let value = this._view.getInt32(this._position, true);
+        const value = this._view.getInt32(this._position, true);
         this._position += 4;
         return value;
     }
 
     int64() {
-        let low = this._view.getUint32(this._position, true);
-        let hi = this._view.getUint32(this._position + 4, true);
+        const low = this._view.getUint32(this._position, true);
+        const hi = this._view.getUint32(this._position + 4, true);
         this._position += 8;
         return new long.Long(low, hi, false).toNumber();
     }
 
     uint64() {
-        let low = this._view.getUint32(this._position, true);
-        let hi = this._view.getUint32(this._position + 4, true);
+        const low = this._view.getUint32(this._position, true);
+        const hi = this._view.getUint32(this._position + 4, true);
         this._position += 8;
         return new long.Long(low, hi, true).toNumber();
     }

+ 13 - 13
src/caffe.js

@@ -10,9 +10,8 @@ var marked = marked || require('marked');
 caffe.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
-        let tags = null;
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'caffemodel') {
             return true;
         }
@@ -22,15 +21,15 @@ caffe.ModelFactory = class {
                 identifier.endsWith('init_net.pbtxt') || identifier.endsWith('init_net.prototxt')) {
                 return false;
             }
-            tags = context.tags('pbtxt');
+            const tags = context.tags('pbtxt');
             if (tags.has('layer') || tags.has('layers') || tags.has('net') || tags.has('train_net') || tags.has('net_param')) {
                 return true;
             }
         }
         if (extension == 'pt') {
             // Reject PyTorch models
-            let buffer = context.buffer;
-            let torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+            const buffer = context.buffer;
+            const torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
             if (buffer && buffer.length > 14 && buffer[0] == 0x80 && torch.every((v, i) => v == buffer[i + 2])) {
                 return false;
             }
@@ -38,7 +37,7 @@ caffe.ModelFactory = class {
             if (buffer && buffer.length > 2 && buffer[0] == 0x50 && buffer[1] == 0x4B) {
                 return false;
             }
-            tags = context.tags('pbtxt');
+            const tags = context.tags('pbtxt');
             if (tags.has('layer') || tags.has('layers') || tags.has('net') || tags.has('train_net') || tags.has('net_param')) {
                 return true;
             }
@@ -50,9 +49,9 @@ caffe.ModelFactory = class {
         return host.require('./caffe-proto').then(() => {
             caffe.proto = protobuf.roots.caffe.caffe;
             return caffe.Metadata.open(host).then((metadata) => {
-                let extension = context.identifier.split('.').pop();
+                const extension = context.identifier.split('.').pop();
                 if (extension == 'pbtxt' || extension == 'prototxt' || extension == 'pt') {
-                    let tags = context.tags('pbtxt');
+                    const tags = context.tags('pbtxt');
                     if (tags.has('net') || tags.has('train_net') || tags.has('net_param')) {
                         try {
                             let reader = prototxt.TextReader.create(context.text);
@@ -492,7 +491,7 @@ caffe.Node = class {
                 break;
         }
 
-        let schema = this._metadata.getSchema(this.operator);
+        const schema = this._metadata.getSchema(this.operator);
 
         this._inputs = [];
         let inputs = layer.input.concat(initializers);
@@ -551,7 +550,7 @@ caffe.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._type);
+        const schema = this._metadata.getSchema(this._type);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -590,7 +589,7 @@ caffe.Attribute = class {
             this._value = new caffe.TensorShape(value.dim);
         }
 
-        let schema = metadata.getAttributeSchema(operator, this._name);
+        const schema = metadata.getAttributeSchema(operator, this._name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) {
                 this._visible = false;
@@ -812,7 +811,7 @@ caffe.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;
@@ -825,6 +824,7 @@ caffe.Metadata = class {
 };
 
 caffe.Error = class extends Error {
+
     constructor(message) {
         super(message);
         this.name = 'Error loading Caffe model.';

+ 18 - 17
src/caffe2.js

@@ -9,14 +9,13 @@ var marked = marked || require('marked');
 caffe2.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier.toLowerCase();
-        let extension = identifier.split('.').pop().toLowerCase();
-        let tags = null;
+        const identifier = context.identifier.toLowerCase();
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'pb') {
             if (identifier.endsWith('predict_net.pb') || identifier.endsWith('init_net.pb')) {
                 return true;
             }
-            tags = context.tags('pb');
+            const tags = context.tags('pb');
             // ignore input_0.pb, output_0.pb
             if (tags.size > 0 &&
                 tags.has(1) && tags.get(1) == 0 && 
@@ -49,7 +48,7 @@ caffe2.ModelFactory = class {
             if (identifier.endsWith('predict_net.pbtxt') || identifier.endsWith('predict_net.prototxt')) {
                 return true;
             }
-            tags = context.tags('pbtxt');
+            const tags = context.tags('pbtxt');
             if (tags.has('op')) {
                 return true;
             }
@@ -60,15 +59,15 @@ caffe2.ModelFactory = class {
     open(context, host) {
         return host.require('./caffe2-proto').then(() => {
             return caffe2.Metadata.open(host).then((metadata) => {
-                let identifier = context.identifier; 
-                let extension = identifier.split('.').pop().toLowerCase();
+                const identifier = context.identifier; 
+                const extension = identifier.split('.').pop().toLowerCase();
                 if (extension == 'pbtxt' || extension == 'prototxt') {
-                    let open_text = (predict, init) => {
+                    const open_text = (predict, init) => {
                         let predict_net = null;
                         let init_net = null;
                         try {
                             caffe2.proto = protobuf.roots.caffe2.caffe2;
-                            let reader = prototxt.TextReader.create(predict);
+                            const reader = prototxt.TextReader.create(predict);
                             reader.field = function(tag, message) {
                                 if (message instanceof caffe2.proto.DeviceOption) {
                                     message[tag] = this.skip();
@@ -114,7 +113,7 @@ caffe2.ModelFactory = class {
                     }
                 }
                 else {
-                    let open_binary = (predict, init) => {
+                    const open_binary = (predict, init) => {
                         let predict_net = null;
                         let init_net = null;
                         try {
@@ -165,7 +164,7 @@ caffe2.Model = class {
 
     constructor(metadata, predict_net, init_net) {
         this._domain = predict_net.domain || null;
-        let graph = new caffe2.Graph(metadata, predict_net, init_net);
+        const graph = new caffe2.Graph(metadata, predict_net, init_net);
         this._graphs = [ graph ];
     }
 
@@ -196,7 +195,7 @@ caffe2.Graph = class {
         if (init) {
             for (let op of init.op) {
                 if (op.output && op.output.length == 1) {
-                    let name = op.output[0];
+                    const name = op.output[0];
                     let dataType = null;
                     switch (op.type) {
                         case 'GivenTensorFill':
@@ -312,6 +311,7 @@ caffe2.Graph = class {
 };
 
 caffe2.Parameter = class {
+
     constructor(name, args) {
         this._name = name;
         this._arguments = args;
@@ -331,6 +331,7 @@ caffe2.Parameter = class {
 };
 
 caffe2.Argument = class {
+
     constructor(id, type, initializer) {
         this._id = id;
         this._type = type || null;
@@ -374,7 +375,7 @@ caffe2.Node = class {
             this._attributes.push(new caffe2.Attribute(metadata, this, arg));
         }
 
-        let schema = metadata.getSchema(this._operator);
+        const schema = metadata.getSchema(this._operator);
 
         let inputs = op.input;
         let tensors = {};
@@ -447,7 +448,7 @@ caffe2.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -535,7 +536,7 @@ caffe2.Attribute = class {
             this._value = arg.i;
         }
 
-        let schema = metadata.getAttributeSchema(this._node.operator, this._name);
+        const schema = metadata.getAttributeSchema(this._node.operator, this._name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'type')) {
                 this._type = schema.type;
@@ -724,7 +725,7 @@ caffe2.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push(indentation + '[');
-            let items = value.map((item) => caffe2.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => caffe2.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -820,7 +821,7 @@ caffe2.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 12 - 12
src/cntk.js

@@ -11,11 +11,11 @@ var cntk_v2 = null;
 cntk.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         if (extension == 'model' || extension == 'cmf' || extension == 'dnn' || extension == 'cntk') {
-            let buffer = context.buffer;
+            const buffer = context.buffer;
             // Reject PyTorch models with .model file extension.
-            let torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+            const torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
             if (buffer && buffer.length > 14 && buffer[0] == 0x80 && torch.every((v, i) => v == buffer[i + 2])) {
                 return false;
             }
@@ -26,7 +26,7 @@ cntk.ModelFactory = class {
                 return true;
             }
             // CNTK v2
-            let tags = context.tags('pb');
+            const tags = context.tags('pb');
             if (tags.get(1) === 0 && tags.get(2) === 2) {
                 return true;
             }
@@ -39,7 +39,7 @@ cntk.ModelFactory = class {
             let version = 0;
             let obj = null;
             try {
-                let buffer = context.buffer;
+                const buffer = context.buffer;
                 if (buffer && buffer.length >= 8 && 
                     buffer[0] == 0x42 && buffer[1] == 0x00 && buffer[2] == 0x43 && buffer[3] == 0x00 &&
                     buffer[4] == 0x4E && buffer[5] == 0x00 && buffer[6] == 0x00 && buffer[7] == 0x00) {
@@ -54,7 +54,7 @@ cntk.ModelFactory = class {
                 if (!obj) {
                     cntk_v2 = protobuf.roots.cntk.CNTK.proto;
                     cntk_v2.PoolingType = { 0: 'Max', 1: 'Average' };
-                    let dictionary = cntk_v2.Dictionary.decode(context.buffer);
+                    const dictionary = cntk_v2.Dictionary.decode(context.buffer);
                     obj = cntk.ModelFactory._convertDictionary(dictionary);
                     version = 2;
                 }
@@ -438,7 +438,7 @@ cntk.Node = class {
         }
 
         let inputIndex = 0;
-        let schema = this._metadata.getSchema(this._function ? ('Function:' + this._operator) : this._operator);
+        const schema = this._metadata.getSchema(this._function ? ('Function:' + this._operator) : this._operator);
         if (schema && schema.inputs) {
             for (let inputSchema of schema.inputs) {
                 if (inputIndex < inputs.length || inputSchema.option != 'optional') {
@@ -486,7 +486,7 @@ cntk.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._function ? ('Function:' + this._operator) : this._operator);
+        const schema = this._metadata.getSchema(this._function ? ('Function:' + this._operator) : this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -522,14 +522,14 @@ cntk.Attribute = class {
             this._type = 'shape';
         }
         if (cntk_v2 && this._value instanceof cntk_v2.Axis) {
-            let axis = { __type__: 'Axis' };
+            const axis = { __type__: 'Axis' };
             for (let key of Object.keys(value).filter((key) => key !== 'name')) {
                 axis[key] = value[key];
             }
             this._value = axis;
         }
 
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (schema) {
             if (schema.type) {
                 this._type = schema.type;
@@ -802,8 +802,8 @@ cntk.Metadata = class {
             if (items) {
                 for (let item of items) {
                     if (item.name && item.schema) {
-                        let name = item.name;
-                        let schema = item.schema;
+                        const name = item.name;
+                        const schema = item.schema;
                         this._map[name] = schema;
                         if (Object.prototype.hasOwnProperty.call(schema, 'operator')) {
                             this._operatorMap[schema.operator.toString()] = name;

+ 26 - 25
src/coreml.js

@@ -10,13 +10,13 @@ var marked = marked || require('marked');
 coreml.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         return extension == 'mlmodel';
     }
 
     open(context, host) { 
         return host.require('./coreml-proto').then(() => {
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             let decodedBuffer = null;
             try {
                 coreml.proto = protobuf.roots.coreml.CoreML.Specification;
@@ -46,7 +46,7 @@ coreml.Model = class {
         this._specificationVersion = model.specificationVersion;
         this._graphs = [ new coreml.Graph(metadata, model) ];
         if (model.description && model.description.metadata) {
-            let properties = model.description.metadata;
+            const properties = model.description.metadata;
             if (properties.versionString) {
                 this._version = properties.versionString;
             }
@@ -102,12 +102,12 @@ coreml.Graph = class {
 
         if (this._description) {
             this._inputs = this._description.input.map((input) => {
-                let argument = new coreml.Argument(input.name, coreml.Graph._formatFeatureType(input.type), input.shortDescription, null);
+                const argument = new coreml.Argument(input.name, coreml.Graph._formatFeatureType(input.type), input.shortDescription, null);
                 return new coreml.Parameter(input.name, true, [ argument ]);
             });
 
             this._outputs = this._description.output.map((output) => {
-                let argument = new coreml.Argument(output.name, coreml.Graph._formatFeatureType(output.type), output.shortDescription, null);
+                const argument = new coreml.Argument(output.name, coreml.Graph._formatFeatureType(output.type), output.shortDescription, null);
                 return new coreml.Parameter(output.name, true, [ argument ]);
             });
         }
@@ -188,7 +188,7 @@ coreml.Graph = class {
     _loadModel(model, scope, group) {
         this._groups = this._groups | (group.length > 0 ? true : false);
         if (model.neuralNetworkClassifier) {
-            let neuralNetworkClassifier = model.neuralNetworkClassifier;
+            const neuralNetworkClassifier = model.neuralNetworkClassifier;
             for (let layer of neuralNetworkClassifier.layers) {
                 this._createNode(scope, group, layer.layer, layer.name, layer[layer.layer], layer.input, layer.output);
             }
@@ -197,7 +197,7 @@ coreml.Graph = class {
             return 'Neural Network Classifier';
         }
         else if (model.neuralNetwork) {
-            let neuralNetwork = model.neuralNetwork;
+            const neuralNetwork = model.neuralNetwork;
             for (let layer of neuralNetwork.layers) {
                 this._createNode(scope, group, layer.layer, layer.name, layer[layer.layer], layer.input, layer.output);
             }
@@ -205,7 +205,7 @@ coreml.Graph = class {
             return 'Neural Network';
         }
         else if (model.neuralNetworkRegressor) {
-            let neuralNetworkRegressor = model.neuralNetworkRegressor;
+            const neuralNetworkRegressor = model.neuralNetworkRegressor;
             for (let layer of neuralNetworkRegressor.layers) {
                 this._createNode(scope, group, layer.layer, layer.name, layer[layer.layer], layer.input, layer.output);
             }
@@ -311,8 +311,8 @@ coreml.Graph = class {
             return 'Array Feature Extractor';
         }
         else if (model.oneHotEncoder) {
-            let categoryType = model.oneHotEncoder.CategoryType;
-            let oneHotEncoderParams = { outputSparse: model.oneHotEncoder.outputSparse };
+            const categoryType = model.oneHotEncoder.CategoryType;
+            const oneHotEncoderParams = { outputSparse: model.oneHotEncoder.outputSparse };
             oneHotEncoderParams[categoryType] = model.oneHotEncoder[categoryType];
             this._createNode(scope, group, 'oneHotEncoder', null, 
                 oneHotEncoderParams,
@@ -321,8 +321,8 @@ coreml.Graph = class {
             return 'One Hot Encoder';
         }
         else if (model.imputer) {
-            let imputedValue = model.imputer.ImputedValue;
-            let replaceValue = model.imputer.ReplaceValue;
+            const imputedValue = model.imputer.ImputedValue;
+            const replaceValue = model.imputer.ReplaceValue;
             let imputerParams = {};
             imputerParams[imputedValue] = model.imputer[imputedValue];
             imputerParams[replaceValue] = model.imputer[replaceValue];
@@ -360,7 +360,7 @@ coreml.Graph = class {
             return 'Text Classifier';
         }
         else if (model.nonMaximumSuppression) {
-            let nonMaximumSuppressionParams = { 
+            const nonMaximumSuppressionParams = { 
                 pickTop: model.nonMaximumSuppression.pickTop,
                 stringClassLabels: model.nonMaximumSuppression.stringClassLabels,
                 iouThreshold: model.nonMaximumSuppression.iouThreshold, 
@@ -381,7 +381,7 @@ coreml.Graph = class {
             return 'Non Maximum Suppression';
         }
         else if (model.visionFeaturePrint) {
-            let visionFeaturePrintParams = {
+            const visionFeaturePrintParams = {
                 scene: model.visionFeaturePrint.scene
             }
             this._createNode(scope, group, 'visionFeaturePrint', null,
@@ -431,7 +431,7 @@ coreml.Graph = class {
             return output;
         });
 
-        let node = new coreml.Node(this._metadata, group, operator, name, data, inputs, outputs);
+        const node = new coreml.Node(this._metadata, group, operator, name, data, inputs, outputs);
         this._nodes.push(node);
         return node;
     }
@@ -488,6 +488,7 @@ coreml.Graph = class {
 };
 
 coreml.Parameter = class {
+
     constructor(name, visible, args) {
         this._name = name;
         this._visible = visible;
@@ -575,7 +576,7 @@ coreml.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this.operator);
+        const schema = this._metadata.getSchema(this.operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -618,7 +619,7 @@ coreml.Node = class {
     }
 
     get inputs() {
-        let inputs = this._metadata.getInputs(this._operator, this._inputs).map((input) => {
+        const inputs = this._metadata.getInputs(this._operator, this._inputs).map((input) => {
             return new coreml.Parameter(input.name, true, input.arguments.map((argument) => {
                 return new coreml.Argument(argument.id, argument.type, null, null);
             }));
@@ -763,10 +764,10 @@ coreml.Node = class {
     }
 
     _initializer(kind, name, shape, data) {
-        let initializer = new coreml.Tensor(kind, name, shape, data);
-        let argument = new coreml.Argument('', null, null, initializer);
+        const initializer = new coreml.Tensor(kind, name, shape, data);
+        const argument = new coreml.Argument('', null, null, initializer);
         let visible = true;
-        let schema = this._metadata.getInputSchema(this._operator, name);
+        const schema = this._metadata.getInputSchema(this._operator, name);
         if (schema && Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) {
             visible = false;
         }
@@ -779,7 +780,7 @@ coreml.Attribute = class {
     constructor(metadata, operator, name, value) {
         this._name = name;
         this._value = value;
-        let schema = metadata.getAttributeSchema(operator, this._name);
+        const schema = metadata.getAttributeSchema(operator, this._name);
         if (schema) {
             if (schema.type) {
                 this._type = schema.type;
@@ -1120,7 +1121,7 @@ coreml.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;
@@ -1135,7 +1136,7 @@ coreml.Metadata = class {
         let map = this._inputCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.inputs && schema.inputs.length > 0) {
                 for (let input of schema.inputs) {
                     map[input.name] = input;
@@ -1148,7 +1149,7 @@ coreml.Metadata = class {
 
     getInputs(operator, inputs) {
         let results = [];
-        let schema = this._map[operator];
+        const schema = this._map[operator];
         let index = 0;
         while (index < inputs.length) {
             let result = { arguments: [] };
@@ -1180,7 +1181,7 @@ coreml.Metadata = class {
     }
 
     getOutputName(operator, index) {
-        let schema = this._map[operator];
+        const schema = this._map[operator];
         if (schema) {
             let outputs = schema.outputs;
             if (outputs && index < outputs.length) {

+ 7 - 7
src/darknet.js

@@ -7,7 +7,7 @@ var base = base || require('./base');
 darknet.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         if (extension == 'cfg') {
             return true;
         }
@@ -16,10 +16,10 @@ darknet.ModelFactory = class {
 
     open(context, host) {
         return darknet.Metadata.open(host).then((metadata) => {
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             try {
-                let reader = new darknet.CfgReader(context.text);
-                let cfg = reader.read();
+                const reader = new darknet.CfgReader(context.text);
+                const cfg = reader.read();
                 return new darknet.Model(metadata, cfg);
             }
             catch (error) {
@@ -67,7 +67,7 @@ darknet.Graph = class {
         net.height = net.height ? Number.parseInt(net.height, 10) : 0;
         net.channels = net.channels ? Number.parseInt(net.channels, 10) : 0;
 
-        let inputType = new darknet.TensorType('float32', new darknet.TensorShape([ net.width, net.height, net.channels ]));
+        const inputType = new darknet.TensorType('float32', new darknet.TensorShape([ net.width, net.height, net.channels ]));
 
         let input = 'input';
         this._inputs.push(new darknet.Parameter(input, true, [
@@ -265,7 +265,7 @@ darknet.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -325,7 +325,7 @@ darknet.Attribute = class {
             }
         }
 
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (schema) {
             if (schema.type == 'boolean') {
                 switch (this._value) {

+ 11 - 11
src/dl4j.js

@@ -9,8 +9,8 @@ var long = long || { Long: require('long') };
 dl4j.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier.toLowerCase();
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier.toLowerCase();
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'zip' && context.entries.length > 0) {
             if (dl4j.ModelFactory._openContainer(context)) {
                 return true;
@@ -20,10 +20,10 @@ dl4j.ModelFactory = class {
     }
 
     open(context, host) {
-        let identifier = context.identifier;
+        const identifier = context.identifier;
         try {
-            let container = dl4j.ModelFactory._openContainer(context); 
-            let configuration = JSON.parse(container.configuration);
+            const container = dl4j.ModelFactory._openContainer(context); 
+            const configuration = JSON.parse(container.configuration);
             return dl4j.Metadata.open(host).then((metadata) => {
                 try {
                     return new dl4j.Model(metadata, configuration, container.coefficients);
@@ -45,7 +45,7 @@ dl4j.ModelFactory = class {
     }
 
     static _openContainer(context) {
-        let configurationEntries = context.entries.filter((entry) => entry.name === 'configuration.json');
+        const configurationEntries = context.entries.filter((entry) => entry.name === 'configuration.json');
         if (configurationEntries.length != 1) {
             return null;
         }
@@ -59,11 +59,11 @@ dl4j.ModelFactory = class {
         if (configuration.indexOf('"vertices"') === -1 && configuration.indexOf('"confs"') === -1) {
             return null;
         }
-        let coefficientsEntries = context.entries.filter((entry) => entry.name === 'coefficients.bin');
+        const coefficientsEntries = context.entries.filter((entry) => entry.name === 'coefficients.bin');
         if (coefficientsEntries.length > 1) {
             return null;
         }
-        let coefficients = coefficientsEntries.length == 1 ? coefficientsEntries[0].data : 0;
+        const coefficients = coefficientsEntries.length == 1 ? coefficientsEntries[0].data : 0;
         let container = {};
         container.configuration = configuration;
         container.coefficients = coefficients;
@@ -346,7 +346,7 @@ dl4j.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -399,7 +399,7 @@ dl4j.Attribute = class {
         this._name = name;
         this._value = value;
         this._visible = false;
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (schema) {
             if (schema.visible) {
                 this._visible = true;
@@ -521,7 +521,7 @@ dl4j.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 7 - 9
src/flux.js

@@ -9,8 +9,8 @@ var marked = marked || require('marked');
 flux.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier; 
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier; 
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'bson') {
             return true;
         }
@@ -20,12 +20,12 @@ flux.ModelFactory = class {
     open(context, host) {
         return host.require('./bson').then((bson) => {
             let model = null;
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             try {
-                let reader = new bson.Reader(context.buffer);
-                let root = reader.read();
-                root = flux.ModelFactory._backref(root, root);
-                model = root.model;
+                const reader = new bson.Reader(context.buffer);
+                const root = reader.read();
+                const obj = flux.ModelFactory._backref(root, root);
+                model = obj.model;
                 if (!model) {
                     throw new flux.Error('File does not contain Flux model.');
                 }
@@ -35,9 +35,7 @@ flux.ModelFactory = class {
                 message = message.endsWith('.') ? message.substring(0, message.length - 1) : message;
                 throw new flux.Error(message + " in '" + identifier + "'.");
             }
-
             return flux.Metadata.open(host).then((metadata) => {
-                let identifier = context.identifier;
                 try {
                     return new flux.Model(metadata, model);
                 }

+ 9 - 9
src/gzip.js

@@ -11,7 +11,7 @@ gzip.Archive = class {
         if (buffer.length < 18 || buffer[0] != 0x1f || buffer[1] != 0x8b) {
             throw new gzip.Error('Invalid GZIP archive.');
         }
-        let reader = new gzip.Reader(buffer, 0, buffer.length);
+        const reader = new gzip.Reader(buffer, 0, buffer.length);
         this._entries.push(new gzip.Entry(reader));
     }
 
@@ -26,16 +26,16 @@ gzip.Entry = class {
         if (!reader.match([ 0x1f, 0x8b ])) {
             throw new gzip.Error('Invalid GZIP signature.');
         }
-        let compressionMethod = reader.byte();
+        const compressionMethod = reader.byte();
         if (compressionMethod != 8) {
             throw new gzip.Error("Invalid compression method '" + compressionMethod.toString() + "'.");
         }
-        let flags = reader.byte();
+        const flags = reader.byte();
         reader.uint32(); // MTIME
         reader.byte();
         reader.byte(); // OS
         if ((flags & 4) != 0) {
-            let xlen = reader.uint16();
+            const xlen = reader.uint16();
             reader.skip(xlen);
         }
         if ((flags & 8) != 0) {
@@ -59,7 +59,7 @@ gzip.Entry = class {
         }
         reader.position = -8;
         reader.uint32(); // CRC32
-        let size = reader.uint32();
+        const size = reader.uint32();
         if (size != this._data.length) {
             throw new gzip.Error('Invalid size.');
         }
@@ -115,7 +115,7 @@ gzip.Reader = class {
             throw new gzip.Error('Data not available.');
         }
         size = size === undefined ? this._end : size;
-        let data = this._buffer.subarray(this._position, this._position + size);
+        const data = this._buffer.subarray(this._position, this._position + size);
         this._position += size;
         return data;
     }
@@ -124,7 +124,7 @@ gzip.Reader = class {
         if (this._position + 1 > this._end) {
             throw new gzip.Error('Data not available.');
         }
-        let value = this._buffer[this._position];
+        const value = this._buffer[this._position];
         this._position++;
         return value;
     }
@@ -133,7 +133,7 @@ gzip.Reader = class {
         if (this._position + 2 > this._end) {
             throw new gzip.Error('Data not available.');
         }
-        let value = this._buffer[this._position] | (this._buffer[this._position + 1] << 8);
+        const value = this._buffer[this._position] | (this._buffer[this._position + 1] << 8);
         this._position += 2;
         return value;
     }
@@ -144,7 +144,7 @@ gzip.Reader = class {
 
     string() {
         let result = '';
-        let end = this._buffer.indexOf(0x00, this._position);
+        const end = this._buffer.indexOf(0x00, this._position);
         if (end < 0) {
             throw new gzip.Error('End of string not found.');
         }

+ 20 - 18
src/keras.js

@@ -8,24 +8,24 @@ var marked = marked || require('marked');
 keras.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'keras' || extension == 'h5' || extension == 'hd5' || extension == 'hdf5') {
             // Reject PyTorch models with .h5 file extension.
-            let buffer = context.buffer;
-            let torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+            const buffer = context.buffer;
+            const torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
             if (buffer && buffer.length > 14 && buffer[0] == 0x80 && torch.every((v, i) => v == buffer[i + 2])) {
                 return false;
             }
             return true;
         }
         if (extension == 'model') {
-            let buffer = context.buffer;
-            let hdf5 = [ 0x89, 0x48, 0x44, 0x46 ];
+            const buffer = context.buffer;
+            const hdf5 = [ 0x89, 0x48, 0x44, 0x46 ];
             return (buffer && buffer.length > hdf5.length && hdf5.every((v, i) => v == buffer[i]));
         }
         if (extension == 'json' && !identifier.endsWith('-symbol.json')) {
-            let json = context.text;
+            const json = context.text;
             if (json.indexOf('"mxnet_version":', 0) == -1) {
                 try {
                     let root = JSON.parse(json);
@@ -59,7 +59,7 @@ keras.ModelFactory = class {
             let model_config = null;
             let rootGroup = null;
             let weightsManifest = null;
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             try {
                 switch (identifier.split('.').pop().toLowerCase()) {
                     case 'keras':
@@ -463,6 +463,7 @@ keras.Graph = class {
 };
 
 keras.Parameter = class {
+
     constructor(name, visible, args) {
         this._name = name;
         this._visible = visible;
@@ -483,6 +484,7 @@ keras.Parameter = class {
 };
 
 keras.Argument = class {
+
     constructor(id, type, initializer) {
         this._id = id;
         this._type = type || null;
@@ -549,7 +551,7 @@ keras.Node = class {
             }
         }
 
-        let schema = this._metadata.getSchema(this.operator);
+        const schema = this._metadata.getSchema(this.operator);
         let innerOperator = this.inner ? this.inner.operator : null;
         let innerSchema = innerOperator ? this._metadata.getSchema(innerOperator) : null;
         let inputIndex = 0;
@@ -591,14 +593,14 @@ keras.Node = class {
                         break;
                 }
             }
-            let inputArguments = inputs.slice(inputIndex, inputIndex + inputCount).map((id) => {
+            const inputArguments = inputs.slice(inputIndex, inputIndex + inputCount).map((id) => {
                 return new keras.Argument(id, null, initializers[id]);
             });
             if (!inputName && inputArguments.length == 1 && inputArguments[0].initializer && inputArguments[0].initializer.name) {
                 let parts = inputArguments[0].initializer.name.split('/').pop().split(':').shift().split('_');
-                let inputName1 = parts.pop();
-                let inputName2 = parts.length > 0 ? [ parts.pop(), inputName1 ].join('_') : '';
-                let inputNames = new Set([ 'recurrent_kernel', 'running_mean', 'running_std', 'moving_mean', 'moving_variance' ]);
+                const inputName1 = parts.pop();
+                const inputName2 = parts.length > 0 ? [ parts.pop(), inputName1 ].join('_') : '';
+                const inputNames = new Set([ 'recurrent_kernel', 'running_mean', 'running_std', 'moving_mean', 'moving_variance' ]);
                 inputName = inputNames.has(inputName2) ? inputName2 : inputName1;
             }
             inputName = inputName || inputIndex.toString();
@@ -607,7 +609,7 @@ keras.Node = class {
         }
 
         this._outputs = outputs.map((output, outputIndex) => {
-            let outputName = 
+            const outputName = 
                 (schema && schema.outputs && outputIndex < schema.outputs.length && schema.outputs[outputIndex] && schema.outputs[outputIndex].name) ?
                     schema.outputs[outputIndex].name :
                     outputIndex.toString();
@@ -628,7 +630,7 @@ keras.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -894,7 +896,7 @@ keras.Tensor = class {
 
     _decode(context, dimension) {
         let results = [];
-        let size = context.dimensions[dimension];
+        const size = context.dimensions[dimension];
         if (dimension == context.dimensions.length - 1) {
             for (let i = 0; i < size; i++) {
                 if (context.count > context.limit) {
@@ -936,7 +938,7 @@ keras.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push(indentation + '[');
-            let items = value.map((item) => keras.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => keras.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -1032,7 +1034,7 @@ keras.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 6 - 6
src/mlnet.js

@@ -10,10 +10,10 @@ var zip = zip || require('./zip');
 mlnet.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier; 
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier; 
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'zip' && context.entries.length > 0) {
-            var root = new Set([ 'TransformerChain', 'Predictor']);
+            const root = new Set([ 'TransformerChain', 'Predictor']);
             if (context.entries.some((e) => root.has(e.name.split('\\').shift().split('/').shift()))) {
                 return true;
             }
@@ -22,10 +22,10 @@ mlnet.ModelFactory = class {
     }
 
     open(context, host) {
-        let identifier = context.identifier;
+        const identifier = context.identifier;
         return mlnet.Metadata.open(host).then((metadata) => {
             try {
-                let reader = new mlnet.ModelReader(context.entries);
+                const reader = new mlnet.ModelReader(context.entries);
                 return new mlnet.Model(metadata, reader);
             }
             catch (error) {
@@ -441,7 +441,7 @@ mlnet.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 13 - 13
src/mxnet.js

@@ -10,18 +10,18 @@ var ndarray = ndarray || {};
 mxnet.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'model' || extension == 'mar') {
             if (context.entries.length > 0) {
                 return true;
             }
         }
         else if (extension == 'json') {
-            let json = context.text;
+            const json = context.text;
             if (json.indexOf('"nodes":', 0) != -1) {
                 try {
-                    let symbol = JSON.parse(json);
+                    const symbol = JSON.parse(json);
                     if (symbol && symbol.nodes && symbol.arg_nodes && symbol.heads) {
                         return true;
                     }
@@ -32,8 +32,8 @@ mxnet.ModelFactory = class {
             }
         }
         else if (extension == 'params') {
-            let buffer = context.buffer;
-            let signature = [ 0x12, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];
+            const buffer = context.buffer;
+            const signature = [ 0x12, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];
             if (buffer && buffer.length > signature.length && signature.every((v, i) => v == buffer[i])) {
                 return true;
             }
@@ -42,8 +42,8 @@ mxnet.ModelFactory = class {
     }
 
     open(context, host) {
-        let identifier = context.identifier;
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier;
+        const extension = context.identifier.split('.').pop().toLowerCase();
         let symbol = null;
         let params = null;
         let format = null;
@@ -604,7 +604,7 @@ mxnet.Node = class {
         this._inputs = [];
         this._outputs = [];
 
-        let attrs = node.attrs || node.attr || node.param;
+        const attrs = node.attrs || node.attr || node.param;
         if (attrs) {
             if (this._operator == 'tvm_op' && attrs.func_name) {
                 this._operator = attrs.func_name;
@@ -617,7 +617,7 @@ mxnet.Node = class {
         }
 
         let initializer = null;
-        let schema = metadata.getSchema(this.operator);
+        const schema = metadata.getSchema(this.operator);
         if (node.inputs) {
             let inputs = node.inputs;
             if (this._operator == 'RNN') {
@@ -750,7 +750,7 @@ mxnet.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator); 
+        const schema = this._metadata.getSchema(this._operator); 
         return schema && schema.category ? schema.category : '';
     }
 
@@ -812,7 +812,7 @@ mxnet.Attribute = class {
         this._value = value;
 
         let number;
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (schema && schema.type) {
             switch (schema.type) {
                 case 'boolean':
@@ -1134,7 +1134,7 @@ mxnet.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 20 - 19
src/ncnn.js

@@ -10,28 +10,28 @@ var base = base || require('./base');
 ncnn.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier.toLowerCase();
+        const identifier = context.identifier.toLowerCase();
         if (identifier.endsWith('.param') || identifier.endsWith('.cfg.ncnn')) {
             let text = context.text;
             text = text.substring(0, Math.min(text.length, 32));
-            let signature = text.split('\n').shift().trim();
+            const signature = text.split('\n').shift().trim();
             if (signature === '7767517') {
                 return true;
             }
         }
         if (identifier.endsWith('.param.bin')) {
-            let buffer = context.buffer;
+            const buffer = context.buffer;
             if (buffer.length > 4) {
-                let signature = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24;
+                const signature = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24;
                 if (signature == 0x007685DD) {
                     return true;
                 }
             }
         }
         if (identifier.endsWith('.bin') || identifier.endsWith('.weights.ncnn')) {
-            let buffer = context.buffer;
+            const buffer = context.buffer;
             if (buffer.length > 4) {
-                let signature = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24;
+                const signature = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24;
                 if (signature === 0x00000000 || signature === 0x00000001 || 
                     signature === 0x01306B47 || signature === 0x000D4B38 || signature === 0x0002C056) {
                     return true;
@@ -43,8 +43,8 @@ ncnn.ModelFactory = class {
 
     open(context, host) {
         return ncnn.Metadata.open(host).then((metadata) => {
-            let identifier = context.identifier.toLowerCase();
-            let param = (param, bin) => {
+            const identifier = context.identifier.toLowerCase();
+            const param = (param, bin) => {
                 try {
                     return new ncnn.Model(metadata, param, bin);
                 }
@@ -120,7 +120,7 @@ ncnn.Graph = class {
         this._outputs = [];
         this._nodes = [];
 
-        let blobReader = new ncnn.BlobReader(bin);
+        const blobReader = new ncnn.BlobReader(bin);
 
         let layers = (typeof param == 'string') ?
             this._param(metadata, param, bin) :
@@ -141,11 +141,11 @@ ncnn.Graph = class {
 
     _param(metadata, param) {
         let lines = param.split('\n');
-        let signature = lines.shift();
+        const signature = lines.shift();
         if (signature !== '7767517') {
             throw new ncnn.Error('Invalid signature.')
         }
-        let header = lines.shift().split(' ');
+        const header = lines.shift().split(' ');
         if (header.length !== 2) {
             throw new ncnn.Error('Invalid header count.');
         }
@@ -159,8 +159,8 @@ ncnn.Graph = class {
                 layer = {};
                 layer.type = columns.shift();
                 layer.name = columns.shift();
-                let inputCount = parseInt(columns.shift(), 10);
-                let outputCount = parseInt(columns.shift(), 10);
+                const inputCount = parseInt(columns.shift(), 10);
+                const outputCount = parseInt(columns.shift(), 10);
                 layer.inputs = columns.splice(0, inputCount);
                 layer.outputs = columns.splice(0, outputCount);
                 layer.attr = {};
@@ -184,11 +184,11 @@ ncnn.Graph = class {
     }
 
     _param_bin(metadata, param) {
-        let reader = new ncnn.BinaryParamReader(param);
+        const reader = new ncnn.BinaryParamReader(param);
         if (!reader.signature()) {
             throw new ncnn.Error('Invalid signature.')
         }
-        let layerCount = reader.int32();
+        const layerCount = reader.int32();
         /* var blobCount = */ reader.int32();
         let layers = [];
         for (let i = 0; i < layerCount; i++) {
@@ -271,6 +271,7 @@ ncnn.Parameter = class {
 };
 
 ncnn.Argument = class {
+
     constructor(id, type, initializer) {
         this._id = id;
         this._type = type || null;
@@ -303,12 +304,12 @@ ncnn.Node = class {
         this._operator = layer.type;
         this._name = layer.name;
 
-        let operator = metadata.getOperatorName(this._operator);
+        const operator = metadata.getOperatorName(this._operator);
         if (operator) {
             this._operator = operator;
         }
 
-        let schema = metadata.getSchema(this._operator);
+        const schema = metadata.getSchema(this._operator);
 
         let attributeMetadata = {};
         if (schema && schema.attributes) {
@@ -471,7 +472,7 @@ ncnn.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -762,7 +763,7 @@ ncnn.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 12 - 13
src/onnx.js

@@ -11,12 +11,11 @@ var marked = marked || require('marked');
 onnx.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'onnx') {
             return true;
         }
-        let tags = null;
         if (extension == 'pb') {
             if (identifier.endsWith('saved_model.pb')) {
                 return false;
@@ -24,7 +23,7 @@ onnx.ModelFactory = class {
             if (identifier.endsWith('predict_net.pb') || identifier.endsWith('init_net.pb')) {
                 return false;
             }
-            tags = context.tags('pb');
+            const tags = context.tags('pb');
             if (tags.size === 0) {
                 return false;
             }
@@ -58,7 +57,7 @@ onnx.ModelFactory = class {
                 identifier.endsWith('init_net.pbtxt') || identifier.endsWith('init_net.prototxt')) {
                 return false;
             }
-            tags = context.tags('pbtxt');
+            const tags = context.tags('pbtxt');
             if (tags.has('ir_version') || tags.has('graph')) {
                 return true;
             }
@@ -69,12 +68,12 @@ onnx.ModelFactory = class {
     open(context, host) { 
         return host.require('./onnx-proto').then(() => {
             let model = null;
-            let identifier = context.identifier; 
-            let extension = identifier.split('.').pop().toLowerCase();
+            const identifier = context.identifier; 
+            const extension = identifier.split('.').pop().toLowerCase();
             if (extension == 'pbtxt' || extension == 'prototxt') {
                 try {
                     onnx.proto = protobuf.roots.onnx.onnx;
-                    let reader = prototxt.TextReader.create(context.text);
+                    const reader = prototxt.TextReader.create(context.text);
                     model = onnx.proto.ModelProto.decodeText(reader);
                 }
                 catch (error) {
@@ -316,7 +315,7 @@ onnx.Graph = class {
             }
             for (let node of nodes) {
                 let inputs = [];
-                let schema = metadata.getSchema(node.op_type);
+                const schema = metadata.getSchema(node.op_type);
                 if (node.input && node.input.length > 0) {
                     let inputIndex = 0;
                     if (schema && schema.inputs) {
@@ -493,7 +492,7 @@ onnx.Node = class {
     get documentation() {
         let schema = this._metadata.getSchema(this._operator);
         if (schema) {
-            let options = { baseUrl: 'https://github.com/onnx/onnx/blob/master/docs/' };
+            const options = { baseUrl: 'https://github.com/onnx/onnx/blob/master/docs/' };
             schema = JSON.parse(JSON.stringify(schema));
             schema.name = this._operator;
             if (schema.description) {
@@ -546,7 +545,7 @@ onnx.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -946,7 +945,7 @@ onnx.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push(indentation + '[');
-            let items = value.map((item) => onnx.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => onnx.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -1162,7 +1161,7 @@ onnx.GraphMetadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 5 - 5
src/openvino.js

@@ -402,7 +402,7 @@ openvino.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._type);
+        const schema = this._metadata.getSchema(this._type);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -523,7 +523,7 @@ openvino.Attribute = class {
         this._name = name;
         this._value = value;
 
-        let schema = metadata.getAttributeSchema(node.operator, name);
+        const schema = metadata.getAttributeSchema(node.operator, name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'type')) {
                 switch (schema.type) {
@@ -728,8 +728,8 @@ openvino.Metadata = class {
             if (items) {
                 for (let item of items) {
                     if (item.name && item.schema) {
-                        let name = item.name;
-                        let schema = item.schema;
+                        const name = item.name;
+                        const schema = item.schema;
                         this._map[name] = schema;
                     }
                 }
@@ -745,7 +745,7 @@ openvino.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 6 - 6
src/paddle.js

@@ -8,8 +8,8 @@ var base = base || require('./base');
 paddle.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (identifier == '__model__' || extension == 'paddle') {
             return true;
         }
@@ -19,7 +19,7 @@ paddle.ModelFactory = class {
     open(context, host) {
         return host.require('./paddle-proto').then(() => {
             let desc = null;
-            let identifier = context.identifier; 
+            const identifier = context.identifier; 
             try {
                 paddle.proto = protobuf.roots.paddle.paddle.framework.proto;
                 desc = paddle.proto.ProgramDesc.decode(context.buffer);
@@ -251,7 +251,7 @@ paddle.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -349,7 +349,7 @@ paddle.Attribute = class {
                 break;
         }
 
-        let schema = metadata.getAttributeSchema(operator, this._name);
+        const schema = metadata.getAttributeSchema(operator, this._name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'default')) {
                 let defaultValue = schema.default;
@@ -502,7 +502,7 @@ paddle.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 3 - 3
src/python.js

@@ -25,7 +25,7 @@ python.Parser = class {
         let node = this._node('program');
         node.body = [];
         while (!this._tokenizer.match('eof')) {
-            let statement = this._parseStatement();
+            const statement = this._parseStatement();
             if (statement) {
                 node.body.push(statement);
                 continue;
@@ -667,7 +667,7 @@ python.Parser = class {
                 stack.push(node);
                 continue;
             }
-            let identifier = this._parseName();
+            const identifier = this._parseName();
             if (identifier) {
                 stack.push(identifier);
                 continue;
@@ -854,7 +854,7 @@ python.Parser = class {
         if (this._tokenizer.eat('*')) {
             node.parameterType = '*';
         }
-        let identifier = this._parseName();
+        const identifier = this._parseName();
         if (identifier !== null) {
             node.name = identifier.value;
             if (terminal !== ':' && this._tokenizer.eat(':')) {

+ 14 - 14
src/pytorch.js

@@ -13,13 +13,13 @@ var zip = zip || require('./zip');
 pytorch.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier; 
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier; 
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'pth' || extension === 'pkl' || extension === 'pt' || extension === 'bin' ||
             extension === 'h5' || extension === 't7' || extension === 'dms' || extension === 'model' ||
             extension === 'ckpt' || identifier.endsWith('.pth.tar')) {
-            let buffer = context.buffer;
-            let torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+            const buffer = context.buffer;
+            const torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
             if (buffer && buffer.length > 14 && buffer[0] == 0x80 && torch.every((v, i) => v == buffer[i + 2])) {
                 return true;
             }
@@ -32,8 +32,8 @@ pytorch.ModelFactory = class {
 
     open(context, host) {
         return host.require('./pickle').then((pickle) => {
-            let identifier = context.identifier;
-            let buffer = context.buffer;
+            const identifier = context.identifier;
+            const buffer = context.buffer;
             let sys_info = null;
             let root_module = null;
             let state_dict = null;
@@ -41,8 +41,8 @@ pytorch.ModelFactory = class {
             try {
                 let unpickler = new pickle.Unpickler(buffer);
 
-                let signature = [ 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
-                let magic_number = unpickler.load();
+                const signature = [ 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+                const magic_number = unpickler.load();
 
                 let deserialized_objects = {};
                 let storage = null;
@@ -923,8 +923,8 @@ pytorch.Graph = class {
 
     _createNode(groups, key, obj, args) {
 
-        let operator = obj.__type__.split('.').pop();
-        let schema = this._metadata.getSchema(operator);
+        const operator = obj.__type__.split('.').pop();
+        const schema = this._metadata.getSchema(operator);
 
         let inputSchema = [ { name: 'input'} ];
         if (schema && schema.inputs && schema.inputs.length > 0) {
@@ -1075,7 +1075,7 @@ pytorch.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -1137,7 +1137,7 @@ pytorch.Attribute = class {
         this._name = name;
         this._value = value;
 
-        let schema = metadata.getAttributeSchema(this._node.operator, this._name);
+        const schema = metadata.getAttributeSchema(this._node.operator, this._name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) {
                 this._visible = false;
@@ -1313,7 +1313,7 @@ pytorch.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push(indentation + '[');
-            let items = value.map((item) => pytorch.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => pytorch.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -1417,7 +1417,7 @@ pytorch.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 9 - 9
src/sklearn.js

@@ -10,12 +10,12 @@ var marked = marked || require('marked');
 sklearn.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         if (extension == 'pkl' || extension == 'joblib' || extension == 'model') {
-            let buffer = context.buffer;
+            const buffer = context.buffer;
             if (buffer) {
                 // Reject PyTorch models with .pkl file extension.
-                let torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
+                const torch = [ 0x8a, 0x0a, 0x6c, 0xfc, 0x9c, 0x46, 0xf9, 0x20, 0x6a, 0xa8, 0x50, 0x19 ];
                 if (buffer.length > 14 && buffer[0] == 0x80 && torch.every((v, i) => v == buffer[i + 2])) {
                     return false;
                 }
@@ -34,9 +34,9 @@ sklearn.ModelFactory = class {
         return host.require('./pickle').then((pickle) => {
             let obj = null;
             let weights = null;
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             try {
-                let unpickler = new pickle.Unpickler(context.buffer);
+                const unpickler = new pickle.Unpickler(context.buffer);
 
                 let constructorTable = {};
                 let functionTable = {};
@@ -665,7 +665,7 @@ sklearn.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this.operator);
+        const schema = this._metadata.getSchema(this.operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -688,7 +688,7 @@ sklearn.Attribute = class {
         this._name = name;
         this._value = value;
 
-        let schema = metadata.getAttributeSchema(node.operator, this._name);
+        const schema = metadata.getAttributeSchema(node.operator, this._name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'option') && schema.option == 'optional' && this._value == null) {
                 this._visible = false;
@@ -923,7 +923,7 @@ sklearn.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push('[');
-            let items = value.map((item) => sklearn.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => sklearn.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -1007,7 +1007,7 @@ sklearn.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 7 - 7
src/tar.js

@@ -6,7 +6,7 @@ tar.Archive = class {
 
     constructor(buffer) {
         this._entries = [];
-        let reader = new tar.Reader(buffer, 0, buffer.length);
+        const reader = new tar.Reader(buffer, 0, buffer.length);
         while (reader.peek()) {
             this._entries.push(new tar.Entry(reader));
             if (reader.match(512, 0)) {
@@ -23,8 +23,8 @@ tar.Archive = class {
 tar.Entry = class {
 
     constructor(reader) {
-        let position = reader.position;
-        let header = reader.bytes(512);
+        const position = reader.position;
+        const header = reader.bytes(512);
         reader.position = position;
         let sum = 0;
         for (let i = 0; i < header.length; i++) {
@@ -34,9 +34,9 @@ tar.Entry = class {
         reader.string(8); // file mode
         reader.string(8); // owner
         reader.string(8); // group
-        let size = parseInt(reader.string(12).trim(), 8); // size
+        const size = parseInt(reader.string(12).trim(), 8); // size
         reader.string(12); // timestamp
-        let checksum = parseInt(reader.string(8).trim(), 8); // checksum
+        const checksum = parseInt(reader.string(8).trim(), 8); // checksum
         if (isNaN(checksum) || sum != checksum) {
             throw new tar.Error('Invalid tar archive.');
         }
@@ -90,13 +90,13 @@ tar.Reader = class {
         if (this._position + size > this._end) {
             throw new tar.Error('Data not available.');
         }
-        let data = this._buffer.subarray(this._position, this._position + size);
+        const data = this._buffer.subarray(this._position, this._position + size);
         this._position += size;
         return data;
     }
 
     string(size) {
-        let buffer = this.bytes(size);
+        const buffer = this.bytes(size);
         let position = 0;
         let str = '';
         for (let i = 0; i < size; i++) {

+ 38 - 35
src/tf.js

@@ -12,11 +12,10 @@ var marked = marked || require('marked');
 tf.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier;
-        let extension = identifier.split('.').pop().toLowerCase();
-        let tags = null;
+        const identifier = context.identifier;
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'meta') {
-            tags = context.tags('pb');
+            const tags = context.tags('pb');
             if (tags.size === 0) {
                 return false;
             }
@@ -27,15 +26,15 @@ tf.ModelFactory = class {
                 return false;
             }
             if (identifier == 'tfhub_module.pb') {
-                let buffer = context.buffer;
+                const buffer = context.buffer;
                 if (buffer && buffer.length == 2 && buffer[0] == 0x08 && buffer[1] == 0x03) {
                     return false;
                 }
             }
-            tags = context.tags('pb');
+            const tags = context.tags('pb');
             if (tags.size === 0) {
-                tags = context.tags('pbtxt');
-                if (tags.has('node') || tags.has('saved_model_schema_version') || tags.has('meta_graphs') || tags.has('graph_def')) {
+                const textTags = context.tags('pbtxt');
+                if (textTags.has('node') || textTags.has('saved_model_schema_version') || textTags.has('meta_graphs') || textTags.has('graph_def')) {
                     return true;
                 }
                 return false;
@@ -58,14 +57,14 @@ tf.ModelFactory = class {
                 identifier.endsWith('init_net.pbtxt') || identifier.endsWith('init_net.prototxt')) {
                 return false;
             }
-            tags = context.tags('pbtxt');
+            const tags = context.tags('pbtxt');
             if (tags.has('node') || tags.has('saved_model_schema_version') || tags.has('meta_graphs') || tags.has('graph_def')) {
                 return true;
             }
         }
         if (extension == 'json') {
             try {
-                let root = JSON.parse(context.text);
+                const root = JSON.parse(context.text);
                 if (root && root.format && root.format === 'graph-model' && root.modelTopology) {
                     return true;
                 }
@@ -85,10 +84,10 @@ tf.ModelFactory = class {
             let saved_model = null;
             let format = null;
             let producer = null;
-            let identifier = context.identifier; 
-            let extension = identifier.split('.').pop().toLowerCase();
+            const identifier = context.identifier; 
+            const extension = identifier.split('.').pop().toLowerCase();
             if (extension !== 'json') {
-                let tags = context.tags('pbtxt');
+                const tags = context.tags('pbtxt');
                 if (tags.has('node') || tags.has('saved_model_schema_version') || tags.has('meta_graphs') || tags.has('graph_def')) {
                     if (tags.has('saved_model_schema_version') || tags.has('meta_graphs')) {
                         try {
@@ -181,7 +180,7 @@ tf.ModelFactory = class {
             }
             else {
                 try {
-                    let root = JSON.parse(context.text);
+                    const root = JSON.parse(context.text);
                     graph_def = new tf.proto.GraphDef();
                     meta_graph = new tf.proto.MetaGraphDef();
                     meta_graph.graph_def = graph_def;
@@ -220,7 +219,7 @@ tf.Model = class {
         this._producer = producer || '';
         this._graphs = [];
         for (let i = 0; i < model.meta_graphs.length; i++) {
-            let metaGraph = model.meta_graphs[i];
+            const metaGraph = model.meta_graphs[i];
             let name = null;
             if (metaGraph.any_info) {
                 name = metaGraph.any_info.toString();
@@ -278,7 +277,7 @@ tf.Graph = class {
         this._functions = [];
 
         if (metaGraph.graph_def) {
-            let graph = metaGraph.graph_def;
+            const graph = metaGraph.graph_def;
             if (graph.versions) {
                 this._version = 'v' + graph.versions.producer.toString();
             }
@@ -291,12 +290,12 @@ tf.Graph = class {
             if (metaGraph.meta_info_def && metaGraph.meta_info_def.tags) {
                 this._tags = metaGraph.meta_info_def.tags.join(', ');
             }
-            let nodes = graph.node
+            const nodes = graph.node
             if (nodes) {
                 let nodeMap = {};
                 this._namespaces = {};
                 for (let node of nodes) {
-                    let nodeName = node.name;
+                    const nodeName = node.name;
                     nodeMap[nodeName] = node;
                     if (node.op != 'Const') {
                         let lastIndex = nodeName.lastIndexOf('/');
@@ -308,7 +307,7 @@ tf.Graph = class {
                     node.output = [];
                 }
                 for (let node of nodes) {
-                    let inputs = node.input;
+                    const inputs = node.input;
                     node.input = [];
                     node.controlDependencies = [];
                     for (let input of inputs) {
@@ -367,11 +366,11 @@ tf.Graph = class {
                 let inputMap = {};
                 for (let node of nodes) {
                     if (node.op == 'Placeholder' && node.input.length == 0 && node.controlDependencies.length == 0 && node.output.length == 1) {
-                        let dtype = node.attr.dtype;
-                        let shape = node.attr.shape;
+                        const dtype = node.attr.dtype;
+                        const shape = node.attr.shape;
                         if (dtype && dtype.type && shape && shape.shape) {
-                            let type = new tf.TensorType(dtype.type, shape.shape);
-                            let argument = new tf.Argument(node.output[0], type, null);
+                            const type = new tf.TensorType(dtype.type, shape.shape);
+                            const argument = new tf.Argument(node.output[0], type, null);
                             inputMap[node.output[0]] = new tf.Parameter(node.name, [ argument ]);
                         }
                     }
@@ -441,8 +440,8 @@ tf.Graph = class {
         if (node.output.length != 1) {
             return false;
         }
-        let output = node.output[0];
-        let count = this._nodeOutputCountMap[output];
+        const output = node.output[0];
+        const count = this._nodeOutputCountMap[output];
         if (count != 1) {
             return false;
         }
@@ -451,6 +450,7 @@ tf.Graph = class {
 };
 
 tf.Parameter = class {
+
     constructor(name, args) {
         this._name = name;
         this._arguments = args;
@@ -470,6 +470,7 @@ tf.Parameter = class {
 };
 
 tf.Argument = class {
+
     constructor(id, type, initializer) {
         this._id = id;
         this._type = type || null;
@@ -681,7 +682,7 @@ tf.Node = class {
         if (Object.prototype.hasOwnProperty.call(node, 'device')) {
             this._device = node.device;
         }
-        let metadata = graph.metadata;
+        const metadata = graph.metadata;
         this._attributes = [];
         if (node.attr) {
             for (let attributeName of Object.keys(node.attr)) {
@@ -689,7 +690,7 @@ tf.Node = class {
             }
         }
 
-        let schema = metadata.getSchema(node.op);
+        const schema = metadata.getSchema(node.op);
 
         this._inputs = [];
         let inputIndex = 0;
@@ -769,7 +770,7 @@ tf.Node = class {
     }
 
     get group() {
-        let name = this._name;
+        const name = this._name;
         if (this._graph.namespaces[name]) {
             return name;
         }
@@ -862,7 +863,7 @@ tf.Node = class {
     }
 
     get category() {
-        let schema = this._graph.metadata.getSchema(this.operator);
+        const schema = this._graph.metadata.getSchema(this.operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -884,11 +885,12 @@ tf.Node = class {
 };
 
 tf.Attribute = class {
+
     constructor(name, value, operator, metadata) {
         this._name = name;
         this._value = null;
         this._type = null;
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (Object.prototype.hasOwnProperty.call(value, 'tensor')) {
             this._type = 'tensor';
             this._value = new tf.Tensor(value.tensor);
@@ -977,7 +979,7 @@ tf.Attribute = class {
         if (name == '_class') {
             this._visible = false;
         }
-        let attributeVisibleMap = metadata.getAttributeVisibleMap(operator);
+        const attributeVisibleMap = metadata.getAttributeVisibleMap(operator);
         if (attributeVisibleMap[name]) {
             this._visible = false;
         }
@@ -1290,7 +1292,7 @@ tf.GraphMetadata = class {
     }
 
     getSchema(operator) {
-        let schema = this._metadata.getSchema(operator);
+        var schema = this._metadata.getSchema(operator);
         if (!schema) {
             schema = this._map[operator];
         }
@@ -1301,7 +1303,7 @@ tf.GraphMetadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;
@@ -1313,7 +1315,7 @@ tf.GraphMetadata = class {
     }
 
     getAttributeVisibleMap(operator) {
-        let schema = this.getSchema(operator);
+        const schema = this.getSchema(operator);
         if (schema) {
             let map = schema.__visisbleAttributeMap__;
             if (!map) {
@@ -1398,7 +1400,7 @@ tf.Metadata = class {
         this._map = {};
         if (data) {
             if (data) {
-                let items = JSON.parse(data);
+                const items = JSON.parse(data);
                 if (items) {
                     for (let item of items) {
                         if (item.name && item.schema) {
@@ -1416,6 +1418,7 @@ tf.Metadata = class {
 };
 
 tf.Error = class extends Error {
+
     constructor(message) {
         super(message);
         this.name = 'Error loading TensorFlow model.';

+ 10 - 10
src/tflite.js

@@ -9,13 +9,13 @@ var long = long || { Long: require('long') };
 tflite.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         if (extension == 'tflite' || extension == 'lite') {
             return true;
         }
         if (extension == 'tfl' || extension == 'bin') {
-            let buffer = context.buffer;
-            let signature = [ 0x54, 0x46, 0x4c, 0x33 ]; // TFL3
+            const buffer = context.buffer;
+            const signature = [ 0x54, 0x46, 0x4c, 0x33 ]; // TFL3
             if (buffer && buffer.length > 8 && signature.every((x, i) => x == buffer[i + 4])) {
                 return true;
             }
@@ -25,11 +25,11 @@ tflite.ModelFactory = class {
 
     open(context, host) {
         return host.require('./tflite-schema').then((tflite_schema) => {
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             let model = null;
             try {
-                let buffer = context.buffer;
-                let byteBuffer = new flatbuffers.ByteBuffer(buffer);
+                const buffer = context.buffer;
+                const byteBuffer = new flatbuffers.ByteBuffer(buffer);
                 tflite.schema = tflite_schema;
                 if (!tflite.schema.Model.bufferHasIdentifier(byteBuffer)) {
                     let signature = Array.from(buffer.subarray(0, Math.min(8, buffer.length))).map((c) => (c < 16 ? '0' : '') + c.toString(16)).join('');
@@ -305,7 +305,7 @@ tflite.Node = class {
         if (this._operator.custom) {
             return 'custom';
         }
-        let schema = this._metadata.getSchema(this.operator);
+        const schema = this._metadata.getSchema(this.operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -348,12 +348,12 @@ tflite.Attribute = class {
         this._type = null;
         this._value = value;
         this._name = '';
-        let lower = name.toLowerCase();
+        const lower = name.toLowerCase();
         for (let i = 0; i < name.length; i++) {
             this._name += (name[i] == lower[i]) ? name[i] : ('_' + lower[i]);
         }
 
-        let schema = metadata.getAttributeSchema(operator, this._name);
+        const schema = metadata.getAttributeSchema(operator, this._name);
         if (schema) {
             if (schema.type) {
                 this._type = schema.type;
@@ -720,7 +720,7 @@ tflite.Metadata = class {
     }
 
     getAttributeSchema(operator, name) {
-        let schema = this.getSchema(operator);
+        const schema = this.getSchema(operator);
         if (schema) {
             let attributeMap = schema.attributeMap;
             if (!attributeMap) {

+ 7 - 6
src/torch.js

@@ -8,9 +8,9 @@ var long = long || { Long: require('long') };
 torch.ModelFactory = class {
 
     match(context) {
-        let extension = context.identifier.split('.').pop().toLowerCase();
+        const extension = context.identifier.split('.').pop().toLowerCase();
         if (extension == 't7') {
-            let buffer = context.buffer;
+            const buffer = context.buffer;
             if (buffer.length >= 1 && buffer[0] > 58) {
                 return false;
             }
@@ -21,7 +21,7 @@ torch.ModelFactory = class {
 
     open(context, host) {
         return torch.Metadata.open(host).then((metadata) => {
-            let identifier = context.identifier;
+            const identifier = context.identifier;
             try {
                 let reader = new torch.T7Reader(context.buffer, (name) => {
                     if (name && name != 'nn.JointTrainModule' && !name.startsWith('nn.MSDNet_') && !name.startsWith('onmt.')) {
@@ -402,7 +402,7 @@ torch.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -453,7 +453,7 @@ torch.Attribute = class {
         if (name == 'train') {
             this._visible = false;
         }
-        let schema = metadata.getAttributeSchema(operator, name);
+        const schema = metadata.getAttributeSchema(operator, name);
         if (schema) {
             if (Object.prototype.hasOwnProperty.call(schema, 'visible')) {
                 this._visible = schema.visible;
@@ -652,7 +652,7 @@ torch.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;
@@ -665,6 +665,7 @@ torch.Metadata = class {
 };
 
 torch.Error = class extends Error {
+
     constructor(message) {
         super(message);
         this.name = 'Error loading Torch model.';

+ 21 - 21
src/torchscript.js

@@ -12,8 +12,8 @@ var zip = zip || require('./zip');
 torchscript.ModelFactory = class {
 
     match(context) {
-        let identifier = context.identifier; 
-        let extension = identifier.split('.').pop().toLowerCase();
+        const identifier = context.identifier; 
+        const extension = identifier.split('.').pop().toLowerCase();
         if (extension == 'pt' || extension == 'pth' || extension == 'pkl' || extension == 'h5' || extension == 't7' ||
             extension == 'dms' || extension == 'model' || extension == 'ckpt' || identifier.endsWith('.pth.tar')) {
             if (torchscript.ModelFactory._openContainer(context.entries)) {
@@ -26,7 +26,7 @@ torchscript.ModelFactory = class {
     open(context, host) {
         return host.require('./python').then((python) => {
             return host.require('./pickle').then((pickle) => {
-                let identifier = context.identifier;
+                const identifier = context.identifier;
                 try {
                     let container = torchscript.ModelFactory._openContainer(context.entries);
                     container.identifier = identifier;
@@ -34,7 +34,7 @@ torchscript.ModelFactory = class {
                     container.constants = (container.constants || []).map((tensor) => new torchscript.Tensor('pickle', tensor));
                     container.data = torchscript.ModelFactory._unpickle(host, identifier, pickle, container.data, torchscript.ModelFactory._storage(container, 'data'));
                     container.attributes = torchscript.ModelFactory._unpickle(host, identifier, pickle, container.attributes, null);
-                    let textDecoder = new TextDecoder('utf-8');
+                    const textDecoder = new TextDecoder('utf-8');
                     if (container.version) {
                         container.version = JSON.parse(textDecoder.decode(container.version));
                     }
@@ -65,8 +65,8 @@ torchscript.ModelFactory = class {
 
     static _openContainer(entries) {
         if (entries && entries.length > 0) {
-            let container = { };
-            let version = entries.find((entry) => entry.name == 'version' || entry.name.endsWith('/version'));
+            let container = {};
+            const version = entries.find((entry) => entry.name == 'version' || entry.name.endsWith('/version'));
             if (version) {
                 container.entries = entries;
                 container.prefix = version.name.substring(0, version.name.length - 7);
@@ -90,10 +90,10 @@ torchscript.ModelFactory = class {
 
     static _storage(container, dirname) {
         let map = new Map();
-        let prefix = container.prefix + dirname + '/';
+        const prefix = container.prefix + dirname + '/';
         for (let entry of container.entries) {
             if (entry.name.startsWith(prefix)) {
-                let key = entry.name.substring(prefix.length);
+                const key = entry.name.substring(prefix.length);
                 map.set(key, entry.data);
             }
         }
@@ -169,15 +169,15 @@ torchscript.ModelFactory = class {
             return obj;
         };
         let deserialized_objects = new Map();
-        let persistent_load = (saved_id) => {
-            let typename = saved_id.shift();
+        const persistent_load = (saved_id) => {
+            const typename = saved_id.shift();
             if (typename !== 'storage') {
                 throw new torchscript.Error("Unknown persistent load type '" + typename + "'.");
             }
-            let data_type = saved_id.shift();
-            let root_key = saved_id.shift();
+            const data_type = saved_id.shift();
+            const root_key = saved_id.shift();
             saved_id.shift(); // location
-            let size = saved_id.shift();
+            const size = saved_id.shift();
             let storage = null;
             if (deserialized_objects.has(root_key)) {
                 storage = deserialized_objects.get(root_key);
@@ -187,7 +187,7 @@ torchscript.ModelFactory = class {
                 storage.data = storage_map.get(root_key);
                 deserialized_objects[root_key] = storage;
             }
-            let view_metadata = saved_id.shift();
+            const view_metadata = saved_id.shift();
             if (view_metadata) {
                 let view_key = view_metadata.shift();
                 view_metadata.shift(); // view_offset
@@ -218,8 +218,8 @@ torchscript.Model = class {
             }
             if (container.model.tensors) {
                 container.tensors = container.model.tensors.map((tensor) => {
-                    let key = container.prefix + tensor.data.key;
-                    let entry = container.entries.find((entry) => entry.name == key);
+                    const key = container.prefix + tensor.data.key;
+                    const entry = container.entries.find((entry) => entry.name == key);
                     return new torchscript.Tensor('json', { tensor: tensor, data: entry.data });
                 });
                 container.constants = container.tensors;
@@ -263,7 +263,7 @@ torchscript.Graph = class {
             }
             else if (container.data) {
                 mainModule = container.data;
-                let typeName = mainModule.__type__.split('.');
+                const typeName = mainModule.__type__.split('.');
                 className = typeName.pop();
                 script = 'code/' + typeName.join('/') + '.py';
             }
@@ -550,7 +550,7 @@ torchscript.Node = class {
             this._operator = node.name;
             this._name = '';
 
-            let schema = metadata.getSchema(this._operator);
+            const schema = metadata.getSchema(this._operator);
 
             module = null; 
             let match = true;
@@ -660,7 +660,7 @@ torchscript.Node = class {
     }
 
     get category() {
-        let schema = this._metadata.getSchema(this._operator);
+        const schema = this._metadata.getSchema(this._operator);
         return (schema && schema.category) ? schema.category : '';
     }
 
@@ -971,7 +971,7 @@ torchscript.Tensor = class {
         if (Array.isArray(value)) {
             let result = [];
             result.push(indentation + '[');
-            let items = value.map((item) => torchscript.Tensor._stringify(item, indentation + indent, indent));
+            const items = value.map((item) => torchscript.Tensor._stringify(item, indentation + indent, indent));
             if (items.length > 0) {
                 result.push(items.join(',\n'));
             }
@@ -1075,7 +1075,7 @@ torchscript.Metadata = class {
         let map = this._attributeCache[operator];
         if (!map) {
             map = {};
-            let schema = this.getSchema(operator);
+            const schema = this.getSchema(operator);
             if (schema && schema.attributes && schema.attributes.length > 0) {
                 for (let attribute of schema.attributes) {
                     map[attribute.name] = attribute;

+ 23 - 23
src/view.js

@@ -855,30 +855,30 @@ view.View = class {
             extension = file.substring(lastIndex + 1);
         }
         if (this._activeGraph && (extension == 'png' || extension == 'svg')) {
-            let graphElement = this._host.document.getElementById('graph');
-            let exportElement = graphElement.cloneNode(true);
+            const graphElement = this._host.document.getElementById('graph');
+            const exportElement = graphElement.cloneNode(true);
             this.applyStyleSheet(exportElement, 'view-grapher.css');
             exportElement.setAttribute('id', 'export');
             exportElement.removeAttribute('width');
             exportElement.removeAttribute('height');
             exportElement.style.removeProperty('opacity');
             exportElement.style.removeProperty('display');
-            let backgroundElement = exportElement.querySelector('#background');
-            let originElement = exportElement.querySelector('#origin');
+            const backgroundElement = exportElement.querySelector('#background');
+            const originElement = exportElement.querySelector('#origin');
             originElement.setAttribute('transform', 'translate(0,0) scale(1)');
             backgroundElement.removeAttribute('width');
             backgroundElement.removeAttribute('height');
 
-            let parentElement = graphElement.parentElement;
+            const parentElement = graphElement.parentElement;
             parentElement.insertBefore(exportElement, graphElement);
-            let size = exportElement.getBBox();
+            const size = exportElement.getBBox();
             parentElement.removeChild(exportElement);
             parentElement.removeChild(graphElement);
             parentElement.appendChild(graphElement);
 
-            let delta = (Math.min(size.width, size.height) / 2.0) * 0.1;
-            let width = Math.ceil(delta + size.width + delta);
-            let height = Math.ceil(delta + size.height + delta);
+            const delta = (Math.min(size.width, size.height) / 2.0) * 0.1;
+            const width = Math.ceil(delta + size.width + delta);
+            const height = Math.ceil(delta + size.height + delta);
             originElement.setAttribute('transform', 'translate(' + delta.toString() + ', ' + delta.toString() + ') scale(1)');
             exportElement.setAttribute('width', width);
             exportElement.setAttribute('height', height);
@@ -886,22 +886,22 @@ view.View = class {
             backgroundElement.setAttribute('height', height);
             backgroundElement.setAttribute('fill', '#fff');
     
-            let data = new XMLSerializer().serializeToString(exportElement);
+            const data = new XMLSerializer().serializeToString(exportElement);
     
             if (extension == 'svg') {
-                let blob = new Blob([ data ], { type: 'image/svg' });
+                const blob = new Blob([ data ], { type: 'image/svg' });
                 this._host.export(file, blob);
             }
     
             if (extension == 'png') {
-                let imageElement = new Image();
+                const imageElement = new Image();
                 imageElement.onload = () => {
-                    let max = Math.max(width, height);
-                    let scale = ((max * 2.0) > 24000) ? (24000.0 / max) : 2.0;
-                    let canvas = this._host.document.createElement('canvas');
+                    const max = Math.max(width, height);
+                    const scale = ((max * 2.0) > 24000) ? (24000.0 / max) : 2.0;
+                    const canvas = this._host.document.createElement('canvas');
                     canvas.width = Math.ceil(width * scale);
                     canvas.height = Math.ceil(height * scale);
-                    let context = canvas.getContext('2d');
+                    const context = canvas.getContext('2d');
                     context.scale(scale, scale);
                     context.drawImage(imageElement, 0, 0);
                     this._host.document.body.removeChild(imageElement);
@@ -910,7 +910,7 @@ view.View = class {
                             this._host.export(file, blob);
                         }
                         else {
-                            let err = new Error();
+                            const err = new Error();
                             err.name = 'Error exporting image.';
                             err.message = 'Image may be too large to render as PNG.';
                             this._host.exception(err, false);
@@ -926,7 +926,7 @@ view.View = class {
 
     showModelProperties() {
         if (this._model) {
-            let modelSidebar = new sidebar.ModelSidebar(this._host, this._model, this._activeGraph);
+            const modelSidebar = new sidebar.ModelSidebar(this._host, this._model, this._activeGraph);
             modelSidebar.on('update-active-graph', (sender, name) => {
                 this._updateActiveGraph(name);
             });
@@ -936,17 +936,17 @@ view.View = class {
     
     showNodeProperties(node, input) {
         if (node) {
-            let nodeSidebar = new sidebar.NodeSidebar(this._host, node);
+            const nodeSidebar = new sidebar.NodeSidebar(this._host, node);
             nodeSidebar.on('show-documentation', (/* sender, e */) => {
                 this.showOperatorDocumentation(node);
             });
             nodeSidebar.on('export-tensor', (sender, tensor) => {
                 this._host.require('./numpy').then((numpy) => {
-                    let defaultPath = tensor.name ? tensor.name.split('/').join('_').split(':').join('_').split('.').join('_') : 'tensor';
+                    const defaultPath = tensor.name ? tensor.name.split('/').join('_').split(':').join('_').split('.').join('_') : 'tensor';
                     this._host.save('NumPy Array', 'npy', defaultPath, (file) => {
                         try {
-                            let array = new numpy.Array(tensor.value, tensor.type.dataType, tensor.type.shape.dimensions);
-                            let blob = new Blob([ array.toBuffer() ], { type: 'application/octet-stream' });
+                            const array = new numpy.Array(tensor.value, tensor.type.dataType, tensor.type.shape.dimensions);
+                            const blob = new Blob([ array.toBuffer() ], { type: 'application/octet-stream' });
                             this._host.export(file, blob);
                         }
                         catch (error) {
@@ -966,7 +966,7 @@ view.View = class {
     showOperatorDocumentation(node) {
         let documentation = node.documentation;
         if (documentation) {
-            let documentationSidebar = new sidebar.OperatorDocumentationSidebar(documentation);
+            const documentationSidebar = new sidebar.OperatorDocumentationSidebar(documentation);
             documentationSidebar.on('navigate', (sender, e) => {
                 this._host.openURL(e.link);
             });

+ 67 - 72
test/test.js

@@ -37,10 +37,10 @@ global.TextDecoder = class {
             return String.fromCharCode.apply(null, data);
         }
 
-        var buffer = [];
-        var start = 0;
+        let buffer = [];
+        let start = 0;
         do {
-            var end = start + 32;
+            let end = start + 32;
             if (end > data.length) {
                 end = data.length;
             }
@@ -52,10 +52,9 @@ global.TextDecoder = class {
     }
 };
 
-var type = process.argv.length > 2 ? process.argv[2] : null;
-
-var items = JSON.parse(fs.readFileSync(__dirname + '/models.json', 'utf-8'));
-var dataFolder = __dirname + '/data';
+const type = process.argv.length > 2 ? process.argv[2] : null;
+const dataFolder = __dirname + '/data';
+let items = JSON.parse(fs.readFileSync(__dirname + '/models.json', 'utf-8'));
 
 class TestHost {
 
@@ -82,7 +81,7 @@ class TestHost {
 
     require(id) {
         try {
-            var file = path.join(path.join(__dirname, '../src'), id + '.js');
+            const file = path.join(path.join(__dirname, '../src'), id + '.js');
             return Promise.resolve(require(file));
         }
         catch (error) {
@@ -91,7 +90,7 @@ class TestHost {
     }
 
     request(base, file, encoding) {
-        var pathname = path.join(base || path.join(__dirname, '../src'), file);
+        const pathname = path.join(base || path.join(__dirname, '../src'), file);
         if (!fs.existsSync(pathname)) {
             return Promise.reject(new Error("File not found '" + file + "'."));
         }
@@ -113,7 +112,7 @@ class TestHost {
 
     _raise(event, data) {
         if (this._events && this._events[event]) {
-            for (var callback of this._events[event]) {
+            for (let callback of this._events[event]) {
                 callback(this, data);
             }
         }
@@ -159,7 +158,7 @@ class HTMLDocument {
     }
 
     getElementById(id) {
-        var element = this._elements[id];
+        let element = this._elements[id];
         if (!element) {
             element = new HTMLHtmlElement();
             this._elements[id] = element;
@@ -232,12 +231,12 @@ function makeDir(dir) {
 }
 
 function decompress(buffer, identifier) {
-    var archive = null;
-    var extension = identifier.split('.').pop().toLowerCase();
+    let archive = null;
+    const extension = identifier.split('.').pop().toLowerCase();
     if (extension == 'gz' || extension == 'tgz') {
         archive = new gzip.Archive(buffer);
         if (archive.entries.length == 1) {
-            var entry = archive.entries[0];
+            const entry = archive.entries[0];
             if (entry.name) {
                 identifier = entry.name;
             }
@@ -263,8 +262,8 @@ function decompress(buffer, identifier) {
 }
 
 function request(location, cookie) {
-    var options = { rejectUnauthorized: false };
-    var httpRequest = null;
+    const options = { rejectUnauthorized: false };
+    let httpRequest = null;
     switch (url.parse(location).protocol) {
         case 'http:': 
             httpRequest = http.request(location, options);
@@ -288,15 +287,15 @@ function request(location, cookie) {
 }
 
 function downloadFile(location, cookie) {
-    var data = [];
-    var position = 0;
+    let data = [];
+    let position = 0;
     return request(location, cookie).then((response) => {
         if (response.statusCode == 200 &&
             url.parse(location).hostname == 'drive.google.com' && 
             response.headers['set-cookie'].some((cookie) => cookie.startsWith('download_warning_'))) {
             cookie = response.headers['set-cookie'];
-            var download = cookie.filter((cookie) => cookie.startsWith('download_warning_')).shift();
-            var confirm = download.split(';').shift().split('=').pop();
+            const download = cookie.filter((cookie) => cookie.startsWith('download_warning_')).shift();
+            const confirm = download.split(';').shift().split('=').pop();
             location = location + '&confirm=' + confirm;
             return downloadFile(location, cookie);
         }
@@ -310,11 +309,11 @@ function downloadFile(location, cookie) {
             throw new Error(response.statusCode.toString() + ' ' + location);
         }
         return new Promise((resolve, reject) => {
-            var length = response.headers['content-length'] ? Number(response.headers['content-length']) : -1;
+            const length = response.headers['content-length'] ? Number(response.headers['content-length']) : -1;
             response.on('data', (chunk) => {
                 position += chunk.length;
                 if (length >= 0) {
-                    var label = location.length > 70 ? location.substring(0, 66) + '...' : location; 
+                    const label = location.length > 70 ? location.substring(0, 66) + '...' : location; 
                     process.stdout.write('  (' + ('  ' + Math.floor(100 * (position / length))).slice(-3) + '%) ' + label + '\r');
                 }
                 else {
@@ -339,10 +338,10 @@ function download(folder, targets, sources) {
     if (!sources) {
         return Promise.reject(new Error('Download source not specified.'));
     }
-    var source = '';
-    var sourceFiles = [];
-    var startIndex = sources.indexOf('[');
-    var endIndex = sources.indexOf(']');
+    let source = '';
+    let sourceFiles = [];
+    const startIndex = sources.indexOf('[');
+    const endIndex = sources.indexOf(']');
     if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) {
         sourceFiles = sources.substring(startIndex + 1, endIndex).split(',').map((sourceFile) => sourceFile.trim());
         source = sources.substring(0, startIndex);
@@ -352,7 +351,7 @@ function download(folder, targets, sources) {
         }
     }
     else {
-        var commaIndex = sources.indexOf(',');
+        const commaIndex = sources.indexOf(',');
         if (commaIndex != -1) {
             source = sources.substring(0, commaIndex);
             sources = sources.substring(commaIndex + 1);
@@ -362,8 +361,7 @@ function download(folder, targets, sources) {
             sources = '';
         }
     }
-    var target;
-    for (target of targets) {
+    for (let target of targets) {
         makeDir(path.dirname(folder + '/' + target));
     }
     return downloadFile(source).then((data) => {
@@ -372,22 +370,22 @@ function download(folder, targets, sources) {
                 process.stdout.clearLine();
             }
             process.stdout.write('  decompress...\r');
-            var archive = decompress(data, source.split('?').shift().split('/').pop());
-            for (var file of sourceFiles) {
+            const archive = decompress(data, source.split('?').shift().split('/').pop());
+            for (let file of sourceFiles) {
                 if (process.stdout.clearLine) {
                     process.stdout.clearLine();
                 }
                 process.stdout.write('  write ' + file + '\n');
-                var entry = archive.entries.filter((entry) => entry.name == file)[0];
+                const entry = archive.entries.filter((entry) => entry.name == file)[0];
                 if (!entry) {
                     throw new Error("Entry not found '" + file + '. Archive contains entries: ' + JSON.stringify(archive.entries.map((entry) => entry.name)) + " .");
                 }
-                var target = targets.shift();
+                const target = targets.shift();
                 fs.writeFileSync(folder + '/' + target, entry.data, null);
             }
         }
         else {
-            target = targets.shift();
+            const target = targets.shift();
             if (process.stdout.clearLine) {
                 process.stdout.clearLine();
             }
@@ -421,21 +419,21 @@ function script(folder, targets, command, args) {
 }
 
 function loadModel(target, item) {
-    var host = new TestHost();
-    var exceptions = [];
+    const host = new TestHost();
+    let exceptions = [];
     host.on('exception', (_, data) => {
         exceptions.push(data.exception);
     });
-    var folder = path.dirname(target);
-    var identifier = path.basename(target);
-    var size = fs.statSync(target).size;
-    var buffer = new Uint8Array(size);
-    var fd = fs.openSync(target, 'r');
+    const folder = path.dirname(target);
+    const identifier = path.basename(target);
+    const size = fs.statSync(target).size;
+    const buffer = new Uint8Array(size);
+    const fd = fs.openSync(target, 'r');
     fs.readSync(fd, buffer, 0, size, 0);
     fs.closeSync(fd);
-    var context = new TestContext(host, folder, identifier, buffer);
-    var modelFactoryService = new view.ModelFactoryService(host);
-    var opened = false;
+    const context = new TestContext(host, folder, identifier, buffer);
+    const modelFactoryService = new view.ModelFactoryService(host);
+    let opened = false;
     return modelFactoryService.open(context).then((model) => {
         if (opened) {
             throw new Error("Model opened more than once '" + target + "'.");
@@ -454,13 +452,11 @@ function loadModel(target, item) {
         model.description;
         model.author;
         model.license;
-        for (var graph of model.graphs) {
-            var input;
-            var argument;
-            for (input of graph.inputs) {
+        for (let graph of model.graphs) {
+            for (let input of graph.inputs) {
                 input.name.toString();
                 input.name.length;
-                for (argument of input.arguments) {
+                for (let argument of input.arguments) {
                     argument.id.toString();
                     argument.id.length;
                     if (argument.type) {
@@ -468,11 +464,10 @@ function loadModel(target, item) {
                     }
                 }
             }
-            var output;
-            for (output of graph.outputs) {
+            for (let output of graph.outputs) {
                 output.name.toString();
                 output.name.length;
-                for (argument of output.arguments) {
+                for (let argument of output.arguments) {
                     argument.id.toString();
                     argument.id.length;
                     if (argument.type) {
@@ -480,25 +475,25 @@ function loadModel(target, item) {
                     }
                 }
             }
-            for (var node of graph.nodes) {
+            for (let node of graph.nodes) {
                 node.name.toString();
                 node.name.length;
                 node.description;
                 node.documentation.toString();
                 node.category.toString();
-                for (var attribute of node.attributes) {
+                for (let attribute of node.attributes) {
                     attribute.name.toString();
                     attribute.name.length;
-                    var value = sidebar.NodeSidebar.formatAttributeValue(attribute.value, attribute.type)
+                    let value = sidebar.NodeSidebar.formatAttributeValue(attribute.value, attribute.type)
                     if (value && value.length > 1000) {
                         value = value.substring(0, 1000) + '...';
                     }
                     value = value.split('<');
                 }
-                for (input of node.inputs) {
+                for (let input of node.inputs) {
                     input.name.toString();
                     input.name.length;
-                    for (argument of input.arguments) {
+                    for (let argument of input.arguments) {
                         argument.id.toString();
                         argument.id.length;
                         argument.description;
@@ -511,10 +506,10 @@ function loadModel(target, item) {
                         }
                     }
                 }
-                for (output of node.outputs) {
+                for (let output of node.outputs) {
                     output.name.toString();
                     output.name.length;
-                    for (argument of output.arguments) {
+                    for (let argument of output.arguments) {
                         argument.id.toString();
                         argument.id.length;
                         if (argument.type) {
@@ -523,7 +518,7 @@ function loadModel(target, item) {
                     }
                 }
                 if (node.chain) {
-                    for (var chain of node.chain) {
+                    for (let chain of node.chain) {
                         chain.name.toString();
                         chain.name.length;
                     }
@@ -539,8 +534,8 @@ function loadModel(target, item) {
 
 function render(model) {
     try {
-        var host = new TestHost();
-        var currentView = new view.View(host);
+        const host = new TestHost();
+        const currentView = new view.View(host);
         if (!currentView.showAttributes) {
             currentView.toggleAttributes();
         }
@@ -558,7 +553,7 @@ function next() {
     if (items.length == 0) {
         return;
     }
-    var item = items.shift();
+    const item = items.shift();
     if (!item.type) {
         console.error("Property 'type' is required for item '" + JSON.stringify(item) + "'.");
         return;
@@ -570,25 +565,25 @@ function next() {
     if (process.stdout.clearLine) {
         process.stdout.clearLine();
     }
-    var targets = item.target.split(',');
-    var target = targets[0];
-    var folder = dataFolder + '/' + item.type;
+    const targets = item.target.split(',');
+    const target = targets[0];
+    const folder = dataFolder + '/' + item.type;
     process.stdout.write(item.type + '/' + target + '\n');
 
-    var promise = null;
+    let promise = null;
     if (item.script) {
-        var root = path.dirname(__dirname);
-        var command = item.script[0].replace('${root}', root);
-        var args = item.script[1].replace('${root}', root);
+        const root = path.dirname(__dirname);
+        const command = item.script[0].replace('${root}', root);
+        const args = item.script[1].replace('${root}', root);
         promise = script(folder, targets, command, args);
     }
     else {
-        var sources = item.source;
+        const sources = item.source;
         promise = download(folder, targets, sources);
     }
     return promise.then(() => {
         return loadModel(folder + '/' + target, item).then((model) => {
-            var promise = null;
+            let promise = null;
             if (item.render == 'skip') {
                 promise = Promise.resolve();
             }